Improve the visual/detailed search logger

This commit is contained in:
Loïc Lecrenier
2023-02-23 13:13:19 +01:00
parent 6ba4d5e987
commit 173e37584c
9 changed files with 192 additions and 24 deletions

View File

@ -11,7 +11,10 @@ use std::ops::ControlFlow;
use heed::RoTxn;
use roaring::RoaringBitmap;
use self::paths_map::PathsMap;
use super::db_cache::DatabaseCache;
use super::logger::SearchLogger;
use super::{QueryGraph, QueryNode};
use crate::{Index, Result};
@ -23,10 +26,10 @@ pub enum EdgeDetails<E> {
#[derive(Debug, Clone)]
pub struct Edge<E> {
from_node: u32,
to_node: u32,
cost: u8,
details: EdgeDetails<E>,
pub from_node: u32,
pub to_node: u32,
pub cost: u8,
pub details: EdgeDetails<E>,
}
#[derive(Debug, Clone)]
@ -35,11 +38,11 @@ pub struct EdgePointer<'graph, E> {
pub edge: &'graph Edge<E>,
}
pub trait RankingRuleGraphTrait {
pub trait RankingRuleGraphTrait: Sized {
/// The details of an edge connecting two query nodes. These details
/// should be sufficient to compute the edge's cost and associated document ids
/// in [`compute_docids`](RankingRuleGraphTrait).
type EdgeDetails: Sized;
type EdgeDetails: Sized + Clone;
type BuildVisitedFromNode;
@ -75,6 +78,12 @@ pub trait RankingRuleGraphTrait {
to_node: &QueryNode,
from_node_data: &'from_data Self::BuildVisitedFromNode,
) -> Result<Vec<(u8, EdgeDetails<Self::EdgeDetails>)>>;
fn log_state(
graph: &RankingRuleGraph<Self>,
paths: &PathsMap<u64>,
logger: &mut dyn SearchLogger<QueryGraph>,
);
}
pub struct RankingRuleGraph<G: RankingRuleGraphTrait> {
@ -90,6 +99,16 @@ pub struct RankingRuleGraph<G: RankingRuleGraphTrait> {
// 2. get node_incoming_edges[to]
// 3. take intersection betweem the two
}
impl<G: RankingRuleGraphTrait> Clone for RankingRuleGraph<G> {
fn clone(&self) -> Self {
Self {
query_graph: self.query_graph.clone(),
all_edges: self.all_edges.clone(),
node_edges: self.node_edges.clone(),
successors: self.successors.clone(),
}
}
}
impl<G: RankingRuleGraphTrait> RankingRuleGraph<G> {
// Visit all edges between the two given nodes in order of increasing cost.
pub fn visit_edges<'graph, O>(

View File

@ -9,10 +9,10 @@ use super::cheapest_paths::Path;
use super::{Edge, EdgeDetails, RankingRuleGraph, RankingRuleGraphTrait};
use crate::new::QueryNode;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct PathsMap<V> {
nodes: Vec<(u32, PathsMap<V>)>,
value: Option<V>,
pub nodes: Vec<(u32, PathsMap<V>)>,
pub value: Option<V>,
}
impl<V> Default for PathsMap<V> {
fn default() -> Self {

View File

@ -3,6 +3,7 @@ pub mod compute_docids;
use heed::RoTxn;
use super::paths_map::PathsMap;
use super::{Edge, EdgeDetails, RankingRuleGraphTrait};
use crate::new::db_cache::DatabaseCache;
use crate::new::query_term::WordDerivations;
@ -18,6 +19,7 @@ pub enum WordPair {
WordPrefixSwapped { left: String, right_prefix: String },
}
#[derive(Clone)]
pub struct ProximityEdge {
pairs: Vec<WordPair>,
proximity: u8,
@ -61,4 +63,12 @@ impl RankingRuleGraphTrait for ProximityGraph {
) -> Result<Vec<(u8, EdgeDetails<Self::EdgeDetails>)>> {
build::visit_to_node(index, txn, db_cache, to_node, from_node_data)
}
fn log_state(
graph: &super::RankingRuleGraph<Self>,
paths: &PathsMap<u64>,
logger: &mut dyn crate::new::logger::SearchLogger<crate::new::QueryGraph>,
) {
logger.log_proximity_state(graph, paths);
}
}