meilisearch-swift icon indicating copy to clipboard operation
meilisearch-swift copied to clipboard

Add a search example with `filter` in README

Open curquiza opened this issue 4 years ago • 0 comments
trafficstars

⚠️ This issue is generated, please adapt the example to the repository language.

Related to: https://github.com/meilisearch/integration-guides/issues/136

In the README, we want to add the Custom Search With Filters sub section in the Getting Started section to make the users are aware of filtering.

This should

  • be placed right after the Custom Search sub section
  • contain the following content:

---------- beginning of the content

If you want to enable filtering, you must add your attributes to the filterableAttributes index setting.

--- Add an example corresponding to the current repository. See this example in JS:

await index.updateAttributesForFaceting([
    'id',
    'genres'
  ])

--- end of example

You only need to perform this operation once.

Note that MeiliSearch will rebuild your index whenever you update filterableAttributes. Depending on the size of your dataset, this might take time. You can track the process using the update status.

Then, you can perform the search:

--- Add an example corresponding to the current repository. See this example in JS:

await index.search(
  'wonder',
  {
    filter: ['id > 1 AND genres = Action']
  }
)

--- end of example

{
  "hits": [
    {
      "id": 2,
      "title": "Wonder Woman",
      "genres": ["Action","Adventure"]
    }
  ],
  "offset": 0,
  "limit": 20,
  "nbHits": 1,
  "processingTimeMs": 0,
  "query": "wonder"
}

------------- end of the content

📣 Example of PR: https://github.com/meilisearch/meilisearch-js/pull/1059/files

curquiza avatar Oct 19 '21 16:10 curquiza