mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-12-24 21:50:07 +01:00
Initialize query time ranking rule for query search
This commit is contained in:
parent
b4a52a622e
commit
abb19d368d
@ -113,6 +113,7 @@ impl<'a> Search<'a> {
|
|||||||
&self.query,
|
&self.query,
|
||||||
self.terms_matching_strategy,
|
self.terms_matching_strategy,
|
||||||
&self.filter,
|
&self.filter,
|
||||||
|
&self.sort_criteria,
|
||||||
self.offset,
|
self.offset,
|
||||||
self.limit,
|
self.limit,
|
||||||
Some(self.words_limit),
|
Some(self.words_limit),
|
||||||
|
@ -33,7 +33,11 @@ use roaring::RoaringBitmap;
|
|||||||
use words::Words;
|
use words::Words;
|
||||||
|
|
||||||
use self::ranking_rules::{BoxRankingRule, RankingRule};
|
use self::ranking_rules::{BoxRankingRule, RankingRule};
|
||||||
use crate::{Filter, Index, MatchingWords, Result, SearchResult, TermsMatchingStrategy};
|
use self::sort::Sort;
|
||||||
|
use crate::{
|
||||||
|
AscDesc, CriterionError, Filter, Index, MatchingWords, Member, Result, SearchResult,
|
||||||
|
TermsMatchingStrategy,
|
||||||
|
};
|
||||||
|
|
||||||
/// A structure used throughout the execution of a search query.
|
/// A structure used throughout the execution of a search query.
|
||||||
pub struct SearchContext<'ctx> {
|
pub struct SearchContext<'ctx> {
|
||||||
@ -106,6 +110,7 @@ fn resolve_maximally_reduced_query_graph(
|
|||||||
/// Return the list of initialised ranking rules to be used for a placeholder search.
|
/// Return the list of initialised ranking rules to be used for a placeholder search.
|
||||||
fn get_ranking_rules_for_placeholder_search<'ctx>(
|
fn get_ranking_rules_for_placeholder_search<'ctx>(
|
||||||
ctx: &SearchContext<'ctx>,
|
ctx: &SearchContext<'ctx>,
|
||||||
|
sort_criteria: &Option<Vec<AscDesc>>,
|
||||||
) -> Result<Vec<BoxRankingRule<'ctx, PlaceholderQuery>>> {
|
) -> Result<Vec<BoxRankingRule<'ctx, PlaceholderQuery>>> {
|
||||||
// let sort = false;
|
// let sort = false;
|
||||||
// let mut asc = HashSet::new();
|
// let mut asc = HashSet::new();
|
||||||
@ -131,13 +136,14 @@ fn get_ranking_rules_for_placeholder_search<'ctx>(
|
|||||||
/// Return the list of initialised ranking rules to be used for a query graph search.
|
/// Return the list of initialised ranking rules to be used for a query graph search.
|
||||||
fn get_ranking_rules_for_query_graph_search<'ctx>(
|
fn get_ranking_rules_for_query_graph_search<'ctx>(
|
||||||
ctx: &SearchContext<'ctx>,
|
ctx: &SearchContext<'ctx>,
|
||||||
|
sort_criteria: &Option<Vec<AscDesc>>,
|
||||||
terms_matching_strategy: TermsMatchingStrategy,
|
terms_matching_strategy: TermsMatchingStrategy,
|
||||||
) -> Result<Vec<BoxRankingRule<'ctx, QueryGraph>>> {
|
) -> Result<Vec<BoxRankingRule<'ctx, QueryGraph>>> {
|
||||||
// query graph search
|
// query graph search
|
||||||
let mut words = false;
|
let mut words = false;
|
||||||
let mut typo = false;
|
let mut typo = false;
|
||||||
let mut proximity = false;
|
let mut proximity = false;
|
||||||
let sort = false;
|
let mut sort = false;
|
||||||
let attribute = false;
|
let attribute = false;
|
||||||
let exactness = false;
|
let exactness = false;
|
||||||
let mut asc = HashSet::new();
|
let mut asc = HashSet::new();
|
||||||
@ -193,8 +199,33 @@ fn get_ranking_rules_for_query_graph_search<'ctx>(
|
|||||||
if sort {
|
if sort {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// todo!();
|
|
||||||
// sort = false;
|
for criterion in sort_criteria.clone().unwrap_or_default() {
|
||||||
|
let sort_ranking_rule = match criterion {
|
||||||
|
AscDesc::Asc(Member::Field(field_name)) => {
|
||||||
|
if asc.contains(&field_name) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
asc.insert(field_name.clone());
|
||||||
|
Sort::new(ctx.index, ctx.txn, field_name, true)?
|
||||||
|
}
|
||||||
|
AscDesc::Desc(Member::Field(field_name)) => {
|
||||||
|
if desc.contains(&field_name) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
desc.insert(field_name.clone());
|
||||||
|
Sort::new(ctx.index, ctx.txn, field_name, false)?
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
return Err(CriterionError::ReservedNameForSort {
|
||||||
|
name: "_geoPoint".to_string(),
|
||||||
|
}
|
||||||
|
.into())
|
||||||
|
}
|
||||||
|
};
|
||||||
|
ranking_rules.push(Box::new(sort_ranking_rule));
|
||||||
|
}
|
||||||
|
sort = true;
|
||||||
}
|
}
|
||||||
crate::Criterion::Exactness => {
|
crate::Criterion::Exactness => {
|
||||||
if exactness {
|
if exactness {
|
||||||
@ -228,6 +259,7 @@ pub fn execute_search(
|
|||||||
query: &Option<String>,
|
query: &Option<String>,
|
||||||
terms_matching_strategy: TermsMatchingStrategy,
|
terms_matching_strategy: TermsMatchingStrategy,
|
||||||
filters: &Option<Filter>,
|
filters: &Option<Filter>,
|
||||||
|
sort_criteria: &Option<Vec<AscDesc>>,
|
||||||
from: usize,
|
from: usize,
|
||||||
length: usize,
|
length: usize,
|
||||||
words_limit: Option<usize>,
|
words_limit: Option<usize>,
|
||||||
@ -268,11 +300,12 @@ pub fn execute_search(
|
|||||||
query_graph_logger,
|
query_graph_logger,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let ranking_rules = get_ranking_rules_for_query_graph_search(ctx, terms_matching_strategy)?;
|
let ranking_rules =
|
||||||
|
get_ranking_rules_for_query_graph_search(ctx, sort_criteria, terms_matching_strategy)?;
|
||||||
|
|
||||||
bucket_sort(ctx, ranking_rules, &graph, &universe, from, length, query_graph_logger)?
|
bucket_sort(ctx, ranking_rules, &graph, &universe, from, length, query_graph_logger)?
|
||||||
} else {
|
} else {
|
||||||
let ranking_rules = get_ranking_rules_for_placeholder_search(ctx)?;
|
let ranking_rules = get_ranking_rules_for_placeholder_search(ctx, sort_criteria)?;
|
||||||
bucket_sort(
|
bucket_sort(
|
||||||
ctx,
|
ctx,
|
||||||
ranking_rules,
|
ranking_rules,
|
||||||
|
@ -51,7 +51,7 @@ pub struct Sort<'ctx, Query> {
|
|||||||
iter: Option<RankingRuleOutputIterWrapper<'ctx, Query>>,
|
iter: Option<RankingRuleOutputIterWrapper<'ctx, Query>>,
|
||||||
}
|
}
|
||||||
impl<'ctx, Query> Sort<'ctx, Query> {
|
impl<'ctx, Query> Sort<'ctx, Query> {
|
||||||
pub fn _new(
|
pub fn new(
|
||||||
index: &Index,
|
index: &Index,
|
||||||
rtxn: &'ctx heed::RoTxn,
|
rtxn: &'ctx heed::RoTxn,
|
||||||
field_name: String,
|
field_name: String,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user