feat: Count the number of deleted/inserted documents

This commit is contained in:
Clément Renault 2019-09-14 12:03:56 +02:00
parent 2658ef0176
commit 8d8aed36a8
No known key found for this signature in database
GPG Key ID: 0151CDAB43460DAE
3 changed files with 13 additions and 9 deletions

View File

@ -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<usize> {
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<DocumentFieldsIter> {

View File

@ -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() {

View File

@ -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)?;
}
}