documentation icon indicating copy to clipboard operation
documentation copied to clipboard

Highlight behavior regarding `searchableAttributes`

Open curquiza opened this issue 3 years ago • 1 comments

If I'm not wrong this behavior is not described in the documentation and I don't really know where it should be added so I open an issue instead of a PR. Feel free to not document this behavior if you think it brings too much complexity for a little help.


Currently, even if attributes are not set in searchableAttributes, the highlight and matches still apply to them.

Example using MeiliSearch v0.23.1

  • Add this document
{
  "id": 1,
  "title_fr": "Le Petit Prince",
  "title_en": "The Little Prince"
}
  • Set only title_fr as searchableAttributes

  • Do the following search

{
    "q": "prince",
    "attributesToHighlight": ["*"],
    "matches": true
}

Here is the following response:

{
    "hits": [
        {
            "title_fr": "Le Petit Prince",
            "id": 1,
            "title_en": "The Little Prince",
            "_formatted": {
                "title_fr": "Le Petit <em>Prince</em>",
                "id": "1",
                "title_en": "The Little <em>Prince</em>"
            },
            "_matchesInfo": {
                "title_en": [
                    {
                        "start": 11,
                        "length": 6
                    }
                ],
                "title_fr": [
                    {
                        "start": 9,
                        "length": 6
                    }
                ]
            }
        }
    ],
    "nbHits": 2,
    "exhaustiveNbHits": false,
    "query": "prince",
    "limit": 20,
    "offset": 0,
    "processingTimeMs": 0
}

Despite only title_fr is considered as searchable, title_en is also highlighted and "matched".

Of course the row document is still available outside the _formatted field. Also, the users can set only title_fr as attributesToHighlight if they want to only highlight title_fr

curquiza avatar Nov 09 '21 11:11 curquiza

This is briefly mentioned in #1280 with the help of a gif

maryamsulemani97 avatar Jan 03 '22 13:01 maryamsulemani97