[SERVER-13532] Provide highlighting of results from full text search Created: 09/Apr/14  Updated: 22/Mar/23

Status: Open
Project: Core Server
Component/s: Text Search
Affects Version/s: None
Fix Version/s: features we're not sure of

Type: New Feature Priority: Major - P3
Reporter: Christian Amor Kvalheim Assignee: Backlog - Query Integration
Resolution: Unresolved Votes: 7
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
Assigned Teams:
Query Integration
Participants:

 Description   

Currently there is no way to know what text in a document matched the query. 2.4 did include the field queryDebugString but that is also gone in 2.6. I think it's worthwhile to look at how elastic search provides this functionality.

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-highlighting.html

The motivation is any search view that contains documents (think pubmed or other scientific search engines)

This should preferably be an option



 Comments   
Comment by Ravi Teja Garlapati [ 08/Feb/21 ]

Until there is official solution, a solution that may work work, is to use projection condition.

Projection could look something like this (assuming documents containing field1, field2, both of which are added to text index):

 

{
 "field1": 1,
 "is_field1_matched": {"$gt": [{"$size": { "$setIntersection": [ <your search string split into array>, { "$split": [ { "$toLower": "$field1" }, " " ] } ] }}, 0]},
 "field2": 1, 
 "is_field2_matched": {"$gt": [{"$size": { "$setIntersection": [ <your search string split into array>, { "$split": [ { "$toLower": "$field2" }, " " ] } ] }}, 0]},
 "score": {"$meta": "textScore"}
}

 

This projection filter only applies on documents after main query filter is applied. So, performance should be fine. 

One could also remove stop words from <your search string split into array> (depending on your text index language), so that the result more accurately matches what the text index has done. 

Generated at Thu Feb 08 03:32:02 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.