diff --git a/meilisearch/src/routes/indexes/facet_search.rs b/meilisearch/src/routes/indexes/facet_search.rs index 3633057e8..b56495c5a 100644 --- a/meilisearch/src/routes/indexes/facet_search.rs +++ b/meilisearch/src/routes/indexes/facet_search.rs @@ -25,7 +25,7 @@ pub fn configure(cfg: &mut web::ServiceConfig) { } // TODO improve the error messages -#[derive(Debug, Clone, Default, PartialEq, Eq, deserr::Deserr)] +#[derive(Debug, Clone, Default, PartialEq, deserr::Deserr)] #[deserr(error = DeserrJsonError, rename_all = camelCase, deny_unknown_fields)] pub struct FacetSearchQuery { #[deserr(default, error = DeserrJsonError)] @@ -34,6 +34,8 @@ pub struct FacetSearchQuery { pub facet_name: String, #[deserr(default, error = DeserrJsonError)] pub q: Option, + #[deserr(default, error = DeserrJsonError)] + pub vector: Option>, #[deserr(default = DEFAULT_SEARCH_OFFSET(), error = DeserrJsonError)] pub offset: usize, #[deserr(default = DEFAULT_SEARCH_LIMIT(), error = DeserrJsonError)] @@ -52,6 +54,10 @@ pub struct FacetSearchQuery { pub attributes_to_highlight: Option>, #[deserr(default, error = DeserrJsonError, default)] pub show_matches_position: bool, + #[deserr(default, error = DeserrJsonError, default)] + pub show_ranking_score: bool, + #[deserr(default, error = DeserrJsonError, default)] + pub show_ranking_score_details: bool, #[deserr(default, error = DeserrJsonError)] pub filter: Option, #[deserr(default, error = DeserrJsonError)] @@ -92,8 +98,9 @@ pub async fn search( } let index = index_scheduler.index(&index_uid)?; + let features = index_scheduler.features()?; let search_result = tokio::task::spawn_blocking(move || { - perform_facet_search(&index, search_query, facet_query, facet_name) + perform_facet_search(&index, search_query, facet_query, facet_name, features) }) .await?; @@ -121,6 +128,8 @@ impl From for SearchQuery { crop_length: value.crop_length, attributes_to_highlight: value.attributes_to_highlight, show_matches_position: value.show_matches_position, + show_ranking_score: value.show_ranking_score, + show_ranking_score_details: value.show_ranking_score_details, filter: value.filter, sort: value.sort, facets: value.facets, @@ -128,6 +137,7 @@ impl From for SearchQuery { highlight_post_tag: value.highlight_post_tag, crop_marker: value.crop_marker, matching_strategy: value.matching_strategy, + vector: value.vector, } } } diff --git a/meilisearch/src/search.rs b/meilisearch/src/search.rs index c32724ec0..8a29f091d 100644 --- a/meilisearch/src/search.rs +++ b/meilisearch/src/search.rs @@ -585,11 +585,12 @@ pub fn perform_facet_search( search_query: SearchQuery, facet_query: Option, facet_name: String, + features: RoFeatures, ) -> Result { let before_search = Instant::now(); let rtxn = index.read_txn()?; - let (search, _, _, _) = prepare_search(index, &rtxn, &search_query)?; + let (search, _, _, _) = prepare_search(index, &rtxn, &search_query, features)?; let mut facet_search = SearchForFacetValues::new(facet_name, search); if let Some(facet_query) = &facet_query { facet_search.query(facet_query); diff --git a/milli/src/search/mod.rs b/milli/src/search/mod.rs index c872e3ee4..7a09a8211 100644 --- a/milli/src/search/mod.rs +++ b/milli/src/search/mod.rs @@ -1,9 +1,9 @@ use std::fmt; -use fst::automaton::{Complement, Intersection, StartsWith, Str, Union}; -use fst::Streamer; +use fst::automaton::{Automaton, Str}; +use fst::{IntoStreamer, Streamer}; use levenshtein_automata::{LevenshteinAutomatonBuilder as LevBuilder, DFA}; -use log::{debug, error}; +use log::error; use once_cell::sync::Lazy; use roaring::bitmap::RoaringBitmap; @@ -314,12 +314,12 @@ impl<'a> SearchForFacetValues<'a> { } } else { let is_prefix = true; - let starts = StartsWith(Str::new(get_first(query))); - let first = - Intersection(build_dfa(query, 1, is_prefix), Complement(&starts)); + let starts = Str::new(get_first(query)).starts_with(); + let first = build_dfa(query, 1, is_prefix) + .intersection(starts.clone().complement()); let second_dfa = build_dfa(query, 2, is_prefix); - let second = Intersection(&second_dfa, &starts); - let automaton = Union(first, &second); + let second = second_dfa.intersection(starts); + let automaton = first.union(&second); let mut stream = fst.search(automaton).into_stream(); let mut length = 0; @@ -348,7 +348,7 @@ impl<'a> SearchForFacetValues<'a> { Ok(results) } else { - let automaton = StartsWith(Str::new(query)); + let automaton = Str::new(query).starts_with(); let mut stream = fst.search(automaton).into_stream(); let mut results = vec![]; let mut length = 0;