use meilisearch_sdk::client::*; use meilisearch_sdk::search::*; use serde::{Serialize, Deserialize}; #[derive(Deserialize, Serialize, Debug, Clone)] pub struct BookMeili { pub id: i32, pub open_library_key: String, pub title: String, pub edition_count: i32, pub first_publish_year: i32, pub median_page_count: i32, pub goodread_id: String, pub description: String, pub cover: String, pub location: String, pub time_added: String, pub rating: i32, pub comments: String, pub author_name: Vec, pub person: Vec, pub place: Vec, pub subject: Vec, pub time: Vec, pub isbn: Vec, } pub async fn create_or_update_book(book: BookMeili, client: &Client) { // An index is where the documents are stored. let books = client.index("books"); // Add some movies in the index. If the index 'movies' does not exist, Meilisearch creates it when you first add the documents. books.add_or_replace(&[ book ], Some("id")).await.unwrap(); } pub async fn delete_book(bookid: i32, client: &Client) { // An index is where the documents are stored. let books = client.index("books"); books.delete_document(bookid).await.unwrap(); } pub async fn search_book(search: &str, page: usize, client: &Client) -> Result<(Vec, usize), meilisearch_sdk::errors::Error> { // An index is where the documents are stored. let books = client.index("books"); let results : SearchResults = books.search().with_query(search).with_offset((page-1)*24) .execute::().await.unwrap(); let formatted_results : Vec = (results.hits).iter().map(|r| r.result.clone()).collect(); //.iter()s.map(|r| r.formatted_result.unwrap()).collect(); return Ok((formatted_results, results.estimated_total_hits)); }