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