Fix crash in search context generator
This commit is contained in:
parent
feaa5fc2de
commit
64025561e3
1 changed files with 4 additions and 3 deletions
|
@ -171,7 +171,8 @@ namespace LibSearchBox
|
|||
foreach ((int, string) token in tokenizer.IterateTokens())
|
||||
{
|
||||
ConcurrentDictionary<int, List<int>> tokenQuery = index.Query(token.Item2);
|
||||
if (!tokenQuery.ContainsKey(pageId)) continue; // Don't bother if this page doesn't contain this token
|
||||
if (tokenQuery == null || !tokenQuery.ContainsKey(pageId))
|
||||
continue; // Don't bother if this page doesn't contain this token
|
||||
offsets.AddRange(tokenQuery[pageId].Select((int offset) => new SearchOffset(token.Item2, offset)));
|
||||
}
|
||||
offsets.Sort((SearchOffset x, SearchOffset y) => x.Offset - y.Offset);
|
||||
|
@ -246,9 +247,9 @@ namespace LibSearchBox
|
|||
);
|
||||
|
||||
// Add the separator at the beginning and end if we aren't at the bounds of the source document
|
||||
if (snippets.First().Item1 > 0)
|
||||
if (snippets.Count > 0 && snippets.First().Item1 > 0)
|
||||
snippetsText.Insert(0, "");
|
||||
if (snippets.Last().Item2 < source.Length)
|
||||
if (snippets.Count > 0 && snippets.Last().Item2 < source.Length)
|
||||
snippetsText.Add("");
|
||||
|
||||
return string.Join(
|
||||
|
|
Loading…
Reference in a new issue