diff --git a/meilisearch-types/src/error.rs b/meilisearch-types/src/error.rs index 4b6711601..60a5d7257 100644 --- a/meilisearch-types/src/error.rs +++ b/meilisearch-types/src/error.rs @@ -235,6 +235,7 @@ InvalidSearchCropMarker , InvalidRequest , BAD_REQUEST ; InvalidSearchFacets , InvalidRequest , BAD_REQUEST ; InvalidFacetSearchFacetName , InvalidRequest , BAD_REQUEST ; InvalidSearchFilter , InvalidRequest , BAD_REQUEST ; +InvalidSearchBoostingFilter , InvalidRequest , BAD_REQUEST ; InvalidSearchHighlightPostTag , InvalidRequest , BAD_REQUEST ; InvalidSearchHighlightPreTag , InvalidRequest , BAD_REQUEST ; InvalidSearchHitsPerPage , InvalidRequest , BAD_REQUEST ; diff --git a/meilisearch/src/analytics/segment_analytics.rs b/meilisearch/src/analytics/segment_analytics.rs index 2f0014ab7..f44dfe41d 100644 --- a/meilisearch/src/analytics/segment_analytics.rs +++ b/meilisearch/src/analytics/segment_analytics.rs @@ -629,6 +629,7 @@ impl SearchAggregator { show_ranking_score, show_ranking_score_details, filter, + boosting_filter, sort, facets: _, highlight_pre_tag, @@ -1002,6 +1003,7 @@ impl MultiSearchAggregator { show_ranking_score_details: _, show_matches_position: _, filter: _, + boosting_filter: _, sort: _, facets: _, highlight_pre_tag: _, diff --git a/meilisearch/src/routes/indexes/facet_search.rs b/meilisearch/src/routes/indexes/facet_search.rs index 142a424c0..614cfae01 100644 --- a/meilisearch/src/routes/indexes/facet_search.rs +++ b/meilisearch/src/routes/indexes/facet_search.rs @@ -111,6 +111,7 @@ impl From for SearchQuery { show_ranking_score: false, show_ranking_score_details: false, filter, + boosting_filter: None, sort: None, facets: None, highlight_pre_tag: DEFAULT_HIGHLIGHT_PRE_TAG(), diff --git a/meilisearch/src/routes/indexes/search.rs b/meilisearch/src/routes/indexes/search.rs index 5a0a9e92b..0b0b70ca8 100644 --- a/meilisearch/src/routes/indexes/search.rs +++ b/meilisearch/src/routes/indexes/search.rs @@ -54,6 +54,8 @@ pub struct SearchQueryGet { attributes_to_highlight: Option>, #[deserr(default, error = DeserrQueryParamError)] filter: Option, + #[deserr(default, error = DeserrQueryParamError)] + boosting_filter: Option, #[deserr(default, error = DeserrQueryParamError)] sort: Option, #[deserr(default, error = DeserrQueryParamError)] @@ -86,6 +88,14 @@ impl From for SearchQuery { None => None, }; + let boosting_filter = match other.boosting_filter { + Some(f) => match serde_json::from_str(&f) { + Ok(v) => Some(v), + _ => Some(Value::String(f)), + }, + None => None, + }; + Self { q: other.q, vector: other.vector.map(CS::into_inner), @@ -98,6 +108,7 @@ impl From for SearchQuery { crop_length: other.crop_length.0, attributes_to_highlight: other.attributes_to_highlight.map(|o| o.into_iter().collect()), filter, + boosting_filter, sort: other.sort.map(|attr| fix_sort_query_parameters(&attr)), show_matches_position: other.show_matches_position.0, show_ranking_score: other.show_ranking_score.0, diff --git a/meilisearch/src/search.rs b/meilisearch/src/search.rs index c9ebed80e..5501cc3e5 100644 --- a/meilisearch/src/search.rs +++ b/meilisearch/src/search.rs @@ -71,6 +71,8 @@ pub struct SearchQuery { pub show_ranking_score_details: bool, #[deserr(default, error = DeserrJsonError)] pub filter: Option, + #[deserr(default, error = DeserrJsonError)] + pub boosting_filter: Option, #[deserr(default, error = DeserrJsonError)] pub sort: Option>, #[deserr(default, error = DeserrJsonError)] @@ -130,6 +132,8 @@ pub struct SearchQueryWithIndex { pub show_matches_position: bool, #[deserr(default, error = DeserrJsonError)] pub filter: Option, + #[deserr(default, error = DeserrJsonError)] + pub boosting_filter: Option, #[deserr(default, error = DeserrJsonError)] pub sort: Option>, #[deserr(default, error = DeserrJsonError)] @@ -164,6 +168,7 @@ impl SearchQueryWithIndex { show_ranking_score_details, show_matches_position, filter, + boosting_filter, sort, facets, highlight_pre_tag, @@ -189,6 +194,7 @@ impl SearchQueryWithIndex { show_ranking_score_details, show_matches_position, filter, + boosting_filter, sort, facets, highlight_pre_tag, @@ -397,8 +403,14 @@ fn prepare_search<'t>( search.limit(limit); if let Some(ref filter) = query.filter { - if let Some(facets) = parse_filter(filter)? { - search.filter(facets); + if let Some(filter) = parse_filter(filter)? { + search.filter(filter); + } + } + + if let Some(ref boosting_filter) = query.boosting_filter { + if let Some(boosting_filter) = parse_filter(boosting_filter)? { + search.boosting_filter(boosting_filter); } }