You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I can search for the content of news articles, documents, and so on and find matching documents. For instance, this is what I see if I search for "Missa inte chansen att vara med" which is part of my recent article "Sista dagen att söka CPU 2025!".
Note that the text shown in the result is just the first part of the article, not the text matching what I searched for.
Describe the solution you'd like
Meilisearch provides a solution to this: the attributesToHighlight parameter. By setting it to ['*'] we get back a formatted search result that wraps matching text in <em> tags (or another tag of your choosing). Instead of showing the first part of the article, we could find and show the text that was wrapped in <em>.
Describe alternatives you've considered
attributesToHighlight is not perfect though: what do we do if there are multiple highlighted parts in a search result? e.g if someone searches for a word that occurs many times in an article. Meilisearch will happily wrap all matching parts, but it's not clear what we should show in the UI.
Instead, we could use showMatchesPosition. It returns an array of match positions (start and length), and we could conceivably extract a substring from the first start position until the end of the last match, within a reasonable maximum length.
We could build on this to make sure PDFs are opened on the correct page by counting how many page breaks occur before the matching part of the document. Eventually we'll be able to highlight a matching part of the PDF.
This would be a very nice feature! I tried showMatchesPosition briefly and it looks promising and IMO the way to move forward. I suggest just use the first match if there are many, keep it simple since the returned values are just a preview and not the full text.
Description
I can search for the content of news articles, documents, and so on and find matching documents. For instance, this is what I see if I search for "Missa inte chansen att vara med" which is part of my recent article "Sista dagen att söka CPU 2025!".
Note that the text shown in the result is just the first part of the article, not the text matching what I searched for.
Describe the solution you'd like
Meilisearch provides a solution to this: the
attributesToHighlight
parameter. By setting it to['*']
we get back a formatted search result that wraps matching text in<em>
tags (or another tag of your choosing). Instead of showing the first part of the article, we could find and show the text that was wrapped in<em>
.Describe alternatives you've considered
attributesToHighlight
is not perfect though: what do we do if there are multiple highlighted parts in a search result? e.g if someone searches for a word that occurs many times in an article. Meilisearch will happily wrap all matching parts, but it's not clear what we should show in the UI.Instead, we could use
showMatchesPosition
. It returns an array of match positions (start and length), and we could conceivably extract a substring from the first start position until the end of the last match, within a reasonable maximum length.Example:
could return
result.substr(4, 16)
The text was updated successfully, but these errors were encountered: