Simplify the logger

This commit is contained in:
Loïc Lecrenier
2023-04-06 16:24:44 +02:00
parent 7ab48ed8c7
commit 96183e804a
9 changed files with 38 additions and 205 deletions

View File

@ -1,3 +1,4 @@
use std::any::Any;
use std::fs::File;
use std::io::Write;
use std::path::PathBuf;
@ -6,6 +7,7 @@ use std::time::Instant;
// use rand::random;
use roaring::RoaringBitmap;
use crate::search::new::graph_based_ranking_rule::Typo;
use crate::search::new::interner::{Interned, MappedInterner};
use crate::search::new::query_graph::QueryNodeData;
use crate::search::new::query_term::LocatedQueryTermSubset;
@ -14,6 +16,8 @@ use crate::search::new::ranking_rule_graph::{
RankingRuleGraphTrait, TypoCondition, TypoGraph,
};
use crate::search::new::ranking_rules::BoxRankingRule;
use crate::search::new::sort::Sort;
use crate::search::new::words::Words;
use crate::search::new::{QueryGraph, QueryNode, RankingRule, SearchContext, SearchLogger};
pub enum SearchEvents {
@ -92,7 +96,7 @@ impl SearchLogger<QueryGraph> for DetailedSearchLogger {
self.initial_query_time = Some(Instant::now());
}
fn query_for_universe(&mut self, query: &QueryGraph) {
fn query_for_initial_universe(&mut self, query: &QueryGraph) {
self.query_for_universe = Some(query.clone());
}
@ -161,46 +165,12 @@ impl SearchLogger<QueryGraph> for DetailedSearchLogger {
self.events.push(SearchEvents::ExtendResults { new: docids.to_vec() });
}
fn log_words_state(&mut self, query_graph: &QueryGraph) {
self.events.push(SearchEvents::WordsState { query_graph: query_graph.clone() });
}
fn log_proximity_state(
&mut self,
query_graph: &RankingRuleGraph<ProximityGraph>,
paths_map: &[Vec<Interned<ProximityCondition>>],
dead_ends_cache: &DeadEndsCache<ProximityCondition>,
universe: &RoaringBitmap,
costs: &MappedInterner<QueryNode, Vec<u64>>,
cost: u64,
) {
self.events.push(SearchEvents::ProximityState {
graph: query_graph.clone(),
paths: paths_map.to_vec(),
dead_ends_cache: dead_ends_cache.clone(),
universe: universe.clone(),
costs: costs.clone(),
cost,
})
}
fn log_typo_state(
&mut self,
query_graph: &RankingRuleGraph<TypoGraph>,
paths_map: &[Vec<Interned<TypoCondition>>],
dead_ends_cache: &DeadEndsCache<TypoCondition>,
universe: &RoaringBitmap,
costs: &MappedInterner<QueryNode, Vec<u64>>,
cost: u64,
) {
self.events.push(SearchEvents::TypoState {
graph: query_graph.clone(),
paths: paths_map.to_vec(),
dead_ends_cache: dead_ends_cache.clone(),
universe: universe.clone(),
costs: costs.clone(),
cost,
})
/// Logs the internal state of the ranking rule
fn log_ranking_rule_state<'ctx>(&mut self, state: &(dyn Any + 'ctx)) {
if let Some(_words) = state.downcast_ref::<Words>() {
} else if let Some(_sort) = state.downcast_ref::<Sort<'ctx, QueryGraph>>() {
} else if let Some(_typo) = state.downcast_ref::<Typo>() {
}
}
}
@ -567,9 +537,8 @@ results.{cur_ranking_rule}{cur_activated_id} {{
file,
"{condition_id} {{
shape: class
{}
label
}}",
R::label_for_condition(ctx, condition).unwrap()
)
.unwrap();
}

View File

@ -1,14 +1,14 @@
// #[cfg(test)]
pub mod detailed;
use std::any::Any;
use roaring::RoaringBitmap;
use super::interner::{Interned, MappedInterner};
use super::query_graph::QueryNode;
use super::ranking_rule_graph::{
DeadEndsCache, ProximityCondition, ProximityGraph, RankingRuleGraph, TypoCondition, TypoGraph,
};
use super::graph_based_ranking_rule::Typo;
use super::ranking_rules::BoxRankingRule;
use super::sort::Sort;
use super::words::Words;
use super::{RankingRule, RankingRuleQueryTrait};
/// Trait for structure logging the execution of a search query.
@ -16,12 +16,12 @@ 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 query that was used to compute the set of all candidates
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>]);
@ -58,30 +58,13 @@ pub trait SearchLogger<Q: RankingRuleQueryTrait> {
/// 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>,
paths: &[Vec<Interned<ProximityCondition>>],
dead_ends_cache: &DeadEndsCache<ProximityCondition>,
universe: &RoaringBitmap,
distances: &MappedInterner<QueryNode, Vec<u64>>,
cost: u64,
);
/// Logs the internal state of the typo ranking rule
fn log_typo_state(
&mut self,
query_graph: &RankingRuleGraph<TypoGraph>,
paths: &[Vec<Interned<TypoCondition>>],
dead_ends_cache: &DeadEndsCache<TypoCondition>,
universe: &RoaringBitmap,
distances: &MappedInterner<QueryNode, Vec<u64>>,
cost: u64,
);
/// Logs the internal state of the ranking rule
fn log_ranking_rule_state<'ctx>(&mut self, rr: &(dyn Any + 'ctx)) {
if let Some(_words) = rr.downcast_ref::<Words>() {
} else if let Some(_sort) = rr.downcast_ref::<Sort<'ctx, Q>>() {
} else if let Some(_typo) = rr.downcast_ref::<Typo>() {
}
}
}
/// A dummy [`SearchLogger`] which does nothing.
@ -90,7 +73,7 @@ pub struct DefaultSearchLogger;
impl<Q: RankingRuleQueryTrait> SearchLogger<Q> for DefaultSearchLogger {
fn initial_query(&mut self, _query: &Q) {}
fn query_for_universe(&mut self, _query: &Q) {}
fn query_for_initial_universe(&mut self, _query: &Q) {}
fn initial_universe(&mut self, _universe: &RoaringBitmap) {}
@ -130,28 +113,4 @@ impl<Q: RankingRuleQueryTrait> SearchLogger<Q> for DefaultSearchLogger {
}
fn add_to_results(&mut self, _docids: &[u32]) {}
fn log_words_state(&mut self, _query_graph: &Q) {}
fn log_proximity_state(
&mut self,
_query_graph: &RankingRuleGraph<ProximityGraph>,
_paths_map: &[Vec<Interned<ProximityCondition>>],
_dead_ends_cache: &DeadEndsCache<ProximityCondition>,
_universe: &RoaringBitmap,
_distances: &MappedInterner<QueryNode, Vec<u64>>,
_cost: u64,
) {
}
fn log_typo_state(
&mut self,
_query_graph: &RankingRuleGraph<TypoGraph>,
_paths: &[Vec<Interned<TypoCondition>>],
_dead_ends_cache: &DeadEndsCache<TypoCondition>,
_universe: &RoaringBitmap,
_distances: &MappedInterner<QueryNode, Vec<u64>>,
_cost: u64,
) {
}
}