diff --git a/meilidb-data/src/database/custom_settings.rs b/meilidb-data/src/database/custom_settings.rs new file mode 100644 index 000000000..565151aaa --- /dev/null +++ b/meilidb-data/src/database/custom_settings.rs @@ -0,0 +1,13 @@ +use std::sync::Arc; +use std::ops::Deref; + +#[derive(Clone)] +pub struct CustomSettings(pub Arc); + +impl Deref for CustomSettings { + type Target = sled::Tree; + + fn deref(&self) -> &sled::Tree { + &self.0 + } +} diff --git a/meilidb-data/src/database/index.rs b/meilidb-data/src/database/index.rs index c534cd33d..2b981f5f1 100644 --- a/meilidb-data/src/database/index.rs +++ b/meilidb-data/src/database/index.rs @@ -12,7 +12,8 @@ use crate::ranked_map::RankedMap; use crate::schema::Schema; use crate::serde::Deserializer; -use super::{Error, RawIndex, DocumentsAddition, DocumentsDeletion}; +use super::{Error, CustomSettings}; +use super::{RawIndex, DocumentsAddition, DocumentsDeletion}; #[derive(Clone)] pub struct Index(pub ArcSwap); @@ -69,6 +70,10 @@ impl Index { self.0.lease().schema.clone() } + pub fn custom_settings(&self) -> CustomSettings { + self.0.lease().raw.custom.clone() + } + pub fn documents_addition(&self) -> DocumentsAddition { let ranked_map = self.0.lease().ranked_map.clone(); DocumentsAddition::new(self, ranked_map) diff --git a/meilidb-data/src/database/mod.rs b/meilidb-data/src/database/mod.rs index 5f415fb1e..dcdc13bd2 100644 --- a/meilidb-data/src/database/mod.rs +++ b/meilidb-data/src/database/mod.rs @@ -5,6 +5,7 @@ use std::sync::{Arc, RwLock}; use crate::Schema; +mod custom_settings; mod docs_words_index; mod documents_addition; mod documents_deletion; @@ -17,6 +18,7 @@ mod words_index; pub use self::error::Error; pub use self::index::Index; +pub use self::custom_settings::CustomSettings; use self::docs_words_index::DocsWordsIndex; use self::documents_addition::DocumentsAddition; @@ -96,7 +98,13 @@ impl Database { DocumentsIndex(tree) }; - let raw_index = RawIndex { main, words, docs_words, documents }; + let custom = { + let tree_name = format!("{}-custom", name); + let tree = self.inner.open_tree(tree_name)?; + CustomSettings(tree) + }; + + let raw_index = RawIndex { main, words, docs_words, documents, custom }; let index = Index::from_raw(raw_index)?; vacant.insert(Arc::new(index)).clone() @@ -145,11 +153,17 @@ impl Database { DocumentsIndex(tree) }; + let custom = { + let tree_name = format!("{}-custom", name); + let tree = self.inner.open_tree(tree_name)?; + CustomSettings(tree) + }; + let mut indexes = self.indexes()?.unwrap_or_else(HashSet::new); indexes.insert(name.to_string()); self.set_indexes(&indexes)?; - let raw_index = RawIndex { main, words, docs_words, documents }; + let raw_index = RawIndex { main, words, docs_words, documents, custom }; let index = Index::from_raw(raw_index)?; vacant.insert(Arc::new(index)).clone() diff --git a/meilidb-data/src/database/raw_index.rs b/meilidb-data/src/database/raw_index.rs index 0b2a56dbd..ada0fd357 100644 --- a/meilidb-data/src/database/raw_index.rs +++ b/meilidb-data/src/database/raw_index.rs @@ -1,4 +1,4 @@ -use super::{MainIndex, WordsIndex, DocsWordsIndex, DocumentsIndex}; +use super::{MainIndex, WordsIndex, DocsWordsIndex, DocumentsIndex, CustomSettings}; #[derive(Clone)] pub struct RawIndex { @@ -6,4 +6,5 @@ pub struct RawIndex { pub words: WordsIndex, pub docs_words: DocsWordsIndex, pub documents: DocumentsIndex, + pub custom: CustomSettings, } diff --git a/meilidb-data/src/lib.rs b/meilidb-data/src/lib.rs index 149a65fa8..22d58fe08 100644 --- a/meilidb-data/src/lib.rs +++ b/meilidb-data/src/lib.rs @@ -6,7 +6,7 @@ mod ranked_map; mod serde; pub mod schema; -pub use self::database::{Database, Index}; +pub use self::database::{Database, Index, CustomSettings}; pub use self::number::Number; pub use self::ranked_map::RankedMap; pub use self::schema::{Schema, SchemaAttr};