From 8d8aed36a855171c4ef95b1eb316ffcbfda3faf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Sat, 14 Sep 2019 12:03:56 +0200 Subject: [PATCH] feat: Count the number of deleted/inserted documents --- meilidb-data/src/database/index/documents_index.rs | 6 ++++-- meilidb-data/src/database/update/documents_addition.rs | 9 ++++----- meilidb-data/src/database/update/documents_deletion.rs | 7 +++++-- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/meilidb-data/src/database/index/documents_index.rs b/meilidb-data/src/database/index/documents_index.rs index 11475e800..83e95530e 100644 --- a/meilidb-data/src/database/index/documents_index.rs +++ b/meilidb-data/src/database/index/documents_index.rs @@ -35,14 +35,16 @@ impl DocumentsIndex { Ok(()) } - pub fn del_all_document_fields(&self, id: DocumentId) -> RocksDbResult<()> { + pub fn del_all_document_fields(&self, id: DocumentId) -> RocksDbResult { let (start, end) = document_fields_range(id); + let mut count = 0; for (key, _) in self.0.range(start, end)? { self.0.remove(key)?; + count += 1; } - Ok(()) + Ok(count) } pub fn document_fields(&self, id: DocumentId) -> RocksDbResult { diff --git a/meilidb-data/src/database/update/documents_addition.rs b/meilidb-data/src/database/update/documents_addition.rs index 2e4e94736..397727fba 100644 --- a/meilidb-data/src/database/update/documents_addition.rs +++ b/meilidb-data/src/database/update/documents_addition.rs @@ -5,11 +5,10 @@ use fst::{SetBuilder, set::OpBuilder}; use sdset::{SetOperation, duo::Union}; use serde::Serialize; +use crate::RankedMap; +use crate::database::{Error, Index, index::Cache, apply_documents_deletion}; use crate::indexer::Indexer; use crate::serde::{extract_document_id, Serializer, RamDocumentStore}; -use crate::RankedMap; - -use crate::database::{Error, Index, index::Cache, apply_documents_deletion}; pub struct DocumentsAddition<'a, D> { index: &'a Index, @@ -73,8 +72,8 @@ pub fn apply_documents_addition( let words = ref_index.words_index; // 1. remove the previous documents match indexes - let document_ids = document_ids.into_iter().collect(); - apply_documents_deletion(index, ranked_map.clone(), document_ids)?; + let documents_to_insert = document_ids.iter().cloned().collect(); + apply_documents_deletion(index, ranked_map.clone(), documents_to_insert)?; // 2. insert new document attributes in the database for ((id, attr), value) in document_store.into_inner() { diff --git a/meilidb-data/src/database/update/documents_deletion.rs b/meilidb-data/src/database/update/documents_deletion.rs index 2c1036b79..b32fe349f 100644 --- a/meilidb-data/src/database/update/documents_deletion.rs +++ b/meilidb-data/src/database/update/documents_deletion.rs @@ -1,4 +1,4 @@ -use std::collections::{HashMap, BTreeSet}; +use std::collections::{HashMap, HashSet, BTreeSet}; use std::sync::Arc; use fst::{SetBuilder, Streamer}; @@ -88,6 +88,7 @@ pub fn apply_documents_deletion( } } + let mut deleted_documents = HashSet::new(); let mut removed_words = BTreeSet::new(); for (word, document_ids) in words_document_ids { let document_ids = SetBuf::from_dirty(document_ids); @@ -105,7 +106,9 @@ pub fn apply_documents_deletion( } for id in document_ids { - documents.del_all_document_fields(id)?; + if documents.del_all_document_fields(id)? != 0 { + deleted_documents.insert(id); + } docs_words.del_doc_words(id)?; } }