Skip to content

Add a search example with filter in README #218

@curquiza

Description

@curquiza

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

Related to: meilisearch/integration-guides#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

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationgood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions