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 0cfecf4e9a
commit df749d424c
No known key found for this signature in database
2 changed files with 34 additions and 1 deletions

View File

@ -68,7 +68,7 @@ impl RankingRuleGraphTrait for FidGraph {
}
let mut edges = vec![];
for fid in all_fields {
for fid in all_fields.iter().copied() {
// TODO: We can improve performances and relevancy by storing
// the term subsets associated to each field ids fetched.
edges.push((
@ -80,6 +80,31 @@ impl RankingRuleGraphTrait for FidGraph {
));
}
// 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

@ -105,6 +105,14 @@ impl RankingRuleGraphTrait for PositionGraph {
));
}
// artificial empty condition for computing max cost
let max_cost = term.term_ids.len() as u32 * 10;
edges.push((
max_cost,
conditions_interner
.insert(PositionCondition { term: term.clone(), positions: Vec::default() }),
));
Ok(edges)
}
}