mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-15 13:58:36 +02:00
implement distinct attribute
distinct can return error facet distinct on numbers return distinct error review fixes make get_facet_value more generic fixes
This commit is contained in:
parent
6e126c96a9
commit
45c45e11dd
13 changed files with 525 additions and 53 deletions
|
@ -70,6 +70,7 @@ pub struct Settings<'a, 't, 'u, 'i> {
|
|||
faceted_fields: Setting<HashMap<String, String>>,
|
||||
criteria: Setting<Vec<String>>,
|
||||
stop_words: Setting<BTreeSet<String>>,
|
||||
distinct_attribute: Setting<String>,
|
||||
}
|
||||
|
||||
impl<'a, 't, 'u, 'i> Settings<'a, 't, 'u, 'i> {
|
||||
|
@ -94,6 +95,7 @@ impl<'a, 't, 'u, 'i> Settings<'a, 't, 'u, 'i> {
|
|||
faceted_fields: Setting::NotSet,
|
||||
criteria: Setting::NotSet,
|
||||
stop_words: Setting::NotSet,
|
||||
distinct_attribute: Setting::NotSet,
|
||||
update_id,
|
||||
}
|
||||
}
|
||||
|
@ -142,6 +144,14 @@ impl<'a, 't, 'u, 'i> Settings<'a, 't, 'u, 'i> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn set_distinct_attribute(&mut self, distinct_attribute: String) {
|
||||
self.distinct_attribute = Setting::Set(distinct_attribute);
|
||||
}
|
||||
|
||||
pub fn reset_distinct_attribute(&mut self) {
|
||||
self.distinct_attribute = Setting::Reset;
|
||||
}
|
||||
|
||||
fn reindex<F>(&mut self, cb: &F, old_fields_ids_map: FieldsIdsMap) -> anyhow::Result<()>
|
||||
where
|
||||
F: Fn(UpdateIndexingStep, u64) + Sync
|
||||
|
@ -220,6 +230,23 @@ impl<'a, 't, 'u, 'i> Settings<'a, 't, 'u, 'i> {
|
|||
Ok(true)
|
||||
}
|
||||
|
||||
fn update_distinct_attribute(&mut self) -> anyhow::Result<bool> {
|
||||
match self.distinct_attribute {
|
||||
Setting::Set(ref attr) => {
|
||||
let mut fields_ids_map = self.index.fields_ids_map(self.wtxn)?;
|
||||
fields_ids_map
|
||||
.insert(attr)
|
||||
.context("field id limit exceeded")?;
|
||||
|
||||
self.index.put_distinct_attribute(self.wtxn, &attr)?;
|
||||
self.index.put_fields_ids_map(self.wtxn, &fields_ids_map)?;
|
||||
}
|
||||
Setting::Reset => { self.index.delete_distinct_attribute(self.wtxn)?; },
|
||||
Setting::NotSet => return Ok(false),
|
||||
}
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
/// Updates the index's searchable attributes. This causes the field map to be recomputed to
|
||||
/// reflect the order of the searchable attributes.
|
||||
fn update_searchable(&mut self) -> anyhow::Result<bool> {
|
||||
|
@ -328,6 +355,7 @@ impl<'a, 't, 'u, 'i> Settings<'a, 't, 'u, 'i> {
|
|||
self.update_displayed()?;
|
||||
let stop_words_updated = self.update_stop_words()?;
|
||||
let facets_updated = self.update_facets()?;
|
||||
self.update_distinct_attribute()?;
|
||||
// update_criteria MUST be called after update_facets, since criterion fields must be set
|
||||
// as facets.
|
||||
self.update_criteria()?;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue