Modify the compute_query_term_subset_docids function to accept the universe

This commit is contained in:
Clément Renault 2024-06-21 11:43:04 +02:00
parent 2099b4f0dd
commit 50a7393c55
No known key found for this signature in database
GPG Key ID: F250A4C4E3AE5F5F
6 changed files with 11 additions and 14 deletions

View File

@ -302,7 +302,7 @@ impl QueryGraph {
for (_, node) in self.nodes.iter() { for (_, node) in self.nodes.iter() {
match &node.data { match &node.data {
QueryNodeData::Term(t) => { QueryNodeData::Term(t) => {
let docids = compute_query_term_subset_docids(ctx, &t.term_subset)?; let docids = compute_query_term_subset_docids(ctx, None, &t.term_subset)?;
for id in t.term_ids.clone() { for id in t.term_ids.clone() {
term_docids term_docids
.entry(id) .entry(id)

View File

@ -59,7 +59,7 @@ impl RankingRuleGraphTrait for ExactnessGraph {
} }
ExactnessCondition::Any(dest_node) => { ExactnessCondition::Any(dest_node) => {
let docids = let docids =
universe & compute_query_term_subset_docids(ctx, &dest_node.term_subset)?; compute_query_term_subset_docids(ctx, Some(universe), &dest_node.term_subset)?;
(docids, dest_node.clone()) (docids, dest_node.clone())
} }
}; };

View File

@ -22,10 +22,8 @@ pub fn compute_docids(
(left_term, right_term, *cost) (left_term, right_term, *cost)
} }
ProximityCondition::Term { term } => { ProximityCondition::Term { term } => {
let mut docids = compute_query_term_subset_docids(ctx, &term.term_subset)?;
docids &= universe;
return Ok(ComputedCondition { return Ok(ComputedCondition {
docids, docids: compute_query_term_subset_docids(ctx, Some(universe), &term.term_subset)?,
universe_len: universe.len(), universe_len: universe.len(),
start_term_subset: None, start_term_subset: None,
end_term_subset: term.clone(), end_term_subset: term.clone(),

View File

@ -27,8 +27,7 @@ impl RankingRuleGraphTrait for TypoGraph {
) -> Result<ComputedCondition> { ) -> Result<ComputedCondition> {
let TypoCondition { term, .. } = condition; let TypoCondition { term, .. } = condition;
// maybe compute_query_term_subset_docids should accept a universe as argument // maybe compute_query_term_subset_docids should accept a universe as argument
let mut docids = compute_query_term_subset_docids(ctx, &term.term_subset)?; let docids = compute_query_term_subset_docids(ctx, Some(universe), &term.term_subset)?;
docids &= universe;
Ok(ComputedCondition { Ok(ComputedCondition {
docids, docids,

View File

@ -26,8 +26,7 @@ impl RankingRuleGraphTrait for WordsGraph {
) -> Result<ComputedCondition> { ) -> Result<ComputedCondition> {
let WordsCondition { term, .. } = condition; let WordsCondition { term, .. } = condition;
// maybe compute_query_term_subset_docids should accept a universe as argument // maybe compute_query_term_subset_docids should accept a universe as argument
let mut docids = compute_query_term_subset_docids(ctx, &term.term_subset)?; let docids = compute_query_term_subset_docids(ctx, Some(universe), &term.term_subset)?;
docids &= universe;
Ok(ComputedCondition { Ok(ComputedCondition {
docids, docids,

View File

@ -31,6 +31,7 @@ impl<'ctx> SearchContext<'ctx> {
} }
pub fn compute_query_term_subset_docids( pub fn compute_query_term_subset_docids(
ctx: &mut SearchContext<'_>, ctx: &mut SearchContext<'_>,
universe: Option<&RoaringBitmap>,
term: &QueryTermSubset, term: &QueryTermSubset,
) -> Result<RoaringBitmap> { ) -> Result<RoaringBitmap> {
let mut docids = RoaringBitmap::new(); let mut docids = RoaringBitmap::new();
@ -49,7 +50,10 @@ pub fn compute_query_term_subset_docids(
} }
} }
Ok(docids) match universe {
Some(universe) => Ok(docids & universe),
None => Ok(docids),
}
} }
pub fn compute_query_term_subset_docids_within_field_id( pub fn compute_query_term_subset_docids_within_field_id(
@ -147,10 +151,7 @@ pub fn compute_query_graph_docids(
term_subset, term_subset,
positions: _, positions: _,
term_ids: _, term_ids: _,
}) => { }) => compute_query_term_subset_docids(ctx, Some(&predecessors_docids), term_subset)?,
let node_docids = compute_query_term_subset_docids(ctx, term_subset)?;
predecessors_docids & node_docids
}
QueryNodeData::Deleted => { QueryNodeData::Deleted => {
panic!() panic!()
} }