1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
//! # 🔧 Installation //! //! To use `meilisearch-sdk`, add this to your `Cargo.toml`: //! //! ```toml //! [dependencies] //! meilisearch-sdk = "0.3.0" //! ``` //! //! The following optional dependencies may also be useful: //! //! ```toml //! tokio = { version = "0.2", features = ["macros"] } //! serde = { version = "1.0", features = ["derive"] } //! ``` //! //! Since this crate is async, you have to run your program in the [tokio](https://crates.io/crates/tokio) runtime. When targetting Wasm, the browser will replace tokio. //! //! Using this crate is possible without [serde](https://crates.io/crates/serde), but a lot of features require serde. //! //! ## Run a MeiliSearch Instance //! //! This crate requires a MeiliSearch server to run. //! //! There are many easy ways to [download and run a MeiliSearch instance](https://docs.meilisearch.com/guides/advanced_guides/installation.html#download-and-launch). //! //! For example, if you use Docker: //! ```bash //! $ docker pull getmeili/meilisearch:latest # Fetch the latest version of MeiliSearch image from Docker Hub //! $ docker run -it --rm -p 7700:7700 getmeili/meilisearch:latest ./meilisearch --master-key=masterKey //! ``` //! //! NB: you can also download MeiliSearch from **Homebrew** or **APT**. //! //! # 🚀 Getting Started //! //! ``` //! use meilisearch_sdk::{document::*, client::*, search::*}; //! use serde::{Serialize, Deserialize}; //! //! #[derive(Serialize, Deserialize, Debug)] //! 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 //! } //! } //! //! #[tokio::main] //! async fn main() { //! // Create a client (without sending any request so that can't fail) //! let client = Client::new("http://localhost:7700", "masterKey"); //! //! // Get the index called "books" //! let books = client.get_or_create("books").await.unwrap(); //! //! // Add some books in the index //! books.add_documents(&[ //! Book{book_id: 123, title: String::from("Pride and Prejudice")}, //! Book{book_id: 456, title: String::from("Le Petit Prince")}, //! Book{book_id: 1, title: String::from("Alice In Wonderland")}, //! Book{book_id: 1344, title: String::from("The Hobbit")}, //! Book{book_id: 4, title: String::from("Harry Potter and the Half-Blood Prince")}, //! Book{book_id: 42, title: String::from("The Hitchhiker's Guide to the Galaxy")}, //! ], Some("book_id")).await.unwrap(); //! //! // Query books (note that there is a typo) //! let query = Query::new("harry pottre"); //! println!("{:?}", books.search::<Book>(&query).await.unwrap().hits); //! } //! ``` //! //! Output: //! //! ```text //! [Book { book_id: 4, title: "Harry Potter and the Half-Blood Prince" }] //! ``` //! //! ## 🌐 Running in the Browser with WASM //! //! This crate fully supports WASM. //! //! The only difference between the WASM and the native version is that the native version has one more variant (`Error::Http`) in the Error enum. That should not matter so much but we could add this variant in WASM too. //! //! However, making a program intended to run in a web browser requires a **very** different design than a CLI program. To see an example of a simple Rust web app using MeiliSearch, see the [tutorial (not available yet)](). //! //! WARNING: `meilisearch-sdk` will panic if no Window is available (ex: Web extension). /// Module containing the Client struct. pub mod client; /// Module containing the Document trait. pub mod document; /// Module containing the Error struct. pub mod errors; /// Module containing the Index struct. pub mod indexes; /// Module containing objects useful for tracking the progress of async operations. pub mod progress; mod request; /// Module related to search queries and results. pub mod search; /// Module containing settings pub mod settings;