From a8935d88ab5b13bc2156407bd3b418a2fdb40ca2 Mon Sep 17 00:00:00 2001 From: ManyTheFish Date: Thu, 25 Jul 2024 08:12:27 +0200 Subject: [PATCH] Add test tryinmg to reproduce bug --- meilisearch/tests/search/mod.rs | 79 +++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/meilisearch/tests/search/mod.rs b/meilisearch/tests/search/mod.rs index 7f4648e57..4e4756271 100644 --- a/meilisearch/tests/search/mod.rs +++ b/meilisearch/tests/search/mod.rs @@ -264,6 +264,85 @@ async fn simple_search() { }) .await; } +#[actix_rt::test] +async fn filter_should_not_return_documents_with_missing_filterable_value() { + let server = Server::new().await; + let index = server.index("test"); + + let documents = NESTED_DOCUMENTS.clone(); + + let (_, code) = index + .update_settings(json!({"filterableAttributes": ["custom_propertie.999.options"]})) + .await; + meili_snap::snapshot!(code, @"202 Accepted"); + index + .add_documents( + json!([ + { + "id": 951, + "custom_propertie": { + "999": { + "type": "multi", + "options": [ + { + "slug": "group_1", + "age": 6, + }, + { + "slug": "group_2", + "age": 8, + }, + ] + } + }, + }]), + None, + ) + .await; + index.wait_task(1).await; + + index + .search( + json!({"filter": "custom_propertie.999.options.slug IN ['group_2']"}), + |response, code| { + assert_eq!(code, 200, "{}", response); + assert_eq!(response["hits"].as_array().unwrap().len(), 1); + }, + ) + .await; + + index + .add_documents( + json!([ + { + "id": 951, + "custom_propertie": { + "999": { + "type": "multi", + "options": [ + { + "slug": "group_1", + "age": 6, + }, + ] + } + }, + }]), + None, + ) + .await; + index.wait_task(2).await; + + index + .search( + json!({"filter": "custom_propertie.999.options.slug IN ['group_2']"}), + |response, code| { + assert_eq!(code, 200, "{}", response); + assert_eq!(response["hits"].as_array().unwrap().len(), 1); + }, + ) + .await; +} #[actix_rt::test] async fn phrase_search_with_stop_word() {