diff --git a/.code-samples.meilisearch.yaml b/.code-samples.meilisearch.yaml index 865057d6..30df1031 100644 --- a/.code-samples.meilisearch.yaml +++ b/.code-samples.meilisearch.yaml @@ -10,16 +10,15 @@ list_all_indexes_1: |- create_an_index_1: |- let movies: Index = client.create_index("movies", Some("movie_id")).await.unwrap(); update_an_index_1: |- - let movie_review: Index = client.get_index("movie_review").await.unwrap(); - movie_review.update("movie_review_id").await.unwrap(); + client.index("movies").update("movie_review_id").await.unwrap(); delete_an_index_1: |- - movies.delete().await.unwrap(); + client.index("movies").delete().await.unwrap(); get_one_document_1: |- - let movie: Movie = movies.get_document(String::from("25684")).await.unwrap(); + let movie: Movie = client.index("movies").get_document(String::from("25684")).await.unwrap(); get_documents_1: |- - let documents: Vec = movies.get_documents(None, Some(2), None).await.unwrap(); + let documents: Vec = client.index("movies").get_documents(None, Some(2), None).await.unwrap(); add_or_replace_documents_1: |- - let progress: Progress = movies.add_or_replace(&[ + let progress: Progress = client.index("movies").add_or_replace(&[ Movie { id: 287947, title: "Shazam".to_string(), @@ -40,20 +39,20 @@ add_or_update_documents_1: |- fn get_uid(&self) -> &Self::UIDType { &self.id } } - let progress: Progress = movies.add_or_update(&[ + let progress: Progress = client.index("movies").add_or_update(&[ IncompleteMovie { id: 287947, title: "Shazam ⚡️".to_string() } ], None).await.unwrap(); delete_all_documents_1: |- - let progress: Progress = movies.delete_all_documents().await.unwrap(); + let progress: Progress = client.index("movies").delete_all_documents().await.unwrap(); delete_one_document_1: |- - let progress: Progress = movies.delete_document(25684).await.unwrap(); + let progress: Progress = client.index("movies").delete_document(25684).await.unwrap(); delete_documents_1: |- - let progress: Progress = movies.delete_documents(&[23488, 153738, 437035, 363869]).await.unwrap(); + let progress: Progress = client.index("movies").delete_documents(&[23488, 153738, 437035, 363869]).await.unwrap(); search_post_1: |- - let results: SearchResults = movies + let results: SearchResults = client.index("movies") .search() .with_query("American ninja") .execute() @@ -64,13 +63,13 @@ get_update_1: |- let status: Status = progress.get_status().await.unwrap(); // Or you can use index to get an update status using its `update_id`: - let status: Status = index.get_update(1).await.unwrap(); + let status: Status = client.index("movies").get_update(1).await.unwrap(); get_all_updates_1: |- - let status: Vec = index.get_all_updates().await.unwrap(); + let status: Vec = client.index("movies").get_all_updates().await.unwrap(); get_keys_1: |- let keys: Keys = client.get_keys().await.unwrap(); get_settings_1: |- - let settings: Settings = movies.get_settings().await.unwrap(); + let settings: Settings = client.index("movies").get_settings().await.unwrap(); update_settings_1: |- let mut synonyms = std::collections::HashMap::new(); synonyms.insert(String::from("wolverine"), vec!["xmen", "logan"]); @@ -110,29 +109,29 @@ update_settings_1: |- ]) .with_synonyms(synonyms); - let progress: Progress = movies.set_settings(&settings).await.unwrap(); + let progress: Progress = client.index("movies").set_settings(&settings).await.unwrap(); reset_settings_1: |- - let progress: Progress = movies.reset_settings().await.unwrap(); + let progress: Progress = client.index("movies").reset_settings().await.unwrap(); get_synonyms_1: |- - let synonyms: HashMap> = movies.get_synonyms().await.unwrap(); + let synonyms: HashMap> = client.index("movies").get_synonyms().await.unwrap(); update_synonyms_1: |- let mut synonyms = std::collections::HashMap::new(); synonyms.insert(String::from("wolverine"), vec![String::from("xmen"), String::from("logan")]); synonyms.insert(String::from("logan"), vec![String::from("xmen"), String::from("wolverine")]); synonyms.insert(String::from("wow"), vec![String::from("world of warcraft")]); - let progress: Progress = movies.set_synonyms(&synonyms).await.unwrap(); + let progress: Progress = client.index("movies").set_synonyms(&synonyms).await.unwrap(); reset_synonyms_1: |- - movies.reset_synonyms().await.unwrap(); + let progress: Progress = client.index("movies").reset_synonyms().await.unwrap(); get_stop_words_1: |- - let stop_words: Vec = movies.get_stop_words().await.unwrap(); + let stop_words: Vec = client.index("movies").get_stop_words().await.unwrap(); update_stop_words_1: |- let stop_words = ["of", "the", "to"]; - let progress: Progress = movies.set_stop_words(&stop_words).await.unwrap(); + let progress: Progress = client.index("movies").set_stop_words(&stop_words).await.unwrap(); reset_stop_words_1: |- - let progress: Progress = movies.reset_stop_words().await.unwrap(); + let progress: Progress = client.index("movies").reset_stop_words().await.unwrap(); get_ranking_rules_1: |- - let ranking_rules: Vec = movies.get_ranking_rules().await.unwrap(); + let ranking_rules: Vec = client.index("movies").get_ranking_rules().await.unwrap(); update_ranking_rules_1: |- let ranking_rules = [ "words", @@ -145,17 +144,17 @@ update_ranking_rules_1: |- "rank:desc", ]; - let progress: Progress = movies.set_ranking_rules(&ranking_rules).await.unwrap(); + let progress: Progress = client.index("movies").set_ranking_rules(&ranking_rules).await.unwrap(); reset_ranking_rules_1: |- - let progress: Progress = movies.reset_ranking_rules().await.unwrap(); + let progress: Progress = client.index("movies").reset_ranking_rules().await.unwrap(); get_distinct_attribute_1: |- - let distinct_attribute: Option = shoes.get_distinct_attribute().await.unwrap(); + let distinct_attribute: Option = client.index("shoes").get_distinct_attribute().await.unwrap(); update_distinct_attribute_1: |- - let progress: Progress = shoes.set_distinct_attribute("skuid").await.unwrap(); + let progress: Progress = client.index("shoes").set_distinct_attribute("skuid").await.unwrap(); reset_distinct_attribute_1: |- - let progress: Progress = shoes.reset_distinct_attribute().await.unwrap(); + let progress: Progress = client.index("shoes").reset_distinct_attribute().await.unwrap(); get_searchable_attributes_1: |- - let searchable_attributes: Vec = movies.get_searchable_attributes().await.unwrap(); + let searchable_attributes: Vec = client.index("movies").get_searchable_attributes().await.unwrap(); update_searchable_attributes_1: |- let searchable_attributes = [ "title", @@ -163,22 +162,22 @@ update_searchable_attributes_1: |- "genre" ]; - let progress: Progress = movies.set_searchable_attributes(&searchable_attributes).await.unwrap(); + let progress: Progress = client.index("movies").set_searchable_attributes(&searchable_attributes).await.unwrap(); reset_searchable_attributes_1: |- - let progress: Progress = movies.reset_searchable_attributes().await.unwrap(); + let progress: Progress = client.index("movies").reset_searchable_attributes().await.unwrap(); get_filterable_attributes_1: |- - let filterable_attributes: Vec = movies.get_filterable_attributes().await.unwrap(); + let filterable_attributes: Vec = client.index("movies").get_filterable_attributes().await.unwrap(); update_filterable_attributes_1: |- let filterable_attributes = [ "genres", "director" ]; - let progress: Progress = movies.set_filterable_attributes(&filterable_attributes).await.unwrap(); + let progress: Progress = client.index("movies").set_filterable_attributes(&filterable_attributes).await.unwrap(); reset_filterable_attributes_1: |- - let progress: Progress = movies.reset_filterable_attributes().await.unwrap(); + let progress: Progress = client.index("movies").reset_filterable_attributes().await.unwrap(); get_displayed_attributes_1: |- - let displayed_attributes: Vec = movies.get_displayed_attributes().await.unwrap(); + let displayed_attributes: Vec = client.index("movies").get_displayed_attributes().await.unwrap(); update_displayed_attributes_1: |- let displayed_attributes = [ "title", @@ -187,11 +186,11 @@ update_displayed_attributes_1: |- "release_date" ]; - let progress: Progress = movies.set_displayed_attributes(&displayed_attributes).await.unwrap(); + let progress: Progress = client.index("movies").set_displayed_attributes(&displayed_attributes).await.unwrap(); reset_displayed_attributes_1: |- - let progress: Progress = movies.reset_displayed_attributes().await.unwrap(); + let progress: Progress = client.index("movies").reset_displayed_attributes().await.unwrap(); get_index_stats_1: |- - let stats: IndexStats = movies.get_stats().await.unwrap(); + let stats: IndexStats = client.index("movies").get_stats().await.unwrap(); get_indexes_stats_1: |- let stats: ClientStats = client.get_stats().await.unwrap(); get_health_1: |- @@ -200,8 +199,7 @@ get_health_1: |- get_version_1: |- let version: Version = client.get_version().await.unwrap(); distinct_attribute_guide_1: |- - let jackets: Index = client.get_index("jackets").await.unwrap(); - let progress: Progress = jackets.set_distinct_attribute("product_id").await.unwrap(); + let progress: Progress = client.index("jackets").set_distinct_attribute("product_id").await.unwrap(); field_properties_guide_searchable_1: |- let searchable_attributes = [ "title", @@ -209,7 +207,7 @@ field_properties_guide_searchable_1: |- "genre" ]; - let progress: Progress = movies.set_searchable_attributes(&searchable_attributes).await.unwrap(); + let progress: Progress = client.index("movies").set_searchable_attributes(&searchable_attributes).await.unwrap(); field_properties_guide_displayed_1: |- let displayed_attributes = [ "title", @@ -218,64 +216,64 @@ field_properties_guide_displayed_1: |- "release_date" ]; - let progress: Progress = movies.set_displayed_attributes(&displayed_attributes).await.unwrap(); + let progress: Progress = client.index("movies").set_displayed_attributes(&displayed_attributes).await.unwrap(); filtering_guide_1: |- - let results: SearchResults = movies.search() + let results: SearchResults = client.index("movies").search() .with_query("Avengers") .with_filter("release_date > 795484800") .execute() .await .unwrap(); filtering_guide_2: |- - let results: SearchResults = movies.search() + let results: SearchResults = client.index("movies").search() .with_query("Batman") .with_filter(r#"release_date > 795484800 AND (director = "Tim Burton" OR director = "Christopher Nolan")"#) .execute() .await .unwrap(); filtering_guide_3: |- - let results: SearchResults = movies.search() + let results: SearchResults = client.index("movies").search() .with_query("horror") .with_filter(r#"director = "Jordan Peele""#) .execute() .await .unwrap(); filtering_guide_4: |- - let results: SearchResults = movies.search() + let results: SearchResults = client.index("movies").search() .with_query("Planet of the Apes") .with_filter(r#"rating >= 3 AND (NOT director = "Tim Burton")"#) .execute() .await .unwrap(); search_parameter_guide_query_1: |- - let results: SearchResults = movies.search() + let results: SearchResults = client.index("movies").search() .with_query("shifu") .execute() .await .unwrap(); search_parameter_guide_offset_1: |- - let results: SearchResults = movies.search() + let results: SearchResults = client.index("movies").search() .with_query("shifu") .with_offset(1) .execute() .await .unwrap(); search_parameter_guide_limit_1: |- - let results: SearchResults = movies.search() + let results: SearchResults = client.index("movies").search() .with_query("shifu") .with_limit(2) .execute() .await .unwrap(); search_parameter_guide_retrieve_1: |- - let results: SearchResults = movies.search() + let results: SearchResults = client.index("movies").search() .with_query("shifu") .with_attributes_to_retrieve(Selectors::Some(&["overview", "title"])) .execute() .await .unwrap(); search_parameter_guide_crop_1: |- - let results: SearchResults = movies.search() + let results: SearchResults = client.index("movies").search() .with_query("shifu") .with_attributes_to_crop(Selectors::Some(&[("overview", None)])) .with_crop_length(10) @@ -286,7 +284,7 @@ search_parameter_guide_crop_1: |- // Get the formatted results let formatted_results: Vec<&Movie> = results.hits.iter().map(|r| r.formatted_result.as_ref().unwrap()).collect(); search_parameter_guide_highlight_1: |- - let results: SearchResults = movies.search() + let results: SearchResults = client.index("movies").search() .with_query("winter feast") .with_attributes_to_highlight(Selectors::Some(&["overview"])) .execute() @@ -296,21 +294,21 @@ search_parameter_guide_highlight_1: |- // Get the formatted results let formatted_results: Vec<&Movie> = results.hits.iter().map(|r| r.formatted_result.as_ref().unwrap()).collect(); search_parameter_guide_filter_1: |- - let results: SearchResults = movies.search() + let results: SearchResults = client.index("movies").search() .with_query("n") .with_filter("title = Nightshift") .execute() .await .unwrap(); search_parameter_guide_filter_2: |- - let results: SearchResults = movies.search() + let results: SearchResults = client.index("movies").search() .with_query("shifu") .with_filter(r#"title = "Kung Fu Panda""#) .execute() .await .unwrap(); search_parameter_guide_matches_1: |- - let results: SearchResults = movies.search() + let results: SearchResults = client.index("movies").search() .with_query("winter feast") .with_matches(true) .execute() @@ -324,12 +322,11 @@ settings_guide_synonyms_1: |- synonyms.insert(String::from("sweater"), vec![String::from("jumper")]); synonyms.insert(String::from("jumper"), vec![String::from("sweater")]); - let tops: Index = client.get_index("tops").await.unwrap(); - let progress: Progress = tops.set_synonyms(&synonyms).await.unwrap(); + let progress: Progress = client.index("tops").set_synonyms(&synonyms).await.unwrap(); settings_guide_stop_words_1: |- - let progress: Progress = movies.set_stop_words(["the", "a", "an"]).await.unwrap(); + let progress: Progress = client.index("movies").set_stop_words(["the", "a", "an"]).await.unwrap(); settings_guide_filterable_attributes_1: |- - let progress: Progress = movies.set_filterable_attributes(["director", "genres"]).await.unwrap(); + let progress: Progress = client.index("movies").set_filterable_attributes(["director", "genres"]).await.unwrap(); settings_guide_ranking_rules_1: |- let ranking_rules = [ "words", @@ -342,10 +339,9 @@ settings_guide_ranking_rules_1: |- "rank:desc", ]; - let progress: Progress = movies.set_ranking_rules(&ranking_rules).await.unwrap(); + let progress: Progress = client.index("movies").set_ranking_rules(&ranking_rules).await.unwrap(); settings_guide_distinct_1: |- - let jackets: Index = client.get_index("jackets").await.unwrap(); - let progress: Progress = jackets.set_distinct_attribute("product_id").await.unwrap(); + let progress: Progress = client.index("jackets").set_distinct_attribute("product_id").await.unwrap(); settings_guide_searchable_1: |- let searchable_attributes = [ "title", @@ -353,7 +349,7 @@ settings_guide_searchable_1: |- "genre" ]; - let progress: Progress = movies.set_searchable_attributes(&searchable_attributes).await.unwrap(); + let progress: Progress = client.index("movies").set_searchable_attributes(&searchable_attributes).await.unwrap(); settings_guide_displayed_1: |- let displayed_attributes = [ "title", @@ -362,7 +358,7 @@ settings_guide_displayed_1: |- "release_date" ]; - let progress: Progress = movies.set_displayed_attributes(&displayed_attributes).await.unwrap(); + let progress: Progress = client.index("movies").set_displayed_attributes(&displayed_attributes).await.unwrap(); add_movies_json_1: |- use meilisearch_sdk::{ indexes::*, @@ -386,8 +382,7 @@ add_movies_json_1: |- let movies_docs: Vec = serde_json::from_str(&content).unwrap(); // adding documents - let movies = client.get_or_create_index("movies").await.unwrap(); - movies.add_documents(&movies_docs, None).await.unwrap(); + client.index("movies").add_documents(&movies_docs, None).await.unwrap(); })} documents_guide_add_movie_1: |- // Define the type of our documents @@ -402,14 +397,14 @@ documents_guide_add_movie_1: |- } // Add a document to our index - let progress: Progress = movies.add_documents(&[ + let progress: Progress = client.index("movies").add_documents(&[ IncompleteMovie { id: "123sq178".to_string(), title: "Amélie Poulain".to_string(), } ], None).await.unwrap(); search_guide_1: |- - let results: SearchResults = movies.search() + let results: SearchResults = client.index("movies").search() .with_query("shifu") .with_limit(5) .with_offset(10) @@ -417,7 +412,7 @@ search_guide_1: |- .await .unwrap(); search_guide_2: |- - let results: SearchResults = movies.search() + let results: SearchResults = client.index("movies").search() .with_query("Avengers") .with_filter("release_date > 795484800") .execute() @@ -496,8 +491,7 @@ getting_started_add_documents_md: |- let movies_docs: Vec = serde_json::from_str(&content).unwrap(); // adding documents - let movies = client.get_or_create_index("movies").await.unwrap(); - movies.add_documents(&movies_docs, None).await.unwrap(); + client.index("movies").add_documents(&movies_docs, None).await.unwrap(); })} ``` @@ -509,7 +503,7 @@ getting_started_search_md: |- .with_query("botman") .build(); - let results: SearchResults = movies.execute_query(&query).await.unwrap(); + let results: SearchResults = client.index("movies").execute_query(&query).await.unwrap(); ``` You can build a `Query` and execute it directly: @@ -523,7 +517,7 @@ getting_started_search_md: |- You can search in an index directly: ```rust - let results: SearchResults = movies.search() + let results: SearchResults = client.index("movies").search() .with_query("botman") .execute() .await @@ -532,16 +526,16 @@ getting_started_search_md: |- [About this SDK](https://github.com/meilisearch/meilisearch-rust/) faceted_search_update_settings_1: |- - let progress: Progress = movies.set_filterable_attributes(["director", "genres"]).await.unwrap(); + let progress: Progress = client.index("movies").set_filterable_attributes(["director", "genres"]).await.unwrap(); faceted_search_filter_1: |- - let results: SearchResults = movies.search() + let results: SearchResults = client.index("movies").search() .with_query("thriller") .with_filter("(genres = Horror AND genres = Mystery) OR director = \"Jordan Peele\"") .execute() .await .unwrap(); faceted_search_facets_distribution_1: |- - let results: SearchResults = movies.search() + let results: SearchResults = client.index("movies").search() .with_query("Batman") .with_facets_distribution(Selectors::Some(&["genres"])) .execute() @@ -556,16 +550,16 @@ faceted_search_walkthrough_filterable_attributes_1: |- "production_companies" ]; - let progress: Progress = movies.set_filterable_attributes(&filterable_attributes).await.unwrap(); + let progress: Progress = client.index("movies").set_filterable_attributes(&filterable_attributes).await.unwrap(); faceted_search_walkthrough_filter_1: |- - let results: SearchResults = movies.search() + let results: SearchResults = client.index("movies").search() .with_query("thriller") .with_filter("(genres = Horror AND genres = Mystery) OR director = \"Jordan Peele\"") .execute() .await .unwrap(); faceted_search_walkthrough_facets_distribution_1: |- - let results: SearchResults = movies.search() + let results: SearchResults = client.index("movies").search() .with_query("Batman") .with_facets_distribution(Selectors::Some(&["genres"])) .execute() @@ -577,7 +571,7 @@ post_dump_1: |- get_dump_status_1: |- client.get_dump_status("20201101-110357260").await.unwrap(); phrase_search_1: |- - let results: SearchResults = movies + let results: SearchResults = client.index("movies") .search() .with_query("\"african american\" horror") .execute() @@ -589,7 +583,7 @@ sorting_guide_update_sortable_attributes_1: |- "price" ]; - let progress: Progress = books.set_sortable_attributes(&sortable_attributes).await.unwrap(); + let progress: Progress = client.index("books").set_sortable_attributes(&sortable_attributes).await.unwrap(); sorting_guide_update_ranking_rules_1: |- let ranking_rules = [ "words", @@ -600,63 +594,63 @@ sorting_guide_update_ranking_rules_1: |- "exactness" ]; - let progress: Progress = books.set_ranking_rules(&ranking_rules).await.unwrap(); + let progress: Progress = client.index("books").set_ranking_rules(&ranking_rules).await.unwrap(); sorting_guide_sort_parameter_1: |- - let results: SearchResults = books.search() + let results: SearchResults = client.index("books").search() .with_query("science fiction") .with_sort(&["price:asc"]) .execute() .await .unwrap(); sorting_guide_sort_parameter_2: |- - let results: SearchResults = books.search() + let results: SearchResults = client.index("books").search() .with_query("butler") .with_sort(&["author:desc"]) .execute() .await .unwrap(); get_sortable_attributes_1: |- - let sortable_attributes: Vec = books.get_sortable_attributes().await.unwrap(); + let sortable_attributes: Vec = client.index("books").get_sortable_attributes().await.unwrap(); update_sortable_attributes_1: |- let sortable_attributes = [ "price", "author" ]; - let progress: Progress = books.set_sortable_attributes(&sortable_attributes).await.unwrap(); + let progress: Progress = client.index("books").set_sortable_attributes(&sortable_attributes).await.unwrap(); reset_sortable_attributes_1: |- - let progress: Progress = books.reset_sortable_attributes().await.unwrap(); + let progress: Progress = client.index("books").reset_sortable_attributes().await.unwrap(); search_parameter_guide_sort_1: |- - let results: SearchResults = books.search() + let results: SearchResults = client.index("books").search() .with_query("science fiction") .with_sort(&["price:asc"]) .execute() .await .unwrap(); geosearch_guide_filter_settings_1: |- - let progress: Progress = restaurants.set_filterable_attributes(&["_geo"]).await.unwrap(); + let progress: Progress = client.index("restaurants").set_filterable_attributes(&["_geo"]).await.unwrap(); geosearch_guide_filter_usage_1: |- - let results: SearchResults = restaurants.search() + let results: SearchResults = client.index("restaurants").search() .with_filter("_geoRadius(45.4628328, 9.1076931, 2000)") .execute() .await .unwrap(); geosearch_guide_filter_usage_2: |- - let results: SearchResults = restaurants.search() + let results: SearchResults = client.index("restaurants").search() .with_filter("_geoRadius(45.4628328, 9.1076931, 2000) AND type = pizza") .execute() .await .unwrap(); geosearch_guide_sort_settings_1: |- - let progress: Progress = restaurants.set_sortable_attributes(&["_geo"]).await.unwrap(); + let progress: Progress = client.index("restaurants").set_sortable_attributes(&["_geo"]).await.unwrap(); geosearch_guide_sort_usage_1: |- - let results: SearchResults = restaurants.search() + let results: SearchResults = client.index("restaurants").search() .with_sort(&["_geoPoint(48.8583701,2.2922926):asc"]) .execute() .await .unwrap(); geosearch_guide_sort_usage_2: |- - let results: SearchResults = restaurants.search() + let results: SearchResults = client.index("restaurants").search() .with_sort(&["_geoPoint(48.8583701,2.2922926):asc", "rating:desc"]) .execute() .await diff --git a/README.md b/README.md index d66f2764..77fae6b8 100644 --- a/README.md +++ b/README.md @@ -85,8 +85,10 @@ NB: you can also download MeiliSearch from **Homebrew** or **APT**. ## 🚀 Getting Started +#### Add Documents + ```rust -use meilisearch_sdk::{document::*, client::*, search::*}; +use meilisearch_sdk::{document::*, client::*}; use serde::{Serialize, Deserialize}; use futures::executor::block_on; @@ -110,10 +112,10 @@ fn main() { block_on(async move { // Create a client (without sending any request so that can't fail) let client = Client::new("http://localhost:7700", "masterKey"); - // Get the index called "movies" - let movies = client.get_or_create("movies").await.unwrap(); + // An index is where the documents are stored. + let movies = client.index("movies"); - // Add some movies in the index + // Add some movies in the index. If the index 'movies' does not exist, MeiliSearch creates it when you first add the documents. movies.add_documents(&[ Movie{id: 1, title: String::from("Carol"), genres: vec!["Romance".to_string(), "Drama".to_string()]}, Movie{id: 2, title: String::from("Wonder Woman"), genres: vec!["Action".to_string(), "Adventure".to_string()]}, @@ -122,19 +124,64 @@ fn main() { block_on(async move { Movie{id: 5, title: String::from("Moana"), genres: vec!["Fantasy".to_string(), "Action".to_string()]}, Movie{id: 6, title: String::from("Philadelphia"), genres: vec!["Drama".to_string()]}, ], Some("id")).await.unwrap(); - - // Query movies (note that there is a typo) - println!("{:?}", movies.search().with_query("carol").execute::().await.unwrap().hits); })} ``` -Output: +#### Basic Search +```rust +// MeiliSearch is typo-tolerant: +println!("{:?}", client.index("movies").search().with_query("caorl").execute::().await.unwrap().hits); +``` + +Output: ``` [Movie{id: 1, title: String::from("Carol"), genres: vec!["Romance", "Drama"]}] ``` -##### Custom Search With Filters +Json output: +```json +{ + "hits": [{ + "id": 1, + "title": "Carol", + "genres": ["Romance", "Drama"] + }], + "offset": 0, + "limit": 10, + "processingTimeMs": 1, + "query": "caorl" +} +``` + +#### Custom Search + +```rust +println!("{:?}", client.index("movies").search().with_query("phil").with_attributes_to_highlight(Selectors::Some(&["*"])).execute::().await.unwrap().hits); +``` + +Json output: +```json +{ + "hits": [ + { + "id": 6, + "title": "Philadelphia", + "_formatted": { + "id": 6, + "title": "Philadelphia", + "genre": ["Drama"] + } + } + ], + "offset": 0, + "limit": 20, + "processingTimeMs": 0, + "query": "phil" +} +``` + +#### Custom Search With Filters If you want to enable filtering, you must add your attributes to the `filterableAttributes` index setting. @@ -144,7 +191,7 @@ let filterable_attributes = [ "id", "genres" ]; -movies.set_filterable_attributes(&filterable_attributes).await.unwrap(); +client.index("movies").set_filterable_attributes(&filterable_attributes).await.unwrap(); ``` You only need to perform this operation once. @@ -157,10 +204,11 @@ status](https://docs.meilisearch.com/reference/api/updates.html#get-an-update-st Then, you can perform the search: ```rust -println!("{:?}", movies.search().with_query("wonder").with_filter("id > 1 AND genres = Action") +println!("{:?}", client.index("movies").search().with_query("wonder").with_filter("id > 1 AND genres = Action") .execute::().await.unwrap().hits); ``` +Json output: ```json { "hits": [ diff --git a/examples/web_app/src/lib.rs b/examples/web_app/src/lib.rs index 24000811..8d38c680 100644 --- a/examples/web_app/src/lib.rs +++ b/examples/web_app/src/lib.rs @@ -49,10 +49,10 @@ impl Component for Model { Self { link: Rc::new(link), - // The assume_index method avoids checking the existence of the index. + // The index method avoids checking the existence of the index. // It won't make any HTTP request so the function is not async so it's easier to use. // Use only if you are sure that the index exists. - index: Rc::new(CLIENT.assume_index("crates")), + index: Rc::new(CLIENT.index("crates")), results: Vec::new(), processing_time_ms: 0, diff --git a/src/client.rs b/src/client.rs index 1f5da3e5..d81331dd 100644 --- a/src/client.rs +++ b/src/client.rs @@ -81,7 +81,7 @@ impl Client { Ok(json_indexes) } - /// Get an [index](../indexes/struct.Index.html). + /// Get an [index](../indexes/struct.Index.html), this index should already exist. /// /// # Example /// @@ -104,7 +104,7 @@ impl Client { } } - /// Get a raw JSON [index](../indexes/struct.Index.html). + /// Get a raw JSON [index](../indexes/struct.Index.html), this index should already exist. /// /// # Example /// @@ -120,17 +120,13 @@ impl Client { /// let movies = client.get_raw_index("movies").await.unwrap(); /// # }); /// ``` + /// If you use it directly from an index, you can use the method [fetch_info](#method.fetch_info), which is the equivalent method from an index. pub async fn get_raw_index(&self, uid: impl AsRef) -> Result { - Ok(request::<(), JsonIndex>( - &format!("{}/indexes/{}", self.host, uid.as_ref()), - &self.api_key, - Method::Get, - 200, - ).await?) + Index::fetch_info(&self.index(uid.as_ref())).await } - /// Assume that an [index](../indexes/struct.Index.html) exist and create a corresponding object without any check. - pub fn assume_index(&self, uid: impl Into) -> Index { + /// Create a corresponding object of an [index](../indexes/struct.Index.html) without any check or doing an HTTP call. + pub fn index(&self, uid: impl Into) -> Index { Index { uid: Rc::new(uid.into()), host: Rc::clone(&self.host), @@ -383,7 +379,18 @@ mod tests { #[async_test] async fn test_get_keys() { let client = Client::new("http://localhost:7700", "masterKey"); - client.get_keys().await.unwrap(); + let keys = client.get_keys().await.unwrap(); + assert!(keys.private.is_some()); + assert!(keys.public.is_some()); + } + + #[async_test] + async fn test_get_index() { + let client = Client::new("http://localhost:7700", "masterKey"); + let index_name = "get_index"; + client.create_index(index_name, None).await.unwrap(); + let index = client.get_index(index_name).await.unwrap(); + assert_eq!(index.uid.to_string(), index_name); } #[async_test] @@ -431,4 +438,33 @@ mod tests { let deleted = client.delete_index_if_exists("bad").await.unwrap(); assert_eq!(deleted, false); } + + #[async_test] + async fn test_fetch_info() { + let client = Client::new("http://localhost:7700", "masterKey"); + let index_name = "fetch_info"; + client.create_index(index_name, None).await.unwrap(); + let index = client.index(index_name).fetch_info().await; + assert!(index.is_ok()); + } + + #[async_test] + async fn test_get_primary_key_is_none() { + let client = Client::new("http://localhost:7700", "masterKey"); + let index_name = "get_primary_key_is_none"; + client.create_index(index_name, None).await.unwrap(); + let primary_key = client.index(index_name).get_primary_key().await; + assert!(primary_key.is_ok()); + assert!(primary_key.unwrap().is_none()); + } + + #[async_test] + async fn test_get_primary_key() { + let client = Client::new("http://localhost:7700", "masterKey"); + let index_name = "get_primary_key"; + client.create_index(index_name, Some("primary_key")).await.unwrap(); + let primary_key = client.index(index_name).get_primary_key().await; + assert!(primary_key.is_ok()); + assert_eq!(primary_key.unwrap().unwrap(), "primary_key"); + } } diff --git a/src/indexes.rs b/src/indexes.rs index 9aa7b038..5ff39b50 100644 --- a/src/indexes.rs +++ b/src/indexes.rs @@ -36,6 +36,12 @@ impl JsonIndex { /// // get the index called movies or create it if it does not exist /// let movies = client.get_or_create("movies").await.unwrap(); /// +/// // use the implicit index creation if the index already exist or +/// // MeiliSearch would be able to create the index if it does not exist during: +/// // - the documents addition (add and update routes) +/// // - the settings update +/// let movies = client.index("movies"); +/// /// // do something with the index /// # }); /// ``` @@ -71,7 +77,7 @@ impl Index { /// # client.create_index("movies", None).await; /// /// // get the index named "movies" and delete it - /// let movies = client.get_index("movies").await.unwrap(); + /// let movies = client.index("movies"); /// movies.delete().await.unwrap(); /// # }); /// ``` @@ -89,20 +95,20 @@ impl Index { /// # Example /// /// ``` - /// # use meilisearch_sdk::{client::*, indexes::*}; + /// # use meilisearch_sdk::{client::*, document::*}; /// # futures::executor::block_on(async move { /// let client = Client::new("http://localhost:7700", "masterKey"); /// client.create_index("movies", None).await; /// /// // get the index named "movies" and delete it - /// let movies = client.assume_index("movies"); + /// let movies = client.index("movies"); /// let mut deleted = movies.delete_if_exists().await.unwrap(); /// assert_eq!(deleted, true); /// let index = client.get_index("movies").await; /// assert!(index.is_err()); /// /// // get an index that doesn't exist and try to delete it - /// let no_index = client.assume_index("no_index"); + /// let no_index = client.index("no_index"); /// deleted = no_index.delete_if_exists().await.unwrap(); /// assert_eq!(deleted, false); /// # }); @@ -144,7 +150,7 @@ impl Index { /// /// # futures::executor::block_on(async move { /// let client = Client::new("http://localhost:7700", "masterKey"); - /// let mut movies = client.get_or_create("movies").await.unwrap(); + /// let movies = client.index("movies"); /// /// // add some documents /// # movies.add_or_replace(&[Movie{name:String::from("Interstellar"), description:String::from("Interstellar chronicles the adventures of a group of explorers who make use of a newly discovered wormhole to surpass the limitations on human space travel and conquer the vast distances involved in an interstellar voyage.")},Movie{name:String::from("Unknown"), description:String::from("Unknown")}], Some("name")).await.unwrap(); @@ -196,7 +202,7 @@ impl Index { /// # futures::executor::block_on(async move { /// let client = Client::new("http://localhost:7700", "masterKey"); /// # client.delete_index("movies_search").await; - /// let mut movies = client.get_or_create("movies").await.unwrap(); + /// let mut movies = client.index("movies"); /// /// // add some documents /// # movies.add_or_replace(&[Movie{name:String::from("Interstellar"), description:String::from("Interstellar chronicles the adventures of a group of explorers who make use of a newly discovered wormhole to surpass the limitations on human space travel and conquer the vast distances involved in an interstellar voyage.")},Movie{name:String::from("Unknown"), description:String::from("Unknown")}], Some("name")).await.unwrap(); @@ -242,9 +248,7 @@ impl Index { /// /// # futures::executor::block_on(async move { /// let client = Client::new("http://localhost:7700", "masterKey"); - /// # client.create_index("movies", None).await; - /// let movies = client.get_index("movies").await.unwrap(); - /// # let mut movies = client.get_index("movies").await.unwrap(); + /// let movies = client.index("movies"); /// # movies.add_or_replace(&[Movie{name:String::from("Interstellar"), description:String::from("Interstellar chronicles the adventures of a group of explorers who make use of a newly discovered wormhole to surpass the limitations on human space travel and conquer the vast distances involved in an interstellar voyage.")}], Some("name")).await.unwrap(); /// # std::thread::sleep(std::time::Duration::from_secs(1)); /// # @@ -300,9 +304,7 @@ impl Index { /// /// # futures::executor::block_on(async move { /// let client = Client::new("http://localhost:7700", "masterKey"); - /// # client.create_index("movies", None).await; - /// let movie_index = client.get_index("movies").await.unwrap(); - /// # let mut movie_index = client.get_index("movies").await.unwrap(); + /// let movie_index = client.index("movies"); /// /// # movie_index.add_or_replace(&[Movie{name:String::from("Interstellar"), description:String::from("Interstellar chronicles the adventures of a group of explorers who make use of a newly discovered wormhole to surpass the limitations on human space travel and conquer the vast distances involved in an interstellar voyage.")}], Some("name")).await.unwrap(); /// # std::thread::sleep(std::time::Duration::from_secs(1)); @@ -374,7 +376,7 @@ impl Index { /// /// # futures::executor::block_on(async move { /// let client = Client::new("http://localhost:7700", "masterKey"); - /// let mut movie_index = client.get_or_create("movies_add_or_replace").await.unwrap(); + /// let movie_index = client.index("movies_add_or_replace"); /// /// let progress = movie_index.add_or_replace(&[ /// Movie{ @@ -444,7 +446,7 @@ impl Index { /// ``` /// use serde::{Serialize, Deserialize}; /// - /// # use meilisearch_sdk::{client::*, indexes::*, document::*}; + /// # use meilisearch_sdk::{client::*, document::*}; /// # use std::thread::sleep; /// # use std::time::Duration; /// #[derive(Serialize, Deserialize, Debug)] @@ -462,7 +464,7 @@ impl Index { /// /// # futures::executor::block_on(async move { /// let client = Client::new("http://localhost:7700", "masterKey"); - /// let mut movie_index = client.get_or_create("movies_add_or_update").await.unwrap(); + /// let movie_index = client.index("movies_add_or_update"); /// /// let progress = movie_index.add_or_update(&[ /// Movie{ @@ -531,8 +533,10 @@ impl Index { /// # futures::executor::block_on(async move { /// # /// let client = Client::new("http://localhost:7700", "masterKey"); - /// let mut movie_index = client.get_or_create("movies").await.unwrap(); + /// let movie_index = client.index("movies"); /// + /// # movie_index.add_or_replace(&[Movie{name:String::from("Interstellar"), description:String::from("Interstellar chronicles the adventures of a group of explorers who make use of a newly discovered wormhole to surpass the limitations on human space travel and conquer the vast distances involved in an interstellar voyage.")}], Some("name")).await.unwrap(); + /// # std::thread::sleep(std::time::Duration::from_secs(1)); /// // add some documents /// /// let progress = movie_index.delete_all_documents().await.unwrap(); @@ -558,7 +562,7 @@ impl Index { /// /// ``` /// # use serde::{Serialize, Deserialize}; - /// # use meilisearch_sdk::{client::*, indexes::*, document::*}; + /// # use meilisearch_sdk::{client::*, document::*}; /// # /// # #[derive(Serialize, Deserialize, Debug)] /// # struct Movie { @@ -577,7 +581,7 @@ impl Index { /// # futures::executor::block_on(async move { /// # /// let client = Client::new("http://localhost:7700", "masterKey"); - /// let mut movies = client.get_or_create("movies").await.unwrap(); + /// let mut movies = client.index("movies"); /// /// # movies.add_or_replace(&[Movie{name:String::from("Interstellar"), description:String::from("Interstellar chronicles the adventures of a group of explorers who make use of a newly discovered wormhole to surpass the limitations on human space travel and conquer the vast distances involved in an interstellar voyage.")}], Some("name")).await.unwrap(); /// # std::thread::sleep(std::time::Duration::from_secs(1)); @@ -606,7 +610,7 @@ impl Index { /// /// ``` /// # use serde::{Serialize, Deserialize}; - /// # use meilisearch_sdk::{client::*, indexes::*, document::*}; + /// # use meilisearch_sdk::{client::*, document::*}; /// # /// # #[derive(Serialize, Deserialize, Debug)] /// # struct Movie { @@ -625,7 +629,7 @@ impl Index { /// # futures::executor::block_on(async move { /// # /// let client = Client::new("http://localhost:7700", "masterKey"); - /// let mut movies = client.get_or_create("movies").await.unwrap(); + /// let movies = client.index("movies"); /// /// // add some documents /// # movies.add_or_replace(&[Movie{name:String::from("Interstellar"), description:String::from("Interstellar chronicles the adventures of a group of explorers who make use of a newly discovered wormhole to surpass the limitations on human space travel and conquer the vast distances involved in an interstellar voyage.")},Movie{name:String::from("Unknown"), description:String::from("Unknown")}], Some("name")).await.unwrap(); @@ -657,6 +661,53 @@ impl Index { self.update(primary_key).await } + /// Fetch the information of the index as a raw JSON [index](../indexes/struct.Index.html), this index should already exist. + /// + /// # Example + /// + /// ``` + /// # use meilisearch_sdk::{client::*, indexes::*}; + /// + /// # futures::executor::block_on(async move { + /// // create the client + /// let client = Client::new("http://localhost:7700", "masterKey"); + /// # client.create_index("movies", None).await; + /// + /// // get the information of the index named "movies" + /// let movies = client.index("movies").fetch_info().await.unwrap(); + /// # }); + /// ``` + /// If you use it directly from the client, you can use the method [get_raw_index](#method.get_raw_index), which is the equivalent method from the client. + pub async fn fetch_info(&self) -> Result { + Ok(request::<(), JsonIndex>( + &format!("{}/indexes/{}", self.host, self.uid), + &self.api_key, + Method::Get, + 200, + ).await?) + } + + /// Fetch the primary key of the index. + /// + /// # Example + /// + /// ``` + /// # use meilisearch_sdk::{client::*, indexes::*}; + /// + /// # futures::executor::block_on(async move { + /// // create the client + /// let client = Client::new("http://localhost:7700", "masterKey"); + /// # client.create_index("movies", None).await; + /// + /// // get the primary key of the index named "movies" + /// let movies = client.index("movies").get_primary_key().await; + /// # }); + /// ``` + pub async fn get_primary_key(&self) -> Result, Error> { + Ok(self.fetch_info() + .await?.primaryKey) + } + /// Get the status of an update on the index. /// /// After executing an update, a `Progress` struct is returned, @@ -697,7 +748,7 @@ impl Index { /// # /// # futures::executor::block_on(async move { /// let client = Client::new("http://localhost:7700", "masterKey"); - /// let movies = client.get_or_create("movies_get_one_update").await.unwrap(); + /// let movies = client.index("movies_get_one_update"); /// /// let progress = movies.add_documents(&[ /// Document { id: 0, kind: "title".into(), value: "The Social Network".to_string() } @@ -768,7 +819,7 @@ impl Index { /// # /// # futures::executor::block_on(async move { /// let client = Client::new("http://localhost:7700", "masterKey"); - /// let movies = client.get_or_create("movies_get_all_updates").await.unwrap(); + /// let movies = client.index("movies_get_all_updates"); /// /// # movies.add_documents(&[ /// # Document { id: 0, kind: "title".into(), value: "The Social Network".to_string() }, diff --git a/src/lib.rs b/src/lib.rs index e3ca648e..434bb679 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,9 @@ //! # 🚀 Getting Started //! +//! ### Add Documents +//! //! ```rust -//! use meilisearch_sdk::{document::*, client::*, search::*}; +//! use meilisearch_sdk::{document::*, client::*}; //! use serde::{Serialize, Deserialize}; //! use futures::executor::block_on; //! @@ -25,10 +27,10 @@ //! // Create a client (without sending any request so that can't fail) //! let client = Client::new("http://localhost:7700", "masterKey"); //! -//! // Get the index called "movies" -//! let movies = client.get_or_create("movies").await.unwrap(); +//! // An index is where the documents are stored. +//! let movies = client.index("movies"); //! -//! // Add some movies in the index +//! // Add some movies in the index. If the index 'movies' does not exist, MeiliSearch creates it when you first add the documents. //! movies.add_documents(&[ //! Movie{id: 1, title: String::from("Carol"), genres: vec!["Romance".to_string(), "Drama".to_string()]}, //! Movie{id: 2, title: String::from("Wonder Woman"), genres: vec!["Action".to_string(), "Adventure".to_string()]}, @@ -37,19 +39,100 @@ //! Movie{id: 5, title: String::from("Moana"), genres: vec!["Fantasy".to_string(), "Action".to_string()]}, //! Movie{id: 6, title: String::from("Philadelphia"), genres: vec!["Drama".to_string()]}, //! ], Some("id")).await.unwrap(); -//! -//! // Query movies (note that there is a typo) -//! println!("{:?}", movies.search().with_query("carol").execute::().await.unwrap().hits); //! })} //! ``` //! +//! ### Basic Search +//! +//! ```rust +//! # use meilisearch_sdk::{document::*, client::*}; +//! # use serde::{Serialize, Deserialize}; +//! # use futures::executor::block_on; +//! # #[derive(Serialize, Deserialize, Debug)] +//! # struct Movie { +//! # id: usize, +//! # title: String, +//! # genres: Vec, +//! # } +//! # impl Document for Movie { +//! # type UIDType = usize; +//! # fn get_uid(&self) -> &Self::UIDType { +//! # &self.id +//! # } +//! # } +//! # fn main() { block_on(async move { +//! # let client = Client::new("http://localhost:7700", "masterKey"); +//! // MeiliSearch is typo-tolerant: +//! println!("{:?}", client.index("movies").search().with_query("caorl").execute::().await.unwrap().hits); +//! # })} +//! ``` +//! //! Output: -//! //! ```text //! [Movie{id: 1, title: String::from("Carol"), genres: vec!["Romance", "Drama"]}] //! ``` -//! -//! #### Custom Search With Filters +//! +//! Json output: +//! ```json +//! { +//! "hits": [{ +//! "id": 1, +//! "title": "Carol", +//! "genres": ["Romance", "Drama"] +//! }], +//! "offset": 0, +//! "limit": 10, +//! "processingTimeMs": 1, +//! "query": "caorl" +//! } +//! ``` +//! +//! ### Custom Search +//! +//! ```rust +//! # use meilisearch_sdk::{document::*, client::*, search::*}; +//! # use serde::{Serialize, Deserialize}; +//! # use futures::executor::block_on; +//! # #[derive(Serialize, Deserialize, Debug)] +//! # struct Movie { +//! # id: usize, +//! # title: String, +//! # genres: Vec, +//! # } +//! # impl Document for Movie { +//! # type UIDType = usize; +//! # fn get_uid(&self) -> &Self::UIDType { +//! # &self.id +//! # } +//! # } +//! # fn main() { block_on(async move { +//! # let client = Client::new("http://localhost:7700", "masterKey"); +//! println!("{:?}", client.index("movies").search().with_query("phil").with_attributes_to_highlight(Selectors::Some(&["*"])).execute::().await.unwrap().hits); +//! # })} +//! ``` +//! +//! Json output: +//! ```json +//! { +//! "hits": [ +//! { +//! "id": 6, +//! "title": "Philadelphia", +//! "_formatted": { +//! "id": 6, +//! "title": "Philadelphia", +//! "genre": ["Drama"] +//! } +//! } +//! ], +//! "offset": 0, +//! "limit": 20, +//! "processingTimeMs": 0, +//! "query": "phil" +//! } +//! ``` +//! +//! ### Custom Search With Filters //! //! If you want to enable filtering, you must add your attributes to the `filterableAttributes` //! index setting. @@ -60,12 +143,11 @@ //! # use futures::executor::block_on; //! # fn main() { block_on(async move { //! # let client = Client::new("http://localhost:7700", "masterKey"); -//! # let movies = client.get_or_create("movies").await.unwrap(); //! let filterable_attributes = [ //! "id", //! "genres" //! ]; -//! movies.set_filterable_attributes(&filterable_attributes).await.unwrap(); +//! client.index("movies").set_filterable_attributes(&filterable_attributes).await.unwrap(); //! # })} //! ``` //! @@ -110,11 +192,12 @@ //! # Movie{id: 5, title: String::from("Moana"), genres: vec!["Fantasy".to_string(), "Action".to_string()]}, //! # Movie{id: 6, title: String::from("Philadelphia"), genres: vec!["Drama".to_string()]}, //! # ], Some("id")).await.unwrap(); -//! println!("{:?}", movies.search().with_query("wonder").with_filter("id > 1 AND genres = Action") +//! println!("{:?}", client.index("movies").search().with_query("wonder").with_filter("id > 1 AND genres = Action") //! .execute::().await.unwrap().hits); //! # })} //! ``` //! +//! Json output: //! ```json //! { //! "hits": [ @@ -132,6 +215,7 @@ //! } //! ``` + #![warn(clippy::all)] #![allow(clippy::needless_doctest_main)] diff --git a/src/progress.rs b/src/progress.rs index 7a0f8cc5..066bfa7c 100644 --- a/src/progress.rs +++ b/src/progress.rs @@ -100,7 +100,7 @@ impl<'a> Progress { /// # /// # futures::executor::block_on(async move { /// let client = Client::new("http://localhost:7700", "masterKey"); - /// let movies = client.create_index("movies_wait_for_pending", None).await.unwrap(); + /// let movies = client.index("movies_wait_for_pending"); /// /// let progress = movies.add_documents(&[ /// Document { id: 0, kind: "title".into(), value: "The Social Network".to_string() }, @@ -297,7 +297,7 @@ mod test { #[async_test] async fn test_wait_for_pending_updates_with_args() { let client = Client::new("http://localhost:7700", "masterKey"); - let movies = client.get_or_create("movies_wait_for_pending_args").await.unwrap(); + let movies = client.index("movies_wait_for_pending_args"); let progress = movies.add_documents(&[ Document { id: 0, @@ -321,7 +321,7 @@ mod test { #[async_test] async fn test_wait_for_pending_updates_time_out() { let client = Client::new("http://localhost:7700", "masterKey"); - let movies = client.get_or_create("movies_wait_for_pending_timeout").await.unwrap(); + let movies = client.index("movies_wait_for_pending_timeout"); let progress = movies.add_documents(&[ Document { id: 0, @@ -365,7 +365,7 @@ mod test { #[async_test] async fn test_failing_update() { let client = Client::new("http://localhost:7700", "masterKey"); - let movies = client.get_or_create("movies_wait_for_pending_timeout").await.unwrap(); + let movies = client.index("movies_wait_for_pending_timeout"); let progress = movies.set_ranking_rules(["wrong_ranking_rule"]).await.unwrap(); let status = progress.wait_for_pending_update( Some(Duration::from_millis(1)), Some(Duration::from_nanos(1)) diff --git a/src/search.rs b/src/search.rs index e9d4a721..7cdb1d17 100644 --- a/src/search.rs +++ b/src/search.rs @@ -103,7 +103,7 @@ type AttributeToCrop<'a> = (&'a str, Option); /// ``` /// # use meilisearch_sdk::{client::Client, search::Query, indexes::Index}; /// # let client = Client::new("http://localhost:7700", "masterKey"); -/// # let index = client.assume_index("does not matter"); +/// # let index = client.index("does not matter"); /// let query = Query::new(&index) /// .with_query("space") /// .with_offset(42) @@ -114,7 +114,7 @@ type AttributeToCrop<'a> = (&'a str, Option); /// ``` /// # use meilisearch_sdk::{client::Client, search::Query, indexes::Index}; /// # let client = Client::new("http://localhost:7700", "masterKey"); -/// # let index = client.assume_index("does not matter"); +/// # let index = client.index("does not matter"); /// let query = index.search() /// .with_query("space") /// .with_offset(42)