meilisearch/integration-guides

New filter example in SDK README.md for v0.21

Closed this issue Β· 9 comments

Filter sample in README

Currently in v0.20 most SDK made an example of filters in their readme.md.

For example in JS (same for PHP, ruby, go, not rust, not java, don't, dart, python, not swift)

await index.search(
  'wonder',
  {
    attributesToHighlight: ['*'],
    filter: 'id > 1' // or based on the books dataset
  }
)

We should think about updating them either to something more relevant either by removing them.

Removing the example πŸŽ‰ (vote)

We remove the example completely from the README.md

Update the example πŸ‘ (vote)

We could go with a better example by joining this PR: #135 with a new filter example.

The previous example could be changed by the following. Knowing that if we go for genres=Action we do not need to change anything in #135.

String option πŸ‘ ❀️ (vote both)

await index.search(
  'wonder',
  {
    attributesToHighlight: ['*'],
    filter: 'id > 1 AND genres=Action' // or based on the books dataset
  }
)

OR

Array option πŸ‘ πŸ‘€ (vote both)

await index.search(
  'wonder',
  {
    attributesToHighlight: ['*'],
    filter: ['id > 1', 'genres=Action'] // or based on the books dataset
  }
)

TODO

  • meilisearch-dart
  • meilisearch-dotnet
  • meilisearch-go
  • meilisearch-java
  • meilisearch-js
  • meilisearch-php
  • meilisearch-python
  • meilisearch-ruby
  • meilisearch-rust
  • meilisearch-swift

I think we need to add the line:

client.index('movies')
    .updateAttributesForFaceting([
      'id',
      'genres'
    ])

or a link to the documentation but this may make it too much complex for a README.
Did we have a fourth option to remove the filter in the first example and add a second example like:
Simple search

await index.search(
  'wonder',
  {
    attributesToHighlight: ['*'],
  }
)

Search with filter

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

I agree with AmΓ©lie, it would be worth adding a third example. I don't really like the idea to add the step of "set your filterable attributes" in the only one example of a custom search.

So maybe 3 examples?

  • basic search: only uses q
  • custom search: uses attributesToHighlight
  • custom search with filter: updates filterableAttributes + uses filter

WDYT?

(sorry for the delay)

We would need to remove the genre field from the documents in the Getting Started if we decide not to make any filter example.

So we would have the following as examples?

Basic

await index.search('wonder')

Custom Search

await index.search(
  'wonder',
  {
    attributesToHighlight: ['*'],
  }
)

Custom Search With Filters

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

Hum the issue is the updateAttributesForFaceting is asynchronous so your example will not work
Maybe in two parts?
It also introduce the settings notion :)


Custom Search With Filters

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

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

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.

Then, you can perform the search:

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

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.


What do you think?

I open this PR as validation: meilisearch/meilisearch-js#1059

All the issues have been opened in the different repos.

I'm closing this issue since all the issues were created in the following repositories, and the most important ones were finished as well! Thanks team πŸŽ‰