We use this semi-HTML mode to highlight words, but if we already
have tags in the document this does not work quite well.
Thus, escape the string before further processing it
The current snippet selection is useless for many queries.
Attempt a more reasonable snippet selection by prioritizing
those where all words are contained. The more words a snippet
has, the more important it is considered.Therefore, those will
be at the top.
Only highlight whole words
It was possible the text was getting too big. The GUI
was lagging for previews of some text files. The first
assumption was that we would only have a couple of hits,
which is unreasonable for large .txt files and common
words.
We only ever see a handful of previews, it makes no sense
to get all snippets. So just allow 7 snippets, that's it.
Also, just cut after 1000 chars no matter what.