settings analytics return null when no set

This commit is contained in:
ad hoc 2022-04-29 16:38:21 +02:00
parent 3d0a4a3d18
commit 34f75d9792
No known key found for this signature in database
GPG Key ID: 4F00A782990CC643

View File

@ -145,8 +145,8 @@ make_setting_route!(
"SortableAttributes Updated".to_string(), "SortableAttributes Updated".to_string(),
json!({ json!({
"sortable_attributes": { "sortable_attributes": {
"total": setting.as_ref().map(|sort| sort.len()).unwrap_or(0), "total": setting.as_ref().map(|sort| sort.len()),
"has_geo": setting.as_ref().map(|sort| sort.contains("_geo")).unwrap_or(false), "has_geo": setting.as_ref().map(|sort| sort.contains("_geo")),
}, },
}), }),
Some(req), Some(req),
@ -174,17 +174,15 @@ make_setting_route!(
"TypoTolerance Updated".to_string(), "TypoTolerance Updated".to_string(),
json!({ json!({
"typo_tolerance": { "typo_tolerance": {
"enabled": setting.as_ref().map(|s| !matches!(s.enabled, Setting::Set(false))).unwrap_or(true), "enabled": setting.as_ref().map(|s| !matches!(s.enabled, Setting::Set(false))),
"disable_on_attributes": setting "disable_on_attributes": setting
.as_ref() .as_ref()
.map(|s| s.disable_on_attributes.as_ref().set().map(|m| !m.is_empty())) .map(|s| s.disable_on_attributes.as_ref().set().map(|m| !m.is_empty()))
.flatten() .flatten(),
.unwrap_or(false),
"disable_on_words": setting "disable_on_words": setting
.as_ref() .as_ref()
.map(|s| s.disable_on_words.as_ref().set().map(|m| !m.is_empty())) .map(|s| s.disable_on_words.as_ref().set().map(|m| !m.is_empty()))
.flatten() .flatten(),
.unwrap_or(false),
"min_word_size_for_one_typo": setting "min_word_size_for_one_typo": setting
.as_ref() .as_ref()
.map(|s| s.min_word_size_for_typos .map(|s| s.min_word_size_for_typos
@ -192,8 +190,7 @@ make_setting_route!(
.set() .set()
.map(|s| s.one_typo.set())) .map(|s| s.one_typo.set()))
.flatten() .flatten()
.flatten() .flatten(),
.unwrap_or(5),
"min_word_size_for_two_typos": setting "min_word_size_for_two_typos": setting
.as_ref() .as_ref()
.map(|s| s.min_word_size_for_typos .map(|s| s.min_word_size_for_typos
@ -201,8 +198,7 @@ make_setting_route!(
.set() .set()
.map(|s| s.two_typos.set())) .map(|s| s.two_typos.set()))
.flatten() .flatten()
.flatten() .flatten(),
.unwrap_or(9),
}, },
}), }),
Some(req), Some(req),
@ -223,7 +219,7 @@ make_setting_route!(
"SearchableAttributes Updated".to_string(), "SearchableAttributes Updated".to_string(),
json!({ json!({
"searchable_attributes": { "searchable_attributes": {
"total": setting.as_ref().map(|searchable| searchable.len()).unwrap_or(0), "total": setting.as_ref().map(|searchable| searchable.len()),
}, },
}), }),
Some(req), Some(req),
@ -315,15 +311,15 @@ pub async fn update_all(
"sort_position": settings.ranking_rules.as_ref().set().map(|sort| sort.iter().position(|s| s == "sort")), "sort_position": settings.ranking_rules.as_ref().set().map(|sort| sort.iter().position(|s| s == "sort")),
}, },
"searchable_attributes": { "searchable_attributes": {
"total": settings.searchable_attributes.as_ref().set().map(|searchable| searchable.len()).unwrap_or(0), "total": settings.searchable_attributes.as_ref().set().map(|searchable| searchable.len()),
}, },
"sortable_attributes": { "sortable_attributes": {
"total": settings.sortable_attributes.as_ref().set().map(|sort| sort.len()).unwrap_or(0), "total": settings.sortable_attributes.as_ref().set().map(|sort| sort.len()),
"has_geo": settings.sortable_attributes.as_ref().set().map(|sort| sort.iter().any(|s| s == "_geo")).unwrap_or(false), "has_geo": settings.sortable_attributes.as_ref().set().map(|sort| sort.iter().any(|s| s == "_geo")),
}, },
"filterable_attributes": { "filterable_attributes": {
"total": settings.filterable_attributes.as_ref().set().map(|filter| filter.len()).unwrap_or(0), "total": settings.filterable_attributes.as_ref().set().map(|filter| filter.len()),
"has_geo": settings.filterable_attributes.as_ref().set().map(|filter| filter.iter().any(|s| s == "_geo")).unwrap_or(false), "has_geo": settings.filterable_attributes.as_ref().set().map(|filter| filter.iter().any(|s| s == "_geo")),
}, },
"typo_tolerance": { "typo_tolerance": {
"enabled": settings.typo_tolerance "enabled": settings.typo_tolerance
@ -331,20 +327,17 @@ pub async fn update_all(
.set() .set()
.map(|s| s.enabled.as_ref().set()) .map(|s| s.enabled.as_ref().set())
.flatten() .flatten()
.copied() .copied(),
.unwrap_or(true),
"disable_on_attributes": settings.typo_tolerance "disable_on_attributes": settings.typo_tolerance
.as_ref() .as_ref()
.set() .set()
.map(|s| s.disable_on_attributes.as_ref().set().map(|m| !m.is_empty())) .map(|s| s.disable_on_attributes.as_ref().set().map(|m| !m.is_empty()))
.flatten() .flatten(),
.unwrap_or(false),
"disable_on_words": settings.typo_tolerance "disable_on_words": settings.typo_tolerance
.as_ref() .as_ref()
.set() .set()
.map(|s| s.disable_on_words.as_ref().set().map(|m| !m.is_empty())) .map(|s| s.disable_on_words.as_ref().set().map(|m| !m.is_empty()))
.flatten() .flatten(),
.unwrap_or(false),
"min_word_size_for_one_typo": settings.typo_tolerance "min_word_size_for_one_typo": settings.typo_tolerance
.as_ref() .as_ref()
.set() .set()
@ -353,8 +346,7 @@ pub async fn update_all(
.set() .set()
.map(|s| s.one_typo.set())) .map(|s| s.one_typo.set()))
.flatten() .flatten()
.flatten() .flatten(),
.unwrap_or(5),
"min_word_size_for_two_typos": settings.typo_tolerance "min_word_size_for_two_typos": settings.typo_tolerance
.as_ref() .as_ref()
.set() .set()
@ -363,8 +355,7 @@ pub async fn update_all(
.set() .set()
.map(|s| s.two_typos.set())) .map(|s| s.two_typos.set()))
.flatten() .flatten()
.flatten() .flatten(),
.unwrap_or(9),
}, },
}), }),
Some(&req), Some(&req),