Fix bug in exact_attribute

This commit is contained in:
Loïc Lecrenier 2023-05-01 17:20:10 +02:00
parent 58735d6d8f
commit aa63091752

View File

@ -34,7 +34,6 @@ impl<'ctx> RankingRule<'ctx, QueryGraph> for ExactAttribute {
query: &QueryGraph, query: &QueryGraph,
) -> Result<()> { ) -> Result<()> {
self.state = State::start_iteration(ctx, universe, query)?; self.state = State::start_iteration(ctx, universe, query)?;
Ok(()) Ok(())
} }
@ -169,7 +168,8 @@ impl State {
// longer phrases we'll be losing on precision here. // longer phrases we'll be losing on precision here.
let bucketed_position = crate::bucketed_position(position + offset); let bucketed_position = crate::bucketed_position(position + offset);
let word_position_docids = let word_position_docids =
ctx.get_db_word_position_docids(*word, bucketed_position)?.unwrap_or_default(); ctx.get_db_word_position_docids(*word, bucketed_position)?.unwrap_or_default()
& universe;
candidates &= word_position_docids; candidates &= word_position_docids;
if candidates.is_empty() { if candidates.is_empty() {
return Ok(State::Empty(query_graph.clone())); return Ok(State::Empty(query_graph.clone()));
@ -183,10 +183,15 @@ impl State {
return Ok(State::Empty(query_graph.clone())); return Ok(State::Empty(query_graph.clone()));
} }
let searchable_fields_ids = ctx.index.searchable_fields_ids(ctx.txn)?.unwrap_or_default(); let searchable_fields_ids = {
if let Some(fids) = ctx.index.searchable_fields_ids(ctx.txn)? {
fids
} else {
ctx.index.fields_ids_map(ctx.txn)?.ids().collect()
}
};
let mut candidates_per_attribute = Vec::with_capacity(searchable_fields_ids.len()); let mut candidates_per_attribute = Vec::with_capacity(searchable_fields_ids.len());
// then check that there exists at least one attribute that has all of the terms // then check that there exists at least one attribute that has all of the terms
for fid in searchable_fields_ids { for fid in searchable_fields_ids {
let mut intersection = MultiOps::intersection( let mut intersection = MultiOps::intersection(
@ -208,10 +213,10 @@ impl State {
.field_id_word_count_docids .field_id_word_count_docids
.get(ctx.txn, &(fid, count_all_positions as u8))? .get(ctx.txn, &(fid, count_all_positions as u8))?
.unwrap_or_default() .unwrap_or_default()
& universe
} else { } else {
RoaringBitmap::default() RoaringBitmap::default()
}; };
candidates_per_attribute.push(FieldCandidates { candidates_per_attribute.push(FieldCandidates {
start_with_exact: intersection, start_with_exact: intersection,
exact_word_count: candidates_with_exact_word_count, exact_word_count: candidates_with_exact_word_count,