From 6526ce12084ace10e9fe93b70a5fc82b84697bea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Mon, 2 Sep 2024 14:41:20 +0200 Subject: [PATCH] Fix the merging of documents --- .../update/new/indexer/document_operation.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/milli/src/update/new/indexer/document_operation.rs b/milli/src/update/new/indexer/document_operation.rs index ba93915ea..80e7de51a 100644 --- a/milli/src/update/new/indexer/document_operation.rs +++ b/milli/src/update/new/indexer/document_operation.rs @@ -210,17 +210,22 @@ fn merge_document_for_updates( let current = index.documents.remap_data_type::().get(rtxn, &docid)?; let current: Option<&KvReaderFieldId> = current.map(Into::into); - if let Some(current) = current { - current.into_iter().for_each(|(k, v)| { - document.insert(k, v.into()); - }); + if operations.is_empty() { + return Ok(None); // but it's strange } - let last_deletion = - operations.iter().rposition(|operation| matches!(operation, DocumentOperation::Deletion)); - + let last_deletion = operations.iter().rposition(|op| matches!(op, InnerDocOp::Deletion)); let operations = &operations[last_deletion.map_or(0, |i| i + 1)..]; + // If there was a deletion we must not start + // from the original document but from scratch. + if last_deletion.is_none() { + if let Some(current) = current { + current.into_iter().for_each(|(k, v)| { + document.insert(k, v.into()); + }); + } + } if operations.is_empty() { match current { Some(current) => {