From 2123d76089b28a5ffc5f49568c81eff0ffe87fe9 Mon Sep 17 00:00:00 2001 From: Louis Dureuil Date: Thu, 11 Jul 2024 16:35:11 +0200 Subject: [PATCH] search: introduce "search_from_kind" --- meilisearch/src/search.rs | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/meilisearch/src/search.rs b/meilisearch/src/search.rs index 14ff6deff..54dc6b0b7 100644 --- a/meilisearch/src/search.rs +++ b/meilisearch/src/search.rs @@ -866,15 +866,7 @@ pub fn perform_search( used_negative_operator, }, semantic_hit_count, - ) = match &search_kind { - SearchKind::KeywordOnly => (search.execute()?, None), - SearchKind::SemanticOnly { .. } => { - let results = search.execute()?; - let semantic_hit_count = results.document_scores.len() as u32; - (results, Some(semantic_hit_count)) - } - SearchKind::Hybrid { semantic_ratio, .. } => search.execute_hybrid(*semantic_ratio)?, - }; + ) = search_from_kind(search_kind, search)?; let SearchQuery { q, @@ -990,6 +982,22 @@ pub fn perform_search( Ok(result) } +pub fn search_from_kind( + search_kind: SearchKind, + search: milli::Search<'_>, +) -> Result<(milli::SearchResult, Option), MeilisearchHttpError> { + let (milli_result, semantic_hit_count) = match &search_kind { + SearchKind::KeywordOnly => (search.execute()?, None), + SearchKind::SemanticOnly { .. } => { + let results = search.execute()?; + let semantic_hit_count = results.document_scores.len() as u32; + (results, Some(semantic_hit_count)) + } + SearchKind::Hybrid { semantic_ratio, .. } => search.execute_hybrid(*semantic_ratio)?, + }; + Ok((milli_result, semantic_hit_count)) +} + struct AttributesFormat { attributes_to_retrieve: Option>, retrieve_vectors: RetrieveVectors,