472: Remove useless variables in proximity r=Kerollmops a=ManyTheFish

Was passing by plane sweep algorithm to find some inspiration, and I discover that we have useless variables that were not detected because of the recursive function.

Co-authored-by: ManyTheFish <many@meilisearch.com>
This commit is contained in:
bors[bot] 2022-03-16 15:33:11 +00:00 committed by GitHub
commit 90276d9a2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,7 +11,7 @@ use super::{
}; };
use crate::search::query_tree::{maximum_proximity, Operation, Query, QueryKind}; use crate::search::query_tree::{maximum_proximity, Operation, Query, QueryKind};
use crate::search::{build_dfa, WordDerivationsCache}; use crate::search::{build_dfa, WordDerivationsCache};
use crate::{DocumentId, Position, Result}; use crate::{Position, Result};
type Cache = HashMap<(Operation, u8), Vec<(Query, Query, RoaringBitmap)>>; type Cache = HashMap<(Operation, u8), Vec<(Query, Query, RoaringBitmap)>>;
@ -90,7 +90,6 @@ impl<'t> Criterion for Proximity<'t> {
self.ctx, self.ctx,
query_tree, query_tree,
allowed_candidates, allowed_candidates,
params.wdcache,
)?; )?;
self.plane_sweep_cache = Some(cache.into_iter()); self.plane_sweep_cache = Some(cache.into_iter());
@ -343,7 +342,6 @@ fn resolve_plane_sweep_candidates(
ctx: &dyn Context, ctx: &dyn Context,
query_tree: &Operation, query_tree: &Operation,
allowed_candidates: &RoaringBitmap, allowed_candidates: &RoaringBitmap,
wdcache: &mut WordDerivationsCache,
) -> Result<BTreeMap<u8, RoaringBitmap>> { ) -> Result<BTreeMap<u8, RoaringBitmap>> {
/// FIXME may be buggy with query like "new new york" /// FIXME may be buggy with query like "new new york"
fn plane_sweep( fn plane_sweep(
@ -467,12 +465,9 @@ fn resolve_plane_sweep_candidates(
} }
fn resolve_operation<'a>( fn resolve_operation<'a>(
ctx: &dyn Context,
query_tree: &'a Operation, query_tree: &'a Operation,
docid: DocumentId,
rocache: &mut HashMap<&'a Operation, Vec<(Position, u8, Position)>>, rocache: &mut HashMap<&'a Operation, Vec<(Position, u8, Position)>>,
words_positions: &HashMap<String, RoaringBitmap>, words_positions: &HashMap<String, RoaringBitmap>,
wdcache: &mut WordDerivationsCache,
) -> Result<Vec<(Position, u8, Position)>> { ) -> Result<Vec<(Position, u8, Position)>> {
use Operation::{And, Or, Phrase}; use Operation::{And, Or, Phrase};
@ -484,14 +479,7 @@ fn resolve_plane_sweep_candidates(
And(ops) => { And(ops) => {
let mut groups_positions = Vec::with_capacity(ops.len()); let mut groups_positions = Vec::with_capacity(ops.len());
for operation in ops { for operation in ops {
let positions = resolve_operation( let positions = resolve_operation(operation, rocache, words_positions)?;
ctx,
operation,
docid,
rocache,
words_positions,
wdcache,
)?;
groups_positions.push(positions); groups_positions.push(positions);
} }
plane_sweep(groups_positions, false)? plane_sweep(groups_positions, false)?
@ -501,7 +489,7 @@ fn resolve_plane_sweep_candidates(
for word in words { for word in words {
let positions = match words_positions.get(word) { let positions = match words_positions.get(word) {
Some(positions) => positions.iter().map(|p| (p, 0, p)).collect(), Some(positions) => positions.iter().map(|p| (p, 0, p)).collect(),
None => vec![], None => return Ok(vec![]),
}; };
groups_positions.push(positions); groups_positions.push(positions);
} }
@ -510,14 +498,7 @@ fn resolve_plane_sweep_candidates(
Or(_, ops) => { Or(_, ops) => {
let mut result = Vec::new(); let mut result = Vec::new();
for op in ops { for op in ops {
result.extend(resolve_operation( result.extend(resolve_operation(op, rocache, words_positions)?)
ctx,
op,
docid,
rocache,
words_positions,
wdcache,
)?)
} }
result.sort_unstable(); result.sort_unstable();
@ -572,14 +553,8 @@ fn resolve_plane_sweep_candidates(
for docid in allowed_candidates { for docid in allowed_candidates {
let words_positions = ctx.docid_words_positions(docid)?; let words_positions = ctx.docid_words_positions(docid)?;
resolve_operation_cache.clear(); resolve_operation_cache.clear();
let positions = resolve_operation( let positions =
ctx, resolve_operation(query_tree, &mut resolve_operation_cache, &words_positions)?;
query_tree,
docid,
&mut resolve_operation_cache,
&words_positions,
wdcache,
)?;
let best_proximity = positions.into_iter().min_by_key(|(_, proximity, _)| *proximity); let best_proximity = positions.into_iter().min_by_key(|(_, proximity, _)| *proximity);
let best_proximity = best_proximity.map(|(_, proximity, _)| proximity).unwrap_or(7); let best_proximity = best_proximity.map(|(_, proximity, _)| proximity).unwrap_or(7);
candidates.entry(best_proximity).or_insert_with(RoaringBitmap::new).insert(docid); candidates.entry(best_proximity).or_insert_with(RoaringBitmap::new).insert(docid);