mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-03-06 22:02:34 +08:00
Add the max_weight of the weight map if it's lacking
This commit is contained in:
parent
ca41ce3bbd
commit
5ceddbda84
@ -48,11 +48,6 @@ impl FieldidsWeightsMap {
|
||||
self.map.values().copied().max()
|
||||
}
|
||||
|
||||
/// Returns the field id with the highest weight.
|
||||
pub fn max_weight_fid(&self) -> Option<(FieldId, Weight)> {
|
||||
self.map.iter().max_by_key(|(_, weight)| *weight).map(|(fid, weight)| (*fid, *weight))
|
||||
}
|
||||
|
||||
/// Return an iterator visiting all field ids in arbitrary order.
|
||||
pub fn ids(&self) -> impl Iterator<Item = FieldId> + '_ {
|
||||
self.map.keys().copied()
|
||||
|
@ -57,6 +57,7 @@ impl RankingRuleGraphTrait for FidGraph {
|
||||
let term = to_term;
|
||||
|
||||
let mut all_fields = FxHashSet::default();
|
||||
let mut current_max_weight = 0;
|
||||
for word in term.term_subset.all_single_words_except_prefix_db(ctx)? {
|
||||
let fields = ctx.get_db_word_fids(word.interned())?;
|
||||
all_fields.extend(fields);
|
||||
@ -81,6 +82,9 @@ impl RankingRuleGraphTrait for FidGraph {
|
||||
let weight = weights_map
|
||||
.weight(fid)
|
||||
.ok_or(InternalError::FieldidsWeightsMapMissingEntry { key: fid })?;
|
||||
if weight > current_max_weight {
|
||||
current_max_weight = weight;
|
||||
}
|
||||
edges.push((
|
||||
weight as u32 * term.term_ids.len() as u32,
|
||||
conditions_interner.insert(FidCondition { term: term.clone(), fid: Some(fid) }),
|
||||
@ -88,10 +92,10 @@ impl RankingRuleGraphTrait for FidGraph {
|
||||
}
|
||||
|
||||
// always lookup the max_fid if we don't already and add an artificial condition for max scoring
|
||||
let max_weight_fid = weights_map.max_weight_fid();
|
||||
let max_weight = weights_map.max_weight();
|
||||
|
||||
if let Some((max_fid, max_weight)) = max_weight_fid {
|
||||
if !all_fields.contains(&max_fid) {
|
||||
if let Some(max_weight) = max_weight {
|
||||
if current_max_weight < max_weight {
|
||||
edges.push((
|
||||
max_weight as u32 * term.term_ids.len() as u32, // TODO improve the fid score i.e. fid^10.
|
||||
conditions_interner.insert(FidCondition {
|
||||
|
Loading…
x
Reference in New Issue
Block a user