diff --git a/src/database/database_view.rs b/src/database/database_view.rs index 576fd1f9b..c6c30d39f 100644 --- a/src/database/database_view.rs +++ b/src/database/database_view.rs @@ -5,7 +5,9 @@ use rocksdb::rocksdb::{DB, DBVector, Snapshot, SeekKey}; use rocksdb::rocksdb_options::ReadOptions; use serde::de::DeserializeOwned; -use crate::database::{retrieve_data_schema, DocumentKey, DocumentKeyAttr}; +use crate::database::{DocumentKey, DocumentKeyAttr}; +use crate::database::{retrieve_data_schema, retrieve_data_index}; +use crate::database::blob::positive::PositiveBlob; use crate::database::deserializer::Deserializer; use crate::rank::criterion::Criterion; use crate::database::schema::Schema; @@ -14,19 +16,25 @@ use crate::DocumentId; pub struct DatabaseView<'a> { snapshot: Snapshot<&'a DB>, + blob: PositiveBlob, schema: Schema, } impl<'a> DatabaseView<'a> { pub fn new(snapshot: Snapshot<&'a DB>) -> Result> { let schema = retrieve_data_schema(&snapshot)?; - Ok(DatabaseView { snapshot, schema }) + let blob = retrieve_data_index(&snapshot)?; + Ok(DatabaseView { snapshot, blob, schema }) } pub fn schema(&self) -> &Schema { &self.schema } + pub fn blob(&self) -> &PositiveBlob { + &self.blob + } + pub fn into_snapshot(self) -> Snapshot<&'a DB> { self.snapshot } diff --git a/src/rank/query_builder.rs b/src/rank/query_builder.rs index 6dc13eb9b..1a43d30fb 100644 --- a/src/rank/query_builder.rs +++ b/src/rank/query_builder.rs @@ -10,8 +10,6 @@ use fst::Streamer; use crate::automaton::{self, DfaExt, AutomatonExt}; use crate::rank::criterion::{self, Criterion}; use crate::rank::distinct_map::DistinctMap; -use crate::database::retrieve_data_index; -use crate::database::blob::PositiveBlob; use crate::database::DatabaseView; use crate::{Match, DocumentId}; use crate::rank::Document; @@ -27,7 +25,6 @@ fn split_whitespace_automatons(query: &str) -> Vec { pub struct QueryBuilder<'a, C> { view: &'a DatabaseView<'a>, - blob: PositiveBlob, criteria: Vec, } @@ -39,8 +36,7 @@ impl<'a> QueryBuilder<'a, Box> { impl<'a, C> QueryBuilder<'a, C> { pub fn with_criteria(view: &'a DatabaseView<'a>, criteria: Vec) -> Result> { - let blob = retrieve_data_index(view.snapshot())?; - Ok(QueryBuilder { view, blob, criteria }) + Ok(QueryBuilder { view, criteria }) } pub fn criteria(&mut self, criteria: Vec) -> &mut Self { @@ -62,7 +58,7 @@ impl<'a, C> QueryBuilder<'a, C> { let mut stream = { let mut op_builder = fst::map::OpBuilder::new(); for automaton in &automatons { - let stream = self.blob.as_map().search(automaton); + let stream = self.view.blob().as_map().search(automaton); op_builder.push(stream); } op_builder.union() @@ -76,7 +72,7 @@ impl<'a, C> QueryBuilder<'a, C> { let distance = automaton.eval(input).to_u8(); let is_exact = distance == 0 && input.len() == automaton.query_len(); - let doc_indexes = self.blob.as_indexes(); + let doc_indexes = self.view.blob().as_indexes(); let doc_indexes = &doc_indexes[iv.value as usize]; for doc_index in doc_indexes {