From 7384650d856aab4705a0a3308a36422a796418bf Mon Sep 17 00:00:00 2001 From: ManyTheFish Date: Wed, 17 Aug 2022 15:03:08 +0200 Subject: [PATCH 1/3] Update test to showcase the bug --- milli/src/update/index_documents/mod.rs | 27 ++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/milli/src/update/index_documents/mod.rs b/milli/src/update/index_documents/mod.rs index 114903e39..0951cf227 100644 --- a/milli/src/update/index_documents/mod.rs +++ b/milli/src/update/index_documents/mod.rs @@ -654,6 +654,9 @@ mod tests { let rtxn = index.read_txn().unwrap(); let count = index.number_of_documents(&rtxn).unwrap(); assert_eq!(count, 3); + let count = index.all_documents(&rtxn).unwrap().count(); + assert_eq!(count, 3); + drop(rtxn); } @@ -888,12 +891,26 @@ mod tests { index.index_documents_config.update_method = IndexDocumentsMethod::UpdateDocuments; index - .add_documents(documents!([{ - "id": 2, - "author": "J. Austen", - "date": "1813" - }])) + .add_documents(documents!([ + {"id":4,"title":"Harry Potter and the Half-Blood Princess"}, + {"id":456,"title":"The Little Prince"} + ])) .unwrap(); + + index + .add_documents(documents!([ + { "id": 2, "author": "J. Austen", "date": "1813" } + ])) + .unwrap(); + + // Check that there is **always** 3 documents. + let rtxn = index.read_txn().unwrap(); + let count = index.number_of_documents(&rtxn).unwrap(); + assert_eq!(count, 6); + let count = index.all_documents(&rtxn).unwrap().count(); + assert_eq!(count, 6); + + drop(rtxn); } #[test] From 2668f841d18fef109d885f7f5f2cea26e807d6ed Mon Sep 17 00:00:00 2001 From: ManyTheFish Date: Wed, 17 Aug 2022 15:03:37 +0200 Subject: [PATCH 2/3] Fix update indexing --- milli/src/update/index_documents/mod.rs | 2 +- milli/src/update/index_documents/transform.rs | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/milli/src/update/index_documents/mod.rs b/milli/src/update/index_documents/mod.rs index 0951cf227..493935a79 100644 --- a/milli/src/update/index_documents/mod.rs +++ b/milli/src/update/index_documents/mod.rs @@ -407,7 +407,7 @@ where // We write the external documents ids into the main database. self.index.put_external_documents_ids(self.wtxn, &external_documents_ids)?; - let all_documents_ids = index_documents_ids | new_documents_ids | replaced_documents_ids; + let all_documents_ids = index_documents_ids | new_documents_ids; self.index.put_documents_ids(self.wtxn, &all_documents_ids)?; self.execute_prefix_databases( diff --git a/milli/src/update/index_documents/transform.rs b/milli/src/update/index_documents/transform.rs index b61395a96..8818909a3 100644 --- a/milli/src/update/index_documents/transform.rs +++ b/milli/src/update/index_documents/transform.rs @@ -249,11 +249,10 @@ impl<'a, 'i> Transform<'a, 'i> { None => self.flattened_sorter.insert(docid.to_be_bytes(), base_obkv)?, } } - } else { - self.new_documents_ids.insert(docid); } if !skip_insertion { + self.new_documents_ids.insert(docid); // We use the extracted/generated user id as the key for this document. self.original_sorter.insert(&docid.to_be_bytes(), obkv_buffer.clone())?; From e9e2349ce67381c9550b47fc43916a8afc6472f1 Mon Sep 17 00:00:00 2001 From: ManyTheFish Date: Wed, 17 Aug 2022 15:09:48 +0200 Subject: [PATCH 3/3] Fix typo in comment --- milli/src/update/index_documents/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/milli/src/update/index_documents/mod.rs b/milli/src/update/index_documents/mod.rs index 493935a79..d1f030fdd 100644 --- a/milli/src/update/index_documents/mod.rs +++ b/milli/src/update/index_documents/mod.rs @@ -903,7 +903,7 @@ mod tests { ])) .unwrap(); - // Check that there is **always** 3 documents. + // Check that there is **always** 6 documents. let rtxn = index.read_txn().unwrap(); let count = index.number_of_documents(&rtxn).unwrap(); assert_eq!(count, 6);