mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-02-17 08:10:14 +08:00
Simplify the logger
This commit is contained in:
parent
7ab48ed8c7
commit
96183e804a
@ -190,10 +190,8 @@ impl<'ctx, G: RankingRuleGraphTrait> RankingRule<'ctx, QueryGraph> for GraphBase
|
||||
cur_distance_idx: _,
|
||||
} = &mut state;
|
||||
|
||||
let original_universe = universe;
|
||||
let mut universe = universe.clone();
|
||||
|
||||
let original_graph = graph.clone();
|
||||
let mut used_conditions = SmallBitmap::for_interned_values_in(&graph.conditions_interner);
|
||||
let mut good_paths = vec![];
|
||||
let mut considered_paths = vec![];
|
||||
@ -272,16 +270,6 @@ impl<'ctx, G: RankingRuleGraphTrait> RankingRule<'ctx, QueryGraph> for GraphBase
|
||||
}
|
||||
})?;
|
||||
|
||||
G::log_state(
|
||||
&original_graph,
|
||||
&considered_paths,
|
||||
dead_ends_cache,
|
||||
original_universe,
|
||||
all_costs,
|
||||
cost,
|
||||
logger,
|
||||
);
|
||||
|
||||
// We modify the next query graph so that it only contains the subgraph
|
||||
// that was used to compute this bucket
|
||||
// But we only do it in case the bucket length is >1, because otherwise
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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,
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ fn resolve_maximally_reduced_query_graph(
|
||||
};
|
||||
graph.remove_nodes_keep_edges(&nodes_to_remove);
|
||||
|
||||
logger.query_for_universe(&graph);
|
||||
logger.query_for_initial_universe(&graph);
|
||||
let docids = compute_query_graph_docids(ctx, &graph, universe)?;
|
||||
|
||||
Ok(docids)
|
||||
|
@ -1,11 +1,10 @@
|
||||
use heed::BytesDecode;
|
||||
use roaring::RoaringBitmap;
|
||||
|
||||
use super::{ComputedCondition, DeadEndsCache, RankingRuleGraph, RankingRuleGraphTrait};
|
||||
use crate::search::new::interner::{DedupInterner, Interned, MappedInterner};
|
||||
use crate::search::new::query_graph::{QueryGraph, QueryNode};
|
||||
use super::{ComputedCondition, RankingRuleGraphTrait};
|
||||
use crate::search::new::interner::{DedupInterner, Interned};
|
||||
use crate::search::new::query_term::{ExactTerm, LocatedQueryTermSubset};
|
||||
use crate::{Result, RoaringBitmapCodec, SearchContext, SearchLogger};
|
||||
use crate::{Result, RoaringBitmapCodec, SearchContext};
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Hash)]
|
||||
pub enum ExactnessCondition {
|
||||
@ -77,26 +76,4 @@ impl RankingRuleGraphTrait for ExactnessGraph {
|
||||
|
||||
Ok(vec![(0, exact_condition), (dest_node.term_ids.len() as u32, skip_condition)])
|
||||
}
|
||||
|
||||
fn log_state(
|
||||
_graph: &RankingRuleGraph<Self>,
|
||||
_paths: &[Vec<Interned<Self::Condition>>],
|
||||
_dead_ends_cache: &DeadEndsCache<Self::Condition>,
|
||||
_niverse: &RoaringBitmap,
|
||||
_costs: &MappedInterner<QueryNode, Vec<u64>>,
|
||||
_cost: u64,
|
||||
_logger: &mut dyn SearchLogger<QueryGraph>,
|
||||
) {
|
||||
}
|
||||
|
||||
fn label_for_condition(
|
||||
_ctx: &mut SearchContext,
|
||||
condition: &Self::Condition,
|
||||
) -> Result<String> {
|
||||
Ok(match condition {
|
||||
ExactnessCondition::ExactInAttribute(_) => "exact",
|
||||
ExactnessCondition::Skip(_) => "skip",
|
||||
}
|
||||
.to_owned())
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,6 @@ use roaring::RoaringBitmap;
|
||||
pub use typo::{TypoCondition, TypoGraph};
|
||||
|
||||
use super::interner::{DedupInterner, FixedSizeInterner, Interned, MappedInterner};
|
||||
use super::logger::SearchLogger;
|
||||
use super::query_term::LocatedQueryTermSubset;
|
||||
use super::small_bitmap::SmallBitmap;
|
||||
use super::{QueryGraph, QueryNode, SearchContext};
|
||||
@ -86,10 +85,6 @@ impl<E> PartialEq for Edge<E> {
|
||||
pub trait RankingRuleGraphTrait: Sized {
|
||||
type Condition: Sized + Clone + PartialEq + Eq + Hash;
|
||||
|
||||
/// Return the label of the given edge condition, to be used when visualising
|
||||
/// the ranking rule graph.
|
||||
fn label_for_condition(ctx: &mut SearchContext, condition: &Self::Condition) -> Result<String>;
|
||||
|
||||
/// Compute the document ids associated with the given edge condition,
|
||||
/// restricted to the given universe.
|
||||
fn resolve_condition(
|
||||
@ -105,16 +100,6 @@ pub trait RankingRuleGraphTrait: Sized {
|
||||
source_node: Option<&LocatedQueryTermSubset>,
|
||||
dest_node: &LocatedQueryTermSubset,
|
||||
) -> Result<Vec<(u32, Interned<Self::Condition>)>>;
|
||||
|
||||
fn log_state(
|
||||
graph: &RankingRuleGraph<Self>,
|
||||
paths: &[Vec<Interned<Self::Condition>>],
|
||||
dead_ends_cache: &DeadEndsCache<Self::Condition>,
|
||||
universe: &RoaringBitmap,
|
||||
costs: &MappedInterner<QueryNode, Vec<u64>>,
|
||||
cost: u64,
|
||||
logger: &mut dyn SearchLogger<QueryGraph>,
|
||||
);
|
||||
}
|
||||
|
||||
/// The graph used by graph-based ranking rules.
|
||||
|
@ -3,11 +3,10 @@ pub mod compute_docids;
|
||||
|
||||
use roaring::RoaringBitmap;
|
||||
|
||||
use super::{ComputedCondition, DeadEndsCache, RankingRuleGraph, RankingRuleGraphTrait};
|
||||
use crate::search::new::interner::{DedupInterner, Interned, MappedInterner};
|
||||
use crate::search::new::logger::SearchLogger;
|
||||
use super::{ComputedCondition, RankingRuleGraphTrait};
|
||||
use crate::search::new::interner::{DedupInterner, Interned};
|
||||
use crate::search::new::query_term::LocatedQueryTermSubset;
|
||||
use crate::search::new::{QueryGraph, QueryNode, SearchContext};
|
||||
use crate::search::new::SearchContext;
|
||||
use crate::Result;
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Hash)]
|
||||
@ -37,28 +36,4 @@ impl RankingRuleGraphTrait for ProximityGraph {
|
||||
) -> Result<Vec<(u32, Interned<Self::Condition>)>> {
|
||||
build::build_edges(ctx, conditions_interner, source_term, dest_term)
|
||||
}
|
||||
|
||||
fn log_state(
|
||||
graph: &RankingRuleGraph<Self>,
|
||||
paths: &[Vec<Interned<ProximityCondition>>],
|
||||
dead_ends_cache: &DeadEndsCache<Self::Condition>,
|
||||
universe: &RoaringBitmap,
|
||||
distances: &MappedInterner<QueryNode, Vec<u64>>,
|
||||
cost: u64,
|
||||
logger: &mut dyn SearchLogger<QueryGraph>,
|
||||
) {
|
||||
logger.log_proximity_state(graph, paths, dead_ends_cache, universe, distances, cost);
|
||||
}
|
||||
|
||||
fn label_for_condition(ctx: &mut SearchContext, condition: &Self::Condition) -> Result<String> {
|
||||
match condition {
|
||||
ProximityCondition::Uninit { cost, .. } => {
|
||||
// TODO
|
||||
Ok(format!("{cost}: cost"))
|
||||
}
|
||||
ProximityCondition::Term { term } => {
|
||||
Ok(format!("{} : exists", term.term_subset.description(ctx)))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,10 @@
|
||||
use roaring::RoaringBitmap;
|
||||
|
||||
use super::{ComputedCondition, DeadEndsCache, RankingRuleGraph, RankingRuleGraphTrait};
|
||||
use crate::search::new::interner::{DedupInterner, Interned, MappedInterner};
|
||||
use crate::search::new::logger::SearchLogger;
|
||||
use super::{ComputedCondition, RankingRuleGraphTrait};
|
||||
use crate::search::new::interner::{DedupInterner, Interned};
|
||||
use crate::search::new::query_term::LocatedQueryTermSubset;
|
||||
use crate::search::new::resolve_query_graph::compute_query_term_subset_docids;
|
||||
use crate::search::new::{QueryGraph, QueryNode, SearchContext};
|
||||
use crate::search::new::SearchContext;
|
||||
use crate::Result;
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Hash)]
|
||||
@ -76,21 +75,4 @@ impl RankingRuleGraphTrait for TypoGraph {
|
||||
}
|
||||
Ok(edges)
|
||||
}
|
||||
|
||||
fn log_state(
|
||||
graph: &RankingRuleGraph<Self>,
|
||||
paths: &[Vec<Interned<TypoCondition>>],
|
||||
dead_ends_cache: &DeadEndsCache<TypoCondition>,
|
||||
universe: &RoaringBitmap,
|
||||
distances: &MappedInterner<QueryNode, Vec<u64>>,
|
||||
cost: u64,
|
||||
logger: &mut dyn SearchLogger<QueryGraph>,
|
||||
) {
|
||||
logger.log_typo_state(graph, paths, dead_ends_cache, universe, distances, cost);
|
||||
}
|
||||
|
||||
fn label_for_condition(ctx: &mut SearchContext, condition: &Self::Condition) -> Result<String> {
|
||||
let TypoCondition { term, nbr_typos } = condition;
|
||||
Ok(format!("{}: {nbr_typos}", term.term_subset.description(ctx)))
|
||||
}
|
||||
}
|
||||
|
@ -66,8 +66,6 @@ impl<'ctx> RankingRule<'ctx, QueryGraph> for Words {
|
||||
}
|
||||
let Some(query_graph) = &mut self.query_graph else { panic!() };
|
||||
|
||||
logger.log_words_state(query_graph);
|
||||
|
||||
let this_bucket = compute_query_graph_docids(ctx, query_graph, universe)?;
|
||||
|
||||
let child_query_graph = query_graph.clone();
|
||||
|
Loading…
x
Reference in New Issue
Block a user