Skip to content

Commit f740ba0

Browse files
bors[bot]mk1107curquiza
authored
Merge #185
185: Update README.md r=curquiza a=mk1107 Issue #181 I have done changes in readme.md. Please once review it. Co-authored-by: mk1107 <[email protected]> Co-authored-by: Clémentine Urquizar <[email protected]>
2 parents c143d9e + 766f164 commit f740ba0

File tree

2 files changed

+42
-40
lines changed

2 files changed

+42
-40
lines changed

README.md

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -86,46 +86,47 @@ use serde::{Serialize, Deserialize};
8686
use futures::executor::block_on;
8787

8888
#[derive(Serialize, Deserialize, Debug)]
89-
struct Book {
90-
book_id: usize,
89+
struct Movie {
90+
id: usize,
9191
title: String,
92+
genres: Vec<String>,
9293
}
9394

9495
// That trait is required to make a struct usable by an index
95-
impl Document for Book {
96+
impl Document for Movie {
9697
type UIDType = usize;
9798

9899
fn get_uid(&self) -> &Self::UIDType {
99-
&self.book_id
100+
&self.id
100101
}
101102
}
102103

103104
fn main() { block_on(async move {
104105
// Create a client (without sending any request so that can't fail)
105106
let client = Client::new("http://localhost:7700", "masterKey");
106107

107-
// Get the index called "books"
108-
let books = client.get_or_create("books").await.unwrap();
109-
110-
// Add some books in the index
111-
books.add_documents(&[
112-
Book{book_id: 123, title: String::from("Pride and Prejudice")},
113-
Book{book_id: 456, title: String::from("Le Petit Prince")},
114-
Book{book_id: 1, title: String::from("Alice In Wonderland")},
115-
Book{book_id: 1344, title: String::from("The Hobbit")},
116-
Book{book_id: 4, title: String::from("Harry Potter and the Half-Blood Prince")},
117-
Book{book_id: 42, title: String::from("The Hitchhiker's Guide to the Galaxy")},
118-
], Some("book_id")).await.unwrap();
119-
120-
// Query books (note that there is a typo)
121-
println!("{:?}", books.search().with_query("harry pottre").execute::<Book>().await.unwrap().hits);
108+
// Get the index called "movies"
109+
let movies = client.get_or_create("movies").await.unwrap();
110+
111+
// Add some movies in the index
112+
movies.add_documents(&[
113+
Movie{id: 1, title: String::from("Carol"), genres: vec!["Romance".to_string(), "Drama".to_string()]},
114+
Movie{id: 2, title: String::from("Wonder Woman"), genres: vec!["Action".to_string(), "Adventure".to_string()]},
115+
Movie{id: 3, title: String::from("Life of Pi"), genres: vec!["Adventure".to_string(), "Drama".to_string()]},
116+
Movie{id: 4, title: String::from("Mad Max"), genres: vec!["Adventure".to_string(), "Science Fiction".to_string()]},
117+
Movie{id: 5, title: String::from("Moana"), genres: vec!["Fantasy".to_string(), "Action".to_string()]},
118+
Movie{id: 6, title: String::from("Philadelphia"), genres: vec!["Drama".to_string()]},
119+
], Some("id")).await.unwrap();
120+
121+
// Query movies (note that there is a typo)
122+
println!("{:?}", movies.search().with_query("carol").execute::<Movie>().await.unwrap().hits);
122123
})}
123124
```
124125

125126
Output:
126127

127128
```
128-
[Book { book_id: 4, title: "Harry Potter and the Half-Blood Prince" }]
129+
[Movie{id: 1, title: String::from("Carol"), genres: vec!["Romance", "Drama"]}]
129130
```
130131

131132
### 🌐 Running in the Browser with WASM <!-- omit in TOC -->

src/lib.rs

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,46 +41,47 @@
4141
//! use futures::executor::block_on;
4242
//!
4343
//! #[derive(Serialize, Deserialize, Debug)]
44-
//! struct Book {
45-
//! book_id: usize,
44+
//! struct Movie {
45+
//! id: usize,
4646
//! title: String,
47+
//! genres: Vec<String>,
4748
//! }
4849
//!
4950
//! // That trait is required to make a struct usable by an index
50-
//! impl Document for Book {
51+
//! impl Document for Movie {
5152
//! type UIDType = usize;
5253
//!
5354
//! fn get_uid(&self) -> &Self::UIDType {
54-
//! &self.book_id
55+
//! &self.id
5556
//! }
5657
//! }
5758
//!
5859
//! fn main() { block_on(async move {
5960
//! // Create a client (without sending any request so that can't fail)
6061
//! let client = Client::new("http://localhost:7700", "masterKey");
6162
//!
62-
//! // Get the index called "books"
63-
//! let books = client.get_or_create("books").await.unwrap();
64-
//!
65-
//! // Add some books in the index
66-
//! books.add_documents(&[
67-
//! Book{book_id: 123, title: String::from("Pride and Prejudice")},
68-
//! Book{book_id: 456, title: String::from("Le Petit Prince")},
69-
//! Book{book_id: 1, title: String::from("Alice In Wonderland")},
70-
//! Book{book_id: 1344, title: String::from("The Hobbit")},
71-
//! Book{book_id: 4, title: String::from("Harry Potter and the Half-Blood Prince")},
72-
//! Book{book_id: 42, title: String::from("The Hitchhiker's Guide to the Galaxy")},
73-
//! ], Some("book_id")).await.unwrap();
74-
//!
75-
//! // Query books (note that there is a typo)
76-
//! println!("{:?}", books.search().with_query("harry pottre").execute::<Book>().await.unwrap().hits);
63+
//! // Get the index called "movies"
64+
//! let movies = client.get_or_create("movies").await.unwrap();
65+
//!
66+
//! // Add some movies in the index
67+
//! movies.add_documents(&[
68+
//! Movie{id: 1, title: String::from("Carol"), genres: vec!["Romance".to_string(), "Drama".to_string()]},
69+
//! Movie{id: 2, title: String::from("Wonder Woman"), genres: vec!["Action".to_string(), "Adventure".to_string()]},
70+
//! Movie{id: 3, title: String::from("Life of Pi"), genres: vec!["Adventure".to_string(), "Drama".to_string()]},
71+
//! Movie{id: 4, title: String::from("Mad Max"), genres: vec!["Adventure".to_string(), "Science Fiction".to_string()]},
72+
//! Movie{id: 5, title: String::from("Moana"), genres: vec!["Fantasy".to_string(), "Action".to_string()]},
73+
//! Movie{id: 6, title: String::from("Philadelphia"), genres: vec!["Drama".to_string()]},
74+
//! ], Some("id")).await.unwrap();
75+
//!
76+
//! // Query movies (note that there is a typo)
77+
//! println!("{:?}", movies.search().with_query("carol").execute::<Movie>().await.unwrap().hits);
7778
//! })}
7879
//! ```
7980
//!
8081
//! Output:
8182
//!
8283
//! ```text
83-
//! [Book { book_id: 4, title: "Harry Potter and the Half-Blood Prince" }]
84+
//! [Movie{id: 1, title: String::from("Carol"), genres: vec!["Romance", "Drama"]}]
8485
//! ```
8586
//!
8687
//! ## 🌐 Running in the Browser with WASM <!-- omit in TOC -->

0 commit comments

Comments
 (0)