"Cropping" result string around matches?

Hi Folks,

Meilisearch offers a "cropping" function that trims or shortens the result string while still including the matching term.

So using an example from their docs (which this forum won't let me link to :sweat_smile:), if the user searches shifu and the match is the following string:

The Winter Feast is Po's favorite holiday. Every year he and his father hang decorations, cook together, and serve noodle soup to the villagers. But this year Shifu informs Po that as Dragon Warrior, it is his duty to host the formal Winter Feast at the Jade Palace. Po is caught between his obligations as the Dragon Warrior and his family traditions: between Shifu and Mr. Ping.

Then the cropped result would be:

…this year Shifu informs Po…

Does Elasticsearch have a similar function?

Hi,

Elasticsearch does have a similar feature. It's called "highlighting". When you perform a search, you can ask Elasticsearch to highlight the parts of the fields in the search results that match the query.

Highlighting | Elasticsearch Guide [8.12] | Elastic

Regards

Hi,

Thanks for your response. When I first saw that "highlighting" function I assumed is was just for inserting <em> tags around matched words, rather than cropping. So just to clarify, is number_of_fragments the main option for controlling the cropping?

Also, is it possible to get Elasticsearch to automatically add the ... characters at the start/end of the cropped string depending on whether the match is at the edge of the original string?

Many Thanks

Seb

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.