add virtual conditions to fid and position to always have the max cost

This commit is contained in:
Louis Dureuil 2023-06-06 18:15:42 +02:00
parent becf1f066a
commit f050634b1e
No known key found for this signature in database
2 changed files with 38 additions and 2 deletions

View File

@ -68,13 +68,38 @@ impl RankingRuleGraphTrait for FidGraph {
}
let mut edges = vec![];
for fid in all_fields {
for fid in all_fields.iter().copied() {
edges.push((
fid as u32 * term.term_ids.len() as u32,
conditions_interner.insert(FidCondition { term: term.clone(), fid }),
));
}
// always lookup the max_fid if we don't already and add an artificial condition for max scoring
let max_fid: Option<u16> = {
if let Some(max_fid) = ctx
.index
.searchable_fields_ids(ctx.txn)?
.map(|field_ids| field_ids.into_iter().max())
{
max_fid
} else {
ctx.index.fields_ids_map(ctx.txn)?.ids().max()
}
};
if let Some(max_fid) = max_fid {
if !all_fields.contains(&max_fid) {
edges.push((
max_fid as u32 * term.term_ids.len() as u32, // TODO improve the fid score i.e. fid^10.
conditions_interner.insert(FidCondition {
term: term.clone(), // TODO remove this ugly clone
fid: max_fid,
}),
));
}
}
Ok(edges)
}
}

View File

@ -93,8 +93,10 @@ impl RankingRuleGraphTrait for PositionGraph {
positions_for_costs.entry(cost).or_default().push(position);
}
let mut edges = vec![];
let max_cost = term.term_ids.len() as u32 * 10;
let max_cost_exists = positions_for_costs.contains_key(&max_cost);
let mut edges = vec![];
for (cost, positions) in positions_for_costs {
edges.push((
cost,
@ -102,6 +104,15 @@ impl RankingRuleGraphTrait for PositionGraph {
));
}
if !max_cost_exists {
// artificial empty condition for computing max cost
edges.push((
max_cost,
conditions_interner
.insert(PositionCondition { term: term.clone(), positions: Vec::default() }),
));
}
Ok(edges)
}
}