mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-26 06:44:27 +01:00
Make the search for facet work
This commit is contained in:
parent
ce7e7f12c8
commit
e81809aae7
@ -119,7 +119,7 @@ pub async fn search(
|
|||||||
) -> Result<HttpResponse, ResponseError> {
|
) -> Result<HttpResponse, ResponseError> {
|
||||||
let index_uid = IndexUid::try_from(index_uid.into_inner())?;
|
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);
|
debug!("facet search called with params: {:?}", query);
|
||||||
|
|
||||||
let facet_query = query.facet_query.clone();
|
let facet_query = query.facet_query.clone();
|
||||||
|
@ -14,7 +14,9 @@ use meilisearch_types::error::deserr_codes::*;
|
|||||||
use meilisearch_types::heed::RoTxn;
|
use meilisearch_types::heed::RoTxn;
|
||||||
use meilisearch_types::index_uid::IndexUid;
|
use meilisearch_types::index_uid::IndexUid;
|
||||||
use meilisearch_types::milli::score_details::{ScoreDetails, ScoringStrategy};
|
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::settings::DEFAULT_PAGINATION_MAX_TOTAL_HITS;
|
||||||
use meilisearch_types::{milli, Document};
|
use meilisearch_types::{milli, Document};
|
||||||
use milli::tokenizer::TokenizerBuilder;
|
use milli::tokenizer::TokenizerBuilder;
|
||||||
@ -575,16 +577,19 @@ pub fn perform_search(
|
|||||||
pub fn perform_facet_search(
|
pub fn perform_facet_search(
|
||||||
index: &Index,
|
index: &Index,
|
||||||
search_query: SearchQuery,
|
search_query: SearchQuery,
|
||||||
facet_query: Option<String>,
|
mut facet_query: Option<String>,
|
||||||
facet_name: String,
|
facet_name: String,
|
||||||
) -> Result<Vec<FacetSearchResult>, MeilisearchHttpError> {
|
) -> Result<Vec<FacetSearchResult>, MeilisearchHttpError> {
|
||||||
let before_search = Instant::now();
|
let before_search = Instant::now();
|
||||||
let rtxn = index.read_txn()?;
|
let rtxn = index.read_txn()?;
|
||||||
|
|
||||||
let (search, is_finite_pagination, max_total_hits, offset) =
|
let (search, _, _, _) = prepare_search(index, &rtxn, &search_query)?;
|
||||||
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) {
|
fn insert_geo_distance(sorts: &[String], document: &mut Document) {
|
||||||
|
@ -248,25 +248,25 @@ pub struct SearchForFacetValue<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> 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 }
|
SearchForFacetValue { query: None, facet, search_query }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn query(&mut self, query: impl Into<String>) -> &mut Self {
|
pub fn query(&mut self, query: impl Into<String>) -> &mut Self {
|
||||||
self.query = Some(query.into());
|
self.query = Some(query.into());
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
fn execute(&self) -> Result<Vec<FacetSearchResult>> {
|
pub fn execute(&self) -> Result<Vec<FacetSearchResult>> {
|
||||||
let index = self.search_query.index;
|
let index = self.search_query.index;
|
||||||
let rtxn = self.search_query.rtxn;
|
let rtxn = self.search_query.rtxn;
|
||||||
|
|
||||||
let sortable_fields = index.sortable_fields(rtxn)?;
|
let filterable_fields = index.filterable_fields(rtxn)?;
|
||||||
if !sortable_fields.contains(&self.facet) {
|
if !filterable_fields.contains(&self.facet) {
|
||||||
// TODO create a new type of error
|
// TODO create a new type of error
|
||||||
return Err(UserError::InvalidSortableAttribute {
|
return Err(UserError::InvalidSortableAttribute {
|
||||||
field: self.facet.clone(),
|
field: self.facet.clone(),
|
||||||
valid_fields: sortable_fields.into_iter().collect(),
|
valid_fields: filterable_fields.into_iter().collect(),
|
||||||
})?;
|
})?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user