Skip to content

Commit c072e09

Browse files
bors[bot]Sukriti-soodcurquiza
authored
Merge #352
352: Add search example with `filter` r=curquiza a=Sukriti-sood Fixes #349 Co-authored-by: Sukriti-sood <[email protected]> Co-authored-by: Sukriti Sood <[email protected]> Co-authored-by: Clémentine Urquizar <[email protected]>
2 parents 8a2ce0c + 4c2fbed commit c072e09

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,49 @@ JSON output:
152152
}
153153
```
154154

155+
#### Custom Search With Filters <!-- omit in toc -->
156+
157+
If you want to enable filtering, you must add your attributes to the `filterableAttributes` index setting.
158+
159+
```py
160+
index.update_filterable_attributes([
161+
'id',
162+
'genres'
163+
])
164+
```
165+
166+
You only need to perform this operation once.
167+
168+
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](https://docs.meilisearch.com/reference/api/updates.html#get-an-update-status).
169+
170+
Then, you can perform the search:
171+
172+
```py
173+
index.search(
174+
'wonder',
175+
{
176+
filter: ['id > 1 AND genres = Action']
177+
}
178+
)
179+
```
180+
181+
```json
182+
{
183+
"hits": [
184+
{
185+
"id": 2,
186+
"title": "Wonder Woman",
187+
"genres": ["Action","Adventure"]
188+
}
189+
],
190+
"offset": 0,
191+
"limit": 20,
192+
"nbHits": 1,
193+
"processingTimeMs": 0,
194+
"query": "wonder"
195+
}
196+
```
197+
155198
## 🤖 Compatibility with MeiliSearch
156199

157200
This package only guarantees the compatibility with the [version v0.23.0 of MeiliSearch](https://github.com/meilisearch/MeiliSearch/releases/tag/v0.23.0).

0 commit comments

Comments
 (0)