mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-30 00:55:00 +08:00
Rename attributes for faceting into filterable attributes
This commit is contained in:
parent
7009906d55
commit
88bf867a3e
@ -87,7 +87,7 @@ impl Index {
|
|||||||
Ok(Settings {
|
Ok(Settings {
|
||||||
displayed_attributes: Some(displayed_attributes),
|
displayed_attributes: Some(displayed_attributes),
|
||||||
searchable_attributes: Some(searchable_attributes),
|
searchable_attributes: Some(searchable_attributes),
|
||||||
attributes_for_faceting: Some(Some(faceted_attributes)),
|
filterable_attributes: Some(Some(faceted_attributes)),
|
||||||
ranking_rules: Some(Some(criteria)),
|
ranking_rules: Some(Some(criteria)),
|
||||||
stop_words: Some(Some(stop_words)),
|
stop_words: Some(Some(stop_words)),
|
||||||
distinct_attribute: Some(distinct_field),
|
distinct_attribute: Some(distinct_field),
|
||||||
|
@ -51,7 +51,7 @@ pub struct Settings<T> {
|
|||||||
deserialize_with = "deserialize_some",
|
deserialize_with = "deserialize_some",
|
||||||
skip_serializing_if = "Option::is_none"
|
skip_serializing_if = "Option::is_none"
|
||||||
)]
|
)]
|
||||||
pub attributes_for_faceting: Option<Option<HashSet<String>>>,
|
pub filterable_attributes: Option<Option<HashSet<String>>>,
|
||||||
|
|
||||||
#[serde(
|
#[serde(
|
||||||
default,
|
default,
|
||||||
@ -81,7 +81,7 @@ impl Settings<Checked> {
|
|||||||
Settings {
|
Settings {
|
||||||
displayed_attributes: Some(None),
|
displayed_attributes: Some(None),
|
||||||
searchable_attributes: Some(None),
|
searchable_attributes: Some(None),
|
||||||
attributes_for_faceting: Some(None),
|
filterable_attributes: Some(None),
|
||||||
ranking_rules: Some(None),
|
ranking_rules: Some(None),
|
||||||
stop_words: Some(None),
|
stop_words: Some(None),
|
||||||
distinct_attribute: Some(None),
|
distinct_attribute: Some(None),
|
||||||
@ -93,7 +93,7 @@ impl Settings<Checked> {
|
|||||||
let Self {
|
let Self {
|
||||||
displayed_attributes,
|
displayed_attributes,
|
||||||
searchable_attributes,
|
searchable_attributes,
|
||||||
attributes_for_faceting,
|
filterable_attributes,
|
||||||
ranking_rules,
|
ranking_rules,
|
||||||
stop_words,
|
stop_words,
|
||||||
distinct_attribute,
|
distinct_attribute,
|
||||||
@ -103,7 +103,7 @@ impl Settings<Checked> {
|
|||||||
Settings {
|
Settings {
|
||||||
displayed_attributes,
|
displayed_attributes,
|
||||||
searchable_attributes,
|
searchable_attributes,
|
||||||
attributes_for_faceting,
|
filterable_attributes,
|
||||||
ranking_rules,
|
ranking_rules,
|
||||||
stop_words,
|
stop_words,
|
||||||
distinct_attribute,
|
distinct_attribute,
|
||||||
@ -139,7 +139,7 @@ impl Settings<Unchecked> {
|
|||||||
Settings {
|
Settings {
|
||||||
displayed_attributes,
|
displayed_attributes,
|
||||||
searchable_attributes,
|
searchable_attributes,
|
||||||
attributes_for_faceting: self.attributes_for_faceting,
|
filterable_attributes: self.filterable_attributes,
|
||||||
ranking_rules: self.ranking_rules,
|
ranking_rules: self.ranking_rules,
|
||||||
stop_words: self.stop_words,
|
stop_words: self.stop_words,
|
||||||
distinct_attribute: self.distinct_attribute,
|
distinct_attribute: self.distinct_attribute,
|
||||||
@ -252,7 +252,7 @@ impl Index {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(ref facet_types) = settings.attributes_for_faceting {
|
if let Some(ref facet_types) = settings.filterable_attributes {
|
||||||
let facet_types = facet_types.clone().unwrap_or_else(HashSet::new);
|
let facet_types = facet_types.clone().unwrap_or_else(HashSet::new);
|
||||||
builder.set_filterable_fields(facet_types);
|
builder.set_filterable_fields(facet_types);
|
||||||
}
|
}
|
||||||
@ -329,7 +329,7 @@ mod test {
|
|||||||
let settings = Settings {
|
let settings = Settings {
|
||||||
displayed_attributes: Some(Some(vec![String::from("hello")])),
|
displayed_attributes: Some(Some(vec![String::from("hello")])),
|
||||||
searchable_attributes: Some(Some(vec![String::from("hello")])),
|
searchable_attributes: Some(Some(vec![String::from("hello")])),
|
||||||
attributes_for_faceting: None,
|
filterable_attributes: None,
|
||||||
ranking_rules: None,
|
ranking_rules: None,
|
||||||
stop_words: None,
|
stop_words: None,
|
||||||
distinct_attribute: None,
|
distinct_attribute: None,
|
||||||
@ -348,7 +348,7 @@ mod test {
|
|||||||
let settings = Settings {
|
let settings = Settings {
|
||||||
displayed_attributes: Some(Some(vec![String::from("*")])),
|
displayed_attributes: Some(Some(vec![String::from("*")])),
|
||||||
searchable_attributes: Some(Some(vec![String::from("hello"), String::from("*")])),
|
searchable_attributes: Some(Some(vec![String::from("hello"), String::from("*")])),
|
||||||
attributes_for_faceting: None,
|
filterable_attributes: None,
|
||||||
ranking_rules: None,
|
ranking_rules: None,
|
||||||
stop_words: None,
|
stop_words: None,
|
||||||
distinct_attribute: None,
|
distinct_attribute: None,
|
||||||
|
@ -73,7 +73,7 @@ struct Settings {
|
|||||||
#[serde(default, deserialize_with = "deserialize_some")]
|
#[serde(default, deserialize_with = "deserialize_some")]
|
||||||
pub synonyms: Option<Option<BTreeMap<String, Vec<String>>>>,
|
pub synonyms: Option<Option<BTreeMap<String, Vec<String>>>>,
|
||||||
#[serde(default, deserialize_with = "deserialize_some")]
|
#[serde(default, deserialize_with = "deserialize_some")]
|
||||||
pub attributes_for_faceting: Option<Option<Vec<String>>>,
|
pub filterable_attributes: Option<Option<Vec<String>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load_index(
|
fn load_index(
|
||||||
@ -145,7 +145,7 @@ impl From<Settings> for index_controller::Settings<Unchecked> {
|
|||||||
// representing the name of the faceted field + the type of the field. Since the type
|
// representing the name of the faceted field + the type of the field. Since the type
|
||||||
// was not known in the V1 of the dump we are just going to assume everything is a
|
// was not known in the V1 of the dump we are just going to assume everything is a
|
||||||
// String
|
// String
|
||||||
attributes_for_faceting: settings.attributes_for_faceting.map(|o| o.map(|vec| vec.into_iter().collect())),
|
filterable_attributes: settings.filterable_attributes.map(|o| o.map(|vec| vec.into_iter().collect())),
|
||||||
// we need to convert the old `Vec<String>` into a `BTreeSet<String>`
|
// we need to convert the old `Vec<String>` into a `BTreeSet<String>`
|
||||||
ranking_rules: settings.ranking_rules.map(|o| o.map(|vec| vec.into_iter().filter_map(|criterion| {
|
ranking_rules: settings.ranking_rules.map(|o| o.map(|vec| vec.into_iter().filter_map(|criterion| {
|
||||||
match criterion.as_str() {
|
match criterion.as_str() {
|
||||||
|
@ -74,9 +74,9 @@ macro_rules! make_setting_route {
|
|||||||
}
|
}
|
||||||
|
|
||||||
make_setting_route!(
|
make_setting_route!(
|
||||||
"/indexes/{index_uid}/settings/attributes-for-faceting",
|
"/indexes/{index_uid}/settings/filterable-attributes",
|
||||||
std::collections::HashSet<String>,
|
std::collections::HashSet<String>,
|
||||||
attributes_for_faceting
|
filterable_attributes
|
||||||
);
|
);
|
||||||
|
|
||||||
make_setting_route!(
|
make_setting_route!(
|
||||||
@ -126,7 +126,7 @@ macro_rules! create_services {
|
|||||||
}
|
}
|
||||||
|
|
||||||
create_services!(
|
create_services!(
|
||||||
attributes_for_faceting,
|
filterable_attributes,
|
||||||
displayed_attributes,
|
displayed_attributes,
|
||||||
searchable_attributes,
|
searchable_attributes,
|
||||||
distinct_attribute,
|
distinct_attribute,
|
||||||
|
@ -50,7 +50,7 @@
|
|||||||
"wolverine": ["xmen", "logan"],
|
"wolverine": ["xmen", "logan"],
|
||||||
"logan": ["wolverine", "xmen"]
|
"logan": ["wolverine", "xmen"]
|
||||||
},
|
},
|
||||||
"attributesForFaceting": [
|
"filterableAttributes": [
|
||||||
"gender",
|
"gender",
|
||||||
"color",
|
"color",
|
||||||
"tags",
|
"tags",
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
{"status": "processed","updateId": 0,"type": {"name":"Settings","settings":{"ranking_rules":{"Update":["Typo","Words","Proximity","Attribute","WordsPosition","Exactness"]},"distinct_attribute":"Nothing","primary_key":"Nothing","searchable_attributes":{"Update":["balance","picture","age","color","name","gender","email","phone","address","about","registered","latitude","longitude","tags"]},"displayed_attributes":{"Update":["about","address","age","balance","color","email","gender","id","isActive","latitude","longitude","name","phone","picture","registered","tags"]},"stop_words":"Nothing","synonyms":"Nothing","attributes_for_faceting":"Nothing"}}}
|
{"status": "processed","updateId": 0,"type": {"name":"Settings","settings":{"ranking_rules":{"Update":["Typo","Words","Proximity","Attribute","WordsPosition","Exactness"]},"distinct_attribute":"Nothing","primary_key":"Nothing","searchable_attributes":{"Update":["balance","picture","age","color","name","gender","email","phone","address","about","registered","latitude","longitude","tags"]},"displayed_attributes":{"Update":["about","address","age","balance","color","email","gender","id","isActive","latitude","longitude","name","phone","picture","registered","tags"]},"stop_words":"Nothing","synonyms":"Nothing","filterable_attributes":"Nothing"}}}
|
||||||
{"status": "processed", "updateId": 1, "type": { "name": "DocumentsAddition"}}
|
{"status": "processed", "updateId": 1, "type": { "name": "DocumentsAddition"}}
|
@ -19,7 +19,7 @@ async fn get_settings() {
|
|||||||
assert_eq!(settings.keys().len(), 6);
|
assert_eq!(settings.keys().len(), 6);
|
||||||
assert_eq!(settings["displayedAttributes"], json!(["*"]));
|
assert_eq!(settings["displayedAttributes"], json!(["*"]));
|
||||||
assert_eq!(settings["searchableAttributes"], json!(["*"]));
|
assert_eq!(settings["searchableAttributes"], json!(["*"]));
|
||||||
assert_eq!(settings["attributesForFaceting"], json!([]));
|
assert_eq!(settings["filterableAttributes"], json!([]));
|
||||||
assert_eq!(settings["distinctAttribute"], json!(null));
|
assert_eq!(settings["distinctAttribute"], json!(null));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
settings["rankingRules"],
|
settings["rankingRules"],
|
||||||
@ -87,7 +87,7 @@ async fn reset_all_settings() {
|
|||||||
index.wait_update_id(0).await;
|
index.wait_update_id(0).await;
|
||||||
|
|
||||||
index
|
index
|
||||||
.update_settings(json!({"displayedAttributes": ["name", "age"], "searchableAttributes": ["name"], "stopWords": ["the"], "attributesForFaceting": ["age"] }))
|
.update_settings(json!({"displayedAttributes": ["name", "age"], "searchableAttributes": ["name"], "stopWords": ["the"], "filterableAttributes": ["age"] }))
|
||||||
.await;
|
.await;
|
||||||
index.wait_update_id(1).await;
|
index.wait_update_id(1).await;
|
||||||
let (response, code) = index.settings().await;
|
let (response, code) = index.settings().await;
|
||||||
@ -95,7 +95,7 @@ async fn reset_all_settings() {
|
|||||||
assert_eq!(response["displayedAttributes"], json!(["name", "age"]));
|
assert_eq!(response["displayedAttributes"], json!(["name", "age"]));
|
||||||
assert_eq!(response["searchableAttributes"], json!(["name"]));
|
assert_eq!(response["searchableAttributes"], json!(["name"]));
|
||||||
assert_eq!(response["stopWords"], json!(["the"]));
|
assert_eq!(response["stopWords"], json!(["the"]));
|
||||||
assert_eq!(response["attributesForFaceting"], json!(["age"]));
|
assert_eq!(response["filterableAttributes"], json!(["age"]));
|
||||||
|
|
||||||
index.delete_settings().await;
|
index.delete_settings().await;
|
||||||
index.wait_update_id(2).await;
|
index.wait_update_id(2).await;
|
||||||
@ -105,7 +105,7 @@ async fn reset_all_settings() {
|
|||||||
assert_eq!(response["displayedAttributes"], json!(["*"]));
|
assert_eq!(response["displayedAttributes"], json!(["*"]));
|
||||||
assert_eq!(response["searchableAttributes"], json!(["*"]));
|
assert_eq!(response["searchableAttributes"], json!(["*"]));
|
||||||
assert_eq!(response["stopWords"], json!([]));
|
assert_eq!(response["stopWords"], json!([]));
|
||||||
assert_eq!(response["attributesForFaceting"], json!([]));
|
assert_eq!(response["filterableAttributes"], json!([]));
|
||||||
|
|
||||||
let (response, code) = index.get_document(1, None).await;
|
let (response, code) = index.get_document(1, None).await;
|
||||||
assert_eq!(code, 200);
|
assert_eq!(code, 200);
|
||||||
@ -181,7 +181,7 @@ macro_rules! test_setting_routes {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test_setting_routes!(
|
test_setting_routes!(
|
||||||
attributes_for_faceting,
|
filterable_attributes,
|
||||||
displayed_attributes,
|
displayed_attributes,
|
||||||
searchable_attributes,
|
searchable_attributes,
|
||||||
stop_words
|
stop_words
|
||||||
|
Loading…
Reference in New Issue
Block a user