mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-23 13:24:27 +01:00
requested changes
This commit is contained in:
parent
33c7c5a7e3
commit
d35a104ad3
@ -12,14 +12,14 @@ pub struct Synonyms {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Synonyms {
|
impl Synonyms {
|
||||||
pub fn put_synonyms<A>(self, writer: &mut heed::RwTxn<MainT>, word: &[u8], synonyms: &fst::Set<A>) -> ZResult<()>
|
pub(crate) fn put_synonyms<A>(self, writer: &mut heed::RwTxn<MainT>, word: &[u8], synonyms: &fst::Set<A>) -> ZResult<()>
|
||||||
where A: AsRef<[u8]>,
|
where A: AsRef<[u8]>,
|
||||||
{
|
{
|
||||||
let bytes = synonyms.as_fst().as_bytes();
|
let bytes = synonyms.as_fst().as_bytes();
|
||||||
self.synonyms.put(writer, word, bytes)
|
self.synonyms.put(writer, word, bytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clear(self, writer: &mut heed::RwTxn<MainT>) -> ZResult<()> {
|
pub(crate) fn clear(self, writer: &mut heed::RwTxn<MainT>) -> ZResult<()> {
|
||||||
self.synonyms.clear(writer)
|
self.synonyms.clear(writer)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use std::collections::{BTreeMap, BTreeSet, btree_map::Entry};
|
use std::collections::{BTreeMap, BTreeSet};
|
||||||
|
|
||||||
use heed::Result as ZResult;
|
use heed::Result as ZResult;
|
||||||
use fst::{set::OpBuilder, SetBuilder};
|
use fst::{set::OpBuilder, SetBuilder};
|
||||||
@ -126,7 +126,7 @@ pub fn apply_settings_update(
|
|||||||
}
|
}
|
||||||
|
|
||||||
match settings.synonyms {
|
match settings.synonyms {
|
||||||
UpdateState::Update(synonyms) => apply_synonyms_update(writer, index, transform_synonyms(synonyms))? ,
|
UpdateState::Update(synonyms) => apply_synonyms_update(writer, index, canonicalize_synonyms(synonyms))? ,
|
||||||
UpdateState::Clear => apply_synonyms_update(writer, index, BTreeMap::new())?,
|
UpdateState::Clear => apply_synonyms_update(writer, index, BTreeMap::new())?,
|
||||||
UpdateState::Nothing => (),
|
UpdateState::Nothing => (),
|
||||||
}
|
}
|
||||||
@ -138,21 +138,16 @@ pub fn apply_settings_update(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn transform_synonyms(synonyms: BTreeMap<String, Vec<String>>) -> BTreeMap<String, Vec<String>> {
|
fn canonicalize_synonyms(synonyms: BTreeMap<String, Vec<String>>) -> BTreeMap<String, Vec<String>> {
|
||||||
synonyms
|
let mut canonicalized = BTreeMap::new();
|
||||||
.into_iter()
|
for (key, values) in synonyms {
|
||||||
.fold(BTreeMap::new(), |mut map, (key, values)| {
|
|
||||||
let deunicoded = deunicode::deunicode(&key);
|
let deunicoded = deunicode::deunicode(&key);
|
||||||
match map.entry(deunicoded) {
|
canonicalized
|
||||||
Entry::Vacant(entry) => {
|
.entry(deunicoded)
|
||||||
entry.insert(values);
|
.or_insert_with(Vec::new)
|
||||||
|
.extend_from_slice(&values);
|
||||||
}
|
}
|
||||||
Entry::Occupied(mut entry) => {
|
canonicalized
|
||||||
entry.get_mut().extend_from_slice(&values);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
map
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn apply_attributes_for_faceting_update(
|
fn apply_attributes_for_faceting_update(
|
||||||
|
@ -1844,7 +1844,6 @@ async fn test_search_synonyms_unicased() {
|
|||||||
server.update_all_settings(settings).await;
|
server.update_all_settings(settings).await;
|
||||||
|
|
||||||
let (response, _) = server.get_synonyms().await;
|
let (response, _) = server.get_synonyms().await;
|
||||||
println!("response: {}", response);
|
|
||||||
assert_json_eq!(response, json!({"case":["machin", "truc"]}));
|
assert_json_eq!(response, json!({"case":["machin", "truc"]}));
|
||||||
|
|
||||||
let update = json!([
|
let update = json!([
|
||||||
@ -1860,4 +1859,8 @@ async fn test_search_synonyms_unicased() {
|
|||||||
});
|
});
|
||||||
let (response, _) = server.search_post(search).await;
|
let (response, _) = server.search_post(search).await;
|
||||||
assert_eq!(response["hits"].as_array().unwrap().len(), 1);
|
assert_eq!(response["hits"].as_array().unwrap().len(), 1);
|
||||||
|
|
||||||
|
server.delete_synonyms().await;
|
||||||
|
let (response, _) = server.get_synonyms().await;
|
||||||
|
assert_json_eq!(response, json!({}));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user