From 2e3b678ba70f52378323b936843cf3b0e32af02c Mon Sep 17 00:00:00 2001 From: Hinome <57831472+RealHinome@users.noreply.github.com> Date: Sat, 24 Aug 2024 17:28:26 +0200 Subject: [PATCH] add RwLock on searcher --- graphql/api/src/main.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/graphql/api/src/main.rs b/graphql/api/src/main.rs index 5f453af..36f8ffe 100644 --- a/graphql/api/src/main.rs +++ b/graphql/api/src/main.rs @@ -15,6 +15,7 @@ use search::{Attributes, Search}; use std::{sync::Arc, time::Duration}; use strum::IntoEnumIterator; use tokio::sync::mpsc; +use tokio::sync::RwLock; use tracing::{debug, error, info, Level}; use tracing_subscriber::fmt; use url::Url; @@ -120,7 +121,7 @@ async fn main() -> Result<(), Box> { crawler.crawl()?; // Create meilisearch client. - let searcher = Arc::new( + let searcher = Arc::new(RwLock::new( Search::new( std::env::var("MEILISEARCH_URL") .unwrap_or("http://localhost:7700".into()), @@ -128,7 +129,17 @@ async fn main() -> Result<(), Box> { )? .index("news".into()) .await, - ); + )); + + // Add country field as a filterable attribute. + searcher + .write() + .await + .index + .as_ref() + .unwrap() + .set_filterable_attributes(&["source.country"]) + .await?; // Create ranking platform. let ranker = Ranker::new().await?;