From 837905fc0428e2041be42a6d792ed1a8498ba93a Mon Sep 17 00:00:00 2001 From: Louis Dureuil Date: Wed, 29 Jan 2025 11:12:36 +0100 Subject: [PATCH] Multi search reads header to know if it is being proxied --- crates/meilisearch/src/routes/multi_search.rs | 17 +++++++++++------ crates/meilisearch/src/search/mod.rs | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/crates/meilisearch/src/routes/multi_search.rs b/crates/meilisearch/src/routes/multi_search.rs index 46c931b10..b3af98fd5 100644 --- a/crates/meilisearch/src/routes/multi_search.rs +++ b/crates/meilisearch/src/routes/multi_search.rs @@ -20,6 +20,7 @@ use crate::routes::indexes::search::search_kind; use crate::search::{ add_search_rules, perform_federated_search, perform_search, FederatedSearch, FederatedSearchResult, RetrieveVectors, SearchQueryWithIndex, SearchResultWithIndex, + PROXY_SEARCH_HEADER, PROXY_SEARCH_HEADER_VALUE, }; use crate::search_queue::SearchQueue; @@ -187,18 +188,22 @@ pub async fn multi_search_with_post( let response = match federation { Some(federation) => { - let search_result = tokio::task::spawn_blocking(move || { - perform_federated_search(&index_scheduler, queries, federation, features) - }) - .await; + // check remote header + let is_proxy = req + .headers() + .get(PROXY_SEARCH_HEADER) + .is_some_and(|value| value.as_bytes() == PROXY_SEARCH_HEADER_VALUE.as_bytes()); + let search_result = + perform_federated_search(&index_scheduler, queries, federation, features, is_proxy) + .await; permit.drop().await; - if let Ok(Ok(_)) = search_result { + if search_result.is_ok() { multi_aggregate.succeed(); } analytics.publish(multi_aggregate, &req); - HttpResponse::Ok().json(search_result??) + HttpResponse::Ok().json(search_result?) } None => { // Explicitly expect a `(ResponseError, usize)` for the error type rather than `ResponseError` only, diff --git a/crates/meilisearch/src/search/mod.rs b/crates/meilisearch/src/search/mod.rs index 03e0172e0..2091047fc 100644 --- a/crates/meilisearch/src/search/mod.rs +++ b/crates/meilisearch/src/search/mod.rs @@ -41,7 +41,7 @@ use crate::error::MeilisearchHttpError; mod federated; pub use federated::{ perform_federated_search, FederatedSearch, FederatedSearchResult, Federation, - FederationOptions, MergeFacets, + FederationOptions, MergeFacets, PROXY_SEARCH_HEADER, PROXY_SEARCH_HEADER_VALUE, }; mod ranking_rules;