mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-23 13:24:27 +01:00
feat: Introduce synonyms deletion using the update system
This commit is contained in:
parent
451c0a6d03
commit
4deee93a55
@ -27,7 +27,7 @@ use super::{
|
||||
DocumentsAddition, FinalDocumentsAddition,
|
||||
DocumentsDeletion, FinalDocumentsDeletion,
|
||||
SynonymsAddition, FinalSynonymsAddition,
|
||||
SynonymsDeletion,
|
||||
SynonymsDeletion, FinalSynonymsDeletion,
|
||||
};
|
||||
|
||||
mod custom_settings_index;
|
||||
@ -49,7 +49,7 @@ enum UpdateOwned {
|
||||
DocumentsAddition(Vec<serde_json::Value>),
|
||||
DocumentsDeletion(Vec<DocumentId>),
|
||||
SynonymsAddition(BTreeMap<String, Vec<String>>),
|
||||
SynonymsDeletion( () /*SynonymsDeletion*/),
|
||||
SynonymsDeletion(BTreeMap<String, Option<Vec<String>>>),
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
@ -57,7 +57,7 @@ enum Update<D: serde::Serialize> {
|
||||
DocumentsAddition(Vec<D>),
|
||||
DocumentsDeletion(Vec<DocumentId>),
|
||||
SynonymsAddition(BTreeMap<String, Vec<String>>),
|
||||
SynonymsDeletion( () /*SynonymsDeletion*/),
|
||||
SynonymsDeletion(BTreeMap<String, Option<Vec<String>>>),
|
||||
}
|
||||
|
||||
fn spawn_update_system(index: Index) -> thread::JoinHandle<()> {
|
||||
@ -95,8 +95,9 @@ fn spawn_update_system(index: Index) -> thread::JoinHandle<()> {
|
||||
let addition = FinalSynonymsAddition::from_map(&index, synonyms);
|
||||
addition.finalize()?;
|
||||
},
|
||||
UpdateOwned::SynonymsDeletion(_) => {
|
||||
// ...
|
||||
UpdateOwned::SynonymsDeletion(synonyms) => {
|
||||
let deletion = FinalSynonymsDeletion::from_map(&index, synonyms);
|
||||
deletion.finalize()?;
|
||||
},
|
||||
}
|
||||
Ok(())
|
||||
@ -323,8 +324,12 @@ impl Index {
|
||||
self.raw_push_update(update)
|
||||
}
|
||||
|
||||
pub(crate) fn push_synonyms_deletion(&self, deletion: SynonymsDeletion) -> Result<u64, Error> {
|
||||
let update = bincode::serialize(&())?;
|
||||
pub(crate) fn push_synonyms_deletion(
|
||||
&self,
|
||||
deletion: BTreeMap<String, Option<Vec<String>>>,
|
||||
) -> Result<u64, Error>
|
||||
{
|
||||
let update = bincode::serialize(&deletion)?;
|
||||
self.raw_push_update(update)
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@ pub use self::index::{Index, CustomSettingsIndex};
|
||||
use self::documents_addition::{DocumentsAddition, FinalDocumentsAddition};
|
||||
use self::documents_deletion::{DocumentsDeletion, FinalDocumentsDeletion};
|
||||
use self::synonyms_addition::{SynonymsAddition, FinalSynonymsAddition};
|
||||
use self::synonyms_deletion::SynonymsDeletion;
|
||||
use self::synonyms_deletion::{SynonymsDeletion, FinalSynonymsDeletion};
|
||||
|
||||
fn load_indexes(tree: &sled::Tree) -> Result<HashSet<String>, Error> {
|
||||
match tree.get("indexes")? {
|
||||
|
@ -10,13 +10,13 @@ use super::{Error, Index};
|
||||
use super::index::Cache;
|
||||
|
||||
pub struct SynonymsDeletion<'a> {
|
||||
inner: &'a Index,
|
||||
index: &'a Index,
|
||||
synonyms: BTreeMap<String, Option<Vec<String>>>,
|
||||
}
|
||||
|
||||
impl<'a> SynonymsDeletion<'a> {
|
||||
pub fn new(inner: &'a Index) -> SynonymsDeletion<'a> {
|
||||
SynonymsDeletion { inner, synonyms: BTreeMap::new() }
|
||||
pub fn new(index: &'a Index) -> SynonymsDeletion<'a> {
|
||||
SynonymsDeletion { index, synonyms: BTreeMap::new() }
|
||||
}
|
||||
|
||||
pub fn delete_all_alternatives_of<S: AsRef<str>>(&mut self, synonym: S) {
|
||||
@ -38,6 +38,29 @@ impl<'a> SynonymsDeletion<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn finalize(self) -> Result<u64, Error> {
|
||||
self.index.push_synonyms_deletion(self.synonyms)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct FinalSynonymsDeletion<'a> {
|
||||
inner: &'a Index,
|
||||
synonyms: BTreeMap<String, Option<Vec<String>>>,
|
||||
}
|
||||
|
||||
impl<'a> FinalSynonymsDeletion<'a> {
|
||||
pub fn new(inner: &'a Index) -> FinalSynonymsDeletion<'a> {
|
||||
FinalSynonymsDeletion { inner, synonyms: BTreeMap::new() }
|
||||
}
|
||||
|
||||
pub fn from_map(
|
||||
inner: &'a Index,
|
||||
synonyms: BTreeMap<String, Option<Vec<String>>>,
|
||||
) -> FinalSynonymsDeletion<'a>
|
||||
{
|
||||
FinalSynonymsDeletion { inner, synonyms }
|
||||
}
|
||||
|
||||
pub fn finalize(self) -> Result<(), Error> {
|
||||
let ref_index = self.inner.as_ref();
|
||||
let synonyms = ref_index.synonyms_index;
|
||||
|
Loading…
Reference in New Issue
Block a user