From 3a0861694d314b7216c492ba605853f5d512951c Mon Sep 17 00:00:00 2001 From: mpostma Date: Thu, 19 Nov 2020 14:03:50 +0100 Subject: [PATCH 1/2] fix clear document bug --- meilisearch-core/src/update/clear_all.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/meilisearch-core/src/update/clear_all.rs b/meilisearch-core/src/update/clear_all.rs index a4c5780b9..434e8a245 100644 --- a/meilisearch-core/src/update/clear_all.rs +++ b/meilisearch-core/src/update/clear_all.rs @@ -11,12 +11,14 @@ pub fn apply_clear_all( index.main.put_internal_docids(writer, &sdset::SetBuf::default())?; index.main.put_ranked_map(writer, &RankedMap::default())?; index.main.put_number_of_documents(writer, |_| 0)?; + index.main.put_sorted_document_ids_cache(writer, &[])?; index.documents_fields.clear(writer)?; index.documents_fields_counts.clear(writer)?; index.postings_lists.clear(writer)?; index.docs_words.clear(writer)?; index.prefix_documents_cache.clear(writer)?; index.prefix_postings_lists_cache.clear(writer)?; + index.facets.clear(writer)?; Ok(()) } From 0645a6568ec60186f8ef5f075cc8f41daf6363e7 Mon Sep 17 00:00:00 2001 From: mpostma Date: Thu, 19 Nov 2020 14:13:27 +0100 Subject: [PATCH 2/2] add test clear all documents --- meilisearch-http/tests/documents_delete.rs | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/meilisearch-http/tests/documents_delete.rs b/meilisearch-http/tests/documents_delete.rs index b491a044a..4353a5355 100644 --- a/meilisearch-http/tests/documents_delete.rs +++ b/meilisearch-http/tests/documents_delete.rs @@ -1,5 +1,7 @@ mod common; +use serde_json::json; + #[actix_rt::test] async fn delete() { let mut server = common::Server::test_server().await; @@ -32,3 +34,34 @@ async fn delete_batch() { assert_eq!(status_code, 404); } } + +#[actix_rt::test] +async fn text_clear_all_placeholder_search() { + let mut server = common::Server::with_uid("test"); + let body = json!({ + "uid": "test", + }); + + server.create_index(body).await; + let settings = json!({ + "attributesForFaceting": ["genre"], + }); + + server.update_all_settings(settings).await; + + let documents = json!([ + { "id": 2, "title": "Pride and Prejudice", "author": "Jane Austin", "genre": "romance" }, + { "id": 456, "title": "Le Petit Prince", "author": "Antoine de Saint-Exupéry", "genre": "adventure" }, + { "id": 1, "title": "Alice In Wonderland", "author": "Lewis Carroll", "genre": "fantasy" }, + { "id": 1344, "title": "The Hobbit", "author": "J. R. R. Tolkien", "genre": "fantasy" }, + { "id": 4, "title": "Harry Potter and the Half-Blood Prince", "author": "J. K. Rowling", "genre": "fantasy" }, + { "id": 42, "title": "The Hitchhiker's Guide to the Galaxy", "author": "Douglas Adams" } + ]); + + server.add_or_update_multiple_documents(documents).await; + server.clear_all_documents().await; + let (response, _) = server.search_post(json!({ "q": "", "facetsDistribution": ["genre"] })).await; + assert_eq!(response["nbHits"], 0); + let (response, _) = server.search_post(json!({ "q": "" })).await; + assert_eq!(response["nbHits"], 0); +}