Change the settings tests and macros to avoid oversights

This commit is contained in:
ManyTheFish 2024-11-28 11:34:35 +01:00
parent a2f64f6552
commit 68c4717e21
2 changed files with 274 additions and 275 deletions

View File

@ -17,6 +17,26 @@ use crate::extractors::authentication::GuardedData;
use crate::routes::{get_task_id, is_dry_run, SummarizedTaskView}; use crate::routes::{get_task_id, is_dry_run, SummarizedTaskView};
use crate::Opt; use crate::Opt;
macro_rules! make_setting_routes {
($({$route:literal, $update_verb:ident, $type:ty, $err_ty:ty, $attr:ident, $camelcase_attr:literal, $analytics:ident}),*) => {
$(
make_setting_route!($route, $update_verb, $type, $err_ty, $attr, $camelcase_attr, $analytics);
)*
pub fn configure(cfg: &mut web::ServiceConfig) {
use crate::extractors::sequential_extractor::SeqHandler;
cfg.service(
web::resource("")
.route(web::patch().to(SeqHandler(update_all)))
.route(web::get().to(SeqHandler(get_all)))
.route(web::delete().to(SeqHandler(delete_all))))
$(.service($attr::resources()))*;
}
pub const ALL_SETTINGS_NAMES: &[&str] = &[$(stringify!($attr)),*];
};
}
#[macro_export] #[macro_export]
macro_rules! make_setting_route { macro_rules! make_setting_route {
($route:literal, $update_verb:ident, $type:ty, $err_ty:ty, $attr:ident, $camelcase_attr:literal, $analytics:ident) => { ($route:literal, $update_verb:ident, $type:ty, $err_ty:ty, $attr:ident, $camelcase_attr:literal, $analytics:ident) => {
@ -153,279 +173,227 @@ macro_rules! make_setting_route {
}; };
} }
make_setting_route!( make_setting_routes!(
"/filterable-attributes", {
put, "/filterable-attributes",
std::collections::BTreeSet<String>, put,
meilisearch_types::deserr::DeserrJsonError< std::collections::BTreeSet<String>,
meilisearch_types::error::deserr_codes::InvalidSettingsFilterableAttributes, meilisearch_types::deserr::DeserrJsonError<
>, meilisearch_types::error::deserr_codes::InvalidSettingsFilterableAttributes,
filterable_attributes, >,
"filterableAttributes", filterable_attributes,
FilterableAttributesAnalytics "filterableAttributes",
); FilterableAttributesAnalytics
},
make_setting_route!( {
"/sortable-attributes", "/sortable-attributes",
put, put,
std::collections::BTreeSet<String>, std::collections::BTreeSet<String>,
meilisearch_types::deserr::DeserrJsonError< meilisearch_types::deserr::DeserrJsonError<
meilisearch_types::error::deserr_codes::InvalidSettingsSortableAttributes, meilisearch_types::error::deserr_codes::InvalidSettingsSortableAttributes,
>, >,
sortable_attributes, sortable_attributes,
"sortableAttributes", "sortableAttributes",
SortableAttributesAnalytics SortableAttributesAnalytics
); },
{
make_setting_route!( "/displayed-attributes",
"/displayed-attributes", put,
put, Vec<String>,
Vec<String>, meilisearch_types::deserr::DeserrJsonError<
meilisearch_types::deserr::DeserrJsonError< meilisearch_types::error::deserr_codes::InvalidSettingsDisplayedAttributes,
meilisearch_types::error::deserr_codes::InvalidSettingsDisplayedAttributes, >,
>, displayed_attributes,
displayed_attributes, "displayedAttributes",
"displayedAttributes", DisplayedAttributesAnalytics
DisplayedAttributesAnalytics },
); {
"/typo-tolerance",
make_setting_route!( patch,
"/typo-tolerance", meilisearch_types::settings::TypoSettings,
patch, meilisearch_types::deserr::DeserrJsonError<
meilisearch_types::settings::TypoSettings, meilisearch_types::error::deserr_codes::InvalidSettingsTypoTolerance,
meilisearch_types::deserr::DeserrJsonError< >,
meilisearch_types::error::deserr_codes::InvalidSettingsTypoTolerance, typo_tolerance,
>, "typoTolerance",
typo_tolerance, TypoToleranceAnalytics
"typoTolerance", },
TypoToleranceAnalytics {
); "/searchable-attributes",
put,
make_setting_route!( Vec<String>,
"/searchable-attributes", meilisearch_types::deserr::DeserrJsonError<
put, meilisearch_types::error::deserr_codes::InvalidSettingsSearchableAttributes,
Vec<String>, >,
meilisearch_types::deserr::DeserrJsonError< searchable_attributes,
meilisearch_types::error::deserr_codes::InvalidSettingsSearchableAttributes, "searchableAttributes",
>, SearchableAttributesAnalytics
searchable_attributes, },
"searchableAttributes", {
SearchableAttributesAnalytics "/stop-words",
); put,
std::collections::BTreeSet<String>,
make_setting_route!( meilisearch_types::deserr::DeserrJsonError<
"/stop-words", meilisearch_types::error::deserr_codes::InvalidSettingsStopWords,
put, >,
std::collections::BTreeSet<String>, stop_words,
meilisearch_types::deserr::DeserrJsonError< "stopWords",
meilisearch_types::error::deserr_codes::InvalidSettingsStopWords, StopWordsAnalytics
>, },
stop_words, {
"stopWords", "/non-separator-tokens",
StopWordsAnalytics put,
); std::collections::BTreeSet<String>,
meilisearch_types::deserr::DeserrJsonError<
make_setting_route!( meilisearch_types::error::deserr_codes::InvalidSettingsNonSeparatorTokens,
"/non-separator-tokens", >,
put, non_separator_tokens,
std::collections::BTreeSet<String>, "nonSeparatorTokens",
meilisearch_types::deserr::DeserrJsonError< NonSeparatorTokensAnalytics
meilisearch_types::error::deserr_codes::InvalidSettingsNonSeparatorTokens, },
>, {
non_separator_tokens, "/separator-tokens",
"nonSeparatorTokens", put,
NonSeparatorTokensAnalytics std::collections::BTreeSet<String>,
); meilisearch_types::deserr::DeserrJsonError<
meilisearch_types::error::deserr_codes::InvalidSettingsSeparatorTokens,
make_setting_route!( >,
"/separator-tokens", separator_tokens,
put, "separatorTokens",
std::collections::BTreeSet<String>, SeparatorTokensAnalytics
meilisearch_types::deserr::DeserrJsonError< },
meilisearch_types::error::deserr_codes::InvalidSettingsSeparatorTokens, {
>, "/dictionary",
separator_tokens, put,
"separatorTokens", std::collections::BTreeSet<String>,
SeparatorTokensAnalytics meilisearch_types::deserr::DeserrJsonError<
); meilisearch_types::error::deserr_codes::InvalidSettingsDictionary,
>,
make_setting_route!( dictionary,
"/dictionary", "dictionary",
put, DictionaryAnalytics
std::collections::BTreeSet<String>, },
meilisearch_types::deserr::DeserrJsonError< {
meilisearch_types::error::deserr_codes::InvalidSettingsDictionary, "/synonyms",
>, put,
dictionary, std::collections::BTreeMap<String, Vec<String>>,
"dictionary", meilisearch_types::deserr::DeserrJsonError<
DictionaryAnalytics meilisearch_types::error::deserr_codes::InvalidSettingsSynonyms,
); >,
synonyms,
make_setting_route!( "synonyms",
"/synonyms", SynonymsAnalytics
put, },
std::collections::BTreeMap<String, Vec<String>>, {
meilisearch_types::deserr::DeserrJsonError< "/distinct-attribute",
meilisearch_types::error::deserr_codes::InvalidSettingsSynonyms, put,
>, String,
synonyms, meilisearch_types::deserr::DeserrJsonError<
"synonyms", meilisearch_types::error::deserr_codes::InvalidSettingsDistinctAttribute,
SynonymsAnalytics >,
); distinct_attribute,
"distinctAttribute",
make_setting_route!( DistinctAttributeAnalytics
"/distinct-attribute", },
put, {
String, "/proximity-precision",
meilisearch_types::deserr::DeserrJsonError< put,
meilisearch_types::error::deserr_codes::InvalidSettingsDistinctAttribute, meilisearch_types::settings::ProximityPrecisionView,
>, meilisearch_types::deserr::DeserrJsonError<
distinct_attribute, meilisearch_types::error::deserr_codes::InvalidSettingsProximityPrecision,
"distinctAttribute", >,
DistinctAttributeAnalytics proximity_precision,
); "proximityPrecision",
ProximityPrecisionAnalytics
make_setting_route!( },
"/proximity-precision", {
put, "/localized-attributes",
meilisearch_types::settings::ProximityPrecisionView, put,
meilisearch_types::deserr::DeserrJsonError< Vec<meilisearch_types::locales::LocalizedAttributesRuleView>,
meilisearch_types::error::deserr_codes::InvalidSettingsProximityPrecision, meilisearch_types::deserr::DeserrJsonError<
>, meilisearch_types::error::deserr_codes::InvalidSettingsLocalizedAttributes,
proximity_precision, >,
"proximityPrecision", localized_attributes,
ProximityPrecisionAnalytics "localizedAttributes",
); LocalesAnalytics
},
make_setting_route!( {
"/localized-attributes", "/ranking-rules",
put, put,
Vec<meilisearch_types::locales::LocalizedAttributesRuleView>, Vec<meilisearch_types::settings::RankingRuleView>,
meilisearch_types::deserr::DeserrJsonError< meilisearch_types::deserr::DeserrJsonError<
meilisearch_types::error::deserr_codes::InvalidSettingsLocalizedAttributes, meilisearch_types::error::deserr_codes::InvalidSettingsRankingRules,
>, >,
localized_attributes, ranking_rules,
"localizedAttributes", "rankingRules",
LocalesAnalytics RankingRulesAnalytics
); },
{
make_setting_route!( "/faceting",
"/ranking-rules", patch,
put, meilisearch_types::settings::FacetingSettings,
Vec<meilisearch_types::settings::RankingRuleView>, meilisearch_types::deserr::DeserrJsonError<
meilisearch_types::deserr::DeserrJsonError< meilisearch_types::error::deserr_codes::InvalidSettingsFaceting,
meilisearch_types::error::deserr_codes::InvalidSettingsRankingRules, >,
>, faceting,
ranking_rules, "faceting",
"rankingRules", FacetingAnalytics
RankingRulesAnalytics },
); {
"/pagination",
make_setting_route!( patch,
"/faceting", meilisearch_types::settings::PaginationSettings,
patch, meilisearch_types::deserr::DeserrJsonError<
meilisearch_types::settings::FacetingSettings, meilisearch_types::error::deserr_codes::InvalidSettingsPagination,
meilisearch_types::deserr::DeserrJsonError< >,
meilisearch_types::error::deserr_codes::InvalidSettingsFaceting, pagination,
>, "pagination",
faceting, PaginationAnalytics
"faceting", },
FacetingAnalytics {
); "/embedders",
patch,
make_setting_route!( std::collections::BTreeMap<String, Setting<meilisearch_types::milli::vector::settings::EmbeddingSettings>>,
"/pagination", meilisearch_types::deserr::DeserrJsonError<
patch, meilisearch_types::error::deserr_codes::InvalidSettingsEmbedders,
meilisearch_types::settings::PaginationSettings, >,
meilisearch_types::deserr::DeserrJsonError< embedders,
meilisearch_types::error::deserr_codes::InvalidSettingsPagination, "embedders",
>, EmbeddersAnalytics
pagination, },
"pagination", {
PaginationAnalytics "/search-cutoff-ms",
); put,
u64,
make_setting_route!( meilisearch_types::deserr::DeserrJsonError<
"/embedders", meilisearch_types::error::deserr_codes::InvalidSettingsSearchCutoffMs,
patch, >,
std::collections::BTreeMap<String, Setting<meilisearch_types::milli::vector::settings::EmbeddingSettings>>, search_cutoff_ms,
meilisearch_types::deserr::DeserrJsonError< "searchCutoffMs",
meilisearch_types::error::deserr_codes::InvalidSettingsEmbedders, SearchCutoffMsAnalytics
>, },
embedders, {
"embedders", "/facet-search",
EmbeddersAnalytics put,
); bool,
meilisearch_types::deserr::DeserrJsonError<
make_setting_route!( meilisearch_types::error::deserr_codes::InvalidSettingsFacetSearch,
"/search-cutoff-ms", >,
put, facet_search,
u64, "facetSearch",
meilisearch_types::deserr::DeserrJsonError< FacetSearchAnalytics
meilisearch_types::error::deserr_codes::InvalidSettingsSearchCutoffMs, },
>, {
search_cutoff_ms, "/prefix-search",
"searchCutoffMs", put,
SearchCutoffMsAnalytics meilisearch_types::settings::PrefixSearchSettings,
); meilisearch_types::deserr::DeserrJsonError<
meilisearch_types::error::deserr_codes::InvalidSettingsPrefixSearch,
make_setting_route!( >,
"/facet-search", prefix_search,
put, "prefixSearch",
bool, PrefixSearchAnalytics
meilisearch_types::deserr::DeserrJsonError< }
meilisearch_types::error::deserr_codes::InvalidSettingsFacetSearch,
>,
facet_search,
"facetSearch",
FacetSearchAnalytics
);
make_setting_route!(
"/prefix-search",
put,
meilisearch_types::settings::PrefixSearchSettings,
meilisearch_types::deserr::DeserrJsonError<
meilisearch_types::error::deserr_codes::InvalidSettingsPrefixSearch,
>,
prefix_search,
"prefixSearch",
PrefixSearchAnalytics
);
macro_rules! generate_configure {
($($mod:ident),*) => {
pub fn configure(cfg: &mut web::ServiceConfig) {
use crate::extractors::sequential_extractor::SeqHandler;
cfg.service(
web::resource("")
.route(web::patch().to(SeqHandler(update_all)))
.route(web::get().to(SeqHandler(get_all)))
.route(web::delete().to(SeqHandler(delete_all))))
$(.service($mod::resources()))*;
}
};
}
generate_configure!(
filterable_attributes,
sortable_attributes,
displayed_attributes,
localized_attributes,
searchable_attributes,
distinct_attribute,
proximity_precision,
stop_words,
separator_tokens,
non_separator_tokens,
dictionary,
synonyms,
ranking_rules,
typo_tolerance,
pagination,
faceting,
embedders,
search_cutoff_ms
); );
pub async fn update_all( pub async fn update_all(

View File

@ -37,6 +37,23 @@ static DEFAULT_SETTINGS_VALUES: Lazy<HashMap<&'static str, Value>> = Lazy::new(|
}), }),
); );
map.insert("search_cutoff_ms", json!(null)); map.insert("search_cutoff_ms", json!(null));
map.insert("embedders", json!(null));
map.insert("facet_search", json!(true));
map.insert("prefix_search", json!("indexingTime"));
map.insert("proximity_precision", json!("byWord"));
map.insert("sortable_attributes", json!([]));
map.insert(
"typo_tolerance",
json!({
"enabled": true,
"minWordSizeForTypos": {
"oneTypo": 5,
"twoTypos": 9
},
"disableOnWords": [],
"disableOnAttributes": []
}),
);
map map
}); });
@ -343,7 +360,7 @@ async fn error_update_setting_unexisting_index_invalid_uid() {
} }
macro_rules! test_setting_routes { macro_rules! test_setting_routes {
($($setting:ident $write_method:ident), *) => { ($($setting:ident $write_method:ident,) *) => {
$( $(
mod $setting { mod $setting {
use crate::common::Server; use crate::common::Server;
@ -409,6 +426,14 @@ macro_rules! test_setting_routes {
} }
} }
)* )*
#[actix_rt::test]
async fn all_setting_tested() {
let expected = std::collections::BTreeSet::from_iter(meilisearch::routes::indexes::settings::ALL_SETTINGS_NAMES.iter());
let tested = std::collections::BTreeSet::from_iter([$(stringify!($setting)),*].iter());
let diff: Vec<_> = expected.difference(&tested).collect();
assert!(diff.is_empty(), "Not all settings were tested, please add the following settings to the `test_setting_routes!` macro: {:?}", diff);
}
}; };
} }
@ -426,7 +451,13 @@ test_setting_routes!(
synonyms put, synonyms put,
pagination patch, pagination patch,
faceting patch, faceting patch,
search_cutoff_ms put search_cutoff_ms put,
embedders patch,
facet_search put,
prefix_search put,
proximity_precision put,
sortable_attributes put,
typo_tolerance patch,
); );
#[actix_rt::test] #[actix_rt::test]