[−][src]Struct meilisearch_sdk::indexes::Index
An index containing Documents.
Example
let client = Client::new("http://localhost:7700", "masterKey"); // get the index called movies or create it if it does not exist let movies = client.get_or_create("movies").await.unwrap(); // do something with the index
Implementations
impl<'a> Index<'a>[src]
pub async fn update<'_, '_>(&'_ self, primary_key: &'_ str) -> Result<(), Error>[src]
Set the primary key of the index.
If you prefer, you can use the method set_primary_key, which is an alias.
pub async fn delete(self) -> Result<(), Error>[src]
Delete the index.
Example
let client = Client::new("http://localhost:7700", "masterKey"); // get the index named "movies" and delete it let movies = client.get_index("movies").await.unwrap(); movies.delete().await.unwrap();
pub async fn execute_query<T: 'static + DeserializeOwned, '_, '_, '_>(
&'_ self,
query: &'_ Query<'_>
) -> Result<SearchResults<T>, Error>[src]
&'_ self,
query: &'_ Query<'_>
) -> Result<SearchResults<T>, Error>
Search for documents matching a specific query in the index.
See also the search method.
Example
use serde::{Serialize, Deserialize}; #[derive(Serialize, Deserialize, Debug)] struct Movie { name: String, description: String, } // that trait is used by the sdk when the primary key is needed impl Document for Movie { type UIDType = String; fn get_uid(&self) -> &Self::UIDType { &self.name } } let client = Client::new("http://localhost:7700", "masterKey"); let mut movies = client.get_or_create("movies").await.unwrap(); // add some documents let query = Query::new(&movies).with_query("Interstellar").with_limit(5).build(); let results = movies.execute_query::<Movie>(&query).await.unwrap();
pub fn search(&self) -> Query<'_>[src]
Search for documents matching a specific query in the index.
See also the execute_query method.
Example
use serde::{Serialize, Deserialize}; #[derive(Serialize, Deserialize, Debug)] struct Movie { name: String, description: String, } // that trait is used by the sdk when the primary key is needed impl Document for Movie { type UIDType = String; fn get_uid(&self) -> &Self::UIDType { &self.name } } let client = Client::new("http://localhost:7700", "masterKey"); let mut movies = client.get_or_create("movies").await.unwrap(); // add some documents let results = movies.search() .with_query("Interstellar") .with_limit(5) .execute::<Movie>() .await .unwrap();
pub async fn get_document<T: 'static + Document, '_>(
&'_ self,
uid: T::UIDType
) -> Result<T, Error>[src]
&'_ self,
uid: T::UIDType
) -> Result<T, Error>
Get one document using its unique id.
Serde is needed. Add serde = {version="1.0", features=["derive"]} in the dependencies section of your Cargo.toml.
Example
use serde::{Serialize, Deserialize}; #[derive(Serialize, Deserialize, Debug)] struct Movie { name: String, description: String, } // that trait is used by the sdk when the primary key is needed impl Document for Movie { type UIDType = String; fn get_uid(&self) -> &Self::UIDType { &self.name } } let client = Client::new("http://localhost:7700", "masterKey"); let movies = client.get_index("movies").await.unwrap(); // retrieve a document (you have to put the document in the index before) let interstellar = movies.get_document::<Movie>(String::from("Interstellar")).await.unwrap(); assert_eq!(interstellar, 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.") });
pub async fn get_documents<T: 'static + Document, '_, '_>(
&'_ self,
offset: Option<usize>,
limit: Option<usize>,
attributes_to_retrieve: Option<&'_ str>
) -> Result<Vec<T>, Error>[src]
&'_ self,
offset: Option<usize>,
limit: Option<usize>,
attributes_to_retrieve: Option<&'_ str>
) -> Result<Vec<T>, Error>
Get documents by batch.
Using the optional parameters offset and limit, you can browse through all your documents. If None, offset will be set to 0, limit to 20, and all attributes will be retrieved.
Note: Documents are ordered by MeiliSearch depending on the hash of their id.
Example
use serde::{Serialize, Deserialize}; #[derive(Serialize, Deserialize, Debug)] struct Movie { name: String, description: String, } // that trait is used by the sdk when the primary key is needed impl Document for Movie { type UIDType = String; fn get_uid(&self) -> &Self::UIDType { &self.name } } let client = Client::new("http://localhost:7700", "masterKey"); let movie_index = client.get_index("movies").await.unwrap(); // retrieve movies (you have to put some movies in the index before) let movies = movie_index.get_documents::<Movie>(None, None, None).await.unwrap(); assert!(movies.len() > 0);
pub async fn add_or_replace<T: Document, '_, '_>(
&'a self,
documents: &'_ [T],
primary_key: Option<&'_ str>
) -> Result<Progress<'a>, Error>[src]
&'a self,
documents: &'_ [T],
primary_key: Option<&'_ str>
) -> Result<Progress<'a>, Error>
Add a list of documents or replace them if they already exist.
If you send an already existing document (same id) the whole existing document will be overwritten by the new document. Fields previously in the document not present in the new document are removed.
For a partial update of the document see add_or_update.
You can use the alias add_documents if you prefer.
Example
use serde::{Serialize, Deserialize}; #[derive(Serialize, Deserialize, Debug)] struct Movie { name: String, description: String, } // that trait is used by the sdk when the primary key is needed impl Document for Movie { type UIDType = String; fn get_uid(&self) -> &Self::UIDType { &self.name } } let client = Client::new("http://localhost:7700", "masterKey"); let mut movie_index = client.get_or_create("movies").await.unwrap(); 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.") }, Movie{ // note that the id field can only take alphanumerics characters (and '-' and '/') name: String::from("MrsDoubtfire"), description: String::from("Loving but irresponsible dad Daniel Hillard, estranged from his exasperated spouse, is crushed by a court order allowing only weekly visits with his kids. When Daniel learns his ex needs a housekeeper, he gets the job -- disguised as an English nanny. Soon he becomes not only his children's best pal but the kind of parent he should have been from the start.") }, Movie{ name: String::from("Apollo13"), description: String::from("The true story of technical troubles that scuttle the Apollo 13 lunar mission in 1971, risking the lives of astronaut Jim Lovell and his crew, with the failed journey turning into a thrilling saga of heroism. Drifting more than 200,000 miles from Earth, the astronauts work furiously with the ground crew to avert tragedy.") }, ], Some("name")).await.unwrap(); sleep(Duration::from_secs(1)); // MeiliSearch may take some time to execute the request // retrieve movies (you have to put some movies in the index before) let movies = movie_index.get_documents::<Movie>(None, None, None).await.unwrap(); assert!(movies.len() >= 3);
pub async fn add_documents<T: Document, '_, '_>(
&'a self,
documents: &'_ [T],
primary_key: Option<&'_ str>
) -> Result<Progress<'a>, Error>[src]
&'a self,
documents: &'_ [T],
primary_key: Option<&'_ str>
) -> Result<Progress<'a>, Error>
Alias for add_or_replace.
pub async fn add_or_update<T: Document, '_, '_>(
&'a self,
documents: &'_ [T],
primary_key: Option<&'_ str>
) -> Result<Progress<'a>, Error>[src]
&'a self,
documents: &'_ [T],
primary_key: Option<&'_ str>
) -> Result<Progress<'a>, Error>
Add a list of documents and update them if they already.
If you send an already existing document (same id) the old document will be only partially updated according to the fields of the new document. Thus, any fields not present in the new document are kept and remained unchanged.
To completely overwrite a document, check out the add_and_replace documents method.
Example
use serde::{Serialize, Deserialize}; #[derive(Serialize, Deserialize, Debug)] struct Movie { name: String, description: String, } // that trait is used by the sdk when the primary key is needed impl Document for Movie { type UIDType = String; fn get_uid(&self) -> &Self::UIDType { &self.name } } let client = Client::new("http://localhost:7700", "masterKey"); let mut movie_index = client.get_or_create("movies").await.unwrap(); movie_index.add_or_update(&[ 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{ // note that the id field can only take alphanumerics characters (and '-' and '/') name: String::from("MrsDoubtfire"), description: String::from("Loving but irresponsible dad Daniel Hillard, estranged from his exasperated spouse, is crushed by a court order allowing only weekly visits with his kids. When Daniel learns his ex needs a housekeeper, he gets the job -- disguised as an English nanny. Soon he becomes not only his children's best pal but the kind of parent he should have been from the start.") }, Movie{ name: String::from("Apollo13"), description: String::from("The true story of technical troubles that scuttle the Apollo 13 lunar mission in 1971, risking the lives of astronaut Jim Lovell and his crew, with the failed journey turning into a thrilling saga of heroism. Drifting more than 200,000 miles from Earth, the astronauts work furiously with the ground crew to avert tragedy.") }, ], Some("name")).await.unwrap(); sleep(Duration::from_secs(1)); // MeiliSearch may take some time to execute the request // retrieve movies (you have to put some movies in the index before) let movies = movie_index.get_documents::<Movie>(None, None, None).await.unwrap(); assert!(movies.len() >= 3);
pub async fn delete_all_documents(&'a self) -> Result<Progress<'a>, Error>[src]
Delete all documents in the index.
Example
let client = Client::new("http://localhost:7700", "masterKey"); let mut movie_index = client.get_or_create("movies").await.unwrap(); // add some documents movie_index.delete_all_documents().await.unwrap();
pub async fn delete_document<T: Display>(
&'a self,
uid: T
) -> Result<Progress<'a>, Error>[src]
&'a self,
uid: T
) -> Result<Progress<'a>, Error>
Delete one document based on its unique id.
Example
let client = Client::new("http://localhost:7700", "masterKey"); let mut movies = client.get_or_create("movies").await.unwrap(); // add a document with id = Interstellar movies.delete_document("Interstellar").await.unwrap();
pub async fn delete_documents<T: Display + Serialize + Debug, '_>(
&'a self,
uids: &'_ [T]
) -> Result<Progress<'a>, Error>[src]
&'a self,
uids: &'_ [T]
) -> Result<Progress<'a>, Error>
Delete a selection of documents based on array of document id's.
Example
let client = Client::new("http://localhost:7700", "masterKey"); let mut movies = client.get_or_create("movies").await.unwrap(); // add some documents // delete some documents movies.delete_documents(&["Interstellar", "Unknown"]).await.unwrap();
pub async fn set_primary_key<'_, '_>(
&'_ self,
primary_key: &'_ str
) -> Result<(), Error>[src]
&'_ self,
primary_key: &'_ str
) -> Result<(), Error>
Alias for the update method.
pub async fn get_stats<'_>(&'_ self) -> Result<IndexStats, Error>[src]
Get stats of an index.
Example
let client = Client::new("http://localhost:7700", "masterKey"); let movies = client.get_or_create("movies").await.unwrap(); let stats = movies.get_stats().await.unwrap();
impl<'a> Index<'a>[src]
pub async fn get_settings<'_>(&'_ self) -> Result<Settings, Error>[src]
Get settings of the Index.
let client = Client::new("http://localhost:7700", "masterKey"); let movie_index = client.get_or_create("movies").await.unwrap(); let settings = movie_index.get_settings().await.unwrap();
pub async fn get_synonyms<'_>(
&'_ self
) -> Result<HashMap<String, Vec<String>>, Error>[src]
&'_ self
) -> Result<HashMap<String, Vec<String>>, Error>
Get synonyms of the Index.
let client = Client::new("http://localhost:7700", "masterKey"); let movie_index = client.get_or_create("movies").await.unwrap(); let synonyms = movie_index.get_synonyms().await.unwrap();
pub async fn get_stop_words<'_>(&'_ self) -> Result<Vec<String>, Error>[src]
Get stop-words of the Index.
let client = Client::new("http://localhost:7700", "masterKey"); let movie_index = client.get_or_create("movies").await.unwrap(); let stop_words = movie_index.get_stop_words().await.unwrap();
pub async fn get_ranking_rules<'_>(&'_ self) -> Result<Vec<String>, Error>[src]
Get ranking rules of the Index.
let client = Client::new("http://localhost:7700", "masterKey"); let movie_index = client.get_or_create("movies").await.unwrap(); let ranking_rules = movie_index.get_ranking_rules().await.unwrap();
pub async fn get_attributes_for_faceting<'_>(
&'_ self
) -> Result<Vec<String>, Error>[src]
&'_ self
) -> Result<Vec<String>, Error>
Get attributes for faceting of the Index.
let client = Client::new("http://localhost:7700", "masterKey"); let movie_index = client.get_or_create("movies").await.unwrap(); let attributes_for_faceting = movie_index.get_attributes_for_faceting().await.unwrap();
pub async fn get_distinct_attribute<'_>(
&'_ self
) -> Result<Option<String>, Error>[src]
&'_ self
) -> Result<Option<String>, Error>
Get the distinct attribute of the Index.
let client = Client::new("http://localhost:7700", "masterKey"); let movie_index = client.get_or_create("movies").await.unwrap(); let distinct_attribute = movie_index.get_distinct_attribute().await.unwrap();
pub async fn get_searchable_attributes<'_>(
&'_ self
) -> Result<Vec<String>, Error>[src]
&'_ self
) -> Result<Vec<String>, Error>
Get searchable attributes of the Index.
let client = Client::new("http://localhost:7700", "masterKey"); let movie_index = client.get_or_create("movies").await.unwrap(); let searchable_attributes = movie_index.get_searchable_attributes().await.unwrap();
pub async fn get_displayed_attributes<'_>(
&'_ self
) -> Result<Vec<String>, Error>[src]
&'_ self
) -> Result<Vec<String>, Error>
Get displayed attributes of the Index.
let client = Client::new("http://localhost:7700", "masterKey"); let movie_index = client.get_or_create("movies").await.unwrap(); let displayed_attributes = movie_index.get_displayed_attributes().await.unwrap();
pub async fn set_settings<'_>(
&'a self,
settings: &'_ Settings
) -> Result<Progress<'a>, Error>[src]
&'a self,
settings: &'_ Settings
) -> Result<Progress<'a>, Error>
Update settings of the index. Updates in the settings are partial. This means that any parameters corresponding to a None value will be left unchanged.
Example
let client = Client::new("http://localhost:7700", "masterKey"); let mut movie_index = client.get_or_create("movies").await.unwrap(); let stop_words = vec![String::from("a"), String::from("the"), String::from("of")]; let settings = Settings::new() .with_stop_words(stop_words.clone()); let progress = movie_index.set_settings(&settings).await.unwrap();
pub async fn set_synonyms<'_>(
&'a self,
synonyms: &'_ HashMap<String, Vec<String>>
) -> Result<Progress<'a>, Error>[src]
&'a self,
synonyms: &'_ HashMap<String, Vec<String>>
) -> Result<Progress<'a>, Error>
Update synonyms of the index.
Example
let client = Client::new("http://localhost:7700", "masterKey"); let mut movie_index = client.get_or_create("movies").await.unwrap(); 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 = movie_index.set_synonyms(&synonyms).await.unwrap();
pub async fn set_stop_words<'_, '_>(
&'a self,
stop_words: &'_ [&'_ str]
) -> Result<Progress<'a>, Error>[src]
&'a self,
stop_words: &'_ [&'_ str]
) -> Result<Progress<'a>, Error>
Update stop-words of the index.
Example
let client = Client::new("http://localhost:7700", "masterKey"); let mut movie_index = client.get_or_create("movies").await.unwrap(); let stop_words = &["the", "of", "to"]; let progress = movie_index.set_stop_words(stop_words).await.unwrap();
pub async fn set_ranking_rules<'_, '_>(
&'a self,
ranking_rules: &'_ [&'_ str]
) -> Result<Progress<'a>, Error>[src]
&'a self,
ranking_rules: &'_ [&'_ str]
) -> Result<Progress<'a>, Error>
Update ranking rules of the index.
Example
let client = Client::new("http://localhost:7700", "masterKey"); let mut movie_index = client.get_or_create("movies").await.unwrap(); let ranking_rules = &[ "typo", "words", "proximity", "attribute", "wordsPosition", "exactness", "asc(release_date)", "desc(rank)", ]; let progress = movie_index.set_ranking_rules(ranking_rules).await.unwrap();
pub async fn set_attributes_for_faceting<'_, '_>(
&'a self,
attributes_for_faceting: &'_ [&'_ str]
) -> Result<Progress<'a>, Error>[src]
&'a self,
attributes_for_faceting: &'_ [&'_ str]
) -> Result<Progress<'a>, Error>
Update attributes for faceting of the index.
Example
let client = Client::new("http://localhost:7700", "masterKey"); let mut movie_index = client.get_or_create("movies").await.unwrap(); let attributes_for_faceting = &["genre", "director"]; let progress = movie_index.set_attributes_for_faceting(attributes_for_faceting).await.unwrap();
pub async fn set_distinct_attribute<'_>(
&'a self,
distinct_attribute: &'_ str
) -> Result<Progress<'a>, Error>[src]
&'a self,
distinct_attribute: &'_ str
) -> Result<Progress<'a>, Error>
Update the distinct attribute of the index.
Example
let client = Client::new("http://localhost:7700", "masterKey"); let mut movie_index = client.get_or_create("movies").await.unwrap(); let progress = movie_index.set_distinct_attribute("movie_id").await.unwrap();
pub async fn set_searchable_attributes<'_, '_>(
&'a self,
searchable_attributes: &'_ [&'_ str]
) -> Result<Progress<'a>, Error>[src]
&'a self,
searchable_attributes: &'_ [&'_ str]
) -> Result<Progress<'a>, Error>
Update searchable attributes of the index.
Example
let client = Client::new("http://localhost:7700", "masterKey"); let mut movie_index = client.get_or_create("movies").await.unwrap(); let progress = movie_index.set_searchable_attributes(&["title", "description", "uid"]).await.unwrap();
pub async fn set_displayed_attributes<'_, '_>(
&'a self,
displayed_attributes: &'_ [&'_ str]
) -> Result<Progress<'a>, Error>[src]
&'a self,
displayed_attributes: &'_ [&'_ str]
) -> Result<Progress<'a>, Error>
Update displayed attributes of the index.
Example
let client = Client::new("http://localhost:7700", "masterKey"); let mut movie_index = client.get_or_create("movies").await.unwrap(); let progress = movie_index.set_displayed_attributes(&["title", "description", "release_date", "rank", "poster"]).await.unwrap();
pub async fn reset_settings(&'a self) -> Result<Progress<'a>, Error>[src]
Reset settings of the index. All settings will be reset to their default value.
Example
let client = Client::new("http://localhost:7700", "masterKey"); let mut movie_index = client.get_or_create("movies").await.unwrap(); let progress = movie_index.reset_settings().await.unwrap();
pub async fn reset_synonyms(&'a self) -> Result<Progress<'a>, Error>[src]
Reset synonyms of the index.
Example
let client = Client::new("http://localhost:7700", "masterKey"); let mut movie_index = client.get_or_create("movies").await.unwrap(); let progress = movie_index.reset_synonyms().await.unwrap();
pub async fn reset_stop_words(&'a self) -> Result<Progress<'a>, Error>[src]
Reset stop-words of the index.
Example
let client = Client::new("http://localhost:7700", "masterKey"); let mut movie_index = client.get_or_create("movies").await.unwrap(); let progress = movie_index.reset_stop_words().await.unwrap();
pub async fn reset_ranking_rules(&'a self) -> Result<Progress<'a>, Error>[src]
Reset ranking rules of the index to default value. Default value: ["typo", "words", "proximity", "attribute", "wordsPosition", "exactness"].
Example
let client = Client::new("http://localhost:7700", "masterKey"); let mut movie_index = client.get_or_create("movies").await.unwrap(); let progress = movie_index.reset_ranking_rules().await.unwrap();
pub async fn reset_attributes_for_faceting(
&'a self
) -> Result<Progress<'a>, Error>[src]
&'a self
) -> Result<Progress<'a>, Error>
Reset attributes for faceting of the index.
Example
let client = Client::new("http://localhost:7700", "masterKey"); let mut movie_index = client.get_or_create("movies").await.unwrap(); let progress = movie_index.reset_attributes_for_faceting().await.unwrap();
pub async fn reset_distinct_attribute(&'a self) -> Result<Progress<'a>, Error>[src]
Reset the distinct attribute of the index.
Example
let client = Client::new("http://localhost:7700", "masterKey"); let mut movie_index = client.get_or_create("movies").await.unwrap(); let progress = movie_index.reset_distinct_attribute().await.unwrap();
pub async fn reset_searchable_attributes(
&'a self
) -> Result<Progress<'a>, Error>[src]
&'a self
) -> Result<Progress<'a>, Error>
Reset searchable attributes of the index (enable all attributes).
Example
let client = Client::new("http://localhost:7700", "masterKey"); let mut movie_index = client.get_or_create("movies").await.unwrap(); let progress = movie_index.reset_searchable_attributes().await.unwrap();
pub async fn reset_displayed_attributes(&'a self) -> Result<Progress<'a>, Error>[src]
Reset displayed attributes of the index (enable all attributes).
Example
let client = Client::new("http://localhost:7700", "masterKey"); let mut movie_index = client.get_or_create("movies").await.unwrap(); let progress = movie_index.reset_displayed_attributes().await.unwrap();
Trait Implementations
Auto Trait Implementations
impl<'a> RefUnwindSafe for Index<'a>
impl<'a> Send for Index<'a>
impl<'a> Sync for Index<'a>
impl<'a> Unpin for Index<'a>
impl<'a> UnwindSafe for Index<'a>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T[src]
impl<T> From<T> for T[src]
impl<T> Instrument for T[src]
fn instrument(self, span: Span) -> Instrumented<Self>[src]
fn in_current_span(self) -> Instrumented<Self>[src]
impl<T> Instrument for T[src]
fn instrument(self, span: Span) -> Instrumented<Self>[src]
fn in_current_span(self) -> Instrumented<Self>[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,