Compare commits
2 Commits
3d4ca5fd4c
...
64025561e3
Author | SHA1 | Date |
---|---|---|
Starbeamrainbowlabs | 64025561e3 | |
Starbeamrainbowlabs | feaa5fc2de |
|
@ -3,6 +3,7 @@ using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using UnidecodeSharpFork;
|
using UnidecodeSharpFork;
|
||||||
|
@ -170,7 +171,8 @@ namespace LibSearchBox
|
||||||
foreach ((int, string) token in tokenizer.IterateTokens())
|
foreach ((int, string) token in tokenizer.IterateTokens())
|
||||||
{
|
{
|
||||||
ConcurrentDictionary<int, List<int>> tokenQuery = index.Query(token.Item2);
|
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.AddRange(tokenQuery[pageId].Select((int offset) => new SearchOffset(token.Item2, offset)));
|
||||||
}
|
}
|
||||||
offsets.Sort((SearchOffset x, SearchOffset y) => x.Offset - y.Offset);
|
offsets.Sort((SearchOffset x, SearchOffset y) => x.Offset - y.Offset);
|
||||||
|
@ -228,10 +230,14 @@ namespace LibSearchBox
|
||||||
|
|
||||||
if (settings.Html) {
|
if (settings.Html) {
|
||||||
result = WebUtility.HtmlEncode(result);
|
result = WebUtility.HtmlEncode(result);
|
||||||
string resultSearchable = result.Unidecode().ToLower();
|
|
||||||
foreach ((int, string) nextToken in tokenizer.IterateTokens()) {
|
foreach((int, string) nextToken in tokenizer.IterateTokens()) {
|
||||||
// TODO: Insert html tags here
|
result = Regex.Replace(
|
||||||
throw new NotImplementedException("HTML tag insertion hasn't been implemented yet");
|
result,
|
||||||
|
Regex.Escape(nextToken.Item2),
|
||||||
|
$"<strong class='query-term'>{nextToken.Item2}</strong>",
|
||||||
|
RegexOptions.IgnoreCase // Also ignores accents, apparently
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,9 +247,9 @@ namespace LibSearchBox
|
||||||
);
|
);
|
||||||
|
|
||||||
// Add the separator at the beginning and end if we aren't at the bounds of the source document
|
// 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, "");
|
snippetsText.Insert(0, "");
|
||||||
if (snippets.Last().Item2 < source.Length)
|
if (snippets.Count > 0 && snippets.Last().Item2 < source.Length)
|
||||||
snippetsText.Add("");
|
snippetsText.Add("");
|
||||||
|
|
||||||
return string.Join(
|
return string.Join(
|
||||||
|
|
Loading…
Reference in New Issue