Skip to content

Commit

Permalink
add RwLock on searcher
Browse files Browse the repository at this point in the history
  • Loading branch information
RealHinome authored Aug 24, 2024
1 parent 771e710 commit 2e3b678
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions graphql/api/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -120,15 +121,25 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
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()),
std::env::var("MEILISEARCH_URL").ok(),
)?
.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?;
Expand Down

0 comments on commit 2e3b678

Please sign in to comment.