2020-10-26 01:32:01 +08:00
|
|
|
use grenad::CompressionType;
|
|
|
|
|
2020-10-27 03:18:10 +08:00
|
|
|
use crate::Index;
|
2020-10-26 17:57:34 +08:00
|
|
|
use super::clear_documents::ClearDocuments;
|
2020-10-26 18:01:00 +08:00
|
|
|
use super::delete_documents::DeleteDocuments;
|
2020-10-26 18:02:44 +08:00
|
|
|
use super::index_documents::IndexDocuments;
|
2020-10-26 01:32:01 +08:00
|
|
|
|
|
|
|
pub struct UpdateBuilder {
|
2020-10-27 03:18:10 +08:00
|
|
|
pub(crate) log_every_n: Option<usize>,
|
|
|
|
pub(crate) max_nb_chunks: Option<usize>,
|
|
|
|
pub(crate) max_memory: Option<usize>,
|
|
|
|
pub(crate) linked_hash_map_size: Option<usize>,
|
|
|
|
pub(crate) chunk_compression_type: CompressionType,
|
|
|
|
pub(crate) chunk_compression_level: Option<u32>,
|
|
|
|
pub(crate) chunk_fusing_shrink_size: Option<u64>,
|
|
|
|
pub(crate) indexing_jobs: Option<usize>,
|
2020-10-26 01:32:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
impl UpdateBuilder {
|
|
|
|
pub fn new() -> UpdateBuilder {
|
2020-10-27 03:18:10 +08:00
|
|
|
UpdateBuilder {
|
|
|
|
log_every_n: None,
|
|
|
|
max_nb_chunks: None,
|
|
|
|
max_memory: None,
|
|
|
|
linked_hash_map_size: None,
|
|
|
|
chunk_compression_type: CompressionType::None,
|
|
|
|
chunk_compression_level: None,
|
|
|
|
chunk_fusing_shrink_size: None,
|
|
|
|
indexing_jobs: None,
|
|
|
|
}
|
2020-10-26 01:32:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn log_every_n(&mut self, log_every_n: usize) -> &mut Self {
|
2020-10-27 03:18:10 +08:00
|
|
|
self.log_every_n = Some(log_every_n);
|
2020-10-26 01:32:01 +08:00
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn max_nb_chunks(&mut self, max_nb_chunks: usize) -> &mut Self {
|
|
|
|
self.max_nb_chunks = Some(max_nb_chunks);
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn max_memory(&mut self, max_memory: usize) -> &mut Self {
|
2020-10-27 03:18:10 +08:00
|
|
|
self.max_memory = Some(max_memory);
|
2020-10-26 01:32:01 +08:00
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn linked_hash_map_size(&mut self, linked_hash_map_size: usize) -> &mut Self {
|
2020-10-27 03:18:10 +08:00
|
|
|
self.linked_hash_map_size = Some(linked_hash_map_size);
|
2020-10-26 01:32:01 +08:00
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn chunk_compression_type(&mut self, chunk_compression_type: CompressionType) -> &mut Self {
|
|
|
|
self.chunk_compression_type = chunk_compression_type;
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn chunk_compression_level(&mut self, chunk_compression_level: u32) -> &mut Self {
|
|
|
|
self.chunk_compression_level = Some(chunk_compression_level);
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn chunk_fusing_shrink_size(&mut self, chunk_fusing_shrink_size: u64) -> &mut Self {
|
2020-10-27 03:18:10 +08:00
|
|
|
self.chunk_fusing_shrink_size = Some(chunk_fusing_shrink_size);
|
2020-10-26 01:32:01 +08:00
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn indexing_jobs(&mut self, indexing_jobs: usize) -> &mut Self {
|
|
|
|
self.indexing_jobs = Some(indexing_jobs);
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn clear_documents<'t, 'u, 'i>(
|
|
|
|
self,
|
|
|
|
wtxn: &'t mut heed::RwTxn<'u>,
|
|
|
|
index: &'i Index,
|
|
|
|
) -> ClearDocuments<'t, 'u, 'i>
|
|
|
|
{
|
|
|
|
ClearDocuments::new(wtxn, index)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn delete_documents<'t, 'u, 'i>(
|
|
|
|
self,
|
|
|
|
wtxn: &'t mut heed::RwTxn<'u>,
|
|
|
|
index: &'i Index,
|
|
|
|
) -> anyhow::Result<DeleteDocuments<'t, 'u, 'i>>
|
|
|
|
{
|
|
|
|
DeleteDocuments::new(wtxn, index)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn index_documents<'t, 'u, 'i>(
|
|
|
|
self,
|
|
|
|
wtxn: &'t mut heed::RwTxn<'u>,
|
|
|
|
index: &'i Index,
|
|
|
|
) -> IndexDocuments<'t, 'u, 'i>
|
|
|
|
{
|
2020-10-27 03:18:10 +08:00
|
|
|
let mut builder = IndexDocuments::new(wtxn, index);
|
|
|
|
|
|
|
|
if let Some(log_every_n) = self.log_every_n {
|
|
|
|
builder.log_every_n(log_every_n);
|
|
|
|
}
|
|
|
|
if let Some(max_nb_chunks) = self.max_nb_chunks {
|
|
|
|
builder.max_nb_chunks(max_nb_chunks);
|
|
|
|
}
|
|
|
|
if let Some(max_memory) = self.max_memory {
|
|
|
|
builder.max_memory(max_memory);
|
|
|
|
}
|
|
|
|
if let Some(linked_hash_map_size) = self.linked_hash_map_size {
|
|
|
|
builder.linked_hash_map_size(linked_hash_map_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
builder.chunk_compression_type(self.chunk_compression_type);
|
|
|
|
|
|
|
|
if let Some(chunk_compression_level) = self.chunk_compression_level {
|
|
|
|
builder.chunk_compression_level(chunk_compression_level);
|
|
|
|
}
|
|
|
|
if let Some(chunk_fusing_shrink_size) = self.chunk_fusing_shrink_size {
|
|
|
|
builder.chunk_fusing_shrink_size(chunk_fusing_shrink_size);
|
|
|
|
}
|
|
|
|
if let Some(indexing_jobs) = self.indexing_jobs {
|
|
|
|
builder.indexing_jobs(indexing_jobs);
|
|
|
|
}
|
|
|
|
|
|
|
|
builder
|
2020-10-26 01:32:01 +08:00
|
|
|
}
|
|
|
|
}
|