From 29b40295b8440319b859f41f869f0e147d739ce6 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Thu, 22 Jun 2023 14:59:44 +0200 Subject: [PATCH] Ignore unknown facet search query parameters --- .../src/analytics/segment_analytics.rs | 43 +--------- .../src/routes/indexes/facet_search.rs | 85 +++++++------------ 2 files changed, 34 insertions(+), 94 deletions(-) diff --git a/meilisearch/src/analytics/segment_analytics.rs b/meilisearch/src/analytics/segment_analytics.rs index 51bd703a6..990daf74c 100644 --- a/meilisearch/src/analytics/segment_analytics.rs +++ b/meilisearch/src/analytics/segment_analytics.rs @@ -36,7 +36,7 @@ use crate::routes::{create_all_stats, Stats}; use crate::search::{ FacetSearchResult, MatchingStrategy, SearchQuery, SearchQueryWithIndex, SearchResult, DEFAULT_CROP_LENGTH, DEFAULT_CROP_MARKER, DEFAULT_HIGHLIGHT_POST_TAG, - DEFAULT_HIGHLIGHT_PRE_TAG, DEFAULT_SEARCH_LIMIT, DEFAULT_SEARCH_OFFSET, + DEFAULT_HIGHLIGHT_PRE_TAG, DEFAULT_SEARCH_LIMIT, }; use crate::Opt; @@ -960,27 +960,7 @@ pub struct FacetSearchAggregator { impl FacetSearchAggregator { pub fn from_query(query: &FacetSearchQuery, request: &HttpRequest) -> Self { - let FacetSearchQuery { - facet_query: _, - facet_name, - q, - offset, - limit, - page, - hits_per_page, - attributes_to_retrieve, - attributes_to_crop, - crop_length, - attributes_to_highlight, - show_matches_position, - filter, - sort, - facets, - highlight_pre_tag, - highlight_post_tag, - crop_marker, - matching_strategy, - } = query; + let FacetSearchQuery { facet_query: _, facet_name, q, filter, matching_strategy } = query; let mut ret = Self::default(); ret.timestamp = Some(OffsetDateTime::now_utc()); @@ -989,23 +969,8 @@ impl FacetSearchAggregator { ret.user_agents = extract_user_agents(request).into_iter().collect(); ret.facet_names = Some(facet_name.clone()).into_iter().collect(); - ret.additional_search_parameters_provided = q.is_some() - || *offset != DEFAULT_SEARCH_OFFSET() - || *limit != DEFAULT_SEARCH_LIMIT() - || page.is_some() - || hits_per_page.is_some() - || attributes_to_retrieve.is_some() - || attributes_to_crop.is_some() - || *crop_length != DEFAULT_CROP_LENGTH() - || attributes_to_highlight.is_some() - || *show_matches_position - || filter.is_some() - || sort.is_some() - || facets.is_some() - || *highlight_pre_tag != DEFAULT_HIGHLIGHT_PRE_TAG() - || *highlight_post_tag != DEFAULT_HIGHLIGHT_POST_TAG() - || *crop_marker != DEFAULT_CROP_MARKER() - || *matching_strategy != MatchingStrategy::default(); + ret.additional_search_parameters_provided = + q.is_some() || filter.is_some() || *matching_strategy != MatchingStrategy::default(); ret } diff --git a/meilisearch/src/routes/indexes/facet_search.rs b/meilisearch/src/routes/indexes/facet_search.rs index d07a22257..817c2a23d 100644 --- a/meilisearch/src/routes/indexes/facet_search.rs +++ b/meilisearch/src/routes/indexes/facet_search.rs @@ -1,5 +1,3 @@ -use std::collections::{BTreeSet, HashSet}; - use actix_web::web::Data; use actix_web::{web, HttpRequest, HttpResponse}; use deserr::actix_web::AwebJson; @@ -26,7 +24,7 @@ pub fn configure(cfg: &mut web::ServiceConfig) { // TODO improve the error messages #[derive(Debug, Clone, Default, PartialEq, deserr::Deserr)] -#[deserr(error = DeserrJsonError, rename_all = camelCase, deny_unknown_fields)] +#[deserr(error = DeserrJsonError, rename_all = camelCase)] pub struct FacetSearchQuery { #[deserr(default, error = DeserrJsonError)] pub facet_query: Option, @@ -36,40 +34,8 @@ pub struct FacetSearchQuery { pub q: Option, #[deserr(default, error = DeserrJsonError)] pub vector: Option>, - #[deserr(default = DEFAULT_SEARCH_OFFSET(), error = DeserrJsonError)] - pub offset: usize, - #[deserr(default = DEFAULT_SEARCH_LIMIT(), error = DeserrJsonError)] - pub limit: usize, - #[deserr(default, error = DeserrJsonError)] - pub page: Option, - #[deserr(default, error = DeserrJsonError)] - pub hits_per_page: Option, - #[deserr(default, error = DeserrJsonError)] - pub attributes_to_retrieve: Option>, - #[deserr(default, error = DeserrJsonError)] - pub attributes_to_crop: Option>, - #[deserr(default, error = DeserrJsonError, default = DEFAULT_CROP_LENGTH())] - pub crop_length: usize, - #[deserr(default, error = DeserrJsonError)] - pub attributes_to_highlight: Option>, - #[deserr(default, error = DeserrJsonError, default)] - pub show_matches_position: bool, - #[deserr(default, error = DeserrJsonError, default)] - pub show_ranking_score: bool, - #[deserr(default, error = DeserrJsonError, default)] - pub show_ranking_score_details: bool, #[deserr(default, error = DeserrJsonError)] pub filter: Option, - #[deserr(default, error = DeserrJsonError)] - pub sort: Option>, - #[deserr(default, error = DeserrJsonError)] - pub facets: Option>, - #[deserr(default, error = DeserrJsonError, default = DEFAULT_HIGHLIGHT_PRE_TAG())] - pub highlight_pre_tag: String, - #[deserr(default, error = DeserrJsonError, default = DEFAULT_HIGHLIGHT_POST_TAG())] - pub highlight_post_tag: String, - #[deserr(default, error = DeserrJsonError, default = DEFAULT_CROP_MARKER())] - pub crop_marker: String, #[deserr(default, error = DeserrJsonError, default)] pub matching_strategy: MatchingStrategy, } @@ -117,27 +83,36 @@ pub async fn search( impl From for SearchQuery { fn from(value: FacetSearchQuery) -> Self { + let FacetSearchQuery { + facet_query: _, + facet_name: _, + q, + vector, + filter, + matching_strategy, + } = value; + SearchQuery { - q: value.q, - offset: value.offset, - limit: value.limit, - page: value.page, - hits_per_page: value.hits_per_page, - attributes_to_retrieve: value.attributes_to_retrieve, - attributes_to_crop: value.attributes_to_crop, - crop_length: value.crop_length, - attributes_to_highlight: value.attributes_to_highlight, - show_matches_position: value.show_matches_position, - show_ranking_score: value.show_ranking_score, - show_ranking_score_details: value.show_ranking_score_details, - filter: value.filter, - sort: value.sort, - facets: value.facets, - highlight_pre_tag: value.highlight_pre_tag, - highlight_post_tag: value.highlight_post_tag, - crop_marker: value.crop_marker, - matching_strategy: value.matching_strategy, - vector: value.vector, + q, + offset: DEFAULT_SEARCH_OFFSET(), + limit: DEFAULT_SEARCH_LIMIT(), + page: None, + hits_per_page: None, + attributes_to_retrieve: None, + attributes_to_crop: None, + crop_length: DEFAULT_CROP_LENGTH(), + attributes_to_highlight: None, + show_matches_position: false, + show_ranking_score: false, + show_ranking_score_details: false, + filter, + sort: None, + facets: None, + highlight_pre_tag: DEFAULT_HIGHLIGHT_PRE_TAG(), + highlight_post_tag: DEFAULT_HIGHLIGHT_POST_TAG(), + crop_marker: DEFAULT_CROP_MARKER(), + matching_strategy, + vector, } } }