Skip to content

Commit c3f5879

Browse files
committed
Add filter search, include suppressed code blocks for integration tests
1 parent 2492214 commit c3f5879

File tree

2 files changed

+75
-2
lines changed

2 files changed

+75
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ println!("{:?}", movies.search().with_query("wonder").with_filter("id > 1 AND ge
156156
.execute::<Movie>().await.unwrap().hits);
157157
```
158158

159-
```rust
159+
```
160160
{
161161
"hits": [
162162
{

src/lib.rs

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,44 @@
9090
//! index setting.
9191
//!
9292
//! ```
93+
//! # use meilisearch_sdk::{document::*, client::*, search::*};
94+
//! # use serde::{Serialize, Deserialize};
95+
//! # use futures::executor::block_on;
96+
//! # #[derive(Serialize, Deserialize, Debug)]
97+
//! # struct Movie {
98+
//! # id: usize,
99+
//! # title: String,
100+
//! # genres: Vec<String>,
101+
//! # }
102+
//! # // That trait is required to make a struct usable by an index
103+
//! # impl Document for Movie {
104+
//! # type UIDType = usize;
105+
//! # fn get_uid(&self) -> &Self::UIDType {
106+
//! # &self.id
107+
//! # }
108+
//! # }
109+
//! # fn main() { block_on(async move {
110+
//! # // Create a client (without sending any request so that can't fail)
111+
//! # let client = Client::new("http://localhost:7700", "masterKey");
112+
//! # // Get the index called "movies"
113+
//! # let movies = client.get_or_create("movies").await.unwrap();
93114
//! let filterable_attributes = [
94115
//! "id",
95116
//! "genres"
96117
//! ];
97118
//! movies.set_filterable_attributes(&filterable_attributes).await.unwrap();
119+
//! # // Add some movies in the index
120+
//! # movies.add_documents(&[
121+
//! # Movie{id: 1, title: String::from("Carol"), genres: vec!["Romance".to_string(), "Drama".to_string()]},
122+
//! # Movie{id: 2, title: String::from("Wonder Woman"), genres: vec!["Action".to_string(), "Adventure".to_string()]},
123+
//! # Movie{id: 3, title: String::from("Life of Pi"), genres: vec!["Adventure".to_string(), "Drama".to_string()]},
124+
//! # Movie{id: 4, title: String::from("Mad Max"), genres: vec!["Adventure".to_string(), "Science Fiction".to_string()]},
125+
//! # Movie{id: 5, title: String::from("Moana"), genres: vec!["Fantasy".to_string(), "Action".to_string()]},
126+
//! # Movie{id: 6, title: String::from("Philadelphia"), genres: vec!["Drama".to_string()]},
127+
//! # ], Some("id")).await.unwrap();
128+
//! # // Query movies (note that there is a typo)
129+
//! # println!("{:?}", movies.search().with_query("carol").execute::<Movie>().await.unwrap().hits);
130+
//! # })}
98131
//! ```
99132
//!
100133
//! You only need to perform this operation once.
@@ -107,11 +140,51 @@
107140
//! Then, you can perform the search:
108141
//!
109142
//! ```
143+
//! # use meilisearch_sdk::{document::*, client::*, search::*};
144+
//! # use serde::{Serialize, Deserialize};
145+
//! # use futures::executor::block_on;
146+
//! # #[derive(Serialize, Deserialize, Debug)]
147+
//! # struct Movie {
148+
//! # id: usize,
149+
//! # title: String,
150+
//! # genres: Vec<String>,
151+
//! # }
152+
//! # // That trait is required to make a struct usable by an index
153+
//! # impl Document for Movie {
154+
//! # type UIDType = usize;
155+
//! # fn get_uid(&self) -> &Self::UIDType {
156+
//! # &self.id
157+
//! # }
158+
//! # }
159+
//! # fn main() { block_on(async move {
160+
//! # // Create a client (without sending any request so that can't fail)
161+
//! # let client = Client::new("http://localhost:7700", "masterKey");
162+
//! # let filterable_attributes = [
163+
//! # "id",
164+
//! # "genres"
165+
//! # ];
166+
//! # // Get the index called "movies"
167+
//! # let movies = client.get_or_create("movies").await.unwrap();
168+
//! # let filterable_attributes = [
169+
//! # "id",
170+
//! # "genres"
171+
//! # ];
172+
//! # movies.set_filterable_attributes(&filterable_attributes).await.unwrap();
173+
//! # // Add some movies in the index
174+
//! # movies.add_documents(&[
175+
//! # Movie{id: 1, title: String::from("Carol"), genres: vec!["Romance".to_string(), "Drama".to_string()]},
176+
//! # Movie{id: 2, title: String::from("Wonder Woman"), genres: vec!["Action".to_string(), "Adventure".to_string()]},
177+
//! # Movie{id: 3, title: String::from("Life of Pi"), genres: vec!["Adventure".to_string(), "Drama".to_string()]},
178+
//! # Movie{id: 4, title: String::from("Mad Max"), genres: vec!["Adventure".to_string(), "Science Fiction".to_string()]},
179+
//! # Movie{id: 5, title: String::from("Moana"), genres: vec!["Fantasy".to_string(), "Action".to_string()]},
180+
//! # Movie{id: 6, title: String::from("Philadelphia"), genres: vec!["Drama".to_string()]},
181+
//! # ], Some("id")).await.unwrap();
110182
//! println!("{:?}", movies.search().with_query("wonder").with_filter("id > 1 AND genres = Action")
111183
//! .execute::<Movie>().await.unwrap().hits);
184+
//! # })}
112185
//! ```
113186
//!
114-
//! ```
187+
//! ```text
115188
//! {
116189
//! "hits": [
117190
//! {

0 commit comments

Comments
 (0)