Advanced search highlighting doesn't work when you quote something
Problem
As discovered when working on !43083 (merged) any time you do a search for something using the optional quotes around for Elasticsearch phrase matching you won't get the line of code highlighted correctly.
You can see this in the following examples:
Search without quotes
Search with quotes
Quoting is actually just one kind of search where we fail to correctly highlight the result but it is likely to be a common example
Further details
The reason this is happening is that we aren't actually using Elasticsearch highlighting to apply the highlighting. Instead we're using it to find the correct line number (as you can see in !43083 (merged) ) and the highlighting is later applied by ruby code that is just doing string matching.
Solution
From what I can tell reading about Elasticsearch highlighting there is no good way to highlight lines as it's intended for normal text. You can boundary_scanner
to split based on lines which may work but it requires us to use offsets
for our
index_options
to support the Fast vector highlighter which will use considerably more storage so we would like to avoid this if possible.
Another OK option here might be to remember the matching line number and pass this along to the following rendering classes so that they can just highlight that line instead of using the logic which finds the matching substring.