enable distinct

This commit is contained in:
mpostma 2021-03-29 09:22:36 +02:00 committed by Marin Postma
parent bf3c04f2dc
commit ec230c2835
No known key found for this signature in database
GPG Key ID: D5241F0C0C865F30
3 changed files with 693 additions and 745 deletions

File diff suppressed because it is too large Load Diff

View File

@ -59,6 +59,9 @@ impl Index {
})
.transpose()?
.unwrap_or_else(BTreeSet::new);
let distinct_attribute = self
.distinct_attribute(&txn)?
.map(String::from);
Ok(Settings {
displayed_attributes: Some(Some(displayed_attributes)),
@ -66,6 +69,7 @@ impl Index {
attributes_for_faceting: Some(Some(faceted_attributes)),
ranking_rules: Some(Some(criteria)),
stop_words: Some(Some(stop_words)),
distinct_attribute: Some(distinct_attribute),
})
}

View File

@ -43,13 +43,18 @@ pub struct Settings {
skip_serializing_if = "Option::is_none"
)]
pub ranking_rules: Option<Option<Vec<String>>>,
#[serde(
default,
deserialize_with = "deserialize_some",
skip_serializing_if = "Option::is_none"
)]
pub stop_words: Option<Option<BTreeSet<String>>>,
#[serde(
default,
deserialize_with = "deserialize_some",
skip_serializing_if = "Option::is_none"
)]
pub distinct_attribute: Option<Option<String>>,
}
impl Settings {
@ -60,6 +65,7 @@ impl Settings {
attributes_for_faceting: Some(None),
ranking_rules: Some(None),
stop_words: Some(None),
distinct_attribute: Some(None),
}
}
}
@ -145,7 +151,6 @@ impl Index {
let mut wtxn = self.write_txn()?;
let mut builder = update_builder.settings(&mut wtxn, self);
// We transpose the settings JSON struct into a real setting update.
if let Some(ref names) = settings.searchable_attributes {
match names {
Some(names) => builder.set_searchable_fields(names.clone()),
@ -153,7 +158,6 @@ impl Index {
}
}
// We transpose the settings JSON struct into a real setting update.
if let Some(ref names) = settings.displayed_attributes {
match names {
Some(names) => builder.set_displayed_fields(names.clone()),
@ -161,13 +165,11 @@ impl Index {
}
}
// We transpose the settings JSON struct into a real setting update.
if let Some(ref facet_types) = settings.attributes_for_faceting {
let facet_types = facet_types.clone().unwrap_or_else(HashMap::new);
builder.set_faceted_fields(facet_types);
}
// We transpose the settings JSON struct into a real setting update.
if let Some(ref criteria) = settings.ranking_rules {
match criteria {
Some(criteria) => builder.set_criteria(criteria.clone()),
@ -175,7 +177,6 @@ impl Index {
}
}
// We transpose the settings JSON struct into a real setting update.
if let Some(ref stop_words) = settings.stop_words {
match stop_words {
Some(stop_words) => builder.set_stop_words(stop_words.clone()),
@ -183,6 +184,13 @@ impl Index {
}
}
if let Some(ref distinct_attribute) = settings.distinct_attribute {
match distinct_attribute {
Some(attr) => builder.set_distinct_attribute(attr.clone()),
None => builder.reset_distinct_attribute(),
}
}
let result = builder
.execute(|indexing_step, update_id| info!("update {}: {:?}", update_id, indexing_step));