Make sure the facet queries are normalized

This commit is contained in:
Kerollmops 2023-06-12 11:13:34 +02:00 committed by Louis Dureuil
parent 09079a4e88
commit 2bcd8d2983
No known key found for this signature in database

View File

@ -14,7 +14,8 @@ use crate::error::UserError;
use crate::heed_codec::facet::{FacetGroupKey, FacetGroupValue}; use crate::heed_codec::facet::{FacetGroupKey, FacetGroupValue};
use crate::score_details::{ScoreDetails, ScoringStrategy}; use crate::score_details::{ScoreDetails, ScoringStrategy};
use crate::{ use crate::{
execute_search, AscDesc, DefaultSearchLogger, DocumentId, Index, Result, SearchContext, BEU16, execute_search, normalize_facet, AscDesc, DefaultSearchLogger, DocumentId, Index, Result,
SearchContext, BEU16,
}; };
// Building these factories is not free. // Building these factories is not free.
@ -288,6 +289,8 @@ impl<'a> SearchForFacetValues<'a> {
match self.query.as_ref() { match self.query.as_ref() {
Some(query) => { Some(query) => {
let query = normalize_facet(query);
let query = query.as_str();
let authorize_typos = self.search_query.index.authorize_typos(rtxn)?; let authorize_typos = self.search_query.index.authorize_typos(rtxn)?;
let field_authorizes_typos = let field_authorizes_typos =
!self.search_query.index.exact_attributes_ids(rtxn)?.contains(&fid); !self.search_query.index.exact_attributes_ids(rtxn)?.contains(&fid);
@ -297,8 +300,7 @@ impl<'a> SearchForFacetValues<'a> {
let exact_words_fst = self.search_query.index.exact_words(rtxn)?; let exact_words_fst = self.search_query.index.exact_words(rtxn)?;
if exact_words_fst.map_or(false, |fst| fst.contains(query)) { if exact_words_fst.map_or(false, |fst| fst.contains(query)) {
let key = let key = FacetGroupKey { field_id: fid, level: 0, left_bound: query };
FacetGroupKey { field_id: fid, level: 0, left_bound: query.as_ref() };
if let Some(FacetGroupValue { bitmap, .. }) = if let Some(FacetGroupValue { bitmap, .. }) =
index.facet_id_string_docids.get(rtxn, &key)? index.facet_id_string_docids.get(rtxn, &key)?
{ {