|
90 | 90 | //! index setting. |
91 | 91 | //! |
92 | 92 | //! ``` |
| 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(); |
93 | 114 | //! let filterable_attributes = [ |
94 | 115 | //! "id", |
95 | 116 | //! "genres" |
96 | 117 | //! ]; |
97 | 118 | //! 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 | +//! # })} |
98 | 131 | //! ``` |
99 | 132 | //! |
100 | 133 | //! You only need to perform this operation once. |
|
107 | 140 | //! Then, you can perform the search: |
108 | 141 | //! |
109 | 142 | //! ``` |
| 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(); |
110 | 182 | //! println!("{:?}", movies.search().with_query("wonder").with_filter("id > 1 AND genres = Action") |
111 | 183 | //! .execute::<Movie>().await.unwrap().hits); |
| 184 | +//! # })} |
112 | 185 | //! ``` |
113 | 186 | //! |
114 | | -//! ``` |
| 187 | +//! ```text |
115 | 188 | //! { |
116 | 189 | //! "hits": [ |
117 | 190 | //! { |
|
0 commit comments