Fix compilation issues

This commit is contained in:
Clément Renault 2023-05-04 12:27:19 +02:00 committed by Louis Dureuil
parent 0252cfe8b6
commit 87e22e436a
No known key found for this signature in database
3 changed files with 23 additions and 12 deletions

View File

@ -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<InvalidFacetSearchQuery>)]
@ -34,6 +34,8 @@ pub struct FacetSearchQuery {
pub facet_name: String,
#[deserr(default, error = DeserrJsonError<InvalidSearchQ>)]
pub q: Option<String>,
#[deserr(default, error = DeserrJsonError<InvalidSearchVector>)]
pub vector: Option<Vec<f32>>,
#[deserr(default = DEFAULT_SEARCH_OFFSET(), error = DeserrJsonError<InvalidSearchOffset>)]
pub offset: usize,
#[deserr(default = DEFAULT_SEARCH_LIMIT(), error = DeserrJsonError<InvalidSearchLimit>)]
@ -52,6 +54,10 @@ pub struct FacetSearchQuery {
pub attributes_to_highlight: Option<HashSet<String>>,
#[deserr(default, error = DeserrJsonError<InvalidSearchShowMatchesPosition>, default)]
pub show_matches_position: bool,
#[deserr(default, error = DeserrJsonError<InvalidSearchShowRankingScore>, default)]
pub show_ranking_score: bool,
#[deserr(default, error = DeserrJsonError<InvalidSearchShowRankingScoreDetails>, default)]
pub show_ranking_score_details: bool,
#[deserr(default, error = DeserrJsonError<InvalidSearchFilter>)]
pub filter: Option<Value>,
#[deserr(default, error = DeserrJsonError<InvalidSearchSort>)]
@ -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<FacetSearchQuery> 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<FacetSearchQuery> for SearchQuery {
highlight_post_tag: value.highlight_post_tag,
crop_marker: value.crop_marker,
matching_strategy: value.matching_strategy,
vector: value.vector,
}
}
}

View File

@ -585,11 +585,12 @@ pub fn perform_facet_search(
search_query: SearchQuery,
facet_query: Option<String>,
facet_name: String,
features: RoFeatures,
) -> Result<FacetSearchResult, MeilisearchHttpError> {
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);

View File

@ -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;