mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-03 20:07:09 +02:00
Implement the DocumentUpdate batch operation
This commit is contained in:
parent
a6a1043abb
commit
7b4a913704
4 changed files with 51 additions and 7 deletions
|
@ -429,6 +429,7 @@ impl IndexScheduler {
|
|||
Batch::Snapshot(_) => todo!(),
|
||||
Batch::Dump(_) => todo!(),
|
||||
Batch::DocumentClear { tasks, .. } => todo!(),
|
||||
// TODO we should merge both document import with a method field
|
||||
Batch::DocumentAddition {
|
||||
index_uid,
|
||||
primary_key,
|
||||
|
@ -477,22 +478,55 @@ impl IndexScheduler {
|
|||
} => {
|
||||
todo!();
|
||||
}
|
||||
// TODO we should merge both document import with a method field
|
||||
Batch::DocumentUpdate {
|
||||
index_uid,
|
||||
primary_key,
|
||||
content_files,
|
||||
tasks,
|
||||
} => todo!(),
|
||||
mut tasks,
|
||||
} => {
|
||||
// we NEED a write transaction for the index creation.
|
||||
// To avoid blocking the whole process we're going to commit asap.
|
||||
let mut wtxn = self.env.write_txn()?;
|
||||
let index = self.index_mapper.create_index(&mut wtxn, &index_uid)?;
|
||||
wtxn.commit()?;
|
||||
|
||||
let ret = index.update_documents(
|
||||
IndexDocumentsMethod::UpdateDocuments,
|
||||
primary_key,
|
||||
self.file_store.clone(),
|
||||
content_files,
|
||||
)?;
|
||||
|
||||
for (task, ret) in tasks.iter_mut().zip(ret) {
|
||||
match ret {
|
||||
Ok(DocumentAdditionResult {
|
||||
indexed_documents,
|
||||
number_of_documents,
|
||||
}) => {
|
||||
task.details = Some(Details::DocumentAddition {
|
||||
received_documents: number_of_documents,
|
||||
indexed_documents,
|
||||
});
|
||||
}
|
||||
Err(error) => {
|
||||
task.error = Some(error.into());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(tasks)
|
||||
}
|
||||
Batch::DocumentDeletion {
|
||||
index_uid,
|
||||
documents,
|
||||
tasks,
|
||||
mut tasks,
|
||||
} => {
|
||||
let rtxn = self.env.read_txn()?;
|
||||
let index = self.index_mapper.index(&rtxn, &index_uid)?;
|
||||
|
||||
let ret = index.delete_documents(&documents);
|
||||
for task in tasks {
|
||||
for task in &mut tasks {
|
||||
match ret {
|
||||
Ok(DocumentDeletionResult {
|
||||
deleted_documents,
|
||||
|
@ -505,7 +539,7 @@ impl IndexScheduler {
|
|||
deleted_documents: Some(deleted_documents),
|
||||
});
|
||||
}
|
||||
Err(error) => {
|
||||
Err(ref error) => {
|
||||
task.error = Some(error.into());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ use uuid::Uuid;
|
|||
|
||||
use crate::{Error, TaskId};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct TaskView {
|
||||
pub uid: TaskId,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue