[][src]Struct meilisearch_sdk::indexes::Index

pub struct Index<'a> { /* fields omitted */ }

An index containing Documents.

Example

let client = Client::new("http://localhost:7700", "");

// get the index called movies or create it if it does not exist
let movies = client.get_or_create("movies").unwrap();

// do something with the index

Implementations

impl<'a> Index<'a>[src]

pub fn update(&mut 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 fn delete(self) -> Result<(), Error>[src]

Delete the index.

Example

let client = Client::new("http://localhost:7700", "");

// get the index named "movies" and delete it
let movies = client.get_index("movies").unwrap();
movies.delete().unwrap();

pub fn search<T: 'static + DeserializeOwned>(
    &self,
    query: &Query
) -> Result<SearchResults<T>, Error>
[src]

Search for documents matching a specific query in the index.

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", "");
let mut movies = client.get_or_create("movies").unwrap();

// add some documents

let query = Query::new("Interstellar").with_limit(5);
let results = movies.search::<Movie>(&query).unwrap();

pub fn get_document<T: 'static + Document>(
    &self,
    uid: T::UIDType
) -> Result<T, Error>
[src]

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};

let client = Client::new("http://localhost:7700", "");
let movies = client.get_index("movies").unwrap();

#[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
   }
}

// retrieve a document (you have to put the document in the index before)
let interstellar = movies.get_document::<Movie>(String::from("Interstellar")).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 fn get_documents<T: 'static + Document>(
    &self,
    offset: Option<usize>,
    limit: Option<usize>,
    attributes_to_retrieve: Option<&str>
) -> Result<Vec<T>, Error>
[src]

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};

let client = Client::new("http://localhost:7700", "");
let movie_index = client.get_index("movies").unwrap();

#[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
   }
}

// retrieve movies (you have to put some movies in the index before)
let movies = movie_index.get_documents::<Movie>(None, None, None).unwrap();

assert!(movies.len() > 0);

pub fn add_or_replace<T: Document>(
    &mut self,
    documents: Vec<T>,
    primary_key: Option<&str>
) -> Result<Progress, Error>
[src]

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};

let client = Client::new("http://localhost:7700", "");
let mut movie_index = client.get_or_create("movies").unwrap();

#[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
   }
}

movie_index.add_or_replace(vec![
    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")).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).unwrap();
assert!(movies.len() >= 3);

pub fn add_documents<T: Document>(
    &mut self,
    documents: Vec<T>,
    primary_key: Option<&str>
) -> Result<Progress, Error>
[src]

Alias for add_or_replace.

pub fn add_or_update<T: Document>(
    &mut self,
    documents: Vec<T>,
    primary_key: Option<&str>
) -> Result<Progress, Error>
[src]

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};

let client = Client::new("http://localhost:7700", "");
let mut movie_index = client.get_or_create("movies").unwrap();

#[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
   }
}

movie_index.add_or_update(vec![
    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")).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).unwrap();
assert!(movies.len() >= 3);

pub fn delete_all_documents(&mut self) -> Result<Progress, Error>[src]

Delete all documents in the index.

Example

let client = Client::new("http://localhost:7700", "");
let mut movie_index = client.get_or_create("movies").unwrap();

// add some documents

movie_index.delete_all_documents().unwrap();

pub fn delete_document<T: Display>(&mut self, uid: T) -> Result<Progress, Error>[src]

Delete one document based on its unique id.

Example

let client = Client::new("http://localhost:7700", "");
let mut movies = client.get_or_create("movies").unwrap();

// add a document with id = Interstellar

movies.delete_document("Interstellar").unwrap();

pub fn delete_documents<T: Display + Serialize + Debug>(
    &mut self,
    uids: Vec<T>
) -> Result<Progress, Error>
[src]

Delete a selection of documents based on array of document id's.

Example

let client = Client::new("http://localhost:7700", "");
let mut movies = client.get_or_create("movies").unwrap();

// add some documents

// delete some documents
movies.delete_documents(vec!["Interstellar", "Unknown"]).unwrap();

pub fn get_settings(&self) -> Result<Settings, Error>[src]

Get the settings of the Index.

let client = Client::new("http://localhost:7700", "");
let movie_index = client.get_or_create("movies").unwrap();
let settings = movie_index.get_settings().unwrap();

pub fn set_settings(&mut self, settings: &Settings) -> Result<Progress, Error>[src]

Update the 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", "");
let mut movie_index = client.get_or_create("movies").unwrap();

let stop_words = vec![String::from("a"), String::from("the"), String::from("of")];
let settings = Settings::new()
    .with_stop_words(stop_words.clone())
    .with_accept_new_fields(false);

let progress = movie_index.set_settings(&settings).unwrap();

pub fn reset_settings(&mut self) -> Result<Progress, Error>[src]

Reset the settings of the index.
All settings will be reset to their default value.

Example

let client = Client::new("http://localhost:7700", "");
let mut movie_index = client.get_or_create("movies").unwrap();

let progress = movie_index.reset_settings().unwrap();

pub fn set_primary_key(&mut self, primary_key: &str) -> Result<(), Error>[src]

Alias for the update method.

Trait Implementations

impl<'a> Debug for Index<'a>[src]

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]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.