From 1b1ad1923b8ef6e4d07173ef6f5b98d7ffc0b417 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Tue, 8 Nov 2022 14:23:14 +0100 Subject: [PATCH 1/2] Add a test to check that we take care of soft deleted documents --- milli/src/update/settings.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/milli/src/update/settings.rs b/milli/src/update/settings.rs index f82a57cbc..6da32d73f 100644 --- a/milli/src/update/settings.rs +++ b/milli/src/update/settings.rs @@ -719,6 +719,7 @@ mod tests { use super::*; use crate::error::Error; use crate::index::tests::TempIndex; + use crate::update::DeleteDocuments; use crate::{Criterion, Filter, SearchResult}; #[test] @@ -1494,4 +1495,34 @@ mod tests { }) .unwrap(); } + + #[test] + fn settings_must_ignore_soft_deleted() { + use serde_json::json; + + let index = TempIndex::new(); + + let mut docs = vec![]; + for i in 0..10 { + docs.push(json!({ "id": i, "title": format!("{:x}", i) })); + } + index.add_documents(documents! { docs }).unwrap(); + + let mut wtxn = index.write_txn().unwrap(); + let mut builder = DeleteDocuments::new(&mut wtxn, &index).unwrap(); + (0..5).for_each(|id| drop(builder.delete_external_id(&id.to_string()))); + builder.execute().unwrap(); + + index + .update_settings_using_wtxn(&mut wtxn, |settings| { + settings.set_searchable_fields(vec!["id".to_string()]); + }) + .unwrap(); + wtxn.commit().unwrap(); + + let rtxn = index.write_txn().unwrap(); + let docs: StdResult, _> = index.all_documents(&rtxn).unwrap().collect(); + let docs = docs.unwrap(); + assert_eq!(docs.len(), 5); + } } From 37b3c5c323ccb8b3a192c03a9fc59c797b195330 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Tue, 8 Nov 2022 14:01:28 +0100 Subject: [PATCH 2/2] Fix transform to use all_documents and ignore soft_deleted documents --- milli/src/update/index_documents/transform.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/milli/src/update/index_documents/transform.rs b/milli/src/update/index_documents/transform.rs index 59f18b22d..57aa02e04 100644 --- a/milli/src/update/index_documents/transform.rs +++ b/milli/src/update/index_documents/transform.rs @@ -578,9 +578,8 @@ impl<'a, 'i> Transform<'a, 'i> { ); let mut obkv_buffer = Vec::new(); - for result in self.index.documents.iter(wtxn)? { + for result in self.index.all_documents(wtxn)? { let (docid, obkv) = result?; - let docid = docid.get(); obkv_buffer.clear(); let mut obkv_writer = obkv::KvWriter::<_, FieldId>::new(&mut obkv_buffer);