mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-12-24 13:40:31 +01:00
feat: Introduce a custom tree for user custom settings
This commit is contained in:
parent
c5ba34d0b0
commit
830d2f28b9
13
meilidb-data/src/database/custom_settings.rs
Normal file
13
meilidb-data/src/database/custom_settings.rs
Normal file
@ -0,0 +1,13 @@
|
||||
use std::sync::Arc;
|
||||
use std::ops::Deref;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct CustomSettings(pub Arc<sled::Tree>);
|
||||
|
||||
impl Deref for CustomSettings {
|
||||
type Target = sled::Tree;
|
||||
|
||||
fn deref(&self) -> &sled::Tree {
|
||||
&self.0
|
||||
}
|
||||
}
|
@ -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<InnerIndex>);
|
||||
@ -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)
|
||||
|
@ -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()
|
||||
|
@ -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,
|
||||
}
|
||||
|
@ -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};
|
||||
|
Loading…
x
Reference in New Issue
Block a user