MeiliSearch Rust is a client for MeiliSearch written in Rust. MeiliSearch is a powerful, fast, open-source, easy to use and deploy search engine. Both searching and indexing are highly customizable. Features such as typo-tolerance, filters, and synonyms are provided out-of-the-box.
This crate requires a MeiliSearch server to run. See here to install and run MeiliSearch.
Then, put meilisearch-sdk = "0.1"
in your Cargo.toml, as usual.
Using this crate is possible without serde, but a lot of features require serde.
Add serde = {version="1.0", features=["derive"]}
in your Cargo.toml.
Here is a quickstart for a search request (please follow the installation steps before)
```rust use meilisearch_sdk::{document::, indexes::, client::, search::}; use serde::{Serialize, Deserialize};
struct Book { book_id: usize, title: String, }
// That trait is required to make a struct usable by an index impl Document for Book { type UIDType = usize;
fn get_uid(&self) -> &Self::UIDType {
&self.book_id
}
}
// Create a client (without sending any request so that can't fail) let client = Client::new("http://localhost:7700", "");
// Get the index called "books" let mut books = client.getorcreate("books").unwrap();
// Add some books in the index books.adddocuments(vec![ Book{bookid: 123, title: String::from("Pride and Prejudice")}, Book{bookid: 456, title: String::from("Le Petit Prince")}, Book{bookid: 1, title: String::from("Alice In Wonderland")}, Book{bookid: 1344, title: String::from("The Hobbit")}, Book{bookid: 4, title: String::from("Harry Potter and the Half-Blood Prince")}, Book{bookid: 42, title: String::from("The Hitchhiker's Guide to the Galaxy")}, ], Some("bookid")).unwrap();
// Query books (note that there is a typo)
let query = Query::new("harry pottre");
println!("{:?}", books.search::
Output:
rust
[Book { book_id: 4, title: "Harry Potter and the Half-Blood Prince" }]
This crate is currently supporting MeiliSearch v10.0 and will be maintained.
All the tests are documentation tests.
Since they are all making operations on the MeiliSearch server, running all the tests simultaneously would cause panics.
To run the tests one by one, run cargo test -- --test-threads=1
.