v0.12-searchP1
This commit is contained in:
11
backend/search/Cargo.toml
Normal file
11
backend/search/Cargo.toml
Normal file
@@ -0,0 +1,11 @@
|
||||
[package]
|
||||
name = "booksman-search"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
meilisearch-sdk = "0.20.1"
|
||||
tokio = { version = "^1", features = ["full"] }
|
||||
|
||||
30
backend/search/src/lib.rs
Normal file
30
backend/search/src/lib.rs
Normal file
@@ -0,0 +1,30 @@
|
||||
use meilisearch_sdk::{client::*, search::*};
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
struct Movie {
|
||||
id: usize,
|
||||
title: String,
|
||||
genres: Vec<String>,
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
// Create a client (without sending any request so that can't fail)
|
||||
let client = Client::new(MEILISEARCH_URL, MEILISEARCH_API_KEY);
|
||||
|
||||
// An index is where the documents are stored.
|
||||
let movies = client.index("movies");
|
||||
|
||||
// Add some movies in the index. If the index 'movies' does not exist, Meilisearch creates it when you first add the documents.
|
||||
movies.add_documents(&[
|
||||
Movie { id: 1, title: String::from("Carol"), genres: vec!["Romance".to_string(), "Drama".to_string()] },
|
||||
Movie { id: 2, title: String::from("Wonder Woman"), genres: vec!["Action".to_string(), "Adventure".to_string()] },
|
||||
Movie { id: 3, title: String::from("Life of Pi"), genres: vec!["Adventure".to_string(), "Drama".to_string()] },
|
||||
Movie { id: 4, title: String::from("Mad Max"), genres: vec!["Adventure".to_string(), "Science Fiction".to_string()] },
|
||||
Movie { id: 5, title: String::from("Moana"), genres: vec!["Fantasy".to_string(), "Action".to_string()] },
|
||||
Movie { id: 6, title: String::from("Philadelphia"), genres: vec!["Drama".to_string()] },
|
||||
], Some("id")).await.unwrap();
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user