Work on hooking the new query system up to the CLI.
Also add a new SearchOffset struct so that SearchResult can contain offset information for context generation.
This commit is contained in:
parent
2a5a50458f
commit
2c2575998a
3 changed files with 45 additions and 3 deletions
|
@ -97,9 +97,10 @@ namespace SearchBoxCLI
|
||||||
case OperatingModes.Index: return HandleIndex();
|
case OperatingModes.Index: return HandleIndex();
|
||||||
case OperatingModes.Add: return HandleAdd();
|
case OperatingModes.Add: return HandleAdd();
|
||||||
case OperatingModes.Remove: return HandleRemove();
|
case OperatingModes.Remove: return HandleRemove();
|
||||||
|
case OperatingModes.Query: return HandleQuery();
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 128;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int HandleHelp()
|
private static int HandleHelp()
|
||||||
|
@ -210,6 +211,20 @@ namespace SearchBoxCLI
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static int HandleQuery()
|
||||||
|
{
|
||||||
|
switch (OutputMode)
|
||||||
|
{
|
||||||
|
case OutputModes.Json:
|
||||||
|
|
||||||
|
break;
|
||||||
|
case OutputModes.Text:
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
private static int HandleIndex()
|
private static int HandleIndex()
|
||||||
{
|
{
|
||||||
Index index = new Index(Source.ReadToEnd());
|
Index index = new Index(Source.ReadToEnd());
|
||||||
|
|
|
@ -111,7 +111,15 @@ namespace LibSearchBox
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resultsRaw.Add(new SearchResult(idMap.GetPageName(pageDef.Key), rank));
|
List<SearchOffset> offsets = new List<SearchOffset>();
|
||||||
|
foreach (Tuple<int, string> token in tokenizer.IterateTokens())
|
||||||
|
offsets.AddRange(index.Query(token.Item2)[pageDef.Key].Select((int offset) => new SearchOffset(token.Item2, offset)));
|
||||||
|
|
||||||
|
resultsRaw.Add(new SearchResult(
|
||||||
|
idMap.GetPageName(pageDef.Key),
|
||||||
|
rank,
|
||||||
|
offsets
|
||||||
|
));
|
||||||
});
|
});
|
||||||
|
|
||||||
List<SearchResult> results = new List<SearchResult>(resultsRaw.AsEnumerable());
|
List<SearchResult> results = new List<SearchResult>(resultsRaw.AsEnumerable());
|
||||||
|
|
|
@ -1,16 +1,35 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace LibSearchBox
|
namespace LibSearchBox
|
||||||
{
|
{
|
||||||
|
public struct SearchOffset
|
||||||
|
{
|
||||||
|
public string Term;
|
||||||
|
public int Offset;
|
||||||
|
|
||||||
|
public SearchOffset(string inTerm, int inOffset)
|
||||||
|
{
|
||||||
|
Term = inTerm;
|
||||||
|
Offset = inOffset;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public class SearchResult
|
public class SearchResult
|
||||||
{
|
{
|
||||||
public string PageName { get; private set; }
|
public string PageName { get; private set; }
|
||||||
public float Rank { get; private set; }
|
public float Rank { get; private set; }
|
||||||
|
|
||||||
public SearchResult(string inPageName, float inRank)
|
public List<SearchOffset> Offsets { get; private set; }
|
||||||
|
|
||||||
|
public SearchResult(string inPageName, float inRank, List<SearchOffset> inOffsets)
|
||||||
{
|
{
|
||||||
PageName = inPageName;
|
PageName = inPageName;
|
||||||
Rank = inRank;
|
Rank = inRank;
|
||||||
}
|
|
||||||
|
Offsets = inOffsets;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue