diff --git a/meilisearch/src/routes/indexes/facet_search.rs b/meilisearch/src/routes/indexes/facet_search.rs index be3af4f3e..16479c755 100644 --- a/meilisearch/src/routes/indexes/facet_search.rs +++ b/meilisearch/src/routes/indexes/facet_search.rs @@ -119,7 +119,7 @@ pub async fn search( ) -> Result { let index_uid = IndexUid::try_from(index_uid.into_inner())?; - let mut query = params.into_inner(); + let query = params.into_inner(); debug!("facet search called with params: {:?}", query); let facet_query = query.facet_query.clone(); diff --git a/meilisearch/src/search.rs b/meilisearch/src/search.rs index 2093a27ef..cd6a0bc54 100644 --- a/meilisearch/src/search.rs +++ b/meilisearch/src/search.rs @@ -14,7 +14,9 @@ use meilisearch_types::error::deserr_codes::*; use meilisearch_types::heed::RoTxn; use meilisearch_types::index_uid::IndexUid; use meilisearch_types::milli::score_details::{ScoreDetails, ScoringStrategy}; -use meilisearch_types::milli::{dot_product_similarity, FacetSearchResult, InternalError}; +use meilisearch_types::milli::{ + dot_product_similarity, facet, FacetSearchResult, InternalError, SearchForFacetValue, +}; use meilisearch_types::settings::DEFAULT_PAGINATION_MAX_TOTAL_HITS; use meilisearch_types::{milli, Document}; use milli::tokenizer::TokenizerBuilder; @@ -575,16 +577,19 @@ pub fn perform_search( pub fn perform_facet_search( index: &Index, search_query: SearchQuery, - facet_query: Option, + mut facet_query: Option, facet_name: String, ) -> Result, MeilisearchHttpError> { let before_search = Instant::now(); let rtxn = index.read_txn()?; - let (search, is_finite_pagination, max_total_hits, offset) = - prepare_search(index, &rtxn, &search_query)?; + let (search, _, _, _) = prepare_search(index, &rtxn, &search_query)?; + let mut facet_search = SearchForFacetValue::new(facet_name, search); + if let Some(facet_query) = facet_query.take() { + facet_search.query(facet_query); + } - todo!("Execute the search") + facet_search.execute().map_err(Into::into) } fn insert_geo_distance(sorts: &[String], document: &mut Document) { diff --git a/milli/src/search/mod.rs b/milli/src/search/mod.rs index 85ba3df3a..bc88a0ff8 100644 --- a/milli/src/search/mod.rs +++ b/milli/src/search/mod.rs @@ -248,25 +248,25 @@ pub struct SearchForFacetValue<'a> { } impl<'a> SearchForFacetValue<'a> { - fn new(facet: String, search_query: Search<'a>) -> SearchForFacetValue<'a> { + pub fn new(facet: String, search_query: Search<'a>) -> SearchForFacetValue<'a> { SearchForFacetValue { query: None, facet, search_query } } - fn query(&mut self, query: impl Into) -> &mut Self { + pub fn query(&mut self, query: impl Into) -> &mut Self { self.query = Some(query.into()); self } - fn execute(&self) -> Result> { + pub fn execute(&self) -> Result> { let index = self.search_query.index; let rtxn = self.search_query.rtxn; - let sortable_fields = index.sortable_fields(rtxn)?; - if !sortable_fields.contains(&self.facet) { + let filterable_fields = index.filterable_fields(rtxn)?; + if !filterable_fields.contains(&self.facet) { // TODO create a new type of error return Err(UserError::InvalidSortableAttribute { field: self.facet.clone(), - valid_fields: sortable_fields.into_iter().collect(), + valid_fields: filterable_fields.into_iter().collect(), })?; }