return documents number on addition

This commit is contained in:
mpostma 2020-12-30 18:43:50 +01:00
parent fa0cc2dc13
commit 91d8198d17
No known key found for this signature in database
GPG Key ID: CBC8A7C1D7A28C3A
2 changed files with 13 additions and 4 deletions

View File

@ -12,8 +12,9 @@ use grenad::{Writer, Sorter, Merger, Reader, FileFuse, CompressionType};
use heed::types::ByteSlice; use heed::types::ByteSlice;
use log::{debug, info, error}; use log::{debug, info, error};
use memmap::Mmap; use memmap::Mmap;
use rayon::prelude::*;
use rayon::ThreadPool; use rayon::ThreadPool;
use rayon::prelude::*;
use serde::{Serialize, Deserialize};
use crate::index::Index; use crate::index::Index;
use crate::update::{Facets, UpdateIndexingStep}; use crate::update::{Facets, UpdateIndexingStep};
@ -32,6 +33,11 @@ mod merge_function;
mod store; mod store;
mod transform; mod transform;
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct DocumentAdditionResult {
nb_documents: usize,
}
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
pub enum WriteMethod { pub enum WriteMethod {
Append, Append,
@ -253,7 +259,7 @@ impl<'t, 'u, 'i, 'a> IndexDocuments<'t, 'u, 'i, 'a> {
self.autogenerate_docids = false; self.autogenerate_docids = false;
} }
pub fn execute<R, F>(self, reader: R, progress_callback: F) -> anyhow::Result<()> pub fn execute<R, F>(self, reader: R, progress_callback: F) -> anyhow::Result<DocumentAdditionResult>
where where
R: io::Read, R: io::Read,
F: Fn(UpdateIndexingStep) + Sync, F: Fn(UpdateIndexingStep) + Sync,
@ -279,9 +285,12 @@ impl<'t, 'u, 'i, 'a> IndexDocuments<'t, 'u, 'i, 'a> {
UpdateFormat::JsonStream => transform.output_from_json_stream(reader, &progress_callback)?, UpdateFormat::JsonStream => transform.output_from_json_stream(reader, &progress_callback)?,
}; };
let nb_documents = output.documents_count;
info!("Update transformed in {:.02?}", before_transform.elapsed()); info!("Update transformed in {:.02?}", before_transform.elapsed());
self.execute_raw(output, progress_callback) self.execute_raw(output, progress_callback)?;
Ok(DocumentAdditionResult { nb_documents })
} }
pub fn execute_raw<F>(self, output: TransformOutput, progress_callback: F) -> anyhow::Result<()> pub fn execute_raw<F>(self, output: TransformOutput, progress_callback: F) -> anyhow::Result<()>

View File

@ -10,7 +10,7 @@ mod update_step;
pub use self::available_documents_ids::AvailableDocumentsIds; pub use self::available_documents_ids::AvailableDocumentsIds;
pub use self::clear_documents::ClearDocuments; pub use self::clear_documents::ClearDocuments;
pub use self::delete_documents::DeleteDocuments; pub use self::delete_documents::DeleteDocuments;
pub use self::index_documents::{IndexDocuments, IndexDocumentsMethod, UpdateFormat}; pub use self::index_documents::{IndexDocuments, IndexDocumentsMethod, UpdateFormat, DocumentAdditionResult};
pub use self::facets::Facets; pub use self::facets::Facets;
pub use self::settings::Settings; pub use self::settings::Settings;
pub use self::update_builder::UpdateBuilder; pub use self::update_builder::UpdateBuilder;