Introduce a boostingFilter search parameter

This commit is contained in:
Clément Renault 2023-11-28 14:58:29 +01:00
parent 2495058a6e
commit f2041fd78c
No known key found for this signature in database
GPG Key ID: F250A4C4E3AE5F5F
5 changed files with 29 additions and 2 deletions

View File

@ -235,6 +235,7 @@ InvalidSearchCropMarker , InvalidRequest , BAD_REQUEST ;
InvalidSearchFacets , InvalidRequest , BAD_REQUEST ; InvalidSearchFacets , InvalidRequest , BAD_REQUEST ;
InvalidFacetSearchFacetName , InvalidRequest , BAD_REQUEST ; InvalidFacetSearchFacetName , InvalidRequest , BAD_REQUEST ;
InvalidSearchFilter , InvalidRequest , BAD_REQUEST ; InvalidSearchFilter , InvalidRequest , BAD_REQUEST ;
InvalidSearchBoostingFilter , InvalidRequest , BAD_REQUEST ;
InvalidSearchHighlightPostTag , InvalidRequest , BAD_REQUEST ; InvalidSearchHighlightPostTag , InvalidRequest , BAD_REQUEST ;
InvalidSearchHighlightPreTag , InvalidRequest , BAD_REQUEST ; InvalidSearchHighlightPreTag , InvalidRequest , BAD_REQUEST ;
InvalidSearchHitsPerPage , InvalidRequest , BAD_REQUEST ; InvalidSearchHitsPerPage , InvalidRequest , BAD_REQUEST ;

View File

@ -629,6 +629,7 @@ impl SearchAggregator {
show_ranking_score, show_ranking_score,
show_ranking_score_details, show_ranking_score_details,
filter, filter,
boosting_filter,
sort, sort,
facets: _, facets: _,
highlight_pre_tag, highlight_pre_tag,
@ -1002,6 +1003,7 @@ impl MultiSearchAggregator {
show_ranking_score_details: _, show_ranking_score_details: _,
show_matches_position: _, show_matches_position: _,
filter: _, filter: _,
boosting_filter: _,
sort: _, sort: _,
facets: _, facets: _,
highlight_pre_tag: _, highlight_pre_tag: _,

View File

@ -111,6 +111,7 @@ impl From<FacetSearchQuery> for SearchQuery {
show_ranking_score: false, show_ranking_score: false,
show_ranking_score_details: false, show_ranking_score_details: false,
filter, filter,
boosting_filter: None,
sort: None, sort: None,
facets: None, facets: None,
highlight_pre_tag: DEFAULT_HIGHLIGHT_PRE_TAG(), highlight_pre_tag: DEFAULT_HIGHLIGHT_PRE_TAG(),

View File

@ -54,6 +54,8 @@ pub struct SearchQueryGet {
attributes_to_highlight: Option<CS<String>>, attributes_to_highlight: Option<CS<String>>,
#[deserr(default, error = DeserrQueryParamError<InvalidSearchFilter>)] #[deserr(default, error = DeserrQueryParamError<InvalidSearchFilter>)]
filter: Option<String>, filter: Option<String>,
#[deserr(default, error = DeserrQueryParamError<InvalidSearchBoostingFilter>)]
boosting_filter: Option<String>,
#[deserr(default, error = DeserrQueryParamError<InvalidSearchSort>)] #[deserr(default, error = DeserrQueryParamError<InvalidSearchSort>)]
sort: Option<String>, sort: Option<String>,
#[deserr(default, error = DeserrQueryParamError<InvalidSearchShowMatchesPosition>)] #[deserr(default, error = DeserrQueryParamError<InvalidSearchShowMatchesPosition>)]
@ -86,6 +88,14 @@ impl From<SearchQueryGet> for SearchQuery {
None => None, 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 { Self {
q: other.q, q: other.q,
vector: other.vector.map(CS::into_inner), vector: other.vector.map(CS::into_inner),
@ -98,6 +108,7 @@ impl From<SearchQueryGet> for SearchQuery {
crop_length: other.crop_length.0, crop_length: other.crop_length.0,
attributes_to_highlight: other.attributes_to_highlight.map(|o| o.into_iter().collect()), attributes_to_highlight: other.attributes_to_highlight.map(|o| o.into_iter().collect()),
filter, filter,
boosting_filter,
sort: other.sort.map(|attr| fix_sort_query_parameters(&attr)), sort: other.sort.map(|attr| fix_sort_query_parameters(&attr)),
show_matches_position: other.show_matches_position.0, show_matches_position: other.show_matches_position.0,
show_ranking_score: other.show_ranking_score.0, show_ranking_score: other.show_ranking_score.0,

View File

@ -71,6 +71,8 @@ pub struct SearchQuery {
pub show_ranking_score_details: bool, pub show_ranking_score_details: bool,
#[deserr(default, error = DeserrJsonError<InvalidSearchFilter>)] #[deserr(default, error = DeserrJsonError<InvalidSearchFilter>)]
pub filter: Option<Value>, pub filter: Option<Value>,
#[deserr(default, error = DeserrJsonError<InvalidSearchBoostingFilter>)]
pub boosting_filter: Option<Value>,
#[deserr(default, error = DeserrJsonError<InvalidSearchSort>)] #[deserr(default, error = DeserrJsonError<InvalidSearchSort>)]
pub sort: Option<Vec<String>>, pub sort: Option<Vec<String>>,
#[deserr(default, error = DeserrJsonError<InvalidSearchFacets>)] #[deserr(default, error = DeserrJsonError<InvalidSearchFacets>)]
@ -130,6 +132,8 @@ pub struct SearchQueryWithIndex {
pub show_matches_position: bool, pub show_matches_position: bool,
#[deserr(default, error = DeserrJsonError<InvalidSearchFilter>)] #[deserr(default, error = DeserrJsonError<InvalidSearchFilter>)]
pub filter: Option<Value>, pub filter: Option<Value>,
#[deserr(default, error = DeserrJsonError<InvalidSearchBoostingFilter>)]
pub boosting_filter: Option<Value>,
#[deserr(default, error = DeserrJsonError<InvalidSearchSort>)] #[deserr(default, error = DeserrJsonError<InvalidSearchSort>)]
pub sort: Option<Vec<String>>, pub sort: Option<Vec<String>>,
#[deserr(default, error = DeserrJsonError<InvalidSearchFacets>)] #[deserr(default, error = DeserrJsonError<InvalidSearchFacets>)]
@ -164,6 +168,7 @@ impl SearchQueryWithIndex {
show_ranking_score_details, show_ranking_score_details,
show_matches_position, show_matches_position,
filter, filter,
boosting_filter,
sort, sort,
facets, facets,
highlight_pre_tag, highlight_pre_tag,
@ -189,6 +194,7 @@ impl SearchQueryWithIndex {
show_ranking_score_details, show_ranking_score_details,
show_matches_position, show_matches_position,
filter, filter,
boosting_filter,
sort, sort,
facets, facets,
highlight_pre_tag, highlight_pre_tag,
@ -397,8 +403,14 @@ fn prepare_search<'t>(
search.limit(limit); search.limit(limit);
if let Some(ref filter) = query.filter { if let Some(ref filter) = query.filter {
if let Some(facets) = parse_filter(filter)? { if let Some(filter) = parse_filter(filter)? {
search.filter(facets); 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);
} }
} }