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:
Starbeamrainbowlabs 2018-09-21 23:36:03 +01:00
parent 2a5a50458f
commit 2c2575998a
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
3 changed files with 45 additions and 3 deletions

View file

@ -97,9 +97,10 @@ namespace SearchBoxCLI
case OperatingModes.Index: return HandleIndex();
case OperatingModes.Add: return HandleAdd();
case OperatingModes.Remove: return HandleRemove();
case OperatingModes.Query: return HandleQuery();
}
return 0;
return 128;
}
private static int HandleHelp()
@ -210,6 +211,20 @@ namespace SearchBoxCLI
return 0;
}
private static int HandleQuery()
{
switch (OutputMode)
{
case OutputModes.Json:
break;
case OutputModes.Text:
break;
}
return 0;
}
private static int HandleIndex()
{
Index index = new Index(Source.ReadToEnd());

View file

@ -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());

View file

@ -1,16 +1,35 @@
using System;
using System.Collections.Generic;
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 string PageName { 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;
Rank = inRank;
Offsets = inOffsets;
}
}
}