Rename lifetime

This commit is contained in:
Loïc Lecrenier 2023-03-13 14:03:48 +01:00
parent 1c58cf8426
commit 14e8d0aaa2
18 changed files with 177 additions and 213 deletions

View File

@ -14,25 +14,25 @@ use crate::{Index, Result};
/// database lookup and instead get a direct reference to the value using a fast
/// local HashMap lookup.
#[derive(Default)]
pub struct DatabaseCache<'search> {
pub struct DatabaseCache<'ctx> {
pub word_pair_proximity_docids:
FxHashMap<(u8, Interned<String>, Interned<String>), Option<&'search [u8]>>,
FxHashMap<(u8, Interned<String>, Interned<String>), Option<&'ctx [u8]>>,
pub word_prefix_pair_proximity_docids:
FxHashMap<(u8, Interned<String>, Interned<String>), Option<&'search [u8]>>,
FxHashMap<(u8, Interned<String>, Interned<String>), Option<&'ctx [u8]>>,
pub prefix_word_pair_proximity_docids:
FxHashMap<(u8, Interned<String>, Interned<String>), Option<&'search [u8]>>,
pub word_docids: FxHashMap<Interned<String>, Option<&'search [u8]>>,
pub exact_word_docids: FxHashMap<Interned<String>, Option<&'search [u8]>>,
pub word_prefix_docids: FxHashMap<Interned<String>, Option<&'search [u8]>>,
FxHashMap<(u8, Interned<String>, Interned<String>), Option<&'ctx [u8]>>,
pub word_docids: FxHashMap<Interned<String>, Option<&'ctx [u8]>>,
pub exact_word_docids: FxHashMap<Interned<String>, Option<&'ctx [u8]>>,
pub word_prefix_docids: FxHashMap<Interned<String>, Option<&'ctx [u8]>>,
}
impl<'search> DatabaseCache<'search> {
impl<'ctx> DatabaseCache<'ctx> {
fn get_value<'v, K1, KC>(
txn: &'search RoTxn,
txn: &'ctx RoTxn,
cache_key: K1,
db_key: &'v KC::EItem,
cache: &mut FxHashMap<K1, Option<&'search [u8]>>,
cache: &mut FxHashMap<K1, Option<&'ctx [u8]>>,
db: Database<KC, ByteSlice>,
) -> Result<Option<&'search [u8]>>
) -> Result<Option<&'ctx [u8]>>
where
K1: Copy + Eq + Hash,
KC: BytesEncode<'v>,
@ -52,10 +52,10 @@ impl<'search> DatabaseCache<'search> {
pub fn get_word_docids(
&mut self,
index: &Index,
txn: &'search RoTxn,
txn: &'ctx RoTxn,
word_interner: &Interner<String>,
word: Interned<String>,
) -> Result<Option<&'search [u8]>> {
) -> Result<Option<&'ctx [u8]>> {
Self::get_value(
txn,
word,
@ -68,10 +68,10 @@ impl<'search> DatabaseCache<'search> {
pub fn get_word_prefix_docids(
&mut self,
index: &Index,
txn: &'search RoTxn,
txn: &'ctx RoTxn,
word_interner: &Interner<String>,
prefix: Interned<String>,
) -> Result<Option<&'search [u8]>> {
) -> Result<Option<&'ctx [u8]>> {
Self::get_value(
txn,
prefix,
@ -84,12 +84,12 @@ impl<'search> DatabaseCache<'search> {
pub fn get_word_pair_proximity_docids(
&mut self,
index: &Index,
txn: &'search RoTxn,
txn: &'ctx RoTxn,
word_interner: &Interner<String>,
word1: Interned<String>,
word2: Interned<String>,
proximity: u8,
) -> Result<Option<&'search [u8]>> {
) -> Result<Option<&'ctx [u8]>> {
Self::get_value(
txn,
(proximity, word1, word2),
@ -102,12 +102,12 @@ impl<'search> DatabaseCache<'search> {
pub fn get_word_prefix_pair_proximity_docids(
&mut self,
index: &Index,
txn: &'search RoTxn,
txn: &'ctx RoTxn,
word_interner: &Interner<String>,
word1: Interned<String>,
prefix2: Interned<String>,
proximity: u8,
) -> Result<Option<&'search [u8]>> {
) -> Result<Option<&'ctx [u8]>> {
Self::get_value(
txn,
(proximity, word1, prefix2),
@ -119,12 +119,12 @@ impl<'search> DatabaseCache<'search> {
pub fn get_prefix_word_pair_proximity_docids(
&mut self,
index: &Index,
txn: &'search RoTxn,
txn: &'ctx RoTxn,
word_interner: &Interner<String>,
left_prefix: Interned<String>,
right: Interned<String>,
proximity: u8,
) -> Result<Option<&'search [u8]>> {
) -> Result<Option<&'ctx [u8]>> {
Self::get_value(
txn,
(proximity, left_prefix, right),

View File

@ -20,8 +20,8 @@ pub struct DistinctOutput {
pub excluded: RoaringBitmap,
}
pub fn apply_distinct_rule<'search>(
ctx: &mut SearchContext<'search>,
pub fn apply_distinct_rule<'ctx>(
ctx: &mut SearchContext<'ctx>,
field_id: u16,
candidates: &RoaringBitmap,
) -> Result<DistinctOutput> {

View File

@ -92,8 +92,8 @@ pub struct GraphBasedRankingRuleState<G: RankingRuleGraphTrait> {
/// Traverse each edge of the graph, computes its associated document ids,
/// and remove this edge from the graph if its docids are disjoint with the
/// given universe.
fn remove_empty_edges<'search, G: RankingRuleGraphTrait>(
ctx: &mut SearchContext<'search>,
fn remove_empty_edges<'ctx, G: RankingRuleGraphTrait>(
ctx: &mut SearchContext<'ctx>,
graph: &mut RankingRuleGraph<G>,
edge_docids_cache: &mut EdgeConditionsCache<G>,
universe: &RoaringBitmap,
@ -121,15 +121,13 @@ fn remove_empty_edges<'search, G: RankingRuleGraphTrait>(
Ok(())
}
impl<'search, G: RankingRuleGraphTrait> RankingRule<'search, QueryGraph>
for GraphBasedRankingRule<G>
{
impl<'ctx, G: RankingRuleGraphTrait> RankingRule<'ctx, QueryGraph> for GraphBasedRankingRule<G> {
fn id(&self) -> String {
self.id.clone()
}
fn start_iteration(
&mut self,
ctx: &mut SearchContext<'search>,
ctx: &mut SearchContext<'ctx>,
_logger: &mut dyn SearchLogger<QueryGraph>,
universe: &RoaringBitmap,
query_graph: &QueryGraph,
@ -166,7 +164,7 @@ impl<'search, G: RankingRuleGraphTrait> RankingRule<'search, QueryGraph>
fn next_bucket(
&mut self,
ctx: &mut SearchContext<'search>,
ctx: &mut SearchContext<'ctx>,
logger: &mut dyn SearchLogger<QueryGraph>,
universe: &RoaringBitmap,
) -> Result<Option<RankingRuleOutput<QueryGraph>>> {
@ -210,11 +208,11 @@ impl<'search, G: RankingRuleGraphTrait> RankingRule<'search, QueryGraph>
cur_distance_idx: _,
} = &mut state;
// let original_universe = universe;
let original_universe = universe;
let mut universe = universe.clone();
// TODO: remove this unnecessary clone
// let original_graph = graph.clone();
let original_graph = graph.clone();
// and this vector as well
let mut paths = vec![];
@ -297,15 +295,15 @@ impl<'search, G: RankingRuleGraphTrait> RankingRule<'search, QueryGraph>
},
)?;
// G::log_state(
// &original_graph,
// &paths,
// &state.empty_paths_cache,
// original_universe,
// &state.all_distances,
// cost,
// logger,
// );
G::log_state(
&original_graph,
&paths,
&state.empty_paths_cache,
original_universe,
&state.all_distances,
cost,
logger,
);
// TODO: Graph-based ranking rules do not (yet) modify the query graph. We could, however,
// remove nodes and/or terms within nodes that weren't present in any of the paths.
@ -318,7 +316,7 @@ impl<'search, G: RankingRuleGraphTrait> RankingRule<'search, QueryGraph>
fn end_iteration(
&mut self,
_ctx: &mut SearchContext<'search>,
_ctx: &mut SearchContext<'ctx>,
_logger: &mut dyn SearchLogger<QueryGraph>,
) {
self.state = None;

View File

@ -33,6 +33,7 @@ impl<T> Interned<T> {
/// is then identified by a lightweight index of type [`Interned<T>`], which can
/// be copied, compared, and hashed efficiently. An immutable reference to the original value
/// can be retrieved using `self.get(interned)`.
#[derive(Clone)]
pub struct Interner<T> {
stable_store: Vec<T>,
lookup: FxHashMap<T, Interned<T>>,

View File

@ -545,12 +545,13 @@ shape: class"
)
.unwrap();
}
EdgeCondition::Conditional(details) => {
EdgeCondition::Conditional(condition) => {
let condition = graph.conditions_interner.get(*condition);
writeln!(
file,
"{source_node} -> {dest_node} : \"cost {cost} {edge_label}\"",
cost = edge.cost,
edge_label = R::label_for_edge_condition(details)
edge_label = R::label_for_edge_condition(condition)
)
.unwrap();
}

View File

@ -35,17 +35,17 @@ use crate::search::new::query_term::located_query_terms_from_string;
use crate::search::new::words::Words;
use crate::{Filter, Index, Result, TermsMatchingStrategy};
pub struct SearchContext<'search> {
pub index: &'search Index,
pub txn: &'search RoTxn<'search>,
pub db_cache: DatabaseCache<'search>,
pub struct SearchContext<'ctx> {
pub index: &'ctx Index,
pub txn: &'ctx RoTxn<'ctx>,
pub db_cache: DatabaseCache<'ctx>,
pub word_interner: Interner<String>,
pub phrase_interner: Interner<Phrase>,
pub derivations_interner: Interner<WordDerivations>,
pub query_term_docids: QueryTermDocIdsCache,
}
impl<'search> SearchContext<'search> {
pub fn new(index: &'search Index, txn: &'search RoTxn<'search>) -> Self {
impl<'ctx> SearchContext<'ctx> {
pub fn new(index: &'ctx Index, txn: &'ctx RoTxn<'ctx>) -> Self {
Self {
index,
txn,
@ -59,8 +59,8 @@ impl<'search> SearchContext<'search> {
}
#[allow(clippy::too_many_arguments)]
fn resolve_maximally_reduced_query_graph<'search>(
ctx: &mut SearchContext<'search>,
fn resolve_maximally_reduced_query_graph<'ctx>(
ctx: &mut SearchContext<'ctx>,
universe: &RoaringBitmap,
query_graph: &QueryGraph,
matching_strategy: TermsMatchingStrategy,
@ -99,9 +99,9 @@ fn resolve_maximally_reduced_query_graph<'search>(
Ok(docids)
}
fn get_ranking_rules_for_placeholder_search<'search>(
ctx: &SearchContext<'search>,
) -> Result<Vec<Box<dyn RankingRule<'search, PlaceholderQuery>>>> {
fn get_ranking_rules_for_placeholder_search<'ctx>(
ctx: &SearchContext<'ctx>,
) -> Result<Vec<Box<dyn RankingRule<'ctx, PlaceholderQuery>>>> {
// let sort = false;
// let mut asc = HashSet::new();
// let mut desc = HashSet::new();
@ -122,10 +122,10 @@ fn get_ranking_rules_for_placeholder_search<'search>(
}
Ok(ranking_rules)
}
fn get_ranking_rules_for_query_graph_search<'search>(
ctx: &SearchContext<'search>,
fn get_ranking_rules_for_query_graph_search<'ctx>(
ctx: &SearchContext<'ctx>,
terms_matching_strategy: TermsMatchingStrategy,
) -> Result<Vec<Box<dyn RankingRule<'search, QueryGraph>>>> {
) -> Result<Vec<Box<dyn RankingRule<'ctx, QueryGraph>>>> {
// query graph search
let mut words = false;
let mut typo = false;
@ -215,8 +215,8 @@ fn get_ranking_rules_for_query_graph_search<'search>(
}
#[allow(clippy::too_many_arguments)]
pub fn execute_search<'search>(
ctx: &mut SearchContext<'search>,
pub fn execute_search<'ctx>(
ctx: &mut SearchContext<'ctx>,
query: &str,
terms_matching_strategy: TermsMatchingStrategy,
filters: Option<Filter>,
@ -295,45 +295,45 @@ mod tests {
println!("nbr docids: {}", index.documents_ids(&txn).unwrap().len());
// loop {
let start = Instant::now();
loop {
let start = Instant::now();
let mut logger = crate::search::new::logger::detailed::DetailedSearchLogger::new("log");
let mut ctx = SearchContext::new(&index, &txn);
let results = execute_search(
&mut ctx,
"zero config",
TermsMatchingStrategy::Last,
None,
0,
20,
&mut DefaultSearchLogger,
&mut logger,
)
.unwrap();
// let mut logger = crate::search::new::logger::detailed::DetailedSearchLogger::new("log");
let mut ctx = SearchContext::new(&index, &txn);
let results = execute_search(
&mut ctx,
"zero config",
TermsMatchingStrategy::Last,
None,
0,
20,
&mut DefaultSearchLogger,
&mut DefaultSearchLogger,
)
.unwrap();
logger.write_d2_description(&mut ctx);
// logger.write_d2_description(&mut ctx);
let elapsed = start.elapsed();
println!("{}us", elapsed.as_micros());
let elapsed = start.elapsed();
println!("{}us", elapsed.as_micros());
let _documents = index
.documents(&txn, results.iter().copied())
.unwrap()
.into_iter()
.map(|(id, obkv)| {
let mut object = serde_json::Map::default();
for (fid, fid_name) in index.fields_ids_map(&txn).unwrap().iter() {
let value = obkv.get(fid).unwrap();
let value: serde_json::Value = serde_json::from_slice(value).unwrap();
object.insert(fid_name.to_owned(), value);
}
(id, serde_json::to_string_pretty(&object).unwrap())
})
.collect::<Vec<_>>();
let _documents = index
.documents(&txn, results.iter().copied())
.unwrap()
.into_iter()
.map(|(id, obkv)| {
let mut object = serde_json::Map::default();
for (fid, fid_name) in index.fields_ids_map(&txn).unwrap().iter() {
let value = obkv.get(fid).unwrap();
let value: serde_json::Value = serde_json::from_slice(value).unwrap();
object.insert(fid_name.to_owned(), value);
}
(id, serde_json::to_string_pretty(&object).unwrap())
})
.collect::<Vec<_>>();
println!("{}us: {:?}", elapsed.as_micros(), results);
// }
println!("{}us: {:?}", elapsed.as_micros(), results);
}
// for (id, _document) in documents {
// println!("{id}:");
// // println!("{document}");

View File

@ -276,8 +276,8 @@ impl LocatedQueryTerm {
}
/// Convert the tokenised search query into a list of located query terms.
pub fn located_query_terms_from_string<'search>(
ctx: &mut SearchContext<'search>,
pub fn located_query_terms_from_string<'ctx>(
ctx: &mut SearchContext<'ctx>,
query: NormalizedTokenIter<Vec<u8>>,
words_limit: Option<usize>,
) -> Result<Vec<LocatedQueryTerm>> {

View File

@ -7,6 +7,12 @@ use crate::search::new::{QueryGraph, SearchContext};
use crate::Result;
impl<G: RankingRuleGraphTrait> RankingRuleGraph<G> {
// TODO: here, the docids of all the edges should already be computed!
// an edge condition would then be reduced to a (ptr to) a roaring bitmap?
// we could build fewer of them by directly comparing them with the universe
// (e.g. for each word pairs?) with `deserialize_within_universe` maybe
//
/// Build the ranking rule graph from the given query graph
pub fn build(ctx: &mut SearchContext, query_graph: QueryGraph) -> Result<Self> {
let QueryGraph { nodes: graph_nodes, edges: graph_edges, .. } = &query_graph;

View File

@ -24,9 +24,9 @@ impl<G: RankingRuleGraphTrait> EdgeConditionsCache<G> {
///
/// If the cache does not yet contain these docids, they are computed
/// and inserted in the cache.
pub fn get_edge_docids<'s, 'search>(
pub fn get_edge_docids<'s, 'ctx>(
&'s mut self,
ctx: &mut SearchContext<'search>,
ctx: &mut SearchContext<'ctx>,
// TODO: should be Interned<EdgeCondition>
interned_edge_condition: Interned<G::EdgeCondition>,
graph: &RankingRuleGraph<G>,

View File

@ -69,47 +69,6 @@ pub struct Edge<E> {
pub condition: EdgeCondition<E>,
}
// pub struct SubWordDerivations {
// words: FxHashSet<Interned<String>>,
// phrases: FxHashSet<Interned<Phrase>>,
// use_prefix_db: bool,
// }
// pub struct EdgeWordDerivations {
// // TODO: not Option, instead: Any | All | Subset(SubWordDerivations)
// from_words: Option<SubWordDerivations>, // ???
// to_words: Option<SubWordDerivations>, // + use prefix db?
// }
// fn aggregate_edge_word_derivations(
// graph: (),
// edges: Vec<usize>,
// ) -> BTreeMap<usize, SubWordDerivations> {
// todo!()
// }
// fn reduce_word_term_to_sub_word_derivations(
// term: &mut WordDerivations,
// derivations: &SubWordDerivations,
// ) {
// let mut new_one_typo = vec![];
// for w in term.one_typo {
// if derivations.words.contains(w) {
// new_one_typo.push(w);
// }
// }
// if term.use_prefix_db && !derivations.use_prefix_db {
// term.use_prefix_db = false;
// }
// // etc.
// }
// fn word_derivations_used_by_edge<G: RankingRuleGraphTrait>(
// edge: G::EdgeCondition,
// ) -> SubWordDerivations {
// todo!()
// }
/// A trait to be implemented by a marker type to build a graph-based ranking rule.
///
/// It mostly describes how to:
@ -132,8 +91,8 @@ pub trait RankingRuleGraphTrait: Sized {
/// Compute the document ids associated with the given edge condition,
/// restricted to the given universe.
fn resolve_edge_condition<'search>(
ctx: &mut SearchContext<'search>,
fn resolve_edge_condition<'ctx>(
ctx: &mut SearchContext<'ctx>,
edge_condition: &Self::EdgeCondition,
universe: &RoaringBitmap,
) -> Result<RoaringBitmap>;
@ -142,15 +101,15 @@ pub trait RankingRuleGraphTrait: Sized {
///
/// This call is followed by zero, one or more calls to [`build_step_visit_destination_node`](RankingRuleGraphTrait::build_step_visit_destination_node),
/// which builds the actual edges.
fn build_step_visit_source_node<'search>(
ctx: &mut SearchContext<'search>,
fn build_step_visit_source_node<'ctx>(
ctx: &mut SearchContext<'ctx>,
source_node: &QueryNode,
) -> Result<Option<Self::BuildVisitedFromNode>>;
/// Return the cost and condition of the edges going from the previously visited node
/// (with [`build_step_visit_source_node`](RankingRuleGraphTrait::build_step_visit_source_node)) to `dest_node`.
fn build_step_visit_destination_node<'from_data, 'search: 'from_data>(
ctx: &mut SearchContext<'search>,
fn build_step_visit_destination_node<'from_data, 'ctx: 'from_data>(
ctx: &mut SearchContext<'ctx>,
conditions_interner: &mut Interner<Self::EdgeCondition>,
dest_node: &QueryNode,
source_node_data: &'from_data Self::BuildVisitedFromNode,
@ -177,16 +136,16 @@ pub struct RankingRuleGraph<G: RankingRuleGraphTrait> {
pub edges_of_node: Vec<SmallBitmap>,
pub conditions_interner: Interner<G::EdgeCondition>,
}
// impl<G: RankingRuleGraphTrait> Clone for RankingRuleGraph<G> {
// fn clone(&self) -> Self {
// Self {
// query_graph: self.query_graph.clone(),
// edges_store: self.edges_store.clone(),
// edges_of_node: self.edges_of_node.clone(),
// conditions_interner: self.conditions_interner.clone(),
// }
// }
// }
impl<G: RankingRuleGraphTrait> Clone for RankingRuleGraph<G> {
fn clone(&self) -> Self {
Self {
query_graph: self.query_graph.clone(),
edges_store: self.edges_store.clone(),
edges_of_node: self.edges_of_node.clone(),
conditions_interner: self.conditions_interner.clone(),
}
}
}
impl<G: RankingRuleGraphTrait> RankingRuleGraph<G> {
/// Remove the given edge from the ranking rule graph
pub fn remove_ranking_rule_edge(&mut self, edge_index: u16) {

View File

@ -58,8 +58,8 @@ pub fn visit_from_node(
}))
}
pub fn visit_to_node<'search, 'from_data>(
ctx: &mut SearchContext<'search>,
pub fn visit_to_node<'ctx, 'from_data>(
ctx: &mut SearchContext<'ctx>,
conditions_interner: &mut Interner<ProximityEdge>,
to_node: &QueryNode,
from_node_data: &'from_data (WordDerivations, i8),

View File

@ -4,8 +4,8 @@ use super::{ProximityEdge, WordPair};
use crate::search::new::SearchContext;
use crate::{CboRoaringBitmapCodec, Result};
pub fn compute_docids<'search>(
ctx: &mut SearchContext<'search>,
pub fn compute_docids<'ctx>(
ctx: &mut SearchContext<'ctx>,
edge: &ProximityEdge,
universe: &RoaringBitmap,
) -> Result<RoaringBitmap> {

View File

@ -36,23 +36,23 @@ impl RankingRuleGraphTrait for ProximityGraph {
format!(", prox {proximity}, {} pairs", pairs.len())
}
fn resolve_edge_condition<'search>(
ctx: &mut SearchContext<'search>,
fn resolve_edge_condition<'ctx>(
ctx: &mut SearchContext<'ctx>,
edge: &Self::EdgeCondition,
universe: &RoaringBitmap,
) -> Result<roaring::RoaringBitmap> {
compute_docids::compute_docids(ctx, edge, universe)
}
fn build_step_visit_source_node<'search>(
ctx: &mut SearchContext<'search>,
fn build_step_visit_source_node<'ctx>(
ctx: &mut SearchContext<'ctx>,
from_node: &QueryNode,
) -> Result<Option<Self::BuildVisitedFromNode>> {
build::visit_from_node(ctx, from_node)
}
fn build_step_visit_destination_node<'from_data, 'search: 'from_data>(
ctx: &mut SearchContext<'search>,
fn build_step_visit_destination_node<'from_data, 'ctx: 'from_data>(
ctx: &mut SearchContext<'ctx>,
conditions_interner: &mut Interner<Self::EdgeCondition>,
to_node: &QueryNode,
from_node_data: &'from_data Self::BuildVisitedFromNode,

View File

@ -28,8 +28,8 @@ impl RankingRuleGraphTrait for TypoGraph {
}
}
fn resolve_edge_condition<'db_cache, 'search>(
ctx: &mut SearchContext<'search>,
fn resolve_edge_condition<'db_cache, 'ctx>(
ctx: &mut SearchContext<'ctx>,
edge: &Self::EdgeCondition,
universe: &RoaringBitmap,
) -> Result<RoaringBitmap> {
@ -69,15 +69,15 @@ impl RankingRuleGraphTrait for TypoGraph {
}
}
fn build_step_visit_source_node<'search>(
_ctx: &mut SearchContext<'search>,
fn build_step_visit_source_node<'ctx>(
_ctx: &mut SearchContext<'ctx>,
_from_node: &QueryNode,
) -> Result<Option<Self::BuildVisitedFromNode>> {
Ok(Some(()))
}
fn build_step_visit_destination_node<'from_data, 'search: 'from_data>(
ctx: &mut SearchContext<'search>,
fn build_step_visit_destination_node<'from_data, 'ctx: 'from_data>(
ctx: &mut SearchContext<'ctx>,
conditions_interner: &mut Interner<Self::EdgeCondition>,
to_node: &QueryNode,
_from_node_data: &'from_data Self::BuildVisitedFromNode,

View File

@ -17,10 +17,10 @@ impl RankingRuleQueryTrait for QueryGraph {}
/// A trait that must be implemented by all ranking rules.
///
/// It is generic over `'search`, the lifetime of the search context
/// It is generic over `'ctx`, the lifetime of the search context
/// (i.e. the read transaction and the cache) and over `Query`, which
/// can be either [`PlaceholderQuery`] or [`QueryGraph`].
pub trait RankingRule<'search, Query: RankingRuleQueryTrait> {
pub trait RankingRule<'ctx, Query: RankingRuleQueryTrait> {
fn id(&self) -> String;
/// Prepare the ranking rule such that it can start iterating over its
@ -29,7 +29,7 @@ pub trait RankingRule<'search, Query: RankingRuleQueryTrait> {
/// The given universe is the universe that will be given to [`next_bucket`](RankingRule::next_bucket).
fn start_iteration(
&mut self,
ctx: &mut SearchContext<'search>,
ctx: &mut SearchContext<'ctx>,
logger: &mut dyn SearchLogger<Query>,
universe: &RoaringBitmap,
query: &Query,
@ -44,7 +44,7 @@ pub trait RankingRule<'search, Query: RankingRuleQueryTrait> {
/// - the universe given to [`start_iteration`](RankingRule::start_iteration)
fn next_bucket(
&mut self,
ctx: &mut SearchContext<'search>,
ctx: &mut SearchContext<'ctx>,
logger: &mut dyn SearchLogger<Query>,
universe: &RoaringBitmap,
) -> Result<Option<RankingRuleOutput<Query>>>;
@ -53,7 +53,7 @@ pub trait RankingRule<'search, Query: RankingRuleQueryTrait> {
/// The next call to this ranking rule, if any, will be [`start_iteration`](RankingRule::start_iteration).
fn end_iteration(
&mut self,
ctx: &mut SearchContext<'search>,
ctx: &mut SearchContext<'ctx>,
logger: &mut dyn SearchLogger<Query>,
);
}
@ -68,15 +68,16 @@ pub struct RankingRuleOutput<Q> {
pub candidates: RoaringBitmap,
}
pub fn bucket_sort<'search, Q: RankingRuleQueryTrait>(
ctx: &mut SearchContext<'search>,
mut ranking_rules: Vec<Box<dyn RankingRule<'search, Q>>>,
pub fn bucket_sort<'ctx, Q: RankingRuleQueryTrait>(
ctx: &mut SearchContext<'ctx>,
mut ranking_rules: Vec<Box<dyn RankingRule<'ctx, Q>>>,
query: &Q,
universe: &RoaringBitmap,
from: usize,
length: usize,
logger: &mut dyn SearchLogger<Q>,
) -> Result<Vec<u32>> {
logger.initial_query(query);
logger.ranking_rules(&ranking_rules);
logger.initial_universe(universe);

View File

@ -21,11 +21,11 @@ pub struct QueryTermDocIdsCache {
}
impl QueryTermDocIdsCache {
/// Get the document ids associated with the given phrase
pub fn get_phrase_docids<'s, 'search>(
pub fn get_phrase_docids<'s, 'ctx>(
&'s mut self,
index: &Index,
txn: &'search RoTxn,
db_cache: &mut DatabaseCache<'search>,
txn: &'ctx RoTxn,
db_cache: &mut DatabaseCache<'ctx>,
word_interner: &Interner<String>,
phrase_interner: &Interner<Phrase>,
phrase: Interned<Phrase>,
@ -40,11 +40,11 @@ impl QueryTermDocIdsCache {
}
/// Get the document ids associated with the given word derivations
pub fn get_word_derivations_docids<'s, 'search>(
pub fn get_word_derivations_docids<'s, 'ctx>(
&'s mut self,
index: &Index,
txn: &'search RoTxn,
db_cache: &mut DatabaseCache<'search>,
txn: &'ctx RoTxn,
db_cache: &mut DatabaseCache<'ctx>,
word_interner: &Interner<String>,
derivations_interner: &Interner<WordDerivations>,
phrase_interner: &Interner<Phrase>,
@ -110,11 +110,11 @@ impl QueryTermDocIdsCache {
}
/// Get the document ids associated with the given query term.
fn get_query_term_docids<'s, 'search>(
fn get_query_term_docids<'s, 'ctx>(
&'s mut self,
index: &Index,
txn: &'search RoTxn,
db_cache: &mut DatabaseCache<'search>,
txn: &'ctx RoTxn,
db_cache: &mut DatabaseCache<'ctx>,
word_interner: &Interner<String>,
derivations_interner: &Interner<WordDerivations>,
phrase_interner: &Interner<Phrase>,
@ -137,8 +137,8 @@ impl QueryTermDocIdsCache {
}
}
pub fn resolve_query_graph<'search>(
ctx: &mut SearchContext<'search>,
pub fn resolve_query_graph<'ctx>(
ctx: &mut SearchContext<'ctx>,
q: &QueryGraph,
universe: &RoaringBitmap,
) -> Result<RoaringBitmap> {
@ -214,10 +214,10 @@ pub fn resolve_query_graph<'search>(
panic!()
}
pub fn resolve_phrase<'search>(
pub fn resolve_phrase<'ctx>(
index: &Index,
txn: &'search RoTxn,
db_cache: &mut DatabaseCache<'search>,
txn: &'ctx RoTxn,
db_cache: &mut DatabaseCache<'ctx>,
word_interner: &Interner<String>,
phrase_interner: &Interner<Phrase>,
phrase: Interned<Phrase>,

View File

@ -3,21 +3,19 @@ use roaring::RoaringBitmap;
use super::logger::SearchLogger;
use super::{RankingRule, RankingRuleOutput, RankingRuleQueryTrait, SearchContext};
pub trait RankingRuleOutputIter<'search, Query> {
pub trait RankingRuleOutputIter<'ctx, Query> {
fn next_bucket(&mut self) -> Result<Option<RankingRuleOutput<Query>>>;
}
pub struct RankingRuleOutputIterWrapper<'search, Query> {
iter: Box<dyn Iterator<Item = Result<RankingRuleOutput<Query>>> + 'search>,
pub struct RankingRuleOutputIterWrapper<'ctx, Query> {
iter: Box<dyn Iterator<Item = Result<RankingRuleOutput<Query>>> + 'ctx>,
}
impl<'search, Query> RankingRuleOutputIterWrapper<'search, Query> {
pub fn new(iter: Box<dyn Iterator<Item = Result<RankingRuleOutput<Query>>> + 'search>) -> Self {
impl<'ctx, Query> RankingRuleOutputIterWrapper<'ctx, Query> {
pub fn new(iter: Box<dyn Iterator<Item = Result<RankingRuleOutput<Query>>> + 'ctx>) -> Self {
Self { iter }
}
}
impl<'search, Query> RankingRuleOutputIter<'search, Query>
for RankingRuleOutputIterWrapper<'search, Query>
{
impl<'ctx, Query> RankingRuleOutputIter<'ctx, Query> for RankingRuleOutputIterWrapper<'ctx, Query> {
fn next_bucket(&mut self) -> Result<Option<RankingRuleOutput<Query>>> {
match self.iter.next() {
Some(x) => x.map(Some),
@ -35,17 +33,17 @@ use crate::{
Result,
};
pub struct Sort<'search, Query> {
pub struct Sort<'ctx, Query> {
field_name: String,
field_id: Option<FieldId>,
is_ascending: bool,
original_query: Option<Query>,
iter: Option<RankingRuleOutputIterWrapper<'search, Query>>,
iter: Option<RankingRuleOutputIterWrapper<'ctx, Query>>,
}
impl<'search, Query> Sort<'search, Query> {
impl<'ctx, Query> Sort<'ctx, Query> {
pub fn _new(
index: &Index,
rtxn: &'search heed::RoTxn,
rtxn: &'ctx heed::RoTxn,
field_name: String,
is_ascending: bool,
) -> Result<Self> {
@ -56,14 +54,14 @@ impl<'search, Query> Sort<'search, Query> {
}
}
impl<'search, Query: RankingRuleQueryTrait> RankingRule<'search, Query> for Sort<'search, Query> {
impl<'ctx, Query: RankingRuleQueryTrait> RankingRule<'ctx, Query> for Sort<'ctx, Query> {
fn id(&self) -> String {
let Self { field_name, is_ascending, .. } = self;
format!("{field_name}:{}", if *is_ascending { "asc" } else { "desc " })
}
fn start_iteration(
&mut self,
ctx: &mut SearchContext<'search>,
ctx: &mut SearchContext<'ctx>,
_logger: &mut dyn SearchLogger<Query>,
parent_candidates: &RoaringBitmap,
parent_query_graph: &Query,
@ -106,7 +104,7 @@ impl<'search, Query: RankingRuleQueryTrait> RankingRule<'search, Query> for Sort
fn next_bucket(
&mut self,
_ctx: &mut SearchContext<'search>,
_ctx: &mut SearchContext<'ctx>,
_logger: &mut dyn SearchLogger<Query>,
universe: &RoaringBitmap,
) -> Result<Option<RankingRuleOutput<Query>>> {
@ -123,7 +121,7 @@ impl<'search, Query: RankingRuleQueryTrait> RankingRule<'search, Query> for Sort
fn end_iteration(
&mut self,
_ctx: &mut SearchContext<'search>,
_ctx: &mut SearchContext<'ctx>,
_logger: &mut dyn SearchLogger<Query>,
) {
self.original_query = None;

View File

@ -26,13 +26,13 @@ impl Words {
}
}
impl<'search> RankingRule<'search, QueryGraph> for Words {
impl<'ctx> RankingRule<'ctx, QueryGraph> for Words {
fn id(&self) -> String {
"words".to_owned()
}
fn start_iteration(
&mut self,
_ctx: &mut SearchContext<'search>,
_ctx: &mut SearchContext<'ctx>,
_logger: &mut dyn SearchLogger<QueryGraph>,
_parent_candidates: &RoaringBitmap,
parent_query_graph: &QueryGraph,
@ -65,7 +65,7 @@ impl<'search> RankingRule<'search, QueryGraph> for Words {
fn next_bucket(
&mut self,
ctx: &mut SearchContext<'search>,
ctx: &mut SearchContext<'ctx>,
logger: &mut dyn SearchLogger<QueryGraph>,
universe: &RoaringBitmap,
) -> Result<Option<RankingRuleOutput<QueryGraph>>> {
@ -101,7 +101,7 @@ impl<'search> RankingRule<'search, QueryGraph> for Words {
fn end_iteration(
&mut self,
_ctx: &mut SearchContext<'search>,
_ctx: &mut SearchContext<'ctx>,
_logger: &mut dyn SearchLogger<QueryGraph>,
) {
self.iterating = false;