From 2c2575998a85d6c6b11e05fe050203d5f38e640c Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Fri, 21 Sep 2018 23:36:03 +0100 Subject: [PATCH] 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. --- SearchBox-CLI/Program.cs | 17 ++++++++++++++++- SearchBox/SearchBox.cs | 10 +++++++++- SearchBox/SearchResult.cs | 21 ++++++++++++++++++++- 3 files changed, 45 insertions(+), 3 deletions(-) diff --git a/SearchBox-CLI/Program.cs b/SearchBox-CLI/Program.cs index 7e2db00..3778707 100644 --- a/SearchBox-CLI/Program.cs +++ b/SearchBox-CLI/Program.cs @@ -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()); diff --git a/SearchBox/SearchBox.cs b/SearchBox/SearchBox.cs index 2788436..624a01a 100644 --- a/SearchBox/SearchBox.cs +++ b/SearchBox/SearchBox.cs @@ -111,7 +111,15 @@ namespace LibSearchBox } } - resultsRaw.Add(new SearchResult(idMap.GetPageName(pageDef.Key), rank)); + List offsets = new List(); + foreach (Tuple 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 results = new List(resultsRaw.AsEnumerable()); diff --git a/SearchBox/SearchResult.cs b/SearchBox/SearchResult.cs index e73ea9e..7655339 100644 --- a/SearchBox/SearchResult.cs +++ b/SearchBox/SearchResult.cs @@ -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 Offsets { get; private set; } + + public SearchResult(string inPageName, float inRank, List inOffsets) { PageName = inPageName; Rank = inRank; + + Offsets = inOffsets; } + + } }