Skip to content

Commit 2492214

Browse files
committed
Add filterable attributes example to README
1 parent 66df8fe commit 2492214

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,50 @@ Output:
129129
[Movie{id: 1, title: String::from("Carol"), genres: vec!["Romance", "Drama"]}]
130130
```
131131

132+
##### Custom Search With Filters <!-- omit in TOC -->
133+
134+
If you want to enable filtering, you must add your attributes to the `filterableAttributes`
135+
index setting.
136+
137+
```rust
138+
let filterable_attributes = [
139+
"id",
140+
"genres"
141+
];
142+
movies.set_filterable_attributes(&filterable_attributes).await.unwrap();
143+
```
144+
145+
You only need to perform this operation once.
146+
147+
Note that MeiliSearch will rebuild your index whenever you update `filterableAttributes`.
148+
Depending on the size of your dataset, this might take time. You can track the whole process
149+
using the [update
150+
status](https://docs.meilisearch.com/reference/api/updates.html#get-an-update-status).
151+
152+
Then, you can perform the search:
153+
154+
```rust
155+
println!("{:?}", movies.search().with_query("wonder").with_filter("id > 1 AND genres = Action")
156+
.execute::<Movie>().await.unwrap().hits);
157+
```
158+
159+
```rust
160+
{
161+
"hits": [
162+
{
163+
"id": 2,
164+
"title": "Wonder Woman",
165+
"genres": ["Action", "Adventure"]
166+
}
167+
],
168+
"offset": 0,
169+
"limit": 20,
170+
"nbHits": 1,
171+
"processingTimeMs": 0,
172+
"query": "wonder"
173+
}
174+
```
175+
132176
### 🌐 Running in the Browser with WASM <!-- omit in TOC -->
133177

134178
This crate fully supports WASM.

src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,11 @@
9090
//! index setting.
9191
//!
9292
//! ```
93-
//! movies.set_filterable_attributes(["id", "genres"]).await.unwrap();
93+
//! let filterable_attributes = [
94+
//! "id",
95+
//! "genres"
96+
//! ];
97+
//! movies.set_filterable_attributes(&filterable_attributes).await.unwrap();
9498
//! ```
9599
//!
96100
//! You only need to perform this operation once.

0 commit comments

Comments
 (0)