File tree Expand file tree Collapse file tree 2 files changed +49
-1
lines changed
Expand file tree Collapse file tree 2 files changed +49
-1
lines changed Original file line number Diff line number Diff 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
134178This crate fully supports WASM.
Original file line number Diff line number Diff line change 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.
You can’t perform that action at this time.
0 commit comments