From 18ce95dcbf5c8c8ae7527887ae2abf3cb2b1c7a7 Mon Sep 17 00:00:00 2001 From: ManyTheFish Date: Thu, 12 Dec 2024 14:56:45 +0100 Subject: [PATCH] Add test reproducing the bug --- .../meilisearch/tests/search/facet_search.rs | 110 ++++++++++++++++++ 1 file changed, 110 insertions(+) diff --git a/crates/meilisearch/tests/search/facet_search.rs b/crates/meilisearch/tests/search/facet_search.rs index 19224c3df..696c23f91 100644 --- a/crates/meilisearch/tests/search/facet_search.rs +++ b/crates/meilisearch/tests/search/facet_search.rs @@ -57,6 +57,116 @@ async fn simple_facet_search() { assert_eq!(response["facetHits"].as_array().unwrap().len(), 1); } +#[actix_rt::test] +async fn simple_facet_search_on_movies() { + let server = Server::new().await; + let index = server.index("test"); + + let documents = json!([ + { + "id": 1, + "title": "Carol", + "genres": [ + "Romance", + "Drama" + ], + "color": [ + "red" + ], + "platforms": [ + "MacOS", + "Linux", + "Windows" + ] + }, + { + "id": 2, + "title": "Wonder Woman", + "genres": [ + "Action", + "Adventure" + ], + "color": [ + "green" + ], + "platforms": [ + "MacOS" + ] + }, + { + "id": 3, + "title": "Life of Pi", + "genres": [ + "Adventure", + "Drama" + ], + "color": [ + "blue" + ], + "platforms": [ + "Windows" + ] + }, + { + "id": 4, + "title": "Mad Max: Fury Road", + "genres": [ + "Adventure", + "Science Fiction" + ], + "color": [ + "red" + ], + "platforms": [ + "MacOS", + "Linux" + ] + }, + { + "id": 5, + "title": "Moana", + "genres": [ + "Fantasy", + "Action" + ], + "color": [ + "red" + ], + "platforms": [ + "Windows" + ] + }, + { + "id": 6, + "title": "Philadelphia", + "genres": [ + "Drama" + ], + "color": [ + "blue" + ], + "platforms": [ + "MacOS", + "Linux", + "Windows" + ] + } + ]); + let (response, code) = + index.update_settings_filterable_attributes(json!(["genres", "color"])).await; + assert_eq!(202, code, "{:?}", response); + index.wait_task(response.uid()).await; + + let (response, _code) = index.add_documents(documents, None).await; + index.wait_task(response.uid()).await; + + let (response, code) = + index.facet_search(json!({"facetQuery": "", "facetName": "genres", "q": "" })).await; + + assert_eq!(code, 200, "{}", response); + snapshot!(response["facetHits"], @r###"[{"value":"Action","count":2},{"value":"Adventure","count":3},{"value":"Drama","count":3},{"value":"Fantasy","count":1},{"value":"Romance","count":1},{"value":"Science Fiction","count":1}]"###); +} + #[actix_rt::test] async fn advanced_facet_search() { let server = Server::new().await;