feat(search): add Meilisearch-backed SearchClient (index, search, remove)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
use search::{SearchClient, SearchDocument};
|
||||
|
||||
fn meili() -> (String, String) {
|
||||
(
|
||||
std::env::var("MEILI_URL").expect("MEILI_URL must be set"),
|
||||
std::env::var("MEILI_MASTER_KEY").expect("MEILI_MASTER_KEY must be set"),
|
||||
)
|
||||
}
|
||||
|
||||
fn unique_index() -> String {
|
||||
format!("objects_test_{}", uuid::Uuid::new_v4().simple())
|
||||
}
|
||||
|
||||
fn doc(id: &str, object_name: &str, fields_text: &[&str]) -> SearchDocument {
|
||||
SearchDocument {
|
||||
id: id.to_string(),
|
||||
object_number: format!("N-{id}"),
|
||||
object_name: object_name.to_string(),
|
||||
brief_description: None,
|
||||
current_owner: None,
|
||||
recorder: None,
|
||||
visibility: "draft".to_string(),
|
||||
fields_text: fields_text.iter().map(|s| s.to_string()).collect(),
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn index_search_and_remove() {
|
||||
let (url, key) = meili();
|
||||
let client = SearchClient::connect(&url, &key, &unique_index()).unwrap();
|
||||
client.ensure_index().await.unwrap();
|
||||
|
||||
let vase = domain::ObjectId::new();
|
||||
let chair = domain::ObjectId::new();
|
||||
client
|
||||
.index_object(&doc(&vase.to_string(), "vase", &["wood", "trä"]))
|
||||
.await
|
||||
.unwrap();
|
||||
client
|
||||
.index_object(&doc(&chair.to_string(), "chair", &["oak"]))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let hits = client.search("wood").await.unwrap();
|
||||
assert_eq!(hits, vec![vase]);
|
||||
|
||||
let hits = client.search("chair").await.unwrap();
|
||||
assert_eq!(hits, vec![chair]);
|
||||
|
||||
client.remove_object(vase).await.unwrap();
|
||||
assert!(client.search("wood").await.unwrap().is_empty());
|
||||
}
|
||||
Reference in New Issue
Block a user