finish settings

This commit is contained in:
qdequele 2020-01-21 12:03:48 +01:00
parent dbba310770
commit 58fe87067b
No known key found for this signature in database
GPG Key ID: B3F0A000EBF11745
4 changed files with 104 additions and 125 deletions

View File

@ -2,7 +2,7 @@ use std::sync::Mutex;
use std::collections::{BTreeMap, BTreeSet, HashSet}; use std::collections::{BTreeMap, BTreeSet, HashSet};
use std::str::FromStr; use std::str::FromStr;
use serde::{Deserialize, Deserializer, Serialize}; use serde::{Deserialize, Serialize};
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
static RANKING_RULE_REGEX: Lazy<Mutex<regex::Regex>> = Lazy::new(|| { static RANKING_RULE_REGEX: Lazy<Mutex<regex::Regex>> = Lazy::new(|| {
@ -12,6 +12,7 @@ static RANKING_RULE_REGEX: Lazy<Mutex<regex::Regex>> = Lazy::new(|| {
#[derive(Default, Clone, Serialize, Deserialize)] #[derive(Default, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct Settings { pub struct Settings {
pub ranking_rules: Option<Vec<String>>, pub ranking_rules: Option<Vec<String>>,
pub ranking_distinct: Option<String>, pub ranking_distinct: Option<String>,
@ -22,8 +23,8 @@ pub struct Settings {
pub synonyms: Option<BTreeMap<String, Vec<String>>>, pub synonyms: Option<BTreeMap<String, Vec<String>>>,
} }
impl Into<SettingsUpdate> for Settings { impl Settings {
fn into(self) -> SettingsUpdate { pub fn into_cleared(self) -> SettingsUpdate {
let settings = self.clone(); let settings = self.clone();
let ranking_rules = match settings.ranking_rules { let ranking_rules = match settings.ranking_rules {
@ -32,42 +33,23 @@ impl Into<SettingsUpdate> for Settings {
}; };
SettingsUpdate { SettingsUpdate {
ranking_rules: ranking_rules.into(), ranking_rules: UpdateState::convert_with_default(ranking_rules, UpdateState::Clear),
ranking_distinct: settings.ranking_distinct.into(), ranking_distinct: UpdateState::convert_with_default(settings.ranking_distinct, UpdateState::Clear),
attribute_identifier: settings.attribute_identifier.into(), attribute_identifier: UpdateState::convert_with_default(settings.attribute_identifier, UpdateState::Clear),
attributes_searchable: settings.attributes_searchable.into(), attributes_searchable: UpdateState::convert_with_default(settings.attributes_searchable, UpdateState::Clear),
attributes_displayed: settings.attributes_displayed.into(), attributes_displayed: UpdateState::convert_with_default(settings.attributes_displayed, UpdateState::Clear),
stop_words: settings.stop_words.into(), stop_words: UpdateState::convert_with_default(settings.stop_words, UpdateState::Clear),
synonyms: settings.synonyms.into(), synonyms: UpdateState::convert_with_default(settings.synonyms, UpdateState::Clear),
} }
} }
} }
#[derive(Default, Clone, Serialize, Deserialize)] impl Into<SettingsUpdate> for Settings {
pub struct SettingsComplete {
#[serde(default, deserialize_with = "deserialize_some")]
pub ranking_rules: Option<Option<Vec<String>>>,
#[serde(default, deserialize_with = "deserialize_some")]
pub ranking_distinct: Option<Option<String>>,
#[serde(default, deserialize_with = "deserialize_some")]
pub attribute_identifier: Option<Option<String>>,
#[serde(default, deserialize_with = "deserialize_some")]
pub attributes_searchable: Option<Option<Vec<String>>>,
#[serde(default, deserialize_with = "deserialize_some")]
pub attributes_displayed: Option<Option<HashSet<String>>>,
#[serde(default, deserialize_with = "deserialize_some")]
pub stop_words: Option<Option<BTreeSet<String>>>,
#[serde(default, deserialize_with = "deserialize_some")]
pub synonyms: Option<Option<BTreeMap<String, Vec<String>>>>,
}
impl Into<SettingsUpdate> for SettingsComplete {
fn into(self) -> SettingsUpdate { fn into(self) -> SettingsUpdate {
let settings = self.clone(); let settings = self.clone();
let ranking_rules = match settings.ranking_rules { let ranking_rules = match settings.ranking_rules {
Some(Some(rules)) => Some(Some(RankingRule::from_vec(rules))), Some(rules) => Some(RankingRule::from_vec(rules)),
Some(None) => Some(None),
None => None, None => None,
}; };
@ -101,16 +83,6 @@ impl <T> From<Option<T>> for UpdateState<T> {
} }
} }
impl <T> From<Option<Option<T>>> for UpdateState<T> {
fn from(opt: Option<Option<T>>) -> UpdateState<T> {
match opt {
Some(Some(t)) => UpdateState::Update(t),
Some(None) => UpdateState::Clear,
None => UpdateState::Nothing,
}
}
}
impl<T> UpdateState<T> { impl<T> UpdateState<T> {
pub fn is_changed(&self) -> bool { pub fn is_changed(&self) -> bool {
match self { match self {
@ -118,6 +90,13 @@ impl<T> UpdateState<T> {
_ => true, _ => true,
} }
} }
fn convert_with_default(opt: Option<T>, default: UpdateState<T>) -> UpdateState<T> {
match opt {
Some(t) => UpdateState::Update(t),
None => default,
}
}
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
@ -169,9 +148,9 @@ impl FromStr for RankingRule {
"_exact" => RankingRule::Exact, "_exact" => RankingRule::Exact,
_ => { _ => {
let captures = RANKING_RULE_REGEX.lock().unwrap().captures(s).unwrap(); let captures = RANKING_RULE_REGEX.lock().unwrap().captures(s).unwrap();
match captures[0].as_ref() { match captures[1].as_ref() {
"asc" => RankingRule::Asc(captures[1].to_string()), "asc" => RankingRule::Asc(captures[2].to_string()),
"dsc" => RankingRule::Dsc(captures[1].to_string()), "dsc" => RankingRule::Dsc(captures[2].to_string()),
_ => return Err(RankingRuleConversionError) _ => return Err(RankingRuleConversionError)
} }
} }
@ -220,11 +199,3 @@ impl Default for SettingsUpdate {
} }
} }
} }
// Any value that is present is considered Some value, including null.
fn deserialize_some<'de, T, D>(deserializer: D) -> Result<Option<T>, D::Error>
where T: Deserialize<'de>,
D: Deserializer<'de>
{
Deserialize::deserialize(deserializer).map(Some)
}

View File

@ -8,10 +8,10 @@ use tide::Request;
pub trait RequestExt { pub trait RequestExt {
fn is_allowed(&self, acl: ACL) -> SResult<()>; fn is_allowed(&self, acl: ACL) -> SResult<()>;
fn header(&self, name: &str) -> Result<String, ResponseError>; fn header(&self, name: &str) -> SResult<String>;
fn url_param(&self, name: &str) -> Result<String, ResponseError>; fn url_param(&self, name: &str) -> SResult<String>;
fn index(&self) -> Result<Index, ResponseError>; fn index(&self) -> SResult<Index>;
fn identifier(&self) -> Result<String, ResponseError>; fn identifier(&self) -> SResult<String>;
} }
impl RequestExt for Request<Data> { impl RequestExt for Request<Data> {
@ -73,7 +73,7 @@ impl RequestExt for Request<Data> {
Ok(()) Ok(())
} }
fn header(&self, name: &str) -> Result<String, ResponseError> { fn header(&self, name: &str) -> SResult<String> {
let header = self let header = self
.headers() .headers()
.get(name) .get(name)
@ -84,14 +84,13 @@ impl RequestExt for Request<Data> {
Ok(header) Ok(header)
} }
fn url_param(&self, name: &str) -> Result<String, ResponseError> { fn url_param(&self, name: &str) -> SResult<String> {
let param = self let param = self.param::<String>(name)
.param::<String>(name) .map_err(|_| ResponseError::bad_parameter("identifier", ""))?;
.map_err(|e| ResponseError::bad_parameter(name, e))?;
Ok(param) Ok(param)
} }
fn index(&self) -> Result<Index, ResponseError> { fn index(&self) -> SResult<Index> {
let index_uid = self.url_param("index")?; let index_uid = self.url_param("index")?;
let index = self let index = self
.state() .state()
@ -101,10 +100,9 @@ impl RequestExt for Request<Data> {
Ok(index) Ok(index)
} }
fn identifier(&self) -> Result<String, ResponseError> { fn identifier(&self) -> SResult<String> {
let name = self let name = self.param::<String>("identifier")
.param::<String>("identifier") .map_err(|_| ResponseError::bad_parameter("identifier", ""))?;
.map_err(|e| ResponseError::bad_parameter("identifier", e))?;
Ok(name) Ok(name)
} }

View File

@ -1,7 +1,7 @@
use std::collections::{BTreeMap, BTreeSet, HashSet}; use std::collections::{BTreeMap, BTreeSet, HashSet};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use tide::{Request, Response}; use tide::{Request, Response};
use meilisearch_core::settings::{SettingsUpdate, UpdateState, Settings, SettingsComplete}; use meilisearch_core::settings::{SettingsUpdate, UpdateState, Settings};
use crate::error::{ResponseError, SResult}; use crate::error::{ResponseError, SResult};
use crate::helpers::tide::RequestExt; use crate::helpers::tide::RequestExt;
@ -77,11 +77,11 @@ pub async fn get_all(ctx: Request<Data>) -> SResult<Response> {
pub async fn update_all(mut ctx: Request<Data>) -> SResult<Response> { pub async fn update_all(mut ctx: Request<Data>) -> SResult<Response> {
ctx.is_allowed(SettingsWrite)?; ctx.is_allowed(SettingsWrite)?;
let index = ctx.index()?; let index = ctx.index()?;
let settings: SettingsComplete = ctx.body_json().await.map_err(ResponseError::bad_request)?; let settings: Settings = ctx.body_json().await.map_err(ResponseError::bad_request)?;
let db = &ctx.state().db; let db = &ctx.state().db;
let mut writer = db.update_write_txn()?; let mut writer = db.update_write_txn()?;
let update_id = index.settings_update(&mut writer, settings.into())?; let update_id = index.settings_update(&mut writer, settings.into_cleared())?;
writer.commit()?; writer.commit()?;
let response_body = IndexUpdateResponse { update_id }; let response_body = IndexUpdateResponse { update_id };
@ -113,6 +113,7 @@ pub async fn delete_all(ctx: Request<Data>) -> SResult<Response> {
} }
#[derive(Default, Clone, Serialize, Deserialize)] #[derive(Default, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct GetRankingSettings { pub struct GetRankingSettings {
pub ranking_rules: Option<Vec<String>>, pub ranking_rules: Option<Vec<String>>,
pub ranking_distinct: Option<String>, pub ranking_distinct: Option<String>,
@ -141,9 +142,10 @@ pub async fn get_ranking(ctx: Request<Data>) -> SResult<Response> {
} }
#[derive(Default, Clone, Serialize, Deserialize)] #[derive(Default, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct SetRankingSettings { pub struct SetRankingSettings {
pub ranking_rules: Option<Option<Vec<String>>>, pub ranking_rules: Option<Vec<String>>,
pub ranking_distinct: Option<Option<String>>, pub ranking_distinct: Option<String>,
} }
pub async fn update_ranking(mut ctx: Request<Data>) -> SResult<Response> { pub async fn update_ranking(mut ctx: Request<Data>) -> SResult<Response> {
@ -152,14 +154,14 @@ pub async fn update_ranking(mut ctx: Request<Data>) -> SResult<Response> {
let settings: SetRankingSettings = ctx.body_json().await.map_err(ResponseError::bad_request)?; let settings: SetRankingSettings = ctx.body_json().await.map_err(ResponseError::bad_request)?;
let db = &ctx.state().db; let db = &ctx.state().db;
let settings = SettingsComplete { let settings = Settings {
ranking_rules: settings.ranking_rules, ranking_rules: settings.ranking_rules,
ranking_distinct: settings.ranking_distinct, ranking_distinct: settings.ranking_distinct,
.. SettingsComplete::default() .. Settings::default()
}; };
let mut writer = db.update_write_txn()?; let mut writer = db.update_write_txn()?;
let update_id = index.settings_update(&mut writer, settings.into())?; let update_id = index.settings_update(&mut writer, settings.into_cleared())?;
writer.commit()?; writer.commit()?;
let response_body = IndexUpdateResponse { update_id }; let response_body = IndexUpdateResponse { update_id };
@ -187,6 +189,7 @@ pub async fn delete_ranking(ctx: Request<Data>) -> SResult<Response> {
} }
#[derive(Default, Clone, Serialize, Deserialize)] #[derive(Default, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct GetRankingRulesSettings { pub struct GetRankingRulesSettings {
pub ranking_rules: Option<Vec<String>>, pub ranking_rules: Option<Vec<String>>,
} }
@ -212,8 +215,9 @@ pub async fn get_rules(ctx: Request<Data>) -> SResult<Response> {
} }
#[derive(Default, Clone, Serialize, Deserialize)] #[derive(Default, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct SetRankingRulesSettings { pub struct SetRankingRulesSettings {
pub ranking_rules: Option<Option<Vec<String>>>, pub ranking_rules: Option<Vec<String>>,
} }
pub async fn update_rules(mut ctx: Request<Data>) -> SResult<Response> { pub async fn update_rules(mut ctx: Request<Data>) -> SResult<Response> {
@ -223,13 +227,13 @@ pub async fn update_rules(mut ctx: Request<Data>) -> SResult<Response> {
.map_err(ResponseError::bad_request)?; .map_err(ResponseError::bad_request)?;
let db = &ctx.state().db; let db = &ctx.state().db;
let settings = SettingsComplete { let settings = Settings {
ranking_rules: settings.ranking_rules, ranking_rules: settings.ranking_rules,
.. SettingsComplete::default() .. Settings::default()
}; };
let mut writer = db.update_write_txn()?; let mut writer = db.update_write_txn()?;
let update_id = index.settings_update(&mut writer, settings.into())?; let update_id = index.settings_update(&mut writer, settings.into_cleared())?;
writer.commit()?; writer.commit()?;
let response_body = IndexUpdateResponse { update_id }; let response_body = IndexUpdateResponse { update_id };
@ -256,6 +260,7 @@ pub async fn delete_rules(ctx: Request<Data>) -> SResult<Response> {
} }
#[derive(Default, Clone, Serialize, Deserialize)] #[derive(Default, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct GetRankingDistinctSettings { pub struct GetRankingDistinctSettings {
pub ranking_distinct: Option<String>, pub ranking_distinct: Option<String>,
} }
@ -275,8 +280,9 @@ pub async fn get_distinct(ctx: Request<Data>) -> SResult<Response> {
} }
#[derive(Default, Clone, Serialize, Deserialize)] #[derive(Default, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct SetRankingDistinctSettings { pub struct SetRankingDistinctSettings {
pub ranking_distinct: Option<Option<String>>, pub ranking_distinct: Option<String>,
} }
pub async fn update_distinct(mut ctx: Request<Data>) -> SResult<Response> { pub async fn update_distinct(mut ctx: Request<Data>) -> SResult<Response> {
@ -286,13 +292,13 @@ pub async fn update_distinct(mut ctx: Request<Data>) -> SResult<Response> {
.map_err(ResponseError::bad_request)?; .map_err(ResponseError::bad_request)?;
let db = &ctx.state().db; let db = &ctx.state().db;
let settings = SettingsComplete { let settings = Settings {
ranking_distinct: settings.ranking_distinct, ranking_distinct: settings.ranking_distinct,
.. SettingsComplete::default() .. Settings::default()
}; };
let mut writer = db.update_write_txn()?; let mut writer = db.update_write_txn()?;
let update_id = index.settings_update(&mut writer, settings.into())?; let update_id = index.settings_update(&mut writer, settings.into_cleared())?;
writer.commit()?; writer.commit()?;
let response_body = IndexUpdateResponse { update_id }; let response_body = IndexUpdateResponse { update_id };
@ -319,6 +325,7 @@ pub async fn delete_distinct(ctx: Request<Data>) -> SResult<Response> {
} }
#[derive(Default, Clone, Serialize, Deserialize)] #[derive(Default, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct GetAttributesSettings { pub struct GetAttributesSettings {
pub attribute_identifier: Option<String>, pub attribute_identifier: Option<String>,
pub attributes_searchable: Option<Vec<String>>, pub attributes_searchable: Option<Vec<String>>,
@ -347,10 +354,11 @@ pub async fn get_attributes(ctx: Request<Data>) -> SResult<Response> {
} }
#[derive(Default, Clone, Serialize, Deserialize)] #[derive(Default, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct SetAttributesSettings { pub struct SetAttributesSettings {
pub attribute_identifier: Option<Option<String>>, pub attribute_identifier: Option<String>,
pub attributes_searchable: Option<Option<Vec<String>>>, pub attributes_searchable: Option<Vec<String>>,
pub attributes_displayed: Option<Option<HashSet<String>>>, pub attributes_displayed: Option<HashSet<String>>,
} }
pub async fn update_attributes(mut ctx: Request<Data>) -> SResult<Response> { pub async fn update_attributes(mut ctx: Request<Data>) -> SResult<Response> {
@ -360,15 +368,15 @@ pub async fn update_attributes(mut ctx: Request<Data>) -> SResult<Response> {
.map_err(ResponseError::bad_request)?; .map_err(ResponseError::bad_request)?;
let db = &ctx.state().db; let db = &ctx.state().db;
let settings = SettingsComplete { let settings = Settings {
attribute_identifier: settings.attribute_identifier, attribute_identifier: settings.attribute_identifier,
attributes_searchable: settings.attributes_searchable, attributes_searchable: settings.attributes_searchable,
attributes_displayed: settings.attributes_displayed, attributes_displayed: settings.attributes_displayed,
.. SettingsComplete::default() .. Settings::default()
}; };
let mut writer = db.update_write_txn()?; let mut writer = db.update_write_txn()?;
let update_id = index.settings_update(&mut writer, settings.into())?; let update_id = index.settings_update(&mut writer, settings.into_cleared())?;
writer.commit()?; writer.commit()?;
let response_body = IndexUpdateResponse { update_id }; let response_body = IndexUpdateResponse { update_id };
@ -395,6 +403,7 @@ pub async fn delete_attributes(ctx: Request<Data>) -> SResult<Response> {
} }
#[derive(Default, Clone, Serialize, Deserialize)] #[derive(Default, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct AttributesIdentifierSettings { pub struct AttributesIdentifierSettings {
pub attribute_identifier: Option<String>, pub attribute_identifier: Option<String>,
} }
@ -417,6 +426,7 @@ pub async fn get_identifier(ctx: Request<Data>) -> SResult<Response> {
} }
#[derive(Default, Clone, Serialize, Deserialize)] #[derive(Default, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct GetAttributesSearchableSettings { pub struct GetAttributesSearchableSettings {
pub attributes_searchable: Option<Vec<String>>, pub attributes_searchable: Option<Vec<String>>,
} }
@ -439,8 +449,9 @@ pub async fn get_searchable(ctx: Request<Data>) -> SResult<Response> {
} }
#[derive(Default, Clone, Serialize, Deserialize)] #[derive(Default, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct SetAttributesSearchableSettings { pub struct SetAttributesSearchableSettings {
pub attributes_searchable: Option<Option<Vec<String>>>, pub attributes_searchable: Option<Vec<String>>,
} }
pub async fn update_searchable(mut ctx: Request<Data>) -> SResult<Response> { pub async fn update_searchable(mut ctx: Request<Data>) -> SResult<Response> {
@ -450,13 +461,13 @@ pub async fn update_searchable(mut ctx: Request<Data>) -> SResult<Response> {
.map_err(ResponseError::bad_request)?; .map_err(ResponseError::bad_request)?;
let db = &ctx.state().db; let db = &ctx.state().db;
let settings = SettingsComplete { let settings = Settings {
attributes_searchable: settings.attributes_searchable, attributes_searchable: settings.attributes_searchable,
.. SettingsComplete::default() .. Settings::default()
}; };
let mut writer = db.update_write_txn()?; let mut writer = db.update_write_txn()?;
let update_id = index.settings_update(&mut writer, settings.into())?; let update_id = index.settings_update(&mut writer, settings.into_cleared())?;
writer.commit()?; writer.commit()?;
let response_body = IndexUpdateResponse { update_id }; let response_body = IndexUpdateResponse { update_id };
@ -482,6 +493,7 @@ pub async fn delete_searchable(ctx: Request<Data>) -> SResult<Response> {
} }
#[derive(Default, Clone, Serialize, Deserialize)] #[derive(Default, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct AttributesDisplayedSettings { pub struct AttributesDisplayedSettings {
pub attributes_displayed: Option<HashSet<String>>, pub attributes_displayed: Option<HashSet<String>>,
} }
@ -516,7 +528,7 @@ pub async fn update_displayed(mut ctx: Request<Data>) -> SResult<Response> {
}; };
let mut writer = db.update_write_txn()?; let mut writer = db.update_write_txn()?;
let update_id = index.settings_update(&mut writer, settings.into())?; let update_id = index.settings_update(&mut writer, settings.into_cleared())?;
writer.commit()?; writer.commit()?;
let response_body = IndexUpdateResponse { update_id }; let response_body = IndexUpdateResponse { update_id };

View File

@ -27,7 +27,7 @@ fn write_all_and_delete() {
// 2 - Send the settings // 2 - Send the settings
let json = json!({ let json = json!({
"ranking_rules": [ "rankingRules": [
"_typo", "_typo",
"_words", "_words",
"_proximity", "_proximity",
@ -37,9 +37,9 @@ fn write_all_and_delete() {
"dsc(release_date)", "dsc(release_date)",
"dsc(rank)", "dsc(rank)",
], ],
"ranking_distinct": "movie_id", "rankingDistinct": "movie_id",
"attribute_identifier": "uid", "attributeIdentifier": "uid",
"attributes_searchable": [ "attributesSearchable": [
"uid", "uid",
"movie_id", "movie_id",
"title", "title",
@ -48,14 +48,14 @@ fn write_all_and_delete() {
"release_date", "release_date",
"rank", "rank",
], ],
"attributes_displayed": [ "attributesDisplayed": [
"title", "title",
"description", "description",
"poster", "poster",
"release_date", "release_date",
"rank", "rank",
], ],
"stop_words": [ "stopWords": [
"the", "the",
"a", "a",
"an", "an",
@ -105,12 +105,12 @@ fn write_all_and_delete() {
let res_value: Value = serde_json::from_slice(&buf).unwrap(); let res_value: Value = serde_json::from_slice(&buf).unwrap();
let json = json!({ let json = json!({
"ranking_rules": null, "rankingRules": null,
"ranking_distinct": null, "rankingDistinct": null,
"attribute_identifier": null, "attributeIdentifier": null,
"attributes_searchable": null, "attributesSearchable": null,
"attributes_displayed": null, "attributesDisplayed": null,
"stop_words": null, "stopWords": null,
"synonyms": null, "synonyms": null,
}); });
@ -135,7 +135,7 @@ fn write_all_and_update() {
// 2 - Send the settings // 2 - Send the settings
let json = json!({ let json = json!({
"ranking_rules": [ "rankingRules": [
"_typo", "_typo",
"_words", "_words",
"_proximity", "_proximity",
@ -145,9 +145,9 @@ fn write_all_and_update() {
"dsc(release_date)", "dsc(release_date)",
"dsc(rank)", "dsc(rank)",
], ],
"ranking_distinct": "movie_id", "rankingDistinct": "movie_id",
"attribute_identifier": "uid", "attributeIdentifier": "uid",
"attributes_searchable": [ "attributesSearchable": [
"uid", "uid",
"movie_id", "movie_id",
"title", "title",
@ -156,14 +156,14 @@ fn write_all_and_update() {
"release_date", "release_date",
"rank", "rank",
], ],
"attributes_displayed": [ "attributesDisplayed": [
"title", "title",
"description", "description",
"poster", "poster",
"release_date", "release_date",
"rank", "rank",
], ],
"stop_words": [ "stopWords": [
"the", "the",
"a", "a",
"an", "an",
@ -197,7 +197,7 @@ fn write_all_and_update() {
// 4 - Update all settings // 4 - Update all settings
let json_update = json!({ let json_update = json!({
"ranking_rules": [ "rankingRules": [
"_typo", "_typo",
"_words", "_words",
"_proximity", "_proximity",
@ -206,21 +206,20 @@ fn write_all_and_update() {
"_exact", "_exact",
"dsc(release_date)", "dsc(release_date)",
], ],
"ranking_distinct": null, "attributeIdentifier": "uid",
"attribute_identifier": "uid", "attributesSearchable": [
"attributes_searchable": [
"title", "title",
"description", "description",
"uid", "uid",
], ],
"attributes_displayed": [ "attributesDisplayed": [
"title", "title",
"description", "description",
"release_date", "release_date",
"rank", "rank",
"poster", "poster",
], ],
"stop_words": [ "stopWords": [
], ],
"synonyms": { "synonyms": {
"wolverine": ["xmen", "logan"], "wolverine": ["xmen", "logan"],
@ -247,7 +246,7 @@ fn write_all_and_update() {
let res_value: Value = serde_json::from_slice(&buf).unwrap(); let res_value: Value = serde_json::from_slice(&buf).unwrap();
let res_expected = json!({ let res_expected = json!({
"ranking_rules": [ "rankingRules": [
"_typo", "_typo",
"_words", "_words",
"_proximity", "_proximity",
@ -256,27 +255,26 @@ fn write_all_and_update() {
"_exact", "_exact",
"dsc(release_date)", "dsc(release_date)",
], ],
"ranking_distinct": "movie_id", "rankingDistinct": null,
"attribute_identifier": "uid", "attributeIdentifier": "uid",
"attributes_searchable": [ "attributesSearchable": [
"title", "title",
"description", "description",
"uid", "uid",
], ],
"attributes_displayed": [ "attributesDisplayed": [
"title", "title",
"description", "description",
"release_date", "release_date",
"rank", "rank",
"poster", "poster",
], ],
"stop_words": [ "stopWords": null,
],
"synonyms": { "synonyms": {
"wolverine": ["xmen", "logan"], "wolverine": ["xmen", "logan"],
"logan": ["wolverine", "xmen"], "logan": ["wolverine", "xmen"],
} }
}); });
assert_json_eq!(json_update, res_value, ordered: false); assert_json_eq!(res_expected, res_value, ordered: false);
} }