diff --git a/meilisearch/src/analytics/segment_analytics.rs b/meilisearch/src/analytics/segment_analytics.rs index 99298bd43..f20cff5d9 100644 --- a/meilisearch/src/analytics/segment_analytics.rs +++ b/meilisearch/src/analytics/segment_analytics.rs @@ -580,6 +580,7 @@ pub struct SearchAggregator { total_received: usize, total_succeeded: usize, total_degraded: usize, + total_used_negative_operator: usize, time_spent: BinaryHeap, // sort @@ -760,12 +761,16 @@ impl SearchAggregator { facet_distribution: _, facet_stats: _, degraded, + used_negative_operator, } = result; self.total_succeeded = self.total_succeeded.saturating_add(1); if *degraded { self.total_degraded = self.total_degraded.saturating_add(1); } + if *used_negative_operator { + self.total_used_negative_operator = self.total_used_negative_operator.saturating_add(1); + } self.time_spent.push(*processing_time_ms as usize); } @@ -808,6 +813,7 @@ impl SearchAggregator { embedder, hybrid, total_degraded, + total_used_negative_operator, } = other; if self.timestamp.is_none() { @@ -823,6 +829,8 @@ impl SearchAggregator { self.total_received = self.total_received.saturating_add(total_received); self.total_succeeded = self.total_succeeded.saturating_add(total_succeeded); self.total_degraded = self.total_degraded.saturating_add(total_degraded); + self.total_used_negative_operator = + self.total_used_negative_operator.saturating_add(total_used_negative_operator); self.time_spent.append(time_spent); // sort @@ -929,6 +937,7 @@ impl SearchAggregator { embedder, hybrid, total_degraded, + total_used_negative_operator, } = self; if total_received == 0 { @@ -949,6 +958,7 @@ impl SearchAggregator { "total_failed": total_received.saturating_sub(total_succeeded), // just to be sure we never panics "total_received": total_received, "total_degraded": total_degraded, + "total_used_negative_operator": total_used_negative_operator, }, "sort": { "with_geoPoint": sort_with_geo_point, diff --git a/meilisearch/src/search.rs b/meilisearch/src/search.rs index 3c00ca802..db58c6102 100644 --- a/meilisearch/src/search.rs +++ b/meilisearch/src/search.rs @@ -324,9 +324,11 @@ pub struct SearchResult { #[serde(skip_serializing_if = "Option::is_none")] pub facet_stats: Option>, - // This information is only used for analytics purposes + // These fields are only used for analytics purposes #[serde(skip)] pub degraded: bool, + #[serde(skip)] + pub used_negative_operator: bool, } #[derive(Serialize, Debug, Clone, PartialEq)] @@ -512,6 +514,7 @@ pub fn perform_search( candidates, document_scores, degraded, + used_negative_operator, .. } = match &query.hybrid { Some(hybrid) => match *hybrid.semantic_ratio { @@ -717,6 +720,7 @@ pub fn perform_search( facet_distribution, facet_stats, degraded, + used_negative_operator, }; Ok(result) } diff --git a/milli/src/search/hybrid.rs b/milli/src/search/hybrid.rs index a8b7f0fcf..2a6d9f7a5 100644 --- a/milli/src/search/hybrid.rs +++ b/milli/src/search/hybrid.rs @@ -11,6 +11,7 @@ struct ScoreWithRatioResult { candidates: RoaringBitmap, document_scores: Vec<(u32, ScoreWithRatio)>, degraded: bool, + used_negative_operator: bool, } type ScoreWithRatio = (Vec, f32); @@ -78,6 +79,7 @@ impl ScoreWithRatioResult { candidates: results.candidates, document_scores, degraded: results.degraded, + used_negative_operator: results.used_negative_operator, } } @@ -113,6 +115,7 @@ impl ScoreWithRatioResult { documents_ids, document_scores, degraded: left.degraded | right.degraded, + used_negative_operator: left.used_negative_operator | right.used_negative_operator, } } } diff --git a/milli/src/search/mod.rs b/milli/src/search/mod.rs index b3dd0c091..3c709a647 100644 --- a/milli/src/search/mod.rs +++ b/milli/src/search/mod.rs @@ -183,6 +183,7 @@ impl<'a> Search<'a> { documents_ids, document_scores, degraded, + used_negative_operator, } = match self.vector.as_ref() { Some(vector) => execute_vector_search( &mut ctx, @@ -221,7 +222,14 @@ impl<'a> Search<'a> { None => MatchingWords::default(), }; - Ok(SearchResult { matching_words, candidates, document_scores, documents_ids, degraded }) + Ok(SearchResult { + matching_words, + candidates, + document_scores, + documents_ids, + degraded, + used_negative_operator, + }) } } @@ -272,6 +280,7 @@ pub struct SearchResult { pub documents_ids: Vec, pub document_scores: Vec>, pub degraded: bool, + pub used_negative_operator: bool, } #[derive(Debug, Clone, Copy, PartialEq, Eq)] diff --git a/milli/src/search/new/mod.rs b/milli/src/search/new/mod.rs index ec83b84d1..99f4562d6 100644 --- a/milli/src/search/new/mod.rs +++ b/milli/src/search/new/mod.rs @@ -571,6 +571,7 @@ pub fn execute_vector_search( documents_ids: docids, located_query_terms: None, degraded, + used_negative_operator: false, }) } @@ -594,6 +595,7 @@ pub fn execute_search( ) -> Result { check_sort_criteria(ctx, sort_criteria.as_ref())?; + let mut used_negative_operator = false; let mut located_query_terms = None; let query_terms = if let Some(query) = query { let span = tracing::trace_span!(target: "search::tokens", "tokenizer_builder"); @@ -636,6 +638,7 @@ pub fn execute_search( let (query_terms, negative_words) = located_query_terms_from_tokens(ctx, tokens, words_limit)?; + used_negative_operator = !negative_words.is_empty(); let ignored_documents = resolve_negative_words(ctx, &negative_words)?; universe -= ignored_documents; @@ -710,6 +713,7 @@ pub fn execute_search( documents_ids: docids, located_query_terms, degraded, + used_negative_operator, }) } @@ -772,4 +776,5 @@ pub struct PartialSearchResult { pub document_scores: Vec>, pub degraded: bool, + pub used_negative_operator: bool, }