mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-27 04:25:06 +08:00
feat: Count the number of deleted/inserted documents
This commit is contained in:
parent
2658ef0176
commit
8d8aed36a8
@ -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> {
|
||||
|
@ -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() {
|
||||
|
@ -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)?;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user