2020-10-26 01:32:01 +08:00
|
|
|
use grenad::CompressionType;
|
2020-11-03 02:11:22 +08:00
|
|
|
use rayon::ThreadPool;
|
2020-10-26 01:32:01 +08:00
|
|
|
|
2021-06-17 00:33:33 +08:00
|
|
|
use super::{ClearDocuments, DeleteDocuments, Facets, IndexDocuments, Settings};
|
2021-06-14 22:46:19 +08:00
|
|
|
use crate::{Index, Result};
|
2020-10-26 01:32:01 +08:00
|
|
|
|
2020-11-03 02:11:22 +08:00
|
|
|
pub struct UpdateBuilder<'a> {
|
2020-10-27 03:18:10 +08:00
|
|
|
pub(crate) log_every_n: Option<usize>,
|
|
|
|
pub(crate) max_nb_chunks: Option<usize>,
|
2021-09-02 21:25:39 +08:00
|
|
|
pub(crate) documents_chunk_size: Option<usize>,
|
2020-10-27 03:18:10 +08:00
|
|
|
pub(crate) max_memory: Option<usize>,
|
|
|
|
pub(crate) chunk_compression_type: CompressionType,
|
|
|
|
pub(crate) chunk_compression_level: Option<u32>,
|
2020-11-03 02:11:22 +08:00
|
|
|
pub(crate) thread_pool: Option<&'a ThreadPool>,
|
2021-10-06 18:11:07 +08:00
|
|
|
pub(crate) max_positions_per_attributes: Option<u32>,
|
2020-12-22 23:21:07 +08:00
|
|
|
pub(crate) update_id: u64,
|
2020-10-26 01:32:01 +08:00
|
|
|
}
|
|
|
|
|
2020-11-03 02:11:22 +08:00
|
|
|
impl<'a> UpdateBuilder<'a> {
|
2020-12-22 23:21:07 +08:00
|
|
|
pub fn new(update_id: u64) -> UpdateBuilder<'a> {
|
2020-10-27 03:18:10 +08:00
|
|
|
UpdateBuilder {
|
|
|
|
log_every_n: None,
|
|
|
|
max_nb_chunks: None,
|
2021-09-02 21:25:39 +08:00
|
|
|
documents_chunk_size: None,
|
2020-10-27 03:18:10 +08:00
|
|
|
max_memory: None,
|
|
|
|
chunk_compression_type: CompressionType::None,
|
|
|
|
chunk_compression_level: None,
|
2020-11-03 02:11:22 +08:00
|
|
|
thread_pool: None,
|
2021-10-06 18:11:07 +08:00
|
|
|
max_positions_per_attributes: None,
|
2020-12-22 23:21:07 +08:00
|
|
|
update_id,
|
2020-10-27 03:18:10 +08:00
|
|
|
}
|
2020-10-26 01:32:01 +08:00
|
|
|
}
|
|
|
|
|
2020-11-01 21:55:06 +08:00
|
|
|
pub fn log_every_n(&mut self, log_every_n: usize) {
|
2020-10-27 03:18:10 +08:00
|
|
|
self.log_every_n = Some(log_every_n);
|
2020-10-26 01:32:01 +08:00
|
|
|
}
|
|
|
|
|
2020-11-01 21:55:06 +08:00
|
|
|
pub fn max_nb_chunks(&mut self, max_nb_chunks: usize) {
|
2020-10-26 01:32:01 +08:00
|
|
|
self.max_nb_chunks = Some(max_nb_chunks);
|
|
|
|
}
|
|
|
|
|
2020-11-01 21:55:06 +08:00
|
|
|
pub fn max_memory(&mut self, max_memory: usize) {
|
2020-10-27 03:18:10 +08:00
|
|
|
self.max_memory = Some(max_memory);
|
2020-10-26 01:32:01 +08:00
|
|
|
}
|
|
|
|
|
2021-09-02 21:25:39 +08:00
|
|
|
pub fn documents_chunk_size(&mut self, documents_chunk_size: usize) {
|
|
|
|
self.documents_chunk_size = Some(documents_chunk_size);
|
|
|
|
}
|
|
|
|
|
2020-11-01 21:55:06 +08:00
|
|
|
pub fn chunk_compression_type(&mut self, chunk_compression_type: CompressionType) {
|
2020-10-26 01:32:01 +08:00
|
|
|
self.chunk_compression_type = chunk_compression_type;
|
|
|
|
}
|
|
|
|
|
2020-11-01 21:55:06 +08:00
|
|
|
pub fn chunk_compression_level(&mut self, chunk_compression_level: u32) {
|
2020-10-26 01:32:01 +08:00
|
|
|
self.chunk_compression_level = Some(chunk_compression_level);
|
|
|
|
}
|
|
|
|
|
2020-11-03 02:11:22 +08:00
|
|
|
pub fn thread_pool(&mut self, thread_pool: &'a ThreadPool) {
|
|
|
|
self.thread_pool = Some(thread_pool);
|
2020-10-26 01:32:01 +08:00
|
|
|
}
|
|
|
|
|
2021-10-06 18:11:07 +08:00
|
|
|
pub fn max_positions_per_attributes(&mut self, max_positions_per_attributes: u32) {
|
|
|
|
self.max_positions_per_attributes = Some(max_positions_per_attributes);
|
|
|
|
}
|
|
|
|
|
2020-10-26 01:32:01 +08:00
|
|
|
pub fn clear_documents<'t, 'u, 'i>(
|
|
|
|
self,
|
2020-10-30 18:42:00 +08:00
|
|
|
wtxn: &'t mut heed::RwTxn<'i, 'u>,
|
2020-10-26 01:32:01 +08:00
|
|
|
index: &'i Index,
|
2021-06-17 00:33:33 +08:00
|
|
|
) -> ClearDocuments<'t, 'u, 'i> {
|
2020-12-22 23:21:07 +08:00
|
|
|
ClearDocuments::new(wtxn, index, self.update_id)
|
2020-10-26 01:32:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn delete_documents<'t, 'u, 'i>(
|
|
|
|
self,
|
2020-10-30 18:42:00 +08:00
|
|
|
wtxn: &'t mut heed::RwTxn<'i, 'u>,
|
2020-10-26 01:32:01 +08:00
|
|
|
index: &'i Index,
|
2021-06-17 00:33:33 +08:00
|
|
|
) -> Result<DeleteDocuments<'t, 'u, 'i>> {
|
2020-12-22 23:21:07 +08:00
|
|
|
DeleteDocuments::new(wtxn, index, self.update_id)
|
2020-10-26 01:32:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn index_documents<'t, 'u, 'i>(
|
|
|
|
self,
|
2020-10-30 18:42:00 +08:00
|
|
|
wtxn: &'t mut heed::RwTxn<'i, 'u>,
|
2020-10-26 01:32:01 +08:00
|
|
|
index: &'i Index,
|
2021-06-17 00:33:33 +08:00
|
|
|
) -> IndexDocuments<'t, 'u, 'i, 'a> {
|
2020-12-22 23:21:07 +08:00
|
|
|
let mut builder = IndexDocuments::new(wtxn, index, self.update_id);
|
2020-10-27 03:18:10 +08:00
|
|
|
|
2020-11-01 21:55:06 +08:00
|
|
|
builder.log_every_n = self.log_every_n;
|
|
|
|
builder.max_nb_chunks = self.max_nb_chunks;
|
|
|
|
builder.max_memory = self.max_memory;
|
2021-09-02 21:25:39 +08:00
|
|
|
builder.documents_chunk_size = self.documents_chunk_size;
|
2020-11-01 21:55:06 +08:00
|
|
|
builder.chunk_compression_type = self.chunk_compression_type;
|
|
|
|
builder.chunk_compression_level = self.chunk_compression_level;
|
2020-11-03 02:11:22 +08:00
|
|
|
builder.thread_pool = self.thread_pool;
|
2021-10-06 18:11:07 +08:00
|
|
|
builder.max_positions_per_attributes = self.max_positions_per_attributes;
|
2020-10-27 03:18:10 +08:00
|
|
|
|
|
|
|
builder
|
2020-10-26 01:32:01 +08:00
|
|
|
}
|
2020-11-02 22:31:20 +08:00
|
|
|
|
|
|
|
pub fn settings<'t, 'u, 'i>(
|
|
|
|
self,
|
|
|
|
wtxn: &'t mut heed::RwTxn<'i, 'u>,
|
|
|
|
index: &'i Index,
|
2021-06-17 00:33:33 +08:00
|
|
|
) -> Settings<'a, 't, 'u, 'i> {
|
2020-12-22 23:21:07 +08:00
|
|
|
let mut builder = Settings::new(wtxn, index, self.update_id);
|
2020-11-03 20:20:11 +08:00
|
|
|
|
|
|
|
builder.log_every_n = self.log_every_n;
|
|
|
|
builder.max_nb_chunks = self.max_nb_chunks;
|
|
|
|
builder.max_memory = self.max_memory;
|
2021-09-02 21:25:39 +08:00
|
|
|
builder.documents_chunk_size = self.documents_chunk_size;
|
2020-11-03 20:20:11 +08:00
|
|
|
builder.chunk_compression_type = self.chunk_compression_type;
|
|
|
|
builder.chunk_compression_level = self.chunk_compression_level;
|
|
|
|
builder.thread_pool = self.thread_pool;
|
2021-10-06 18:11:07 +08:00
|
|
|
builder.max_positions_per_attributes = self.max_positions_per_attributes;
|
2020-11-03 20:20:11 +08:00
|
|
|
|
|
|
|
builder
|
2020-11-02 22:31:20 +08:00
|
|
|
}
|
2020-11-18 04:19:25 +08:00
|
|
|
|
2020-11-23 20:08:57 +08:00
|
|
|
pub fn facets<'t, 'u, 'i>(
|
2020-11-18 04:19:25 +08:00
|
|
|
self,
|
|
|
|
wtxn: &'t mut heed::RwTxn<'i, 'u>,
|
|
|
|
index: &'i Index,
|
2021-06-17 00:33:33 +08:00
|
|
|
) -> Facets<'t, 'u, 'i> {
|
2020-12-22 23:21:07 +08:00
|
|
|
let mut builder = Facets::new(wtxn, index, self.update_id);
|
2020-11-18 04:19:25 +08:00
|
|
|
|
|
|
|
builder.chunk_compression_type = self.chunk_compression_type;
|
|
|
|
builder.chunk_compression_level = self.chunk_compression_level;
|
|
|
|
|
|
|
|
builder
|
|
|
|
}
|
2020-10-26 01:32:01 +08:00
|
|
|
}
|