Skip to content

Commit ef27daf

Browse files
committed
Update README.md with examples for custom search with filters
1 parent 8e54bd1 commit ef27daf

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,50 @@ 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+
```ruby
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+
```ruby
173+
index.search('road', { filter: ['id > 2 AND genres = Adventure'] })
174+
```
175+
176+
JSON output:
177+
178+
```json
179+
{
180+
"hits": [
181+
{
182+
"id": 4,
183+
"title": "Mad Max: Fury Road",
184+
"genres": [
185+
"Adventure",
186+
"Science Fiction"
187+
]
188+
}
189+
],
190+
"nbHits": 1,
191+
"exhaustiveNbHits": false,
192+
"query": "road",
193+
"limit": 20,
194+
"offset": 0,
195+
"processingTimeMs": 0
196+
}
197+
```
198+
155199
## 🤖 Compatibility with MeiliSearch
156200

157201
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)