From 481d890f53af60079fe77c0bfe0eb1664439cd04 Mon Sep 17 00:00:00 2001 From: Louis Dureuil Date: Wed, 29 Jan 2025 11:10:33 +0100 Subject: [PATCH] Allow rebuilding a SearchQueryWithIndex from its components --- crates/meilisearch/src/search/mod.rs | 66 ++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/crates/meilisearch/src/search/mod.rs b/crates/meilisearch/src/search/mod.rs index af916210c..03e0172e0 100644 --- a/crates/meilisearch/src/search/mod.rs +++ b/crates/meilisearch/src/search/mod.rs @@ -496,6 +496,72 @@ impl SearchQueryWithIndex { self.facets.as_deref().filter(|v| !v.is_empty()) } + pub fn from_index_query_federation( + index_uid: IndexUid, + query: SearchQuery, + federation_options: Option, + ) -> Self { + let SearchQuery { + q, + vector, + hybrid, + offset, + limit, + page, + hits_per_page, + attributes_to_retrieve, + retrieve_vectors, + attributes_to_crop, + crop_length, + attributes_to_highlight, + show_matches_position, + show_ranking_score, + show_ranking_score_details, + filter, + sort, + distinct, + facets, + highlight_pre_tag, + highlight_post_tag, + crop_marker, + matching_strategy, + attributes_to_search_on, + ranking_score_threshold, + locales, + } = query; + + SearchQueryWithIndex { + index_uid, + q, + vector, + hybrid, + offset: if offset == DEFAULT_SEARCH_OFFSET() { None } else { Some(offset) }, + limit: if limit == DEFAULT_SEARCH_LIMIT() { None } else { Some(limit) }, + page, + hits_per_page, + attributes_to_retrieve, + retrieve_vectors, + attributes_to_crop, + crop_length, + attributes_to_highlight, + show_ranking_score, + show_ranking_score_details, + show_matches_position, + filter, + sort, + distinct, + facets, + highlight_pre_tag, + highlight_post_tag, + crop_marker, + matching_strategy, + attributes_to_search_on, + ranking_score_threshold, + locales, + federation_options, + } + } + pub fn into_index_query_federation(self) -> (IndexUid, SearchQuery, Option) { let SearchQueryWithIndex { index_uid,