Proximity costs 0 for documents that are perfectly matching

This commit is contained in:
Louis Dureuil 2023-06-13 09:08:40 +02:00
parent 0c40ef6911
commit af57c3c577
No known key found for this signature in database

View File

@ -12,11 +12,11 @@ pub fn build_edges(
left_term: Option<&LocatedQueryTermSubset>, left_term: Option<&LocatedQueryTermSubset>,
right_term: &LocatedQueryTermSubset, right_term: &LocatedQueryTermSubset,
) -> Result<Vec<(u32, Interned<ProximityCondition>)>> { ) -> Result<Vec<(u32, Interned<ProximityCondition>)>> {
let right_ngram_length = right_term.term_ids.len(); let right_ngram_max = right_term.term_ids.len().saturating_sub(1);
let Some(left_term) = left_term else { let Some(left_term) = left_term else {
return Ok(vec![( return Ok(vec![(
(right_ngram_length - 1) as u32, right_ngram_max as u32,
conditions_interner.insert(ProximityCondition::Term { term: right_term.clone() }), conditions_interner.insert(ProximityCondition::Term { term: right_term.clone() }),
)]) )])
}; };
@ -29,25 +29,25 @@ pub fn build_edges(
// The remaining query graph represents `the sun .. are beautiful` // The remaining query graph represents `the sun .. are beautiful`
// but `sun` and `are` have no proximity condition between them // but `sun` and `are` have no proximity condition between them
return Ok(vec![( return Ok(vec![(
(right_ngram_length - 1) as u32, right_ngram_max as u32,
conditions_interner.insert(ProximityCondition::Term { term: right_term.clone() }), conditions_interner.insert(ProximityCondition::Term { term: right_term.clone() }),
)]); )]);
} }
let mut conditions = vec![]; let mut conditions = vec![];
for cost in right_ngram_length..(7 + right_ngram_length) { for cost in right_ngram_max..(7 + right_ngram_max) {
conditions.push(( conditions.push((
cost as u32, cost as u32,
conditions_interner.insert(ProximityCondition::Uninit { conditions_interner.insert(ProximityCondition::Uninit {
left_term: left_term.clone(), left_term: left_term.clone(),
right_term: right_term.clone(), right_term: right_term.clone(),
cost: cost as u8, cost: (cost + 1) as u8,
}), }),
)) ))
} }
conditions.push(( conditions.push((
(7 + right_ngram_length) as u32, (7 + right_ngram_max) as u32,
conditions_interner.insert(ProximityCondition::Term { term: right_term.clone() }), conditions_interner.insert(ProximityCondition::Term { term: right_term.clone() }),
)); ));