mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-26 23:04:26 +01:00
add virtual conditions to fid and position to always have the max cost
This commit is contained in:
parent
becf1f066a
commit
f050634b1e
@ -68,13 +68,38 @@ impl RankingRuleGraphTrait for FidGraph {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut edges = vec![];
|
let mut edges = vec![];
|
||||||
for fid in all_fields {
|
for fid in all_fields.iter().copied() {
|
||||||
edges.push((
|
edges.push((
|
||||||
fid as u32 * term.term_ids.len() as u32,
|
fid as u32 * term.term_ids.len() as u32,
|
||||||
conditions_interner.insert(FidCondition { term: term.clone(), fid }),
|
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)
|
Ok(edges)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -93,8 +93,10 @@ impl RankingRuleGraphTrait for PositionGraph {
|
|||||||
positions_for_costs.entry(cost).or_default().push(position);
|
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 {
|
for (cost, positions) in positions_for_costs {
|
||||||
edges.push((
|
edges.push((
|
||||||
cost,
|
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)
|
Ok(edges)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user