Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
CommanderStorm committed Jul 28, 2024
1 parent 265878e commit 867fb36
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 18 deletions.
4 changes: 2 additions & 2 deletions server/main-api/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ async fn run_maintenance_work(
let ms_url =
std::env::var("MIELI_URL").unwrap_or_else(|_| "http://localhost:7700".to_string());
let client = Client::new(ms_url, std::env::var("MEILI_MASTER_KEY").ok()).unwrap();
setup::meilisearch::setup(&client).await.unwrap();
setup::meilisearch::load_data(&client).await.unwrap();
setup::meilisearch::setup(&client, true).await.unwrap();
setup::meilisearch::load_data(&client, true).await.unwrap();
} else {
info!("skipping the database setup as SKIP_MS_SETUP=true");
initalisation_started.wait().await;
Expand Down
8 changes: 4 additions & 4 deletions server/main-api/src/search/search_executor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ mod test {
#[tokio::test]
#[tracing_test::traced_test]
async fn test_good_queries() {
let ms = MeiliSearchTestContainer::new().await;
crate::setup::meilisearch::load_data(&ms.client)
let ms = MeiliSearchTestContainer::new(true).await;
crate::setup::meilisearch::load_data(&ms.client, true)
.await
.unwrap();
for query in TestQuery::load_good() {
Expand All @@ -154,8 +154,8 @@ mod test {
#[tokio::test]
#[tracing_test::traced_test]
async fn test_bad_queries() {
let ms = MeiliSearchTestContainer::new().await;
crate::setup::meilisearch::load_data(&ms.client)
let ms = MeiliSearchTestContainer::new(true).await;
crate::setup::meilisearch::load_data(&ms.client, true)
.await
.unwrap();
for query in TestQuery::load_bad() {
Expand Down
19 changes: 11 additions & 8 deletions server/main-api/src/setup/meilisearch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async fn wait_for_healthy(client: &Client) {
}

#[tracing::instrument(skip(client))]
pub async fn setup(client: &Client) -> Result<(), crate::BoxedError> {
pub async fn setup(client: &Client, vector_search: bool) -> Result<(), crate::BoxedError> {
debug!("waiting for Meilisearch to be healthy");
wait_for_healthy(client).await;
info!("Meilisearch is healthy");
Expand All @@ -67,7 +67,7 @@ pub async fn setup(client: &Client) -> Result<(), crate::BoxedError> {
..Default::default()
});

let settings = Settings::new()
let mut settings = Settings::new()
.with_filterable_attributes([
"facet",
"parent_keywords",
Expand Down Expand Up @@ -98,15 +98,18 @@ pub async fn setup(client: &Client) -> Result<(), crate::BoxedError> {
"address",
"operator_name",
])
.with_synonyms(Synonyms::try_load()?.0)
.with_embedders(HashMap::from([
.with_synonyms(Synonyms::try_load()?.0);

if vector_search {
settings=settings.with_embedders(HashMap::from([
("default",en_embedder),
]));
]))
}

let res = entries
.set_settings(&settings)
.await?
.wait_for_completion(client, POLLING_RATE, TIMEOUT_SETUP)
.wait_for_completion(client, POLLING_RATE, if vector_search { TIMEOUT_SETUP } else { TIMEOUT })
.await?;
if let Task::Failed { content } = res {
panic!("Failed to add settings to Meilisearch: {content:?}");
Expand All @@ -116,7 +119,7 @@ pub async fn setup(client: &Client) -> Result<(), crate::BoxedError> {
}

#[tracing::instrument(skip(client))]
pub async fn load_data(client: &Client) -> Result<(), crate::BoxedError> {
pub async fn load_data(client: &Client, vector_search:bool) -> Result<(), crate::BoxedError> {
let entries = client.index("entries");
let cdn_url = std::env::var("CDN_URL").unwrap_or_else(|_| "https://nav.tum.de/cdn".to_string());
let documents = reqwest::get(format!("{cdn_url}/search_data.json"))
Expand All @@ -126,7 +129,7 @@ pub async fn load_data(client: &Client) -> Result<(), crate::BoxedError> {
let res = entries
.add_documents(&documents, Some("ms_id"))
.await?
.wait_for_completion(client, POLLING_RATE, TIMEOUT_SETUP)
.wait_for_completion(client, POLLING_RATE, if vector_search { TIMEOUT_SETUP } else { TIMEOUT })
.await?;
if let Task::Failed { content } = res {
panic!("Failed to add documents to Meilisearch: {content:?}");
Expand Down
8 changes: 4 additions & 4 deletions server/main-api/src/setup/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub struct MeiliSearchTestContainer {

impl MeiliSearchTestContainer {
/// Create a meilisearch instance for testing against
pub async fn new() -> Self {
pub async fn new(vector_search: bool) -> Self {
let container = meilisearch::Meilisearch::default()
.with_tag("v1.9.0")
.start()
Expand All @@ -57,7 +57,7 @@ impl MeiliSearchTestContainer {
);

let client = Client::new(meili_url.clone(), None::<String>).unwrap();
super::meilisearch::setup(&client).await.unwrap();
super::meilisearch::setup(&client, vector_search).await.unwrap();
Self {
_container: container,
client,
Expand All @@ -84,8 +84,8 @@ async fn test_db_setup() {
#[tokio::test]
#[tracing_test::traced_test]
async fn test_meilisearch_setup() {
let ms = MeiliSearchTestContainer::new().await;
crate::setup::meilisearch::load_data(&ms.client)
let ms = MeiliSearchTestContainer::new(false).await;
crate::setup::meilisearch::load_data(&ms.client, false)
.await
.unwrap();
}

0 comments on commit 867fb36

Please sign in to comment.