简体   繁体   中英

Meilisearch - what's the differences & relationship among: searchableAttributes, filterableAttributes, faceting

searchableAttributes , filterableAttributes , faceting . I've read the documents, but a bit confused.

Please give some insights about:

  • Their differences.
  • Their relationships.
  • searchableAttributes are attributes where Meilisearch can search in for matching query words.
  • filterableAttributes are a list of attributes that can be used as filters to refine the search results. Given a movies dataset, if you want to filter movies by release_date , you need to first add the attribute release_date to the filterableAttributes list.

Both searchableAttributes and filterableAttributes are part of Meilisearch settings. An attribute doesn't necessarily have to be searchable for it to be filterable, so no relation between both.

  • facets is a search parameter, not a setting, it must be added to a search request. It gives information about the number of documents found per attribute value. If you want to know how many movies there are per genre for a given query, you can pass the "facets": ["genres"] as a parameter in the search query like so:

     curl \ -X POST 'http://localhost:7700/indexes/movies/search' \ -H 'Content-Type: application/json' \ --data-binary '{ "q": "Batman", "facets": ["genres"] }'

The response should include a facetDistribution object with the information:

{
  "hits": [
    …
  ],
  …
  "facetDistribution": {
    "genres": {
      "action": 273,
      "animation": 118,
      "adventure": 132,
      "fantasy": 67,
      "comedy": 475,
      "mystery": 70,
      "thriller": 217
    }
  }
}

In order to have the facets information about an attribute, it must be first present in the filterableAttributes list.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM