From 96ba62da3692afefb44c6928ec4a4e6de64348b1 Mon Sep 17 00:00:00 2001 From: ManyTheFish Date: Thu, 13 Feb 2025 14:02:53 +0100 Subject: [PATCH] Check the exact_word database when computing zero typo query --- crates/meilisearch/tests/search/mod.rs | 34 +++++++++++++++++++ .../new/query_term/compute_derivations.rs | 2 +- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/crates/meilisearch/tests/search/mod.rs b/crates/meilisearch/tests/search/mod.rs index a7ec35270..a5fa94eea 100644 --- a/crates/meilisearch/tests/search/mod.rs +++ b/crates/meilisearch/tests/search/mod.rs @@ -128,6 +128,40 @@ async fn search_with_stop_word() { .await; } +#[actix_rt::test] +async fn search_with_typo_settings() { + // related to https://github.com/meilisearch/meilisearch/issues/5240 + let server = Server::new().await; + let index = server.index("test"); + + let (_, code) = index + .update_settings(json!({"typoTolerance": { "disableOnAttributes": ["title", "id"]}})) + .await; + meili_snap::snapshot!(code, @"202 Accepted"); + + let documents = DOCUMENTS.clone(); + let (task, _status_code) = index.add_documents(documents, None).await; + index.wait_task(task.uid()).await.succeeded(); + + index + .search(json!({"q": "287947" }), |response, code| { + assert_eq!(code, 200, "{}", response); + snapshot!(json_string!(response["hits"]), @r###" + [ + { + "title": "Shazam!", + "id": "287947", + "color": [ + "green", + "blue" + ] + } + ] + "###); + }) + .await; +} + #[actix_rt::test] async fn phrase_search_with_stop_word() { // related to https://github.com/meilisearch/meilisearch/issues/3521 diff --git a/crates/milli/src/search/new/query_term/compute_derivations.rs b/crates/milli/src/search/new/query_term/compute_derivations.rs index e2a136328..79cd830ca 100644 --- a/crates/milli/src/search/new/query_term/compute_derivations.rs +++ b/crates/milli/src/search/new/query_term/compute_derivations.rs @@ -215,7 +215,7 @@ pub fn partially_initialized_term_from_word( let mut zero_typo = None; let mut prefix_of = BTreeSet::new(); - if fst.contains(word) { + if fst.contains(word) || ctx.index.exact_word_docids.get(ctx.txn, word)?.is_some() { zero_typo = Some(word_interned); }