Browse Source

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.
master
Starbeamrainbowlabs 4 years ago
parent
commit
2c2575998a
Signed by: sbrl
GPG Key ID: 1BE5172E637709C2
  1. 17
      SearchBox-CLI/Program.cs
  2. 10
      SearchBox/SearchBox.cs
  3. 21
      SearchBox/SearchResult.cs

17
SearchBox-CLI/Program.cs

@ -97,9 +97,10 @@ namespace SearchBoxCLI @@ -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 @@ -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());

10
SearchBox/SearchBox.cs

@ -111,7 +111,15 @@ namespace LibSearchBox @@ -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());

21
SearchBox/SearchResult.cs

@ -1,16 +1,35 @@ @@ -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;
}
}
}

Loading…
Cancel
Save