mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-23 10:37:41 +08:00
Implement the previous way for the exhaustive distinct candidates
This commit is contained in:
parent
55fbfb6124
commit
0d2e7bcc13
@ -1,3 +1,9 @@
|
|||||||
|
use std::fmt;
|
||||||
|
|
||||||
|
use levenshtein_automata::{LevenshteinAutomatonBuilder as LevBuilder, DFA};
|
||||||
|
use once_cell::sync::Lazy;
|
||||||
|
use roaring::bitmap::RoaringBitmap;
|
||||||
|
|
||||||
pub use self::facet::{FacetDistribution, Filter, DEFAULT_VALUES_PER_FACET};
|
pub use self::facet::{FacetDistribution, Filter, DEFAULT_VALUES_PER_FACET};
|
||||||
pub use self::matches::{
|
pub use self::matches::{
|
||||||
FormatOptions, MatchBounds, Matcher, MatcherBuilder, MatchingWord, MatchingWords,
|
FormatOptions, MatchBounds, Matcher, MatcherBuilder, MatchingWord, MatchingWords,
|
||||||
@ -5,10 +11,6 @@ pub use self::matches::{
|
|||||||
use crate::{
|
use crate::{
|
||||||
execute_search, AscDesc, DefaultSearchLogger, DocumentId, Index, Result, SearchContext,
|
execute_search, AscDesc, DefaultSearchLogger, DocumentId, Index, Result, SearchContext,
|
||||||
};
|
};
|
||||||
use levenshtein_automata::{LevenshteinAutomatonBuilder as LevBuilder, DFA};
|
|
||||||
use once_cell::sync::Lazy;
|
|
||||||
use roaring::bitmap::RoaringBitmap;
|
|
||||||
use std::fmt;
|
|
||||||
|
|
||||||
// Building these factories is not free.
|
// Building these factories is not free.
|
||||||
static LEVDIST0: Lazy<LevBuilder> = Lazy::new(|| LevBuilder::new(0, true));
|
static LEVDIST0: Lazy<LevBuilder> = Lazy::new(|| LevBuilder::new(0, true));
|
||||||
@ -112,6 +114,7 @@ impl<'a> Search<'a> {
|
|||||||
&mut ctx,
|
&mut ctx,
|
||||||
&self.query,
|
&self.query,
|
||||||
self.terms_matching_strategy,
|
self.terms_matching_strategy,
|
||||||
|
self.exhaustive_number_hits,
|
||||||
&self.filter,
|
&self.filter,
|
||||||
&self.sort_criteria,
|
&self.sort_criteria,
|
||||||
self.offset,
|
self.offset,
|
||||||
|
@ -37,6 +37,7 @@ use self::interner::Interner;
|
|||||||
use self::ranking_rules::{BoxRankingRule, RankingRule};
|
use self::ranking_rules::{BoxRankingRule, RankingRule};
|
||||||
use self::resolve_query_graph::compute_query_graph_docids;
|
use self::resolve_query_graph::compute_query_graph_docids;
|
||||||
use self::sort::Sort;
|
use self::sort::Sort;
|
||||||
|
use crate::search::new::distinct::{apply_distinct_rule, DistinctOutput};
|
||||||
use crate::{
|
use crate::{
|
||||||
AscDesc, Filter, Index, MatchingWords, Member, Result, SearchResult, TermsMatchingStrategy,
|
AscDesc, Filter, Index, MatchingWords, Member, Result, SearchResult, TermsMatchingStrategy,
|
||||||
UserError,
|
UserError,
|
||||||
@ -272,6 +273,7 @@ pub fn execute_search(
|
|||||||
ctx: &mut SearchContext,
|
ctx: &mut SearchContext,
|
||||||
query: &Option<String>,
|
query: &Option<String>,
|
||||||
terms_matching_strategy: TermsMatchingStrategy,
|
terms_matching_strategy: TermsMatchingStrategy,
|
||||||
|
exhaustive_number_hits: bool,
|
||||||
filters: &Option<Filter>,
|
filters: &Option<Filter>,
|
||||||
sort_criteria: &Option<Vec<AscDesc>>,
|
sort_criteria: &Option<Vec<AscDesc>>,
|
||||||
from: usize,
|
from: usize,
|
||||||
@ -333,11 +335,21 @@ pub fn execute_search(
|
|||||||
)?
|
)?
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// The candidates is the universe unless the exhaustive number of hits
|
||||||
|
// is requested and a distinct attribute is set.
|
||||||
|
let mut candidates = universe;
|
||||||
|
if exhaustive_number_hits {
|
||||||
|
if let Some(f) = ctx.index.distinct_field(ctx.txn)? {
|
||||||
|
if let Some(distinct_fid) = ctx.index.fields_ids_map(ctx.txn)?.id(f) {
|
||||||
|
candidates = apply_distinct_rule(ctx, distinct_fid, &candidates)?.remaining;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(SearchResult {
|
Ok(SearchResult {
|
||||||
// TODO: correct matching words
|
// TODO: correct matching words
|
||||||
matching_words: MatchingWords::default(),
|
matching_words: MatchingWords::default(),
|
||||||
// TODO: candidates with distinct
|
candidates,
|
||||||
candidates: universe,
|
|
||||||
documents_ids,
|
documents_ids,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user