Make milli use edition 2021 (#4770)

* Make milli use edition 2021

* Add lifetime annotations to milli.

* Run cargo fmt
This commit is contained in:
hanbings
2024-07-09 11:25:39 -04:00
committed by GitHub
parent aac15f6719
commit 0a40a98bb6
73 changed files with 406 additions and 347 deletions

View File

@ -47,7 +47,7 @@ pub struct FacetDistribution<'a> {
}
impl<'a> FacetDistribution<'a> {
pub fn new(rtxn: &'a heed::RoTxn, index: &'a Index) -> FacetDistribution<'a> {
pub fn new(rtxn: &'a heed::RoTxn<'a>, index: &'a Index) -> FacetDistribution<'a> {
FacetDistribution {
facets: None,
candidates: None,
@ -374,7 +374,7 @@ impl<'a> FacetDistribution<'a> {
}
impl fmt::Debug for FacetDistribution<'_> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let FacetDistribution {
facets,
candidates,

View File

@ -221,14 +221,14 @@ impl<'a> Filter<'a> {
}
impl<'a> Filter<'a> {
pub fn evaluate(&self, rtxn: &heed::RoTxn, index: &Index) -> Result<RoaringBitmap> {
pub fn evaluate(&self, rtxn: &heed::RoTxn<'_>, index: &Index) -> Result<RoaringBitmap> {
// to avoid doing this for each recursive call we're going to do it ONCE ahead of time
let filterable_fields = index.filterable_fields(rtxn)?;
self.inner_evaluate(rtxn, index, &filterable_fields, None)
}
fn evaluate_operator(
rtxn: &heed::RoTxn,
rtxn: &heed::RoTxn<'_>,
index: &Index,
field_id: FieldId,
universe: Option<&RoaringBitmap>,
@ -313,7 +313,7 @@ impl<'a> Filter<'a> {
/// Aggregates the documents ids that are part of the specified range automatically
/// going deeper through the levels.
fn explore_facet_number_levels(
rtxn: &heed::RoTxn,
rtxn: &heed::RoTxn<'_>,
db: heed::Database<FacetGroupKeyCodec<OrderedF64Codec>, FacetGroupValueCodec>,
field_id: FieldId,
left: Bound<f64>,
@ -338,7 +338,7 @@ impl<'a> Filter<'a> {
fn inner_evaluate(
&self,
rtxn: &heed::RoTxn,
rtxn: &heed::RoTxn<'_>,
index: &Index,
filterable_fields: &HashSet<String>,
universe: Option<&RoaringBitmap>,

View File

@ -33,7 +33,7 @@ fn facet_extreme_value<'t>(
pub fn facet_min_value<'t>(
index: &'t Index,
rtxn: &'t heed::RoTxn,
rtxn: &'t heed::RoTxn<'t>,
field_id: u16,
candidates: RoaringBitmap,
) -> Result<Option<f64>> {
@ -44,7 +44,7 @@ pub fn facet_min_value<'t>(
pub fn facet_max_value<'t>(
index: &'t Index,
rtxn: &'t heed::RoTxn,
rtxn: &'t heed::RoTxn<'t>,
field_id: u16,
candidates: RoaringBitmap,
) -> Result<Option<f64>> {
@ -55,7 +55,7 @@ pub fn facet_max_value<'t>(
/// Get the first facet value in the facet database
pub(crate) fn get_first_facet_value<'t, BoundCodec, DC>(
txn: &'t RoTxn,
txn: &'t RoTxn<'t>,
db: heed::Database<FacetGroupKeyCodec<BytesRefCodec>, DC>,
field_id: u16,
) -> heed::Result<Option<BoundCodec::DItem>>
@ -79,7 +79,7 @@ where
/// Get the last facet value in the facet database
pub(crate) fn get_last_facet_value<'t, BoundCodec, DC>(
txn: &'t RoTxn,
txn: &'t RoTxn<'t>,
db: heed::Database<FacetGroupKeyCodec<BytesRefCodec>, DC>,
field_id: u16,
) -> heed::Result<Option<BoundCodec::DItem>>

View File

@ -55,7 +55,7 @@ pub struct Search<'a> {
}
impl<'a> Search<'a> {
pub fn new(rtxn: &'a heed::RoTxn, index: &'a Index) -> Search<'a> {
pub fn new(rtxn: &'a heed::RoTxn<'a>, index: &'a Index) -> Search<'a> {
Search {
query: None,
filter: None,
@ -253,7 +253,7 @@ impl<'a> Search<'a> {
}
impl fmt::Debug for Search<'_> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let Search {
query,
filter,

View File

@ -47,7 +47,7 @@ pub struct DatabaseCache<'ctx> {
}
impl<'ctx> DatabaseCache<'ctx> {
fn get_value<'v, K1, KC, DC>(
txn: &'ctx RoTxn,
txn: &'ctx RoTxn<'_>,
cache_key: K1,
db_key: &'v KC::EItem,
cache: &mut FxHashMap<K1, Option<Cow<'ctx, [u8]>>>,
@ -77,7 +77,7 @@ impl<'ctx> DatabaseCache<'ctx> {
}
fn get_value_from_keys<'v, K1, KC, DC>(
txn: &'ctx RoTxn,
txn: &'ctx RoTxn<'_>,
cache_key: K1,
db_keys: &'v [KC::EItem],
cache: &mut FxHashMap<K1, Option<Cow<'ctx, [u8]>>>,
@ -99,7 +99,7 @@ impl<'ctx> DatabaseCache<'ctx> {
.iter()
.filter_map(|key| db.get(txn, key).transpose())
.map(|v| v.map(Cow::Borrowed))
.collect::<std::result::Result<Vec<Cow<[u8]>>, _>>()?;
.collect::<std::result::Result<Vec<Cow<'_, [u8]>>, _>>()?;
if bitmaps.is_empty() {
None

View File

@ -23,7 +23,7 @@ pub struct DistinctOutput {
/// - `excluded`: the set of document ids that contain a value for the given field that occurs
/// in the given candidates.
pub fn apply_distinct_rule(
ctx: &mut SearchContext,
ctx: &mut SearchContext<'_>,
field_id: u16,
candidates: &RoaringBitmap,
) -> Result<DistinctOutput> {
@ -42,7 +42,7 @@ pub fn apply_distinct_rule(
/// Apply the distinct rule defined by [`apply_distinct_rule`] for a single document id.
pub fn distinct_single_docid(
index: &Index,
txn: &RoTxn,
txn: &RoTxn<'_>,
field_id: u16,
docid: u32,
excluded: &mut RoaringBitmap,
@ -72,7 +72,7 @@ pub fn distinct_single_docid(
/// Return all the docids containing the given value in the given field
fn facet_value_docids(
database: Database<FacetGroupKeyCodec<BytesRefCodec>, FacetGroupValueCodec>,
txn: &RoTxn,
txn: &RoTxn<'_>,
field_id: u16,
facet_value: &[u8],
) -> heed::Result<Option<RoaringBitmap>> {
@ -86,7 +86,7 @@ fn facet_number_values<'a>(
docid: u32,
field_id: u16,
index: &Index,
txn: &'a RoTxn,
txn: &'a RoTxn<'a>,
) -> Result<RoPrefix<'a, FieldDocIdFacetCodec<BytesRefCodec>, Unit>> {
let key = facet_values_prefix_key(field_id, docid);
@ -104,7 +104,7 @@ pub fn facet_string_values<'a>(
docid: u32,
field_id: u16,
index: &Index,
txn: &'a RoTxn,
txn: &'a RoTxn<'a>,
) -> Result<RoPrefix<'a, FieldDocIdFacetCodec<BytesRefCodec>, Str>> {
let key = facet_values_prefix_key(field_id, docid);

View File

@ -28,7 +28,7 @@ fn facet_number_values<'a>(
docid: u32,
field_id: u16,
index: &Index,
txn: &'a RoTxn,
txn: &'a RoTxn<'a>,
) -> Result<RoPrefix<'a, FieldDocIdFacetCodec<OrderedF64Codec>, Unit>> {
let key = facet_values_prefix_key(field_id, docid);
@ -109,7 +109,7 @@ impl<Q: RankingRuleQueryTrait> GeoSort<Q> {
/// Drop the rtree if we don't need it anymore.
fn fill_buffer(
&mut self,
ctx: &mut SearchContext,
ctx: &mut SearchContext<'_>,
geo_candidates: &RoaringBitmap,
) -> Result<()> {
debug_assert!(self.field_ids.is_some(), "fill_buffer can't be called without the lat&lng");
@ -182,7 +182,7 @@ fn geo_value(
field_lat: u16,
field_lng: u16,
index: &Index,
rtxn: &RoTxn,
rtxn: &RoTxn<'_>,
) -> Result<[f64; 2]> {
let extract_geo = |geo_field: u16| -> Result<f64> {
match facet_number_values(docid, geo_field, index, rtxn)?.next() {

View File

@ -375,7 +375,7 @@ impl<'ctx, G: RankingRuleGraphTrait> RankingRule<'ctx, QueryGraph> for GraphBase
/// docids and the previous path docids is empty.
#[allow(clippy::too_many_arguments)]
fn visit_path_condition<G: RankingRuleGraphTrait>(
ctx: &mut SearchContext,
ctx: &mut SearchContext<'_>,
graph: &mut RankingRuleGraph<G>,
universe: &RoaringBitmap,
dead_ends_cache: &mut DeadEndsCache<G::Condition>,

View File

@ -20,13 +20,13 @@ pub trait SearchLogger<Q: RankingRuleQueryTrait> {
fn query_for_initial_universe(&mut self, _query: &Q);
/// Logs the ranking rules used to perform the search query
fn ranking_rules(&mut self, _rr: &[BoxRankingRule<Q>]);
fn ranking_rules(&mut self, _rr: &[BoxRankingRule<'_, Q>]);
/// Logs the start of a ranking rule's iteration.
fn start_iteration_ranking_rule(
&mut self,
_ranking_rule_idx: usize,
_ranking_rule: &dyn RankingRule<Q>,
_ranking_rule: &dyn RankingRule<'_, Q>,
_query: &Q,
_universe: &RoaringBitmap,
) {
@ -35,7 +35,7 @@ pub trait SearchLogger<Q: RankingRuleQueryTrait> {
fn next_bucket_ranking_rule(
&mut self,
_ranking_rule_idx: usize,
_ranking_rule: &dyn RankingRule<Q>,
_ranking_rule: &dyn RankingRule<'_, Q>,
_universe: &RoaringBitmap,
_candidates: &RoaringBitmap,
) {
@ -44,7 +44,7 @@ pub trait SearchLogger<Q: RankingRuleQueryTrait> {
fn skip_bucket_ranking_rule(
&mut self,
_ranking_rule_idx: usize,
_ranking_rule: &dyn RankingRule<Q>,
_ranking_rule: &dyn RankingRule<'_, Q>,
_candidates: &RoaringBitmap,
) {
}
@ -52,7 +52,7 @@ pub trait SearchLogger<Q: RankingRuleQueryTrait> {
fn end_iteration_ranking_rule(
&mut self,
_ranking_rule_idx: usize,
_ranking_rule: &dyn RankingRule<Q>,
_ranking_rule: &dyn RankingRule<'_, Q>,
_universe: &RoaringBitmap,
) {
}
@ -73,7 +73,7 @@ impl<Q: RankingRuleQueryTrait> SearchLogger<Q> for DefaultSearchLogger {
fn query_for_initial_universe(&mut self, _query: &Q) {}
fn ranking_rules(&mut self, _rr: &[BoxRankingRule<Q>]) {}
fn ranking_rules(&mut self, _rr: &[BoxRankingRule<'_, Q>]) {}
fn add_to_results(&mut self, _docids: &[u32]) {}

View File

@ -69,14 +69,14 @@ impl SearchLogger<QueryGraph> for VisualSearchLogger {
fn initial_universe(&mut self, universe: &RoaringBitmap) {
self.initial_universe = Some(universe.clone());
}
fn ranking_rules(&mut self, rr: &[BoxRankingRule<QueryGraph>]) {
fn ranking_rules(&mut self, rr: &[BoxRankingRule<'_, QueryGraph>]) {
self.ranking_rules_ids = Some(rr.iter().map(|rr| rr.id()).collect());
}
fn start_iteration_ranking_rule(
&mut self,
ranking_rule_idx: usize,
ranking_rule: &dyn RankingRule<QueryGraph>,
ranking_rule: &dyn RankingRule<'_, QueryGraph>,
_query: &QueryGraph,
universe: &RoaringBitmap,
) {
@ -97,7 +97,7 @@ impl SearchLogger<QueryGraph> for VisualSearchLogger {
fn next_bucket_ranking_rule(
&mut self,
ranking_rule_idx: usize,
_ranking_rule: &dyn RankingRule<QueryGraph>,
_ranking_rule: &dyn RankingRule<'_, QueryGraph>,
universe: &RoaringBitmap,
bucket: &RoaringBitmap,
) {
@ -110,7 +110,7 @@ impl SearchLogger<QueryGraph> for VisualSearchLogger {
fn skip_bucket_ranking_rule(
&mut self,
ranking_rule_idx: usize,
_ranking_rule: &dyn RankingRule<QueryGraph>,
_ranking_rule: &dyn RankingRule<'_, QueryGraph>,
bucket: &RoaringBitmap,
) {
self.events.push(SearchEvents::RankingRuleSkipBucket {
@ -122,7 +122,7 @@ impl SearchLogger<QueryGraph> for VisualSearchLogger {
fn end_iteration_ranking_rule(
&mut self,
ranking_rule_idx: usize,
_ranking_rule: &dyn RankingRule<QueryGraph>,
_ranking_rule: &dyn RankingRule<'_, QueryGraph>,
_universe: &RoaringBitmap,
) {
self.events.push(SearchEvents::RankingRuleEndIteration { ranking_rule_idx });

View File

@ -32,7 +32,7 @@ pub struct MatchingWords {
}
impl MatchingWords {
pub fn new(ctx: SearchContext, located_terms: Vec<LocatedQueryTerm>) -> Self {
pub fn new(ctx: SearchContext<'_>, located_terms: Vec<LocatedQueryTerm>) -> Self {
let mut phrases = Vec::new();
let mut words = Vec::new();
@ -74,7 +74,7 @@ impl MatchingWords {
}
/// Try to match the token with one of the located_words.
fn match_unique_words<'a>(&'a self, token: &Token) -> Option<MatchType<'a>> {
fn match_unique_words<'a>(&'a self, token: &Token<'_>) -> Option<MatchType<'a>> {
for located_words in &self.words {
for word in &located_words.value {
let word = self.word_interner.get(*word);
@ -166,7 +166,7 @@ impl<'a> PartialMatch<'a> {
/// - None if the given token breaks the partial match
/// - Partial if the given token matches the partial match but doesn't complete it
/// - Full if the given token completes the partial match
pub fn match_token(self, token: &Token) -> Option<MatchType<'a>> {
pub fn match_token(self, token: &Token<'_>) -> Option<MatchType<'a>> {
let Self { mut matching_words, ids, .. } = self;
let is_matching = match matching_words.first()? {
@ -198,7 +198,7 @@ impl<'a> PartialMatch<'a> {
}
impl fmt::Debug for MatchingWords {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let MatchingWords { word_interner, phrase_interner, phrases, words } = self;
let phrases: Vec<_> = phrases

View File

@ -123,7 +123,7 @@ impl<'t> Matcher<'t, '_> {
/// some words are counted as matches only if they are close together and in the good order,
/// compute_partial_match peek into next words to validate if the match is complete.
fn compute_partial_match<'a>(
mut partial: PartialMatch,
mut partial: PartialMatch<'a>,
token_position: usize,
word_position: usize,
words_positions: &mut impl Iterator<Item = (usize, usize, &'a Token<'a>)>,
@ -244,7 +244,12 @@ impl<'t> Matcher<'t, '_> {
}
/// Returns the bounds in byte index of the crop window.
fn crop_bounds(&self, tokens: &[Token], matches: &[Match], crop_size: usize) -> (usize, usize) {
fn crop_bounds(
&self,
tokens: &[Token<'_>],
matches: &[Match],
crop_size: usize,
) -> (usize, usize) {
// if there is no match, we start from the beginning of the string by default.
let first_match_word_position = matches.first().map(|m| m.word_position).unwrap_or(0);
let first_match_token_position = matches.first().map(|m| m.token_position).unwrap_or(0);
@ -505,7 +510,7 @@ mod tests {
use crate::{execute_search, filtered_universe, SearchContext, TimeBudget};
impl<'a> MatcherBuilder<'a> {
fn new_test(rtxn: &'a heed::RoTxn, index: &'a TempIndex, query: &str) -> Self {
fn new_test(rtxn: &'a heed::RoTxn<'a>, index: &'a TempIndex, query: &str) -> Self {
let mut ctx = SearchContext::new(index, rtxn).unwrap();
let universe = filtered_universe(ctx.index, ctx.txn, &None).unwrap();
let crate::search::PartialSearchResult { located_query_terms, .. } = execute_search(

View File

@ -183,7 +183,7 @@ impl RestrictedFids {
/// Apply the [`TermsMatchingStrategy`] to the query graph and resolve it.
fn resolve_maximally_reduced_query_graph(
ctx: &mut SearchContext,
ctx: &mut SearchContext<'_>,
universe: &RoaringBitmap,
query_graph: &QueryGraph,
matching_strategy: TermsMatchingStrategy,
@ -214,7 +214,7 @@ fn resolve_maximally_reduced_query_graph(
#[tracing::instrument(level = "trace", skip_all, target = "search::universe")]
fn resolve_universe(
ctx: &mut SearchContext,
ctx: &mut SearchContext<'_>,
initial_universe: &RoaringBitmap,
query_graph: &QueryGraph,
matching_strategy: TermsMatchingStrategy,
@ -231,7 +231,7 @@ fn resolve_universe(
#[tracing::instrument(level = "trace", skip_all, target = "search::query")]
fn resolve_negative_words(
ctx: &mut SearchContext,
ctx: &mut SearchContext<'_>,
negative_words: &[Word],
) -> Result<RoaringBitmap> {
let mut negative_bitmap = RoaringBitmap::new();
@ -245,7 +245,7 @@ fn resolve_negative_words(
#[tracing::instrument(level = "trace", skip_all, target = "search::query")]
fn resolve_negative_phrases(
ctx: &mut SearchContext,
ctx: &mut SearchContext<'_>,
negative_phrases: &[LocatedQueryTerm],
) -> Result<RoaringBitmap> {
let mut negative_bitmap = RoaringBitmap::new();
@ -267,7 +267,7 @@ fn get_ranking_rules_for_placeholder_search<'ctx>(
let mut sort = false;
let mut sorted_fields = HashSet::new();
let mut geo_sorted = false;
let mut ranking_rules: Vec<BoxRankingRule<PlaceholderQuery>> = vec![];
let mut ranking_rules: Vec<BoxRankingRule<'ctx, PlaceholderQuery>> = vec![];
let settings_ranking_rules = ctx.index.criteria(ctx.txn)?;
for rr in settings_ranking_rules {
match rr {
@ -326,7 +326,7 @@ fn get_ranking_rules_for_vector<'ctx>(
let mut geo_sorted = false;
let mut vector = false;
let mut ranking_rules: Vec<BoxRankingRule<PlaceholderQuery>> = vec![];
let mut ranking_rules: Vec<BoxRankingRule<'ctx, PlaceholderQuery>> = vec![];
let settings_ranking_rules = ctx.index.criteria(ctx.txn)?;
for rr in settings_ranking_rules {
@ -406,7 +406,7 @@ fn get_ranking_rules_for_query_graph_search<'ctx>(
words = true;
}
let mut ranking_rules: Vec<BoxRankingRule<QueryGraph>> = vec![];
let mut ranking_rules: Vec<BoxRankingRule<'ctx, QueryGraph>> = vec![];
let settings_ranking_rules = ctx.index.criteria(ctx.txn)?;
for rr in settings_ranking_rules {
// Add Words before any of: typo, proximity, attribute
@ -552,7 +552,7 @@ fn resolve_sort_criteria<'ctx, Query: RankingRuleQueryTrait>(
pub fn filtered_universe(
index: &Index,
txn: &RoTxn<'_>,
filters: &Option<Filter>,
filters: &Option<Filter<'_>>,
) -> Result<RoaringBitmap> {
Ok(if let Some(filters) = filters {
filters.evaluate(txn, index)?
@ -563,7 +563,7 @@ pub fn filtered_universe(
#[allow(clippy::too_many_arguments)]
pub fn execute_vector_search(
ctx: &mut SearchContext,
ctx: &mut SearchContext<'_>,
vector: &[f32],
scoring_strategy: ScoringStrategy,
universe: RoaringBitmap,
@ -622,7 +622,7 @@ pub fn execute_vector_search(
#[allow(clippy::too_many_arguments)]
#[tracing::instrument(level = "trace", skip_all, target = "search::main")]
pub fn execute_search(
ctx: &mut SearchContext,
ctx: &mut SearchContext<'_>,
query: Option<&str>,
terms_matching_strategy: TermsMatchingStrategy,
scoring_strategy: ScoringStrategy,
@ -775,7 +775,10 @@ pub fn execute_search(
})
}
fn check_sort_criteria(ctx: &SearchContext, sort_criteria: Option<&Vec<AscDesc>>) -> Result<()> {
fn check_sort_criteria(
ctx: &SearchContext<'_>,
sort_criteria: Option<&Vec<AscDesc>>,
) -> Result<()> {
let sort_criteria = if let Some(sort_criteria) = sort_criteria {
sort_criteria
} else {

View File

@ -93,7 +93,7 @@ impl QueryGraph {
/// Build the query graph from the parsed user search query, return an updated list of the located query terms
/// which contains ngrams.
pub fn from_query(
ctx: &mut SearchContext,
ctx: &mut SearchContext<'_>,
// The terms here must be consecutive
terms: &[LocatedQueryTerm],
) -> Result<(QueryGraph, Vec<LocatedQueryTerm>)> {
@ -294,7 +294,7 @@ impl QueryGraph {
pub fn removal_order_for_terms_matching_strategy_frequency(
&self,
ctx: &mut SearchContext,
ctx: &mut SearchContext<'_>,
) -> Result<Vec<SmallBitmap<QueryNode>>> {
// lookup frequency for each term
let mut term_with_frequency: Vec<(u8, u64)> = {
@ -337,7 +337,7 @@ impl QueryGraph {
pub fn removal_order_for_terms_matching_strategy_last(
&self,
ctx: &SearchContext,
ctx: &SearchContext<'_>,
) -> Vec<SmallBitmap<QueryNode>> {
let (first_term_idx, last_term_idx) = {
let mut first_term_idx = u8::MAX;
@ -370,7 +370,7 @@ impl QueryGraph {
pub fn removal_order_for_terms_matching_strategy(
&self,
ctx: &SearchContext,
ctx: &SearchContext<'_>,
order: impl Fn(u8) -> u16,
) -> Vec<SmallBitmap<QueryNode>> {
let mut nodes_to_remove = BTreeMap::<u16, SmallBitmap<QueryNode>>::new();
@ -398,7 +398,7 @@ impl QueryGraph {
}
/// Number of words in the phrases in this query graph
pub(crate) fn words_in_phrases_count(&self, ctx: &SearchContext) -> usize {
pub(crate) fn words_in_phrases_count(&self, ctx: &SearchContext<'_>) -> usize {
let mut word_count = 0;
for (_, node) in self.nodes.iter() {
match &node.data {

View File

@ -27,7 +27,7 @@ pub enum ZeroOrOneTypo {
}
impl Interned<QueryTerm> {
pub fn compute_fully_if_needed(self, ctx: &mut SearchContext) -> Result<()> {
pub fn compute_fully_if_needed(self, ctx: &mut SearchContext<'_>) -> Result<()> {
let s = ctx.term_interner.get_mut(self);
if s.max_levenshtein_distance <= 1 && s.one_typo.is_uninit() {
assert!(s.two_typo.is_uninit());
@ -48,7 +48,7 @@ impl Interned<QueryTerm> {
fn find_zero_typo_prefix_derivations(
word_interned: Interned<String>,
fst: fst::Set<Cow<[u8]>>,
fst: fst::Set<Cow<'_, [u8]>>,
word_interner: &mut DedupInterner<String>,
mut visit: impl FnMut(Interned<String>) -> Result<ControlFlow<()>>,
) -> Result<()> {
@ -71,7 +71,7 @@ fn find_zero_typo_prefix_derivations(
}
fn find_zero_one_typo_derivations(
ctx: &mut SearchContext,
ctx: &mut SearchContext<'_>,
word_interned: Interned<String>,
is_prefix: bool,
mut visit: impl FnMut(Interned<String>, ZeroOrOneTypo) -> Result<ControlFlow<()>>,
@ -114,7 +114,7 @@ fn find_zero_one_typo_derivations(
fn find_zero_one_two_typo_derivations(
word_interned: Interned<String>,
is_prefix: bool,
fst: fst::Set<Cow<[u8]>>,
fst: fst::Set<Cow<'_, [u8]>>,
word_interner: &mut DedupInterner<String>,
mut visit: impl FnMut(Interned<String>, NumberOfTypos) -> Result<ControlFlow<()>>,
) -> Result<()> {
@ -172,7 +172,7 @@ fn find_zero_one_two_typo_derivations(
}
pub fn partially_initialized_term_from_word(
ctx: &mut SearchContext,
ctx: &mut SearchContext<'_>,
word: &str,
max_typo: u8,
is_prefix: bool,
@ -265,7 +265,7 @@ pub fn partially_initialized_term_from_word(
})
}
fn find_split_words(ctx: &mut SearchContext, word: &str) -> Result<Option<Interned<Phrase>>> {
fn find_split_words(ctx: &mut SearchContext<'_>, word: &str) -> Result<Option<Interned<Phrase>>> {
if let Some((l, r)) = split_best_frequency(ctx, word)? {
Ok(Some(ctx.phrase_interner.insert(Phrase { words: vec![Some(l), Some(r)] })))
} else {
@ -274,7 +274,7 @@ fn find_split_words(ctx: &mut SearchContext, word: &str) -> Result<Option<Intern
}
impl Interned<QueryTerm> {
fn initialize_one_typo_subterm(self, ctx: &mut SearchContext) -> Result<()> {
fn initialize_one_typo_subterm(self, ctx: &mut SearchContext<'_>) -> Result<()> {
let self_mut = ctx.term_interner.get_mut(self);
let allows_split_words = self_mut.allows_split_words();
@ -340,7 +340,7 @@ impl Interned<QueryTerm> {
Ok(())
}
fn initialize_one_and_two_typo_subterm(self, ctx: &mut SearchContext) -> Result<()> {
fn initialize_one_and_two_typo_subterm(self, ctx: &mut SearchContext<'_>) -> Result<()> {
let self_mut = ctx.term_interner.get_mut(self);
let QueryTerm {
original,
@ -406,7 +406,7 @@ impl Interned<QueryTerm> {
///
/// Return `None` if the original word cannot be split.
fn split_best_frequency(
ctx: &mut SearchContext,
ctx: &mut SearchContext<'_>,
original: &str,
) -> Result<Option<(Interned<String>, Interned<String>)>> {
let chars = original.char_indices().skip(1);

View File

@ -128,7 +128,7 @@ impl QueryTermSubset {
pub fn make_mandatory(&mut self) {
self.mandatory = true;
}
pub fn exact_term(&self, ctx: &SearchContext) -> Option<ExactTerm> {
pub fn exact_term(&self, ctx: &SearchContext<'_>) -> Option<ExactTerm> {
let full_query_term = ctx.term_interner.get(self.original);
if full_query_term.ngram_words.is_some() {
return None;
@ -174,7 +174,7 @@ impl QueryTermSubset {
self.two_typo_subset.intersect(&other.two_typo_subset);
}
pub fn use_prefix_db(&self, ctx: &SearchContext) -> Option<Word> {
pub fn use_prefix_db(&self, ctx: &SearchContext<'_>) -> Option<Word> {
let original = ctx.term_interner.get(self.original);
let use_prefix_db = original.zero_typo.use_prefix_db?;
let word = match &self.zero_typo_subset {
@ -198,7 +198,7 @@ impl QueryTermSubset {
}
pub fn all_single_words_except_prefix_db(
&self,
ctx: &mut SearchContext,
ctx: &mut SearchContext<'_>,
) -> Result<BTreeSet<Word>> {
let mut result = BTreeSet::default();
if !self.one_typo_subset.is_empty() || !self.two_typo_subset.is_empty() {
@ -290,7 +290,7 @@ impl QueryTermSubset {
Ok(result)
}
pub fn all_phrases(&self, ctx: &mut SearchContext) -> Result<BTreeSet<Interned<Phrase>>> {
pub fn all_phrases(&self, ctx: &mut SearchContext<'_>) -> Result<BTreeSet<Interned<Phrase>>> {
let mut result = BTreeSet::default();
if !self.one_typo_subset.is_empty() {
@ -328,7 +328,7 @@ impl QueryTermSubset {
Ok(result)
}
pub fn original_phrase(&self, ctx: &SearchContext) -> Option<Interned<Phrase>> {
pub fn original_phrase(&self, ctx: &SearchContext<'_>) -> Option<Interned<Phrase>> {
let t = ctx.term_interner.get(self.original);
if let Some(p) = t.zero_typo.phrase {
if self.zero_typo_subset.contains_phrase(p) {
@ -337,7 +337,7 @@ impl QueryTermSubset {
}
None
}
pub fn max_typo_cost(&self, ctx: &SearchContext) -> u8 {
pub fn max_typo_cost(&self, ctx: &SearchContext<'_>) -> u8 {
let t = ctx.term_interner.get(self.original);
match t.max_levenshtein_distance {
0 => {
@ -368,7 +368,7 @@ impl QueryTermSubset {
_ => panic!(),
}
}
pub fn keep_only_exact_term(&mut self, ctx: &SearchContext) {
pub fn keep_only_exact_term(&mut self, ctx: &SearchContext<'_>) {
if let Some(term) = self.exact_term(ctx) {
match term {
ExactTerm::Phrase(p) => {
@ -399,7 +399,7 @@ impl QueryTermSubset {
pub fn clear_two_typo_subset(&mut self) {
self.two_typo_subset = NTypoTermSubset::Nothing;
}
pub fn description(&self, ctx: &SearchContext) -> String {
pub fn description(&self, ctx: &SearchContext<'_>) -> String {
let t = ctx.term_interner.get(self.original);
ctx.word_interner.get(t.original).to_owned()
}
@ -446,7 +446,7 @@ impl QueryTerm {
impl Interned<QueryTerm> {
/// Return the original word from the given query term
fn original_single_word(self, ctx: &SearchContext) -> Option<Interned<String>> {
fn original_single_word(self, ctx: &SearchContext<'_>) -> Option<Interned<String>> {
let self_ = ctx.term_interner.get(self);
if self_.ngram_words.is_some() {
None
@ -477,7 +477,7 @@ impl QueryTerm {
pub fn is_prefix(&self) -> bool {
self.is_prefix
}
pub fn original_word(&self, ctx: &SearchContext) -> String {
pub fn original_word(&self, ctx: &SearchContext<'_>) -> String {
ctx.word_interner.get(self.original).clone()
}

View File

@ -23,8 +23,8 @@ pub struct ExtractedTokens {
/// Convert the tokenised search query into a list of located query terms.
#[tracing::instrument(level = "trace", skip_all, target = "search::query")]
pub fn located_query_terms_from_tokens(
ctx: &mut SearchContext,
query: NormalizedTokenIter,
ctx: &mut SearchContext<'_>,
query: NormalizedTokenIter<'_, '_>,
words_limit: Option<usize>,
) -> Result<ExtractedTokens> {
let nbr_typos = number_of_typos_allowed(ctx)?;
@ -214,7 +214,7 @@ pub fn number_of_typos_allowed<'ctx>(
}
pub fn make_ngram(
ctx: &mut SearchContext,
ctx: &mut SearchContext<'_>,
terms: &[LocatedQueryTerm],
number_of_typos_allowed: &impl Fn(&str) -> u8,
) -> Result<Option<LocatedQueryTerm>> {
@ -297,7 +297,12 @@ impl PhraseBuilder {
}
// precondition: token has kind Word or StopWord
fn push_word(&mut self, ctx: &mut SearchContext, token: &charabia::Token, position: u16) {
fn push_word(
&mut self,
ctx: &mut SearchContext<'_>,
token: &charabia::Token<'_>,
position: u16,
) {
if self.is_empty() {
self.start = position;
}
@ -311,7 +316,7 @@ impl PhraseBuilder {
}
}
fn build(self, ctx: &mut SearchContext) -> Option<LocatedQueryTerm> {
fn build(self, ctx: &mut SearchContext<'_>) -> Option<LocatedQueryTerm> {
if self.is_empty() {
return None;
}

View File

@ -10,11 +10,11 @@ pub struct Phrase {
pub words: Vec<Option<Interned<String>>>,
}
impl Interned<Phrase> {
pub fn description(self, ctx: &SearchContext) -> String {
pub fn description(self, ctx: &SearchContext<'_>) -> String {
let p = ctx.phrase_interner.get(self);
p.words.iter().flatten().map(|w| ctx.word_interner.get(*w)).join(" ")
}
pub fn words(self, ctx: &SearchContext) -> Vec<Option<Interned<String>>> {
pub fn words(self, ctx: &SearchContext<'_>) -> Vec<Option<Interned<String>>> {
let p = ctx.phrase_interner.get(self);
p.words.clone()
}

View File

@ -10,7 +10,7 @@ use crate::Result;
impl<G: RankingRuleGraphTrait> RankingRuleGraph<G> {
/// Build the ranking rule graph from the given query graph
pub fn build(
ctx: &mut SearchContext,
ctx: &mut SearchContext<'_>,
query_graph: QueryGraph,
cost_of_ignoring_node: MappedInterner<QueryNode, Option<(u32, SmallBitmap<QueryNode>)>>,
) -> Result<Self> {

View File

@ -117,7 +117,7 @@ impl<'a, G: RankingRuleGraphTrait> PathVisitor<'a, G> {
}
/// See module documentation
pub fn visit_paths(mut self, visit: VisitFn<G>) -> Result<()> {
pub fn visit_paths(mut self, visit: VisitFn<'_, G>) -> Result<()> {
let _ =
self.state.visit_node(self.ctx.graph.query_graph.root_node, visit, &mut self.ctx)?;
Ok(())
@ -132,8 +132,8 @@ impl<G: RankingRuleGraphTrait> VisitorState<G> {
fn visit_node(
&mut self,
from_node: Interned<QueryNode>,
visit: VisitFn<G>,
ctx: &mut VisitorContext<G>,
visit: VisitFn<'_, G>,
ctx: &mut VisitorContext<'_, G>,
) -> Result<ControlFlow<(), bool>> {
// any valid path will be found from this point
// if a valid path was found, then we know that the DeadEndsCache may have been updated,
@ -189,8 +189,8 @@ impl<G: RankingRuleGraphTrait> VisitorState<G> {
&mut self,
dest_node: Interned<QueryNode>,
edge_new_nodes_to_skip: &SmallBitmap<QueryNode>,
visit: VisitFn<G>,
ctx: &mut VisitorContext<G>,
visit: VisitFn<'_, G>,
ctx: &mut VisitorContext<'_, G>,
) -> Result<ControlFlow<(), bool>> {
if !ctx
.all_costs_from_node
@ -228,8 +228,8 @@ impl<G: RankingRuleGraphTrait> VisitorState<G> {
condition: Interned<G::Condition>,
dest_node: Interned<QueryNode>,
edge_new_nodes_to_skip: &SmallBitmap<QueryNode>,
visit: VisitFn<G>,
ctx: &mut VisitorContext<G>,
visit: VisitFn<'_, G>,
ctx: &mut VisitorContext<'_, G>,
) -> Result<ControlFlow<(), bool>> {
assert!(dest_node != ctx.graph.query_graph.end_node);

View File

@ -33,7 +33,7 @@ impl<G: RankingRuleGraphTrait> ConditionDocIdsCache<G> {
/// and inserted in the cache.
pub fn get_computed_condition<'s>(
&'s mut self,
ctx: &mut SearchContext,
ctx: &mut SearchContext<'_>,
interned_condition: Interned<G::Condition>,
graph: &mut RankingRuleGraph<G>,
universe: &RoaringBitmap,

View File

@ -17,7 +17,7 @@ pub enum ExactnessCondition {
pub enum ExactnessGraph {}
fn compute_docids(
ctx: &mut SearchContext,
ctx: &mut SearchContext<'_>,
dest_node: &LocatedQueryTermSubset,
universe: &RoaringBitmap,
) -> Result<RoaringBitmap> {
@ -46,7 +46,7 @@ impl RankingRuleGraphTrait for ExactnessGraph {
#[tracing::instrument(level = "trace", skip_all, target = "search::exactness")]
fn resolve_condition(
ctx: &mut SearchContext,
ctx: &mut SearchContext<'_>,
condition: &Self::Condition,
universe: &RoaringBitmap,
) -> Result<ComputedCondition> {
@ -74,7 +74,7 @@ impl RankingRuleGraphTrait for ExactnessGraph {
#[tracing::instrument(level = "trace", skip_all, target = "search::exactness")]
fn build_edges(
_ctx: &mut SearchContext,
_ctx: &mut SearchContext<'_>,
conditions_interner: &mut DedupInterner<Self::Condition>,
_source_node: Option<&LocatedQueryTermSubset>,
dest_node: &LocatedQueryTermSubset,

View File

@ -22,7 +22,7 @@ impl RankingRuleGraphTrait for FidGraph {
#[tracing::instrument(level = "trace", skip_all, target = "search::fid")]
fn resolve_condition(
ctx: &mut SearchContext,
ctx: &mut SearchContext<'_>,
condition: &Self::Condition,
universe: &RoaringBitmap,
) -> Result<ComputedCondition> {
@ -47,7 +47,7 @@ impl RankingRuleGraphTrait for FidGraph {
#[tracing::instrument(level = "trace", skip_all, target = "search::fid")]
fn build_edges(
ctx: &mut SearchContext,
ctx: &mut SearchContext<'_>,
conditions_interner: &mut DedupInterner<Self::Condition>,
_from: Option<&LocatedQueryTermSubset>,
to_term: &LocatedQueryTermSubset,

View File

@ -99,14 +99,14 @@ pub trait RankingRuleGraphTrait: Sized + 'static {
/// Compute the document ids associated with the given edge condition,
/// restricted to the given universe.
fn resolve_condition(
ctx: &mut SearchContext,
ctx: &mut SearchContext<'_>,
condition: &Self::Condition,
universe: &RoaringBitmap,
) -> Result<ComputedCondition>;
/// Return the costs and conditions of the edges going from the source node to the destination node
fn build_edges(
ctx: &mut SearchContext,
ctx: &mut SearchContext<'_>,
conditions_interner: &mut DedupInterner<Self::Condition>,
source_node: Option<&LocatedQueryTermSubset>,
dest_node: &LocatedQueryTermSubset,

View File

@ -22,7 +22,7 @@ impl RankingRuleGraphTrait for PositionGraph {
#[tracing::instrument(level = "trace", skip_all, target = "search::position")]
fn resolve_condition(
ctx: &mut SearchContext,
ctx: &mut SearchContext<'_>,
condition: &Self::Condition,
universe: &RoaringBitmap,
) -> Result<ComputedCondition> {
@ -47,7 +47,7 @@ impl RankingRuleGraphTrait for PositionGraph {
#[tracing::instrument(level = "trace", skip_all, target = "search::position")]
fn build_edges(
ctx: &mut SearchContext,
ctx: &mut SearchContext<'_>,
conditions_interner: &mut DedupInterner<Self::Condition>,
_from: Option<&LocatedQueryTermSubset>,
to_term: &LocatedQueryTermSubset,

View File

@ -8,7 +8,7 @@ use crate::search::new::SearchContext;
use crate::Result;
pub fn build_edges(
_ctx: &mut SearchContext,
_ctx: &mut SearchContext<'_>,
conditions_interner: &mut DedupInterner<ProximityCondition>,
left_term: Option<&LocatedQueryTermSubset>,
right_term: &LocatedQueryTermSubset,

View File

@ -13,7 +13,7 @@ use crate::search::new::{SearchContext, Word};
use crate::Result;
pub fn compute_docids(
ctx: &mut SearchContext,
ctx: &mut SearchContext<'_>,
condition: &ProximityCondition,
universe: &RoaringBitmap,
) -> Result<ComputedCondition> {
@ -110,7 +110,7 @@ pub fn compute_docids(
}
fn compute_prefix_edges(
ctx: &mut SearchContext,
ctx: &mut SearchContext<'_>,
left_word: Interned<String>,
right_prefix: Interned<String>,
left_phrase: Option<Interned<Phrase>>,
@ -166,7 +166,7 @@ fn compute_prefix_edges(
}
fn compute_non_prefix_edges(
ctx: &mut SearchContext,
ctx: &mut SearchContext<'_>,
word1: Interned<String>,
word2: Interned<String>,
left_phrase: Option<Interned<Phrase>>,
@ -209,7 +209,7 @@ fn compute_non_prefix_edges(
}
fn last_words_of_term_derivations(
ctx: &mut SearchContext,
ctx: &mut SearchContext<'_>,
t: &QueryTermSubset,
) -> Result<BTreeSet<(Option<Interned<Phrase>>, Word)>> {
let mut result = BTreeSet::new();
@ -228,7 +228,7 @@ fn last_words_of_term_derivations(
Ok(result)
}
fn first_word_of_term_iter(
ctx: &mut SearchContext,
ctx: &mut SearchContext<'_>,
t: &QueryTermSubset,
) -> Result<BTreeSet<(Interned<String>, Option<Interned<Phrase>>)>> {
let mut result = BTreeSet::new();

View File

@ -23,7 +23,7 @@ impl RankingRuleGraphTrait for ProximityGraph {
#[tracing::instrument(level = "trace", skip_all, target = "search::proximity")]
fn resolve_condition(
ctx: &mut SearchContext,
ctx: &mut SearchContext<'_>,
condition: &Self::Condition,
universe: &RoaringBitmap,
) -> Result<ComputedCondition> {
@ -32,7 +32,7 @@ impl RankingRuleGraphTrait for ProximityGraph {
#[tracing::instrument(level = "trace", skip_all, target = "search::proximity")]
fn build_edges(
ctx: &mut SearchContext,
ctx: &mut SearchContext<'_>,
conditions_interner: &mut DedupInterner<Self::Condition>,
source_term: Option<&LocatedQueryTermSubset>,
dest_term: &LocatedQueryTermSubset,

View File

@ -21,7 +21,7 @@ impl RankingRuleGraphTrait for TypoGraph {
#[tracing::instrument(level = "trace", skip_all, target = "search::typo")]
fn resolve_condition(
ctx: &mut SearchContext,
ctx: &mut SearchContext<'_>,
condition: &Self::Condition,
universe: &RoaringBitmap,
) -> Result<ComputedCondition> {
@ -40,7 +40,7 @@ impl RankingRuleGraphTrait for TypoGraph {
#[tracing::instrument(level = "trace", skip_all, target = "search::typo")]
fn build_edges(
ctx: &mut SearchContext,
ctx: &mut SearchContext<'_>,
conditions_interner: &mut DedupInterner<Self::Condition>,
_from: Option<&LocatedQueryTermSubset>,
to_term: &LocatedQueryTermSubset,

View File

@ -20,7 +20,7 @@ impl RankingRuleGraphTrait for WordsGraph {
#[tracing::instrument(level = "trace", skip_all, target = "search::words")]
fn resolve_condition(
ctx: &mut SearchContext,
ctx: &mut SearchContext<'_>,
condition: &Self::Condition,
universe: &RoaringBitmap,
) -> Result<ComputedCondition> {
@ -39,7 +39,7 @@ impl RankingRuleGraphTrait for WordsGraph {
#[tracing::instrument(level = "trace", skip_all, target = "search::words")]
fn build_edges(
_ctx: &mut SearchContext,
_ctx: &mut SearchContext<'_>,
conditions_interner: &mut DedupInterner<Self::Condition>,
_from: Option<&LocatedQueryTermSubset>,
to_term: &LocatedQueryTermSubset,

View File

@ -30,7 +30,7 @@ impl<'ctx> SearchContext<'ctx> {
}
}
pub fn compute_query_term_subset_docids(
ctx: &mut SearchContext,
ctx: &mut SearchContext<'_>,
term: &QueryTermSubset,
) -> Result<RoaringBitmap> {
let mut docids = RoaringBitmap::new();
@ -53,7 +53,7 @@ pub fn compute_query_term_subset_docids(
}
pub fn compute_query_term_subset_docids_within_field_id(
ctx: &mut SearchContext,
ctx: &mut SearchContext<'_>,
term: &QueryTermSubset,
fid: u16,
) -> Result<RoaringBitmap> {
@ -86,7 +86,7 @@ pub fn compute_query_term_subset_docids_within_field_id(
}
pub fn compute_query_term_subset_docids_within_position(
ctx: &mut SearchContext,
ctx: &mut SearchContext<'_>,
term: &QueryTermSubset,
position: u16,
) -> Result<RoaringBitmap> {
@ -121,7 +121,7 @@ pub fn compute_query_term_subset_docids_within_position(
/// Returns the subset of the input universe that satisfies the contraints of the input query graph.
pub fn compute_query_graph_docids(
ctx: &mut SearchContext,
ctx: &mut SearchContext<'_>,
q: &QueryGraph,
universe: &RoaringBitmap,
) -> Result<RoaringBitmap> {
@ -178,7 +178,7 @@ pub fn compute_query_graph_docids(
}
pub fn compute_phrase_docids(
ctx: &mut SearchContext,
ctx: &mut SearchContext<'_>,
phrase: Interned<Phrase>,
) -> Result<RoaringBitmap> {
let Phrase { words } = ctx.phrase_interner.get(phrase).clone();

View File

@ -56,7 +56,7 @@ pub struct Sort<'ctx, Query> {
impl<'ctx, Query> Sort<'ctx, Query> {
pub fn new(
index: &Index,
rtxn: &'ctx heed::RoTxn,
rtxn: &'ctx heed::RoTxn<'ctx>,
field_name: String,
is_ascending: bool,
) -> Result<Self> {
@ -74,7 +74,7 @@ impl<'ctx, Query> Sort<'ctx, Query> {
})
}
fn must_redact(index: &Index, rtxn: &'ctx heed::RoTxn, field_name: &str) -> Result<bool> {
fn must_redact(index: &Index, rtxn: &'ctx heed::RoTxn<'ctx>, field_name: &str) -> Result<bool> {
let Some(displayed_fields) = index.displayed_fields(rtxn)? else {
return Ok(false);
};
@ -97,7 +97,7 @@ impl<'ctx, Query: RankingRuleQueryTrait> RankingRule<'ctx, Query> for Sort<'ctx,
parent_candidates: &RoaringBitmap,
parent_query: &Query,
) -> Result<()> {
let iter: RankingRuleOutputIterWrapper<Query> = match self.field_id {
let iter: RankingRuleOutputIterWrapper<'ctx, Query> = match self.field_id {
Some(field_id) => {
let number_db = ctx
.index

View File

@ -207,7 +207,7 @@ fn create_index() -> TempIndex {
fn verify_distinct(
index: &Index,
txn: &RoTxn,
txn: &RoTxn<'_>,
distinct: Option<&str>,
docids: &[u32],
) -> Vec<String> {

View File

@ -18,7 +18,7 @@ pub mod words_tms;
fn collect_field_values(
index: &crate::Index,
txn: &heed::RoTxn,
txn: &heed::RoTxn<'_>,
fid: &str,
docids: &[u32],
) -> Vec<String> {

View File

@ -20,7 +20,7 @@ pub struct VectorSort<Q: RankingRuleQueryTrait> {
impl<Q: RankingRuleQueryTrait> VectorSort<Q> {
pub fn new(
ctx: &SearchContext,
ctx: &SearchContext<'_>,
target: Vec<f32>,
vector_candidates: RoaringBitmap,
limit: usize,