Am using Atlas and doing some searches - working all fine. However I am looking to return the highlights - which sometimes work - and sometimes don’t. Search is working insofar as it is finding the documents that contain the terms, however it appears that is the terms are ‘too far in’ (the text is often long), and highlights are not returned.
Not sure if I have made an error or there is a known bug (?) or if anyone else has stumbled across this issue. Here is (a somewhat modified) snippet:
$search: {
"compound": {
"must": [{
"queryString": {
"defaultPath": "text",
"query": paramMust
}
}],
"mustNot": [{
"text": {
"query": paramMustNot,
"path": ["text", "name"],
}
}],
"should": [{
"text": {
"query": paramShould,
"path": ["text", "name"],
"fuzzy": {
"maxEdits": maxEdits,
"maxExpansions": maxExpansions,
}
}
}]
},
"highlight": {
"path": "text",
}
}
},
{
$project: {
"_id": 1,
"name": 1,
"highlights": { "$meta": "searchHighlights" }
}
}
After many hours of toiling I found a highlight that returned - half a sentence - I believe not expected behaviour! This leads me to believe perhaps if it doesn’t find the term in the first x characters then it goes ‘ah well, too hard’ and returns no highlights. Whilst I could parse the text myself and do my own deconstruction, this feels sub-optimal when there is a highlighting feature.