2023-02-23 20:13:19 +08:00
|
|
|
#[cfg(test)]
|
2023-02-22 22:34:37 +08:00
|
|
|
pub mod detailed;
|
|
|
|
|
|
|
|
use roaring::RoaringBitmap;
|
|
|
|
|
2023-03-16 16:58:59 +08:00
|
|
|
use super::interner::{Interned, MappedInterner};
|
2023-03-14 23:37:47 +08:00
|
|
|
use super::query_graph::QueryNode;
|
|
|
|
use super::ranking_rule_graph::{
|
2023-03-15 19:52:40 +08:00
|
|
|
DeadEndPathCache, ProximityCondition, ProximityGraph, RankingRuleGraph, TypoEdge, TypoGraph,
|
2023-03-14 23:37:47 +08:00
|
|
|
};
|
2023-03-08 16:55:53 +08:00
|
|
|
use super::small_bitmap::SmallBitmap;
|
|
|
|
use super::{RankingRule, RankingRuleQueryTrait};
|
2023-02-22 22:34:37 +08:00
|
|
|
|
2023-03-08 20:26:29 +08:00
|
|
|
/// Trait for structure logging the execution of a search query.
|
|
|
|
pub trait SearchLogger<Q: RankingRuleQueryTrait> {
|
|
|
|
/// Logs the initial query
|
|
|
|
fn initial_query(&mut self, query: &Q);
|
|
|
|
|
|
|
|
/// Logs the query that was used to compute the set of all candidates
|
|
|
|
fn query_for_universe(&mut self, query: &Q);
|
|
|
|
|
|
|
|
/// Logs the value of the initial set of all candidates
|
|
|
|
fn initial_universe(&mut self, universe: &RoaringBitmap);
|
|
|
|
|
|
|
|
/// Logs the ranking rules used to perform the search query
|
2023-03-13 16:52:17 +08:00
|
|
|
fn ranking_rules(&mut self, rr: &[Box<dyn RankingRule<Q>>]);
|
2023-03-08 20:26:29 +08:00
|
|
|
|
|
|
|
/// Logs the start of a ranking rule's iteration.
|
|
|
|
fn start_iteration_ranking_rule<'transaction>(
|
|
|
|
&mut self,
|
|
|
|
ranking_rule_idx: usize,
|
|
|
|
ranking_rule: &dyn RankingRule<'transaction, Q>,
|
|
|
|
query: &Q,
|
|
|
|
universe: &RoaringBitmap,
|
|
|
|
);
|
|
|
|
/// Logs the end of the computation of a ranking rule bucket
|
|
|
|
fn next_bucket_ranking_rule<'transaction>(
|
|
|
|
&mut self,
|
|
|
|
ranking_rule_idx: usize,
|
|
|
|
ranking_rule: &dyn RankingRule<'transaction, Q>,
|
|
|
|
universe: &RoaringBitmap,
|
|
|
|
candidates: &RoaringBitmap,
|
|
|
|
);
|
|
|
|
/// Logs the skipping of a ranking rule bucket
|
|
|
|
fn skip_bucket_ranking_rule<'transaction>(
|
|
|
|
&mut self,
|
|
|
|
ranking_rule_idx: usize,
|
|
|
|
ranking_rule: &dyn RankingRule<'transaction, Q>,
|
|
|
|
candidates: &RoaringBitmap,
|
|
|
|
);
|
|
|
|
/// Logs the end of a ranking rule's iteration.
|
|
|
|
fn end_iteration_ranking_rule<'transaction>(
|
|
|
|
&mut self,
|
|
|
|
ranking_rule_idx: usize,
|
|
|
|
ranking_rule: &dyn RankingRule<'transaction, Q>,
|
|
|
|
universe: &RoaringBitmap,
|
|
|
|
);
|
|
|
|
/// Logs the addition of document ids to the final results
|
|
|
|
fn add_to_results(&mut self, docids: &[u32]);
|
|
|
|
|
|
|
|
/// Logs the internal state of the words ranking rule
|
|
|
|
fn log_words_state(&mut self, query_graph: &Q);
|
|
|
|
|
|
|
|
/// Logs the internal state of the proximity ranking rule
|
|
|
|
fn log_proximity_state(
|
|
|
|
&mut self,
|
|
|
|
query_graph: &RankingRuleGraph<ProximityGraph>,
|
2023-03-16 16:58:59 +08:00
|
|
|
paths: &[Vec<Interned<ProximityCondition>>],
|
2023-03-16 18:52:51 +08:00
|
|
|
dead_end_path_cache: &DeadEndPathCache<ProximityGraph>,
|
2023-03-08 20:26:29 +08:00
|
|
|
universe: &RoaringBitmap,
|
2023-03-15 19:52:40 +08:00
|
|
|
distances: &MappedInterner<Vec<(u16, SmallBitmap<ProximityCondition>)>, QueryNode>,
|
2023-03-08 20:26:29 +08:00
|
|
|
cost: u16,
|
|
|
|
);
|
|
|
|
|
|
|
|
/// Logs the internal state of the typo ranking rule
|
|
|
|
fn log_typo_state(
|
|
|
|
&mut self,
|
|
|
|
query_graph: &RankingRuleGraph<TypoGraph>,
|
2023-03-16 16:58:59 +08:00
|
|
|
paths: &[Vec<Interned<TypoEdge>>],
|
2023-03-16 18:52:51 +08:00
|
|
|
dead_end_path_cache: &DeadEndPathCache<TypoGraph>,
|
2023-03-08 20:26:29 +08:00
|
|
|
universe: &RoaringBitmap,
|
2023-03-14 23:37:47 +08:00
|
|
|
distances: &MappedInterner<Vec<(u16, SmallBitmap<TypoEdge>)>, QueryNode>,
|
2023-03-08 20:26:29 +08:00
|
|
|
cost: u16,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// A dummy [`SearchLogger`] which does nothing.
|
2023-02-22 22:34:37 +08:00
|
|
|
pub struct DefaultSearchLogger;
|
2023-03-08 20:26:29 +08:00
|
|
|
|
2023-02-22 22:34:37 +08:00
|
|
|
impl<Q: RankingRuleQueryTrait> SearchLogger<Q> for DefaultSearchLogger {
|
2023-03-06 15:35:01 +08:00
|
|
|
fn initial_query(&mut self, _query: &Q) {}
|
|
|
|
|
|
|
|
fn query_for_universe(&mut self, _query: &Q) {}
|
2023-02-22 22:34:37 +08:00
|
|
|
|
2023-02-28 18:49:24 +08:00
|
|
|
fn initial_universe(&mut self, _universe: &RoaringBitmap) {}
|
2023-02-22 22:34:37 +08:00
|
|
|
|
2023-03-13 16:52:17 +08:00
|
|
|
fn ranking_rules(&mut self, _rr: &[Box<dyn RankingRule<Q>>]) {}
|
2023-03-03 04:27:42 +08:00
|
|
|
|
2023-02-22 22:34:37 +08:00
|
|
|
fn start_iteration_ranking_rule<'transaction>(
|
|
|
|
&mut self,
|
2023-02-28 18:49:24 +08:00
|
|
|
_ranking_rule_idx: usize,
|
|
|
|
_ranking_rule: &dyn RankingRule<'transaction, Q>,
|
|
|
|
_query: &Q,
|
|
|
|
_universe: &RoaringBitmap,
|
2023-02-22 22:34:37 +08:00
|
|
|
) {
|
|
|
|
}
|
|
|
|
|
|
|
|
fn next_bucket_ranking_rule<'transaction>(
|
|
|
|
&mut self,
|
2023-02-28 18:49:24 +08:00
|
|
|
_ranking_rule_idx: usize,
|
|
|
|
_ranking_rule: &dyn RankingRule<'transaction, Q>,
|
|
|
|
_universe: &RoaringBitmap,
|
2023-03-03 04:27:42 +08:00
|
|
|
_candidates: &RoaringBitmap,
|
2023-02-22 22:34:37 +08:00
|
|
|
) {
|
|
|
|
}
|
2023-02-27 23:14:53 +08:00
|
|
|
fn skip_bucket_ranking_rule<'transaction>(
|
|
|
|
&mut self,
|
2023-02-28 18:49:24 +08:00
|
|
|
_ranking_rule_idx: usize,
|
|
|
|
_ranking_rule: &dyn RankingRule<'transaction, Q>,
|
|
|
|
_candidates: &RoaringBitmap,
|
2023-02-27 23:14:53 +08:00
|
|
|
) {
|
|
|
|
}
|
2023-02-22 22:34:37 +08:00
|
|
|
|
|
|
|
fn end_iteration_ranking_rule<'transaction>(
|
|
|
|
&mut self,
|
2023-02-28 18:49:24 +08:00
|
|
|
_ranking_rule_idx: usize,
|
|
|
|
_ranking_rule: &dyn RankingRule<'transaction, Q>,
|
|
|
|
_universe: &RoaringBitmap,
|
2023-02-22 22:34:37 +08:00
|
|
|
) {
|
|
|
|
}
|
|
|
|
|
2023-02-28 18:49:24 +08:00
|
|
|
fn add_to_results(&mut self, _docids: &[u32]) {}
|
2023-02-22 22:34:37 +08:00
|
|
|
|
2023-02-28 18:49:24 +08:00
|
|
|
fn log_words_state(&mut self, _query_graph: &Q) {}
|
2023-02-23 20:13:19 +08:00
|
|
|
|
|
|
|
fn log_proximity_state(
|
|
|
|
&mut self,
|
2023-02-28 18:49:24 +08:00
|
|
|
_query_graph: &RankingRuleGraph<ProximityGraph>,
|
2023-03-16 16:58:59 +08:00
|
|
|
_paths_map: &[Vec<Interned<ProximityCondition>>],
|
2023-03-16 18:52:51 +08:00
|
|
|
_dead_end_path_cache: &DeadEndPathCache<ProximityGraph>,
|
2023-03-03 04:27:42 +08:00
|
|
|
_universe: &RoaringBitmap,
|
2023-03-15 19:52:40 +08:00
|
|
|
_distances: &MappedInterner<Vec<(u16, SmallBitmap<ProximityCondition>)>, QueryNode>,
|
2023-03-07 21:42:58 +08:00
|
|
|
_cost: u16,
|
2023-02-23 20:13:19 +08:00
|
|
|
) {
|
|
|
|
}
|
2023-02-28 21:19:57 +08:00
|
|
|
|
|
|
|
fn log_typo_state(
|
|
|
|
&mut self,
|
2023-03-03 04:27:42 +08:00
|
|
|
_query_graph: &RankingRuleGraph<TypoGraph>,
|
2023-03-16 16:58:59 +08:00
|
|
|
_paths: &[Vec<Interned<TypoEdge>>],
|
2023-03-16 18:52:51 +08:00
|
|
|
_dead_end_path_cache: &DeadEndPathCache<TypoGraph>,
|
2023-03-03 04:27:42 +08:00
|
|
|
_universe: &RoaringBitmap,
|
2023-03-14 23:37:47 +08:00
|
|
|
_distances: &MappedInterner<Vec<(u16, SmallBitmap<TypoEdge>)>, QueryNode>,
|
2023-03-07 21:42:58 +08:00
|
|
|
_cost: u16,
|
2023-02-28 21:19:57 +08:00
|
|
|
) {
|
|
|
|
}
|
2023-02-22 22:34:37 +08:00
|
|
|
}
|