In Wikimedia's phabricator( [[https://phabricator.wikimedia.org/T230787| T230787 ]]) I implemented contextual highlighting of (full-text) search results. In upstream Phab (and Phorge) the search results only include the title of matching documents. There is significant amount of extra processing involved in extracting the document bodies and highlighting the matching search terms, however, I never noticed enough performance impact to worry about optimizing it.
For upstream we might want to make it into a configurable setting so that installs can choose to disable the feature if they are running on very limited hardware. Wikimedia has very powerful hardware running their phabricator nodes, so that might be why it never seemed to have a noticeable performance impact.
Another possible improvement that would be fairly easy to implement (I think so anyway) :
The highlighting process could track elapsed time and stop highlighting any further documents after a fixed amount of time elapses, so results get context and highlights but avoid timeouts and keep user experience and perceived performance from degrading.
---
To see the feature in action you can just try a search on phabricator.wikimedia.org, for example [https://phabricator.wikimedia.org/search/query/OD7LqXb8mB6M/#R search for phorge upstream]. The results page features excerpts from each matching document, complete with highlights on the matching search terms.
|{F498748}| {F498772}|
| With context| Without |