mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-27 04:25:06 +08:00
Rename lifetime
This commit is contained in:
parent
1c58cf8426
commit
14e8d0aaa2
@ -14,25 +14,25 @@ use crate::{Index, Result};
|
|||||||
/// database lookup and instead get a direct reference to the value using a fast
|
/// database lookup and instead get a direct reference to the value using a fast
|
||||||
/// local HashMap lookup.
|
/// local HashMap lookup.
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct DatabaseCache<'search> {
|
pub struct DatabaseCache<'ctx> {
|
||||||
pub word_pair_proximity_docids:
|
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:
|
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:
|
pub prefix_word_pair_proximity_docids:
|
||||||
FxHashMap<(u8, Interned<String>, Interned<String>), Option<&'search [u8]>>,
|
FxHashMap<(u8, Interned<String>, Interned<String>), Option<&'ctx [u8]>>,
|
||||||
pub word_docids: FxHashMap<Interned<String>, Option<&'search [u8]>>,
|
pub word_docids: FxHashMap<Interned<String>, Option<&'ctx [u8]>>,
|
||||||
pub exact_word_docids: FxHashMap<Interned<String>, Option<&'search [u8]>>,
|
pub exact_word_docids: FxHashMap<Interned<String>, Option<&'ctx [u8]>>,
|
||||||
pub word_prefix_docids: FxHashMap<Interned<String>, Option<&'search [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>(
|
fn get_value<'v, K1, KC>(
|
||||||
txn: &'search RoTxn,
|
txn: &'ctx RoTxn,
|
||||||
cache_key: K1,
|
cache_key: K1,
|
||||||
db_key: &'v KC::EItem,
|
db_key: &'v KC::EItem,
|
||||||
cache: &mut FxHashMap<K1, Option<&'search [u8]>>,
|
cache: &mut FxHashMap<K1, Option<&'ctx [u8]>>,
|
||||||
db: Database<KC, ByteSlice>,
|
db: Database<KC, ByteSlice>,
|
||||||
) -> Result<Option<&'search [u8]>>
|
) -> Result<Option<&'ctx [u8]>>
|
||||||
where
|
where
|
||||||
K1: Copy + Eq + Hash,
|
K1: Copy + Eq + Hash,
|
||||||
KC: BytesEncode<'v>,
|
KC: BytesEncode<'v>,
|
||||||
@ -52,10 +52,10 @@ impl<'search> DatabaseCache<'search> {
|
|||||||
pub fn get_word_docids(
|
pub fn get_word_docids(
|
||||||
&mut self,
|
&mut self,
|
||||||
index: &Index,
|
index: &Index,
|
||||||
txn: &'search RoTxn,
|
txn: &'ctx RoTxn,
|
||||||
word_interner: &Interner<String>,
|
word_interner: &Interner<String>,
|
||||||
word: Interned<String>,
|
word: Interned<String>,
|
||||||
) -> Result<Option<&'search [u8]>> {
|
) -> Result<Option<&'ctx [u8]>> {
|
||||||
Self::get_value(
|
Self::get_value(
|
||||||
txn,
|
txn,
|
||||||
word,
|
word,
|
||||||
@ -68,10 +68,10 @@ impl<'search> DatabaseCache<'search> {
|
|||||||
pub fn get_word_prefix_docids(
|
pub fn get_word_prefix_docids(
|
||||||
&mut self,
|
&mut self,
|
||||||
index: &Index,
|
index: &Index,
|
||||||
txn: &'search RoTxn,
|
txn: &'ctx RoTxn,
|
||||||
word_interner: &Interner<String>,
|
word_interner: &Interner<String>,
|
||||||
prefix: Interned<String>,
|
prefix: Interned<String>,
|
||||||
) -> Result<Option<&'search [u8]>> {
|
) -> Result<Option<&'ctx [u8]>> {
|
||||||
Self::get_value(
|
Self::get_value(
|
||||||
txn,
|
txn,
|
||||||
prefix,
|
prefix,
|
||||||
@ -84,12 +84,12 @@ impl<'search> DatabaseCache<'search> {
|
|||||||
pub fn get_word_pair_proximity_docids(
|
pub fn get_word_pair_proximity_docids(
|
||||||
&mut self,
|
&mut self,
|
||||||
index: &Index,
|
index: &Index,
|
||||||
txn: &'search RoTxn,
|
txn: &'ctx RoTxn,
|
||||||
word_interner: &Interner<String>,
|
word_interner: &Interner<String>,
|
||||||
word1: Interned<String>,
|
word1: Interned<String>,
|
||||||
word2: Interned<String>,
|
word2: Interned<String>,
|
||||||
proximity: u8,
|
proximity: u8,
|
||||||
) -> Result<Option<&'search [u8]>> {
|
) -> Result<Option<&'ctx [u8]>> {
|
||||||
Self::get_value(
|
Self::get_value(
|
||||||
txn,
|
txn,
|
||||||
(proximity, word1, word2),
|
(proximity, word1, word2),
|
||||||
@ -102,12 +102,12 @@ impl<'search> DatabaseCache<'search> {
|
|||||||
pub fn get_word_prefix_pair_proximity_docids(
|
pub fn get_word_prefix_pair_proximity_docids(
|
||||||
&mut self,
|
&mut self,
|
||||||
index: &Index,
|
index: &Index,
|
||||||
txn: &'search RoTxn,
|
txn: &'ctx RoTxn,
|
||||||
word_interner: &Interner<String>,
|
word_interner: &Interner<String>,
|
||||||
word1: Interned<String>,
|
word1: Interned<String>,
|
||||||
prefix2: Interned<String>,
|
prefix2: Interned<String>,
|
||||||
proximity: u8,
|
proximity: u8,
|
||||||
) -> Result<Option<&'search [u8]>> {
|
) -> Result<Option<&'ctx [u8]>> {
|
||||||
Self::get_value(
|
Self::get_value(
|
||||||
txn,
|
txn,
|
||||||
(proximity, word1, prefix2),
|
(proximity, word1, prefix2),
|
||||||
@ -119,12 +119,12 @@ impl<'search> DatabaseCache<'search> {
|
|||||||
pub fn get_prefix_word_pair_proximity_docids(
|
pub fn get_prefix_word_pair_proximity_docids(
|
||||||
&mut self,
|
&mut self,
|
||||||
index: &Index,
|
index: &Index,
|
||||||
txn: &'search RoTxn,
|
txn: &'ctx RoTxn,
|
||||||
word_interner: &Interner<String>,
|
word_interner: &Interner<String>,
|
||||||
left_prefix: Interned<String>,
|
left_prefix: Interned<String>,
|
||||||
right: Interned<String>,
|
right: Interned<String>,
|
||||||
proximity: u8,
|
proximity: u8,
|
||||||
) -> Result<Option<&'search [u8]>> {
|
) -> Result<Option<&'ctx [u8]>> {
|
||||||
Self::get_value(
|
Self::get_value(
|
||||||
txn,
|
txn,
|
||||||
(proximity, left_prefix, right),
|
(proximity, left_prefix, right),
|
||||||
|
@ -20,8 +20,8 @@ pub struct DistinctOutput {
|
|||||||
pub excluded: RoaringBitmap,
|
pub excluded: RoaringBitmap,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn apply_distinct_rule<'search>(
|
pub fn apply_distinct_rule<'ctx>(
|
||||||
ctx: &mut SearchContext<'search>,
|
ctx: &mut SearchContext<'ctx>,
|
||||||
field_id: u16,
|
field_id: u16,
|
||||||
candidates: &RoaringBitmap,
|
candidates: &RoaringBitmap,
|
||||||
) -> Result<DistinctOutput> {
|
) -> Result<DistinctOutput> {
|
||||||
|
@ -92,8 +92,8 @@ pub struct GraphBasedRankingRuleState<G: RankingRuleGraphTrait> {
|
|||||||
/// Traverse each edge of the graph, computes its associated document ids,
|
/// 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
|
/// and remove this edge from the graph if its docids are disjoint with the
|
||||||
/// given universe.
|
/// given universe.
|
||||||
fn remove_empty_edges<'search, G: RankingRuleGraphTrait>(
|
fn remove_empty_edges<'ctx, G: RankingRuleGraphTrait>(
|
||||||
ctx: &mut SearchContext<'search>,
|
ctx: &mut SearchContext<'ctx>,
|
||||||
graph: &mut RankingRuleGraph<G>,
|
graph: &mut RankingRuleGraph<G>,
|
||||||
edge_docids_cache: &mut EdgeConditionsCache<G>,
|
edge_docids_cache: &mut EdgeConditionsCache<G>,
|
||||||
universe: &RoaringBitmap,
|
universe: &RoaringBitmap,
|
||||||
@ -121,15 +121,13 @@ fn remove_empty_edges<'search, G: RankingRuleGraphTrait>(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'search, G: RankingRuleGraphTrait> RankingRule<'search, QueryGraph>
|
impl<'ctx, G: RankingRuleGraphTrait> RankingRule<'ctx, QueryGraph> for GraphBasedRankingRule<G> {
|
||||||
for GraphBasedRankingRule<G>
|
|
||||||
{
|
|
||||||
fn id(&self) -> String {
|
fn id(&self) -> String {
|
||||||
self.id.clone()
|
self.id.clone()
|
||||||
}
|
}
|
||||||
fn start_iteration(
|
fn start_iteration(
|
||||||
&mut self,
|
&mut self,
|
||||||
ctx: &mut SearchContext<'search>,
|
ctx: &mut SearchContext<'ctx>,
|
||||||
_logger: &mut dyn SearchLogger<QueryGraph>,
|
_logger: &mut dyn SearchLogger<QueryGraph>,
|
||||||
universe: &RoaringBitmap,
|
universe: &RoaringBitmap,
|
||||||
query_graph: &QueryGraph,
|
query_graph: &QueryGraph,
|
||||||
@ -166,7 +164,7 @@ impl<'search, G: RankingRuleGraphTrait> RankingRule<'search, QueryGraph>
|
|||||||
|
|
||||||
fn next_bucket(
|
fn next_bucket(
|
||||||
&mut self,
|
&mut self,
|
||||||
ctx: &mut SearchContext<'search>,
|
ctx: &mut SearchContext<'ctx>,
|
||||||
logger: &mut dyn SearchLogger<QueryGraph>,
|
logger: &mut dyn SearchLogger<QueryGraph>,
|
||||||
universe: &RoaringBitmap,
|
universe: &RoaringBitmap,
|
||||||
) -> Result<Option<RankingRuleOutput<QueryGraph>>> {
|
) -> Result<Option<RankingRuleOutput<QueryGraph>>> {
|
||||||
@ -210,11 +208,11 @@ impl<'search, G: RankingRuleGraphTrait> RankingRule<'search, QueryGraph>
|
|||||||
cur_distance_idx: _,
|
cur_distance_idx: _,
|
||||||
} = &mut state;
|
} = &mut state;
|
||||||
|
|
||||||
// let original_universe = universe;
|
let original_universe = universe;
|
||||||
let mut universe = universe.clone();
|
let mut universe = universe.clone();
|
||||||
|
|
||||||
// TODO: remove this unnecessary clone
|
// TODO: remove this unnecessary clone
|
||||||
// let original_graph = graph.clone();
|
let original_graph = graph.clone();
|
||||||
// and this vector as well
|
// and this vector as well
|
||||||
let mut paths = vec![];
|
let mut paths = vec![];
|
||||||
|
|
||||||
@ -297,15 +295,15 @@ impl<'search, G: RankingRuleGraphTrait> RankingRule<'search, QueryGraph>
|
|||||||
},
|
},
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// G::log_state(
|
G::log_state(
|
||||||
// &original_graph,
|
&original_graph,
|
||||||
// &paths,
|
&paths,
|
||||||
// &state.empty_paths_cache,
|
&state.empty_paths_cache,
|
||||||
// original_universe,
|
original_universe,
|
||||||
// &state.all_distances,
|
&state.all_distances,
|
||||||
// cost,
|
cost,
|
||||||
// logger,
|
logger,
|
||||||
// );
|
);
|
||||||
|
|
||||||
// TODO: Graph-based ranking rules do not (yet) modify the query graph. We could, however,
|
// 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.
|
// 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(
|
fn end_iteration(
|
||||||
&mut self,
|
&mut self,
|
||||||
_ctx: &mut SearchContext<'search>,
|
_ctx: &mut SearchContext<'ctx>,
|
||||||
_logger: &mut dyn SearchLogger<QueryGraph>,
|
_logger: &mut dyn SearchLogger<QueryGraph>,
|
||||||
) {
|
) {
|
||||||
self.state = None;
|
self.state = None;
|
||||||
|
@ -33,6 +33,7 @@ impl<T> Interned<T> {
|
|||||||
/// is then identified by a lightweight index of type [`Interned<T>`], which can
|
/// 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
|
/// be copied, compared, and hashed efficiently. An immutable reference to the original value
|
||||||
/// can be retrieved using `self.get(interned)`.
|
/// can be retrieved using `self.get(interned)`.
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct Interner<T> {
|
pub struct Interner<T> {
|
||||||
stable_store: Vec<T>,
|
stable_store: Vec<T>,
|
||||||
lookup: FxHashMap<T, Interned<T>>,
|
lookup: FxHashMap<T, Interned<T>>,
|
||||||
|
@ -545,12 +545,13 @@ shape: class"
|
|||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
EdgeCondition::Conditional(details) => {
|
EdgeCondition::Conditional(condition) => {
|
||||||
|
let condition = graph.conditions_interner.get(*condition);
|
||||||
writeln!(
|
writeln!(
|
||||||
file,
|
file,
|
||||||
"{source_node} -> {dest_node} : \"cost {cost} {edge_label}\"",
|
"{source_node} -> {dest_node} : \"cost {cost} {edge_label}\"",
|
||||||
cost = edge.cost,
|
cost = edge.cost,
|
||||||
edge_label = R::label_for_edge_condition(details)
|
edge_label = R::label_for_edge_condition(condition)
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
@ -35,17 +35,17 @@ use crate::search::new::query_term::located_query_terms_from_string;
|
|||||||
use crate::search::new::words::Words;
|
use crate::search::new::words::Words;
|
||||||
use crate::{Filter, Index, Result, TermsMatchingStrategy};
|
use crate::{Filter, Index, Result, TermsMatchingStrategy};
|
||||||
|
|
||||||
pub struct SearchContext<'search> {
|
pub struct SearchContext<'ctx> {
|
||||||
pub index: &'search Index,
|
pub index: &'ctx Index,
|
||||||
pub txn: &'search RoTxn<'search>,
|
pub txn: &'ctx RoTxn<'ctx>,
|
||||||
pub db_cache: DatabaseCache<'search>,
|
pub db_cache: DatabaseCache<'ctx>,
|
||||||
pub word_interner: Interner<String>,
|
pub word_interner: Interner<String>,
|
||||||
pub phrase_interner: Interner<Phrase>,
|
pub phrase_interner: Interner<Phrase>,
|
||||||
pub derivations_interner: Interner<WordDerivations>,
|
pub derivations_interner: Interner<WordDerivations>,
|
||||||
pub query_term_docids: QueryTermDocIdsCache,
|
pub query_term_docids: QueryTermDocIdsCache,
|
||||||
}
|
}
|
||||||
impl<'search> SearchContext<'search> {
|
impl<'ctx> SearchContext<'ctx> {
|
||||||
pub fn new(index: &'search Index, txn: &'search RoTxn<'search>) -> Self {
|
pub fn new(index: &'ctx Index, txn: &'ctx RoTxn<'ctx>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
index,
|
index,
|
||||||
txn,
|
txn,
|
||||||
@ -59,8 +59,8 @@ impl<'search> SearchContext<'search> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
fn resolve_maximally_reduced_query_graph<'search>(
|
fn resolve_maximally_reduced_query_graph<'ctx>(
|
||||||
ctx: &mut SearchContext<'search>,
|
ctx: &mut SearchContext<'ctx>,
|
||||||
universe: &RoaringBitmap,
|
universe: &RoaringBitmap,
|
||||||
query_graph: &QueryGraph,
|
query_graph: &QueryGraph,
|
||||||
matching_strategy: TermsMatchingStrategy,
|
matching_strategy: TermsMatchingStrategy,
|
||||||
@ -99,9 +99,9 @@ fn resolve_maximally_reduced_query_graph<'search>(
|
|||||||
|
|
||||||
Ok(docids)
|
Ok(docids)
|
||||||
}
|
}
|
||||||
fn get_ranking_rules_for_placeholder_search<'search>(
|
fn get_ranking_rules_for_placeholder_search<'ctx>(
|
||||||
ctx: &SearchContext<'search>,
|
ctx: &SearchContext<'ctx>,
|
||||||
) -> Result<Vec<Box<dyn RankingRule<'search, PlaceholderQuery>>>> {
|
) -> Result<Vec<Box<dyn RankingRule<'ctx, PlaceholderQuery>>>> {
|
||||||
// let sort = false;
|
// let sort = false;
|
||||||
// let mut asc = HashSet::new();
|
// let mut asc = HashSet::new();
|
||||||
// let mut desc = HashSet::new();
|
// let mut desc = HashSet::new();
|
||||||
@ -122,10 +122,10 @@ fn get_ranking_rules_for_placeholder_search<'search>(
|
|||||||
}
|
}
|
||||||
Ok(ranking_rules)
|
Ok(ranking_rules)
|
||||||
}
|
}
|
||||||
fn get_ranking_rules_for_query_graph_search<'search>(
|
fn get_ranking_rules_for_query_graph_search<'ctx>(
|
||||||
ctx: &SearchContext<'search>,
|
ctx: &SearchContext<'ctx>,
|
||||||
terms_matching_strategy: TermsMatchingStrategy,
|
terms_matching_strategy: TermsMatchingStrategy,
|
||||||
) -> Result<Vec<Box<dyn RankingRule<'search, QueryGraph>>>> {
|
) -> Result<Vec<Box<dyn RankingRule<'ctx, QueryGraph>>>> {
|
||||||
// query graph search
|
// query graph search
|
||||||
let mut words = false;
|
let mut words = false;
|
||||||
let mut typo = false;
|
let mut typo = false;
|
||||||
@ -215,8 +215,8 @@ fn get_ranking_rules_for_query_graph_search<'search>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub fn execute_search<'search>(
|
pub fn execute_search<'ctx>(
|
||||||
ctx: &mut SearchContext<'search>,
|
ctx: &mut SearchContext<'ctx>,
|
||||||
query: &str,
|
query: &str,
|
||||||
terms_matching_strategy: TermsMatchingStrategy,
|
terms_matching_strategy: TermsMatchingStrategy,
|
||||||
filters: Option<Filter>,
|
filters: Option<Filter>,
|
||||||
@ -295,10 +295,10 @@ mod tests {
|
|||||||
|
|
||||||
println!("nbr docids: {}", index.documents_ids(&txn).unwrap().len());
|
println!("nbr docids: {}", index.documents_ids(&txn).unwrap().len());
|
||||||
|
|
||||||
// loop {
|
loop {
|
||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
|
|
||||||
let mut logger = crate::search::new::logger::detailed::DetailedSearchLogger::new("log");
|
// let mut logger = crate::search::new::logger::detailed::DetailedSearchLogger::new("log");
|
||||||
let mut ctx = SearchContext::new(&index, &txn);
|
let mut ctx = SearchContext::new(&index, &txn);
|
||||||
let results = execute_search(
|
let results = execute_search(
|
||||||
&mut ctx,
|
&mut ctx,
|
||||||
@ -308,11 +308,11 @@ mod tests {
|
|||||||
0,
|
0,
|
||||||
20,
|
20,
|
||||||
&mut DefaultSearchLogger,
|
&mut DefaultSearchLogger,
|
||||||
&mut logger,
|
&mut DefaultSearchLogger,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
logger.write_d2_description(&mut ctx);
|
// logger.write_d2_description(&mut ctx);
|
||||||
|
|
||||||
let elapsed = start.elapsed();
|
let elapsed = start.elapsed();
|
||||||
println!("{}us", elapsed.as_micros());
|
println!("{}us", elapsed.as_micros());
|
||||||
@ -333,7 +333,7 @@ mod tests {
|
|||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
println!("{}us: {:?}", elapsed.as_micros(), results);
|
println!("{}us: {:?}", elapsed.as_micros(), results);
|
||||||
// }
|
}
|
||||||
// for (id, _document) in documents {
|
// for (id, _document) in documents {
|
||||||
// println!("{id}:");
|
// println!("{id}:");
|
||||||
// // println!("{document}");
|
// // println!("{document}");
|
||||||
|
@ -276,8 +276,8 @@ impl LocatedQueryTerm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Convert the tokenised search query into a list of located query terms.
|
/// Convert the tokenised search query into a list of located query terms.
|
||||||
pub fn located_query_terms_from_string<'search>(
|
pub fn located_query_terms_from_string<'ctx>(
|
||||||
ctx: &mut SearchContext<'search>,
|
ctx: &mut SearchContext<'ctx>,
|
||||||
query: NormalizedTokenIter<Vec<u8>>,
|
query: NormalizedTokenIter<Vec<u8>>,
|
||||||
words_limit: Option<usize>,
|
words_limit: Option<usize>,
|
||||||
) -> Result<Vec<LocatedQueryTerm>> {
|
) -> Result<Vec<LocatedQueryTerm>> {
|
||||||
|
@ -7,6 +7,12 @@ use crate::search::new::{QueryGraph, SearchContext};
|
|||||||
use crate::Result;
|
use crate::Result;
|
||||||
|
|
||||||
impl<G: RankingRuleGraphTrait> RankingRuleGraph<G> {
|
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
|
/// Build the ranking rule graph from the given query graph
|
||||||
pub fn build(ctx: &mut SearchContext, query_graph: QueryGraph) -> Result<Self> {
|
pub fn build(ctx: &mut SearchContext, query_graph: QueryGraph) -> Result<Self> {
|
||||||
let QueryGraph { nodes: graph_nodes, edges: graph_edges, .. } = &query_graph;
|
let QueryGraph { nodes: graph_nodes, edges: graph_edges, .. } = &query_graph;
|
||||||
|
@ -24,9 +24,9 @@ impl<G: RankingRuleGraphTrait> EdgeConditionsCache<G> {
|
|||||||
///
|
///
|
||||||
/// If the cache does not yet contain these docids, they are computed
|
/// If the cache does not yet contain these docids, they are computed
|
||||||
/// and inserted in the cache.
|
/// and inserted in the cache.
|
||||||
pub fn get_edge_docids<'s, 'search>(
|
pub fn get_edge_docids<'s, 'ctx>(
|
||||||
&'s mut self,
|
&'s mut self,
|
||||||
ctx: &mut SearchContext<'search>,
|
ctx: &mut SearchContext<'ctx>,
|
||||||
// TODO: should be Interned<EdgeCondition>
|
// TODO: should be Interned<EdgeCondition>
|
||||||
interned_edge_condition: Interned<G::EdgeCondition>,
|
interned_edge_condition: Interned<G::EdgeCondition>,
|
||||||
graph: &RankingRuleGraph<G>,
|
graph: &RankingRuleGraph<G>,
|
||||||
|
@ -69,47 +69,6 @@ pub struct Edge<E> {
|
|||||||
pub condition: EdgeCondition<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.
|
/// A trait to be implemented by a marker type to build a graph-based ranking rule.
|
||||||
///
|
///
|
||||||
/// It mostly describes how to:
|
/// It mostly describes how to:
|
||||||
@ -132,8 +91,8 @@ pub trait RankingRuleGraphTrait: Sized {
|
|||||||
|
|
||||||
/// Compute the document ids associated with the given edge condition,
|
/// Compute the document ids associated with the given edge condition,
|
||||||
/// restricted to the given universe.
|
/// restricted to the given universe.
|
||||||
fn resolve_edge_condition<'search>(
|
fn resolve_edge_condition<'ctx>(
|
||||||
ctx: &mut SearchContext<'search>,
|
ctx: &mut SearchContext<'ctx>,
|
||||||
edge_condition: &Self::EdgeCondition,
|
edge_condition: &Self::EdgeCondition,
|
||||||
universe: &RoaringBitmap,
|
universe: &RoaringBitmap,
|
||||||
) -> Result<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),
|
/// 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.
|
/// which builds the actual edges.
|
||||||
fn build_step_visit_source_node<'search>(
|
fn build_step_visit_source_node<'ctx>(
|
||||||
ctx: &mut SearchContext<'search>,
|
ctx: &mut SearchContext<'ctx>,
|
||||||
source_node: &QueryNode,
|
source_node: &QueryNode,
|
||||||
) -> Result<Option<Self::BuildVisitedFromNode>>;
|
) -> Result<Option<Self::BuildVisitedFromNode>>;
|
||||||
|
|
||||||
/// Return the cost and condition of the edges going from the previously visited node
|
/// 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`.
|
/// (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>(
|
fn build_step_visit_destination_node<'from_data, 'ctx: 'from_data>(
|
||||||
ctx: &mut SearchContext<'search>,
|
ctx: &mut SearchContext<'ctx>,
|
||||||
conditions_interner: &mut Interner<Self::EdgeCondition>,
|
conditions_interner: &mut Interner<Self::EdgeCondition>,
|
||||||
dest_node: &QueryNode,
|
dest_node: &QueryNode,
|
||||||
source_node_data: &'from_data Self::BuildVisitedFromNode,
|
source_node_data: &'from_data Self::BuildVisitedFromNode,
|
||||||
@ -177,16 +136,16 @@ pub struct RankingRuleGraph<G: RankingRuleGraphTrait> {
|
|||||||
pub edges_of_node: Vec<SmallBitmap>,
|
pub edges_of_node: Vec<SmallBitmap>,
|
||||||
pub conditions_interner: Interner<G::EdgeCondition>,
|
pub conditions_interner: Interner<G::EdgeCondition>,
|
||||||
}
|
}
|
||||||
// impl<G: RankingRuleGraphTrait> Clone for RankingRuleGraph<G> {
|
impl<G: RankingRuleGraphTrait> Clone for RankingRuleGraph<G> {
|
||||||
// fn clone(&self) -> Self {
|
fn clone(&self) -> Self {
|
||||||
// Self {
|
Self {
|
||||||
// query_graph: self.query_graph.clone(),
|
query_graph: self.query_graph.clone(),
|
||||||
// edges_store: self.edges_store.clone(),
|
edges_store: self.edges_store.clone(),
|
||||||
// edges_of_node: self.edges_of_node.clone(),
|
edges_of_node: self.edges_of_node.clone(),
|
||||||
// conditions_interner: self.conditions_interner.clone(),
|
conditions_interner: self.conditions_interner.clone(),
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
impl<G: RankingRuleGraphTrait> RankingRuleGraph<G> {
|
impl<G: RankingRuleGraphTrait> RankingRuleGraph<G> {
|
||||||
/// Remove the given edge from the ranking rule graph
|
/// Remove the given edge from the ranking rule graph
|
||||||
pub fn remove_ranking_rule_edge(&mut self, edge_index: u16) {
|
pub fn remove_ranking_rule_edge(&mut self, edge_index: u16) {
|
||||||
|
@ -58,8 +58,8 @@ pub fn visit_from_node(
|
|||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn visit_to_node<'search, 'from_data>(
|
pub fn visit_to_node<'ctx, 'from_data>(
|
||||||
ctx: &mut SearchContext<'search>,
|
ctx: &mut SearchContext<'ctx>,
|
||||||
conditions_interner: &mut Interner<ProximityEdge>,
|
conditions_interner: &mut Interner<ProximityEdge>,
|
||||||
to_node: &QueryNode,
|
to_node: &QueryNode,
|
||||||
from_node_data: &'from_data (WordDerivations, i8),
|
from_node_data: &'from_data (WordDerivations, i8),
|
||||||
|
@ -4,8 +4,8 @@ use super::{ProximityEdge, WordPair};
|
|||||||
use crate::search::new::SearchContext;
|
use crate::search::new::SearchContext;
|
||||||
use crate::{CboRoaringBitmapCodec, Result};
|
use crate::{CboRoaringBitmapCodec, Result};
|
||||||
|
|
||||||
pub fn compute_docids<'search>(
|
pub fn compute_docids<'ctx>(
|
||||||
ctx: &mut SearchContext<'search>,
|
ctx: &mut SearchContext<'ctx>,
|
||||||
edge: &ProximityEdge,
|
edge: &ProximityEdge,
|
||||||
universe: &RoaringBitmap,
|
universe: &RoaringBitmap,
|
||||||
) -> Result<RoaringBitmap> {
|
) -> Result<RoaringBitmap> {
|
||||||
|
@ -36,23 +36,23 @@ impl RankingRuleGraphTrait for ProximityGraph {
|
|||||||
format!(", prox {proximity}, {} pairs", pairs.len())
|
format!(", prox {proximity}, {} pairs", pairs.len())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resolve_edge_condition<'search>(
|
fn resolve_edge_condition<'ctx>(
|
||||||
ctx: &mut SearchContext<'search>,
|
ctx: &mut SearchContext<'ctx>,
|
||||||
edge: &Self::EdgeCondition,
|
edge: &Self::EdgeCondition,
|
||||||
universe: &RoaringBitmap,
|
universe: &RoaringBitmap,
|
||||||
) -> Result<roaring::RoaringBitmap> {
|
) -> Result<roaring::RoaringBitmap> {
|
||||||
compute_docids::compute_docids(ctx, edge, universe)
|
compute_docids::compute_docids(ctx, edge, universe)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_step_visit_source_node<'search>(
|
fn build_step_visit_source_node<'ctx>(
|
||||||
ctx: &mut SearchContext<'search>,
|
ctx: &mut SearchContext<'ctx>,
|
||||||
from_node: &QueryNode,
|
from_node: &QueryNode,
|
||||||
) -> Result<Option<Self::BuildVisitedFromNode>> {
|
) -> Result<Option<Self::BuildVisitedFromNode>> {
|
||||||
build::visit_from_node(ctx, from_node)
|
build::visit_from_node(ctx, from_node)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_step_visit_destination_node<'from_data, 'search: 'from_data>(
|
fn build_step_visit_destination_node<'from_data, 'ctx: 'from_data>(
|
||||||
ctx: &mut SearchContext<'search>,
|
ctx: &mut SearchContext<'ctx>,
|
||||||
conditions_interner: &mut Interner<Self::EdgeCondition>,
|
conditions_interner: &mut Interner<Self::EdgeCondition>,
|
||||||
to_node: &QueryNode,
|
to_node: &QueryNode,
|
||||||
from_node_data: &'from_data Self::BuildVisitedFromNode,
|
from_node_data: &'from_data Self::BuildVisitedFromNode,
|
||||||
|
@ -28,8 +28,8 @@ impl RankingRuleGraphTrait for TypoGraph {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resolve_edge_condition<'db_cache, 'search>(
|
fn resolve_edge_condition<'db_cache, 'ctx>(
|
||||||
ctx: &mut SearchContext<'search>,
|
ctx: &mut SearchContext<'ctx>,
|
||||||
edge: &Self::EdgeCondition,
|
edge: &Self::EdgeCondition,
|
||||||
universe: &RoaringBitmap,
|
universe: &RoaringBitmap,
|
||||||
) -> Result<RoaringBitmap> {
|
) -> Result<RoaringBitmap> {
|
||||||
@ -69,15 +69,15 @@ impl RankingRuleGraphTrait for TypoGraph {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_step_visit_source_node<'search>(
|
fn build_step_visit_source_node<'ctx>(
|
||||||
_ctx: &mut SearchContext<'search>,
|
_ctx: &mut SearchContext<'ctx>,
|
||||||
_from_node: &QueryNode,
|
_from_node: &QueryNode,
|
||||||
) -> Result<Option<Self::BuildVisitedFromNode>> {
|
) -> Result<Option<Self::BuildVisitedFromNode>> {
|
||||||
Ok(Some(()))
|
Ok(Some(()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_step_visit_destination_node<'from_data, 'search: 'from_data>(
|
fn build_step_visit_destination_node<'from_data, 'ctx: 'from_data>(
|
||||||
ctx: &mut SearchContext<'search>,
|
ctx: &mut SearchContext<'ctx>,
|
||||||
conditions_interner: &mut Interner<Self::EdgeCondition>,
|
conditions_interner: &mut Interner<Self::EdgeCondition>,
|
||||||
to_node: &QueryNode,
|
to_node: &QueryNode,
|
||||||
_from_node_data: &'from_data Self::BuildVisitedFromNode,
|
_from_node_data: &'from_data Self::BuildVisitedFromNode,
|
||||||
|
@ -17,10 +17,10 @@ impl RankingRuleQueryTrait for QueryGraph {}
|
|||||||
|
|
||||||
/// A trait that must be implemented by all ranking rules.
|
/// 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
|
/// (i.e. the read transaction and the cache) and over `Query`, which
|
||||||
/// can be either [`PlaceholderQuery`] or [`QueryGraph`].
|
/// can be either [`PlaceholderQuery`] or [`QueryGraph`].
|
||||||
pub trait RankingRule<'search, Query: RankingRuleQueryTrait> {
|
pub trait RankingRule<'ctx, Query: RankingRuleQueryTrait> {
|
||||||
fn id(&self) -> String;
|
fn id(&self) -> String;
|
||||||
|
|
||||||
/// Prepare the ranking rule such that it can start iterating over its
|
/// 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).
|
/// The given universe is the universe that will be given to [`next_bucket`](RankingRule::next_bucket).
|
||||||
fn start_iteration(
|
fn start_iteration(
|
||||||
&mut self,
|
&mut self,
|
||||||
ctx: &mut SearchContext<'search>,
|
ctx: &mut SearchContext<'ctx>,
|
||||||
logger: &mut dyn SearchLogger<Query>,
|
logger: &mut dyn SearchLogger<Query>,
|
||||||
universe: &RoaringBitmap,
|
universe: &RoaringBitmap,
|
||||||
query: &Query,
|
query: &Query,
|
||||||
@ -44,7 +44,7 @@ pub trait RankingRule<'search, Query: RankingRuleQueryTrait> {
|
|||||||
/// - the universe given to [`start_iteration`](RankingRule::start_iteration)
|
/// - the universe given to [`start_iteration`](RankingRule::start_iteration)
|
||||||
fn next_bucket(
|
fn next_bucket(
|
||||||
&mut self,
|
&mut self,
|
||||||
ctx: &mut SearchContext<'search>,
|
ctx: &mut SearchContext<'ctx>,
|
||||||
logger: &mut dyn SearchLogger<Query>,
|
logger: &mut dyn SearchLogger<Query>,
|
||||||
universe: &RoaringBitmap,
|
universe: &RoaringBitmap,
|
||||||
) -> Result<Option<RankingRuleOutput<Query>>>;
|
) -> 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).
|
/// The next call to this ranking rule, if any, will be [`start_iteration`](RankingRule::start_iteration).
|
||||||
fn end_iteration(
|
fn end_iteration(
|
||||||
&mut self,
|
&mut self,
|
||||||
ctx: &mut SearchContext<'search>,
|
ctx: &mut SearchContext<'ctx>,
|
||||||
logger: &mut dyn SearchLogger<Query>,
|
logger: &mut dyn SearchLogger<Query>,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -68,15 +68,16 @@ pub struct RankingRuleOutput<Q> {
|
|||||||
pub candidates: RoaringBitmap,
|
pub candidates: RoaringBitmap,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn bucket_sort<'search, Q: RankingRuleQueryTrait>(
|
pub fn bucket_sort<'ctx, Q: RankingRuleQueryTrait>(
|
||||||
ctx: &mut SearchContext<'search>,
|
ctx: &mut SearchContext<'ctx>,
|
||||||
mut ranking_rules: Vec<Box<dyn RankingRule<'search, Q>>>,
|
mut ranking_rules: Vec<Box<dyn RankingRule<'ctx, Q>>>,
|
||||||
query: &Q,
|
query: &Q,
|
||||||
universe: &RoaringBitmap,
|
universe: &RoaringBitmap,
|
||||||
from: usize,
|
from: usize,
|
||||||
length: usize,
|
length: usize,
|
||||||
logger: &mut dyn SearchLogger<Q>,
|
logger: &mut dyn SearchLogger<Q>,
|
||||||
) -> Result<Vec<u32>> {
|
) -> Result<Vec<u32>> {
|
||||||
|
logger.initial_query(query);
|
||||||
logger.ranking_rules(&ranking_rules);
|
logger.ranking_rules(&ranking_rules);
|
||||||
logger.initial_universe(universe);
|
logger.initial_universe(universe);
|
||||||
|
|
||||||
|
@ -21,11 +21,11 @@ pub struct QueryTermDocIdsCache {
|
|||||||
}
|
}
|
||||||
impl QueryTermDocIdsCache {
|
impl QueryTermDocIdsCache {
|
||||||
/// Get the document ids associated with the given phrase
|
/// 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,
|
&'s mut self,
|
||||||
index: &Index,
|
index: &Index,
|
||||||
txn: &'search RoTxn,
|
txn: &'ctx RoTxn,
|
||||||
db_cache: &mut DatabaseCache<'search>,
|
db_cache: &mut DatabaseCache<'ctx>,
|
||||||
word_interner: &Interner<String>,
|
word_interner: &Interner<String>,
|
||||||
phrase_interner: &Interner<Phrase>,
|
phrase_interner: &Interner<Phrase>,
|
||||||
phrase: Interned<Phrase>,
|
phrase: Interned<Phrase>,
|
||||||
@ -40,11 +40,11 @@ impl QueryTermDocIdsCache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get the document ids associated with the given word derivations
|
/// 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,
|
&'s mut self,
|
||||||
index: &Index,
|
index: &Index,
|
||||||
txn: &'search RoTxn,
|
txn: &'ctx RoTxn,
|
||||||
db_cache: &mut DatabaseCache<'search>,
|
db_cache: &mut DatabaseCache<'ctx>,
|
||||||
word_interner: &Interner<String>,
|
word_interner: &Interner<String>,
|
||||||
derivations_interner: &Interner<WordDerivations>,
|
derivations_interner: &Interner<WordDerivations>,
|
||||||
phrase_interner: &Interner<Phrase>,
|
phrase_interner: &Interner<Phrase>,
|
||||||
@ -110,11 +110,11 @@ impl QueryTermDocIdsCache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get the document ids associated with the given query term.
|
/// 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,
|
&'s mut self,
|
||||||
index: &Index,
|
index: &Index,
|
||||||
txn: &'search RoTxn,
|
txn: &'ctx RoTxn,
|
||||||
db_cache: &mut DatabaseCache<'search>,
|
db_cache: &mut DatabaseCache<'ctx>,
|
||||||
word_interner: &Interner<String>,
|
word_interner: &Interner<String>,
|
||||||
derivations_interner: &Interner<WordDerivations>,
|
derivations_interner: &Interner<WordDerivations>,
|
||||||
phrase_interner: &Interner<Phrase>,
|
phrase_interner: &Interner<Phrase>,
|
||||||
@ -137,8 +137,8 @@ impl QueryTermDocIdsCache {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn resolve_query_graph<'search>(
|
pub fn resolve_query_graph<'ctx>(
|
||||||
ctx: &mut SearchContext<'search>,
|
ctx: &mut SearchContext<'ctx>,
|
||||||
q: &QueryGraph,
|
q: &QueryGraph,
|
||||||
universe: &RoaringBitmap,
|
universe: &RoaringBitmap,
|
||||||
) -> Result<RoaringBitmap> {
|
) -> Result<RoaringBitmap> {
|
||||||
@ -214,10 +214,10 @@ pub fn resolve_query_graph<'search>(
|
|||||||
panic!()
|
panic!()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn resolve_phrase<'search>(
|
pub fn resolve_phrase<'ctx>(
|
||||||
index: &Index,
|
index: &Index,
|
||||||
txn: &'search RoTxn,
|
txn: &'ctx RoTxn,
|
||||||
db_cache: &mut DatabaseCache<'search>,
|
db_cache: &mut DatabaseCache<'ctx>,
|
||||||
word_interner: &Interner<String>,
|
word_interner: &Interner<String>,
|
||||||
phrase_interner: &Interner<Phrase>,
|
phrase_interner: &Interner<Phrase>,
|
||||||
phrase: Interned<Phrase>,
|
phrase: Interned<Phrase>,
|
||||||
|
@ -3,21 +3,19 @@ use roaring::RoaringBitmap;
|
|||||||
use super::logger::SearchLogger;
|
use super::logger::SearchLogger;
|
||||||
use super::{RankingRule, RankingRuleOutput, RankingRuleQueryTrait, SearchContext};
|
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>>>;
|
fn next_bucket(&mut self) -> Result<Option<RankingRuleOutput<Query>>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct RankingRuleOutputIterWrapper<'search, Query> {
|
pub struct RankingRuleOutputIterWrapper<'ctx, Query> {
|
||||||
iter: Box<dyn Iterator<Item = Result<RankingRuleOutput<Query>>> + 'search>,
|
iter: Box<dyn Iterator<Item = Result<RankingRuleOutput<Query>>> + 'ctx>,
|
||||||
}
|
}
|
||||||
impl<'search, Query> RankingRuleOutputIterWrapper<'search, Query> {
|
impl<'ctx, Query> RankingRuleOutputIterWrapper<'ctx, Query> {
|
||||||
pub fn new(iter: Box<dyn Iterator<Item = Result<RankingRuleOutput<Query>>> + 'search>) -> Self {
|
pub fn new(iter: Box<dyn Iterator<Item = Result<RankingRuleOutput<Query>>> + 'ctx>) -> Self {
|
||||||
Self { iter }
|
Self { iter }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<'search, Query> RankingRuleOutputIter<'search, Query>
|
impl<'ctx, Query> RankingRuleOutputIter<'ctx, Query> for RankingRuleOutputIterWrapper<'ctx, Query> {
|
||||||
for RankingRuleOutputIterWrapper<'search, Query>
|
|
||||||
{
|
|
||||||
fn next_bucket(&mut self) -> Result<Option<RankingRuleOutput<Query>>> {
|
fn next_bucket(&mut self) -> Result<Option<RankingRuleOutput<Query>>> {
|
||||||
match self.iter.next() {
|
match self.iter.next() {
|
||||||
Some(x) => x.map(Some),
|
Some(x) => x.map(Some),
|
||||||
@ -35,17 +33,17 @@ use crate::{
|
|||||||
Result,
|
Result,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct Sort<'search, Query> {
|
pub struct Sort<'ctx, Query> {
|
||||||
field_name: String,
|
field_name: String,
|
||||||
field_id: Option<FieldId>,
|
field_id: Option<FieldId>,
|
||||||
is_ascending: bool,
|
is_ascending: bool,
|
||||||
original_query: Option<Query>,
|
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(
|
pub fn _new(
|
||||||
index: &Index,
|
index: &Index,
|
||||||
rtxn: &'search heed::RoTxn,
|
rtxn: &'ctx heed::RoTxn,
|
||||||
field_name: String,
|
field_name: String,
|
||||||
is_ascending: bool,
|
is_ascending: bool,
|
||||||
) -> Result<Self> {
|
) -> 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 {
|
fn id(&self) -> String {
|
||||||
let Self { field_name, is_ascending, .. } = self;
|
let Self { field_name, is_ascending, .. } = self;
|
||||||
format!("{field_name}:{}", if *is_ascending { "asc" } else { "desc " })
|
format!("{field_name}:{}", if *is_ascending { "asc" } else { "desc " })
|
||||||
}
|
}
|
||||||
fn start_iteration(
|
fn start_iteration(
|
||||||
&mut self,
|
&mut self,
|
||||||
ctx: &mut SearchContext<'search>,
|
ctx: &mut SearchContext<'ctx>,
|
||||||
_logger: &mut dyn SearchLogger<Query>,
|
_logger: &mut dyn SearchLogger<Query>,
|
||||||
parent_candidates: &RoaringBitmap,
|
parent_candidates: &RoaringBitmap,
|
||||||
parent_query_graph: &Query,
|
parent_query_graph: &Query,
|
||||||
@ -106,7 +104,7 @@ impl<'search, Query: RankingRuleQueryTrait> RankingRule<'search, Query> for Sort
|
|||||||
|
|
||||||
fn next_bucket(
|
fn next_bucket(
|
||||||
&mut self,
|
&mut self,
|
||||||
_ctx: &mut SearchContext<'search>,
|
_ctx: &mut SearchContext<'ctx>,
|
||||||
_logger: &mut dyn SearchLogger<Query>,
|
_logger: &mut dyn SearchLogger<Query>,
|
||||||
universe: &RoaringBitmap,
|
universe: &RoaringBitmap,
|
||||||
) -> Result<Option<RankingRuleOutput<Query>>> {
|
) -> Result<Option<RankingRuleOutput<Query>>> {
|
||||||
@ -123,7 +121,7 @@ impl<'search, Query: RankingRuleQueryTrait> RankingRule<'search, Query> for Sort
|
|||||||
|
|
||||||
fn end_iteration(
|
fn end_iteration(
|
||||||
&mut self,
|
&mut self,
|
||||||
_ctx: &mut SearchContext<'search>,
|
_ctx: &mut SearchContext<'ctx>,
|
||||||
_logger: &mut dyn SearchLogger<Query>,
|
_logger: &mut dyn SearchLogger<Query>,
|
||||||
) {
|
) {
|
||||||
self.original_query = None;
|
self.original_query = None;
|
||||||
|
@ -26,13 +26,13 @@ impl Words {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'search> RankingRule<'search, QueryGraph> for Words {
|
impl<'ctx> RankingRule<'ctx, QueryGraph> for Words {
|
||||||
fn id(&self) -> String {
|
fn id(&self) -> String {
|
||||||
"words".to_owned()
|
"words".to_owned()
|
||||||
}
|
}
|
||||||
fn start_iteration(
|
fn start_iteration(
|
||||||
&mut self,
|
&mut self,
|
||||||
_ctx: &mut SearchContext<'search>,
|
_ctx: &mut SearchContext<'ctx>,
|
||||||
_logger: &mut dyn SearchLogger<QueryGraph>,
|
_logger: &mut dyn SearchLogger<QueryGraph>,
|
||||||
_parent_candidates: &RoaringBitmap,
|
_parent_candidates: &RoaringBitmap,
|
||||||
parent_query_graph: &QueryGraph,
|
parent_query_graph: &QueryGraph,
|
||||||
@ -65,7 +65,7 @@ impl<'search> RankingRule<'search, QueryGraph> for Words {
|
|||||||
|
|
||||||
fn next_bucket(
|
fn next_bucket(
|
||||||
&mut self,
|
&mut self,
|
||||||
ctx: &mut SearchContext<'search>,
|
ctx: &mut SearchContext<'ctx>,
|
||||||
logger: &mut dyn SearchLogger<QueryGraph>,
|
logger: &mut dyn SearchLogger<QueryGraph>,
|
||||||
universe: &RoaringBitmap,
|
universe: &RoaringBitmap,
|
||||||
) -> Result<Option<RankingRuleOutput<QueryGraph>>> {
|
) -> Result<Option<RankingRuleOutput<QueryGraph>>> {
|
||||||
@ -101,7 +101,7 @@ impl<'search> RankingRule<'search, QueryGraph> for Words {
|
|||||||
|
|
||||||
fn end_iteration(
|
fn end_iteration(
|
||||||
&mut self,
|
&mut self,
|
||||||
_ctx: &mut SearchContext<'search>,
|
_ctx: &mut SearchContext<'ctx>,
|
||||||
_logger: &mut dyn SearchLogger<QueryGraph>,
|
_logger: &mut dyn SearchLogger<QueryGraph>,
|
||||||
) {
|
) {
|
||||||
self.iterating = false;
|
self.iterating = false;
|
||||||
|
Loading…
Reference in New Issue
Block a user