mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-12-23 21:20:24 +01:00
Renaming Edge -> Condition
This commit is contained in:
parent
aa59c3bc2c
commit
2853009987
@ -45,7 +45,7 @@ use super::interner::MappedInterner;
|
||||
use super::logger::SearchLogger;
|
||||
use super::query_graph::QueryNode;
|
||||
use super::ranking_rule_graph::{
|
||||
DeadEndPathCache, EdgeConditionDocIdsCache, ProximityGraph, RankingRuleGraph,
|
||||
ConditionDocIdsCache, DeadEndPathCache, ProximityGraph, RankingRuleGraph,
|
||||
RankingRuleGraphTrait, TypoGraph,
|
||||
};
|
||||
use super::small_bitmap::SmallBitmap;
|
||||
@ -85,12 +85,12 @@ pub struct GraphBasedRankingRuleState<G: RankingRuleGraphTrait> {
|
||||
/// The current graph
|
||||
graph: RankingRuleGraph<G>,
|
||||
/// Cache to retrieve the docids associated with each edge
|
||||
edge_conditions_cache: EdgeConditionDocIdsCache<G>,
|
||||
conditions_cache: ConditionDocIdsCache<G>,
|
||||
/// Cache used to optimistically discard paths that resolve to no documents.
|
||||
dead_end_path_cache: DeadEndPathCache<G>,
|
||||
/// A structure giving the list of possible costs from each node to the end node,
|
||||
/// along with a set of unavoidable edges that must be traversed to achieve that distance.
|
||||
all_distances: MappedInterner<Vec<(u16, SmallBitmap<G::EdgeCondition>)>, QueryNode>,
|
||||
all_distances: MappedInterner<Vec<(u16, SmallBitmap<G::Condition>)>, QueryNode>,
|
||||
/// An index in the first element of `all_distances`, giving the cost of the next bucket
|
||||
cur_distance_idx: usize,
|
||||
}
|
||||
@ -101,7 +101,7 @@ pub struct GraphBasedRankingRuleState<G: RankingRuleGraphTrait> {
|
||||
fn remove_empty_edges<'ctx, G: RankingRuleGraphTrait>(
|
||||
ctx: &mut SearchContext<'ctx>,
|
||||
graph: &mut RankingRuleGraph<G>,
|
||||
condition_docids_cache: &mut EdgeConditionDocIdsCache<G>,
|
||||
condition_docids_cache: &mut ConditionDocIdsCache<G>,
|
||||
universe: &RoaringBitmap,
|
||||
dead_end_path_cache: &mut DeadEndPathCache<G>,
|
||||
) -> Result<()> {
|
||||
@ -135,7 +135,7 @@ impl<'ctx, G: RankingRuleGraphTrait> RankingRule<'ctx, QueryGraph> for GraphBase
|
||||
query_graph: &QueryGraph,
|
||||
) -> Result<()> {
|
||||
let mut graph = RankingRuleGraph::build(ctx, query_graph.clone())?;
|
||||
let mut condition_docids_cache = EdgeConditionDocIdsCache::default();
|
||||
let mut condition_docids_cache = ConditionDocIdsCache::default();
|
||||
let mut dead_end_path_cache = DeadEndPathCache::new(&graph.conditions_interner);
|
||||
|
||||
// First simplify the graph as much as possible, by computing the docids of all the conditions
|
||||
@ -153,7 +153,7 @@ impl<'ctx, G: RankingRuleGraphTrait> RankingRule<'ctx, QueryGraph> for GraphBase
|
||||
|
||||
let state = GraphBasedRankingRuleState {
|
||||
graph,
|
||||
edge_conditions_cache: condition_docids_cache,
|
||||
conditions_cache: condition_docids_cache,
|
||||
dead_end_path_cache,
|
||||
all_distances,
|
||||
cur_distance_idx: 0,
|
||||
@ -181,7 +181,7 @@ impl<'ctx, G: RankingRuleGraphTrait> RankingRule<'ctx, QueryGraph> for GraphBase
|
||||
remove_empty_edges(
|
||||
ctx,
|
||||
&mut state.graph,
|
||||
&mut state.edge_conditions_cache,
|
||||
&mut state.conditions_cache,
|
||||
universe,
|
||||
&mut state.dead_end_path_cache,
|
||||
)?;
|
||||
@ -204,7 +204,7 @@ impl<'ctx, G: RankingRuleGraphTrait> RankingRule<'ctx, QueryGraph> for GraphBase
|
||||
|
||||
let GraphBasedRankingRuleState {
|
||||
graph,
|
||||
edge_conditions_cache: condition_docids_cache,
|
||||
conditions_cache: condition_docids_cache,
|
||||
dead_end_path_cache,
|
||||
all_distances,
|
||||
cur_distance_idx: _,
|
||||
@ -326,8 +326,8 @@ impl<'ctx, G: RankingRuleGraphTrait> RankingRule<'ctx, QueryGraph> for GraphBase
|
||||
let mut used_phrases = HashSet::new();
|
||||
for condition in used_conditions.iter() {
|
||||
let condition = graph.conditions_interner.get(condition);
|
||||
used_words.extend(G::words_used_by_edge_condition(ctx, condition)?);
|
||||
used_phrases.extend(G::phrases_used_by_edge_condition(ctx, condition)?);
|
||||
used_words.extend(G::words_used_by_condition(ctx, condition)?);
|
||||
used_phrases.extend(G::phrases_used_by_condition(ctx, condition)?);
|
||||
}
|
||||
// 2. Remove the unused words and phrases from all the nodes in the graph
|
||||
let mut nodes_to_remove = vec![];
|
||||
|
@ -11,7 +11,7 @@ use crate::search::new::query_graph::QueryNodeData;
|
||||
use crate::search::new::query_term::{LocatedQueryTerm, QueryTerm};
|
||||
use crate::search::new::ranking_rule_graph::{
|
||||
DeadEndPathCache, Edge, ProximityCondition, ProximityGraph, RankingRuleGraph,
|
||||
RankingRuleGraphTrait, TypoEdge, TypoGraph,
|
||||
RankingRuleGraphTrait, TypoCondition, TypoGraph,
|
||||
};
|
||||
use crate::search::new::small_bitmap::SmallBitmap;
|
||||
use crate::search::new::{QueryGraph, QueryNode, SearchContext};
|
||||
@ -51,10 +51,10 @@ pub enum SearchEvents {
|
||||
},
|
||||
TypoState {
|
||||
graph: RankingRuleGraph<TypoGraph>,
|
||||
paths: Vec<Vec<Interned<TypoEdge>>>,
|
||||
paths: Vec<Vec<Interned<TypoCondition>>>,
|
||||
dead_end_path_cache: DeadEndPathCache<TypoGraph>,
|
||||
universe: RoaringBitmap,
|
||||
distances: MappedInterner<Vec<(u16, SmallBitmap<TypoEdge>)>, QueryNode>,
|
||||
distances: MappedInterner<Vec<(u16, SmallBitmap<TypoCondition>)>, QueryNode>,
|
||||
cost: u16,
|
||||
},
|
||||
RankingRuleSkipBucket {
|
||||
@ -188,10 +188,10 @@ impl SearchLogger<QueryGraph> for DetailedSearchLogger {
|
||||
fn log_typo_state(
|
||||
&mut self,
|
||||
query_graph: &RankingRuleGraph<TypoGraph>,
|
||||
paths_map: &[Vec<Interned<TypoEdge>>],
|
||||
paths_map: &[Vec<Interned<TypoCondition>>],
|
||||
dead_end_path_cache: &DeadEndPathCache<TypoGraph>,
|
||||
universe: &RoaringBitmap,
|
||||
distances: &MappedInterner<Vec<(u16, SmallBitmap<TypoEdge>)>, QueryNode>,
|
||||
distances: &MappedInterner<Vec<(u16, SmallBitmap<TypoCondition>)>, QueryNode>,
|
||||
cost: u16,
|
||||
) {
|
||||
self.events.push(SearchEvents::TypoState {
|
||||
@ -430,7 +430,7 @@ results.{random} {{
|
||||
ctx: &mut SearchContext,
|
||||
node_idx: Interned<QueryNode>,
|
||||
node: &QueryNode,
|
||||
distances: &[(u16, SmallBitmap<R::EdgeCondition>)],
|
||||
distances: &[(u16, SmallBitmap<R::Condition>)],
|
||||
file: &mut File,
|
||||
) {
|
||||
match &node.data {
|
||||
@ -527,9 +527,9 @@ shape: class"
|
||||
fn ranking_rule_graph_d2_description<R: RankingRuleGraphTrait>(
|
||||
ctx: &mut SearchContext,
|
||||
graph: &RankingRuleGraph<R>,
|
||||
paths: &[Vec<Interned<R::EdgeCondition>>],
|
||||
paths: &[Vec<Interned<R::Condition>>],
|
||||
dead_end_paths_cache: &DeadEndPathCache<R>,
|
||||
distances: MappedInterner<Vec<(u16, SmallBitmap<R::EdgeCondition>)>, QueryNode>,
|
||||
distances: MappedInterner<Vec<(u16, SmallBitmap<R::Condition>)>, QueryNode>,
|
||||
file: &mut File,
|
||||
) {
|
||||
writeln!(file, "direction: right").unwrap();
|
||||
@ -596,7 +596,7 @@ shape: class"
|
||||
fn condition_d2_description<R: RankingRuleGraphTrait>(
|
||||
ctx: &mut SearchContext,
|
||||
graph: &RankingRuleGraph<R>,
|
||||
condition_id: Interned<R::EdgeCondition>,
|
||||
condition_id: Interned<R::Condition>,
|
||||
file: &mut File,
|
||||
) {
|
||||
let condition = graph.conditions_interner.get(condition_id);
|
||||
@ -606,14 +606,14 @@ shape: class"
|
||||
shape: class
|
||||
{}
|
||||
}}",
|
||||
R::label_for_edge_condition(ctx, condition).unwrap()
|
||||
R::label_for_condition(ctx, condition).unwrap()
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
fn paths_d2_description<R: RankingRuleGraphTrait>(
|
||||
ctx: &mut SearchContext,
|
||||
graph: &RankingRuleGraph<R>,
|
||||
paths: &[Vec<Interned<R::EdgeCondition>>],
|
||||
paths: &[Vec<Interned<R::Condition>>],
|
||||
file: &mut File,
|
||||
) {
|
||||
for (path_idx, condition_indexes) in paths.iter().enumerate() {
|
||||
|
@ -6,7 +6,8 @@ use roaring::RoaringBitmap;
|
||||
use super::interner::{Interned, MappedInterner};
|
||||
use super::query_graph::QueryNode;
|
||||
use super::ranking_rule_graph::{
|
||||
DeadEndPathCache, ProximityCondition, ProximityGraph, RankingRuleGraph, TypoEdge, TypoGraph,
|
||||
DeadEndPathCache, ProximityCondition, ProximityGraph, RankingRuleGraph, TypoCondition,
|
||||
TypoGraph,
|
||||
};
|
||||
use super::small_bitmap::SmallBitmap;
|
||||
use super::{RankingRule, RankingRuleQueryTrait};
|
||||
@ -76,10 +77,10 @@ pub trait SearchLogger<Q: RankingRuleQueryTrait> {
|
||||
fn log_typo_state(
|
||||
&mut self,
|
||||
query_graph: &RankingRuleGraph<TypoGraph>,
|
||||
paths: &[Vec<Interned<TypoEdge>>],
|
||||
paths: &[Vec<Interned<TypoCondition>>],
|
||||
dead_end_path_cache: &DeadEndPathCache<TypoGraph>,
|
||||
universe: &RoaringBitmap,
|
||||
distances: &MappedInterner<Vec<(u16, SmallBitmap<TypoEdge>)>, QueryNode>,
|
||||
distances: &MappedInterner<Vec<(u16, SmallBitmap<TypoCondition>)>, QueryNode>,
|
||||
cost: u16,
|
||||
);
|
||||
}
|
||||
@ -147,10 +148,10 @@ impl<Q: RankingRuleQueryTrait> SearchLogger<Q> for DefaultSearchLogger {
|
||||
fn log_typo_state(
|
||||
&mut self,
|
||||
_query_graph: &RankingRuleGraph<TypoGraph>,
|
||||
_paths: &[Vec<Interned<TypoEdge>>],
|
||||
_paths: &[Vec<Interned<TypoCondition>>],
|
||||
_dead_end_path_cache: &DeadEndPathCache<TypoGraph>,
|
||||
_universe: &RoaringBitmap,
|
||||
_distances: &MappedInterner<Vec<(u16, SmallBitmap<TypoEdge>)>, QueryNode>,
|
||||
_distances: &MappedInterner<Vec<(u16, SmallBitmap<TypoCondition>)>, QueryNode>,
|
||||
_cost: u16,
|
||||
) {
|
||||
}
|
||||
|
@ -22,10 +22,10 @@ impl<G: RankingRuleGraphTrait> RankingRuleGraph<G> {
|
||||
&mut self,
|
||||
from: Interned<QueryNode>,
|
||||
cost: u16,
|
||||
all_distances: &MappedInterner<Vec<(u16, SmallBitmap<G::EdgeCondition>)>, QueryNode>,
|
||||
all_distances: &MappedInterner<Vec<(u16, SmallBitmap<G::Condition>)>, QueryNode>,
|
||||
dead_end_path_cache: &mut DeadEndPathCache<G>,
|
||||
mut visit: impl FnMut(
|
||||
&[Interned<G::EdgeCondition>],
|
||||
&[Interned<G::Condition>],
|
||||
&mut Self,
|
||||
&mut DeadEndPathCache<G>,
|
||||
) -> Result<ControlFlow<()>>,
|
||||
@ -46,16 +46,16 @@ impl<G: RankingRuleGraphTrait> RankingRuleGraph<G> {
|
||||
&mut self,
|
||||
from: Interned<QueryNode>,
|
||||
cost: u16,
|
||||
all_distances: &MappedInterner<Vec<(u16, SmallBitmap<G::EdgeCondition>)>, QueryNode>,
|
||||
all_distances: &MappedInterner<Vec<(u16, SmallBitmap<G::Condition>)>, QueryNode>,
|
||||
dead_end_path_cache: &mut DeadEndPathCache<G>,
|
||||
visit: &mut impl FnMut(
|
||||
&[Interned<G::EdgeCondition>],
|
||||
&[Interned<G::Condition>],
|
||||
&mut Self,
|
||||
&mut DeadEndPathCache<G>,
|
||||
) -> Result<ControlFlow<()>>,
|
||||
prev_conditions: &mut Vec<Interned<G::EdgeCondition>>,
|
||||
cur_path: &mut SmallBitmap<G::EdgeCondition>,
|
||||
forbidden_conditions: &mut SmallBitmap<G::EdgeCondition>,
|
||||
prev_conditions: &mut Vec<Interned<G::Condition>>,
|
||||
cur_path: &mut SmallBitmap<G::Condition>,
|
||||
forbidden_conditions: &mut SmallBitmap<G::Condition>,
|
||||
) -> Result<bool> {
|
||||
let mut any_valid = false;
|
||||
|
||||
@ -158,7 +158,7 @@ impl<G: RankingRuleGraphTrait> RankingRuleGraph<G> {
|
||||
|
||||
pub fn initialize_distances_with_necessary_edges(
|
||||
&self,
|
||||
) -> MappedInterner<Vec<(u16, SmallBitmap<G::EdgeCondition>)>, QueryNode> {
|
||||
) -> MappedInterner<Vec<(u16, SmallBitmap<G::Condition>)>, QueryNode> {
|
||||
let mut distances_to_end = self.query_graph.nodes.map(|_| vec![]);
|
||||
let mut enqueued = SmallBitmap::new(self.query_graph.nodes.len());
|
||||
|
||||
@ -173,7 +173,7 @@ impl<G: RankingRuleGraphTrait> RankingRuleGraph<G> {
|
||||
}
|
||||
|
||||
while let Some(cur_node) = node_stack.pop_front() {
|
||||
let mut self_distances = BTreeMap::<u16, SmallBitmap<G::EdgeCondition>>::new();
|
||||
let mut self_distances = BTreeMap::<u16, SmallBitmap<G::Condition>>::new();
|
||||
|
||||
let cur_node_edges = &self.edges_of_node.get(cur_node);
|
||||
for edge_idx in cur_node_edges.iter() {
|
||||
|
@ -19,11 +19,11 @@ mod typo;
|
||||
use std::collections::HashSet;
|
||||
use std::hash::Hash;
|
||||
|
||||
pub use condition_docids_cache::EdgeConditionDocIdsCache;
|
||||
pub use condition_docids_cache::ConditionDocIdsCache;
|
||||
pub use dead_end_path_cache::DeadEndPathCache;
|
||||
pub use proximity::{ProximityCondition, ProximityGraph};
|
||||
use roaring::RoaringBitmap;
|
||||
pub use typo::{TypoEdge, TypoGraph};
|
||||
pub use typo::{TypoCondition, TypoGraph};
|
||||
|
||||
use super::interner::{DedupInterner, FixedSizeInterner, Interned, MappedInterner};
|
||||
use super::logger::SearchLogger;
|
||||
@ -74,48 +74,48 @@ impl<E> PartialEq for Edge<E> {
|
||||
pub trait RankingRuleGraphTrait: Sized {
|
||||
/// The condition of an edge connecting two query nodes. The condition
|
||||
/// should be sufficient to compute the edge's cost and associated document ids
|
||||
/// in [`resolve_edge_condition`](RankingRuleGraphTrait::resolve_edge_condition).
|
||||
type EdgeCondition: Sized + Clone + PartialEq + Eq + Hash;
|
||||
/// in [`resolve_condition`](RankingRuleGraphTrait::resolve_condition).
|
||||
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_edge_condition<'ctx>(
|
||||
fn label_for_condition<'ctx>(
|
||||
ctx: &mut SearchContext<'ctx>,
|
||||
edge: &Self::EdgeCondition,
|
||||
condition: &Self::Condition,
|
||||
) -> Result<String>;
|
||||
|
||||
fn words_used_by_edge_condition<'ctx>(
|
||||
fn words_used_by_condition<'ctx>(
|
||||
ctx: &mut SearchContext<'ctx>,
|
||||
edge: &Self::EdgeCondition,
|
||||
condition: &Self::Condition,
|
||||
) -> Result<HashSet<Interned<String>>>;
|
||||
fn phrases_used_by_edge_condition<'ctx>(
|
||||
|
||||
fn phrases_used_by_condition<'ctx>(
|
||||
ctx: &mut SearchContext<'ctx>,
|
||||
edge: &Self::EdgeCondition,
|
||||
condition: &Self::Condition,
|
||||
) -> Result<HashSet<Interned<Phrase>>>;
|
||||
|
||||
/// Compute the document ids associated with the given edge condition,
|
||||
/// restricted to the given universe.
|
||||
fn resolve_edge_condition<'ctx>(
|
||||
fn resolve_condition<'ctx>(
|
||||
ctx: &mut SearchContext<'ctx>,
|
||||
edge_condition: &Self::EdgeCondition,
|
||||
condition: &Self::Condition,
|
||||
universe: &RoaringBitmap,
|
||||
) -> Result<RoaringBitmap>;
|
||||
|
||||
/// 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`.
|
||||
/// Return the costs and conditions of the edges going from the source node to the destination node
|
||||
fn build_edges<'ctx>(
|
||||
ctx: &mut SearchContext<'ctx>,
|
||||
conditions_interner: &mut DedupInterner<Self::EdgeCondition>,
|
||||
conditions_interner: &mut DedupInterner<Self::Condition>,
|
||||
source_node: &QueryNode,
|
||||
dest_node: &QueryNode,
|
||||
) -> Result<Vec<(u8, Option<Interned<Self::EdgeCondition>>)>>;
|
||||
) -> Result<Vec<(u8, Option<Interned<Self::Condition>>)>>;
|
||||
|
||||
fn log_state(
|
||||
graph: &RankingRuleGraph<Self>,
|
||||
paths: &[Vec<Interned<Self::EdgeCondition>>],
|
||||
paths: &[Vec<Interned<Self::Condition>>],
|
||||
dead_end_path_cache: &DeadEndPathCache<Self>,
|
||||
universe: &RoaringBitmap,
|
||||
distances: &MappedInterner<Vec<(u16, SmallBitmap<Self::EdgeCondition>)>, QueryNode>,
|
||||
distances: &MappedInterner<Vec<(u16, SmallBitmap<Self::Condition>)>, QueryNode>,
|
||||
cost: u16,
|
||||
logger: &mut dyn SearchLogger<QueryGraph>,
|
||||
);
|
||||
@ -127,9 +127,9 @@ pub trait RankingRuleGraphTrait: Sized {
|
||||
/// but replacing the edges.
|
||||
pub struct RankingRuleGraph<G: RankingRuleGraphTrait> {
|
||||
pub query_graph: QueryGraph,
|
||||
pub edges_store: FixedSizeInterner<Option<Edge<G::EdgeCondition>>>,
|
||||
pub edges_of_node: MappedInterner<SmallBitmap<Option<Edge<G::EdgeCondition>>>, QueryNode>,
|
||||
pub conditions_interner: FixedSizeInterner<G::EdgeCondition>,
|
||||
pub edges_store: FixedSizeInterner<Option<Edge<G::Condition>>>,
|
||||
pub edges_of_node: MappedInterner<SmallBitmap<Option<Edge<G::Condition>>>, QueryNode>,
|
||||
pub conditions_interner: FixedSizeInterner<G::Condition>,
|
||||
}
|
||||
impl<G: RankingRuleGraphTrait> Clone for RankingRuleGraph<G> {
|
||||
fn clone(&self) -> Self {
|
||||
@ -143,7 +143,7 @@ impl<G: RankingRuleGraphTrait> Clone for RankingRuleGraph<G> {
|
||||
}
|
||||
impl<G: RankingRuleGraphTrait> RankingRuleGraph<G> {
|
||||
/// Remove all edges with the given condition
|
||||
pub fn remove_edges_with_condition(&mut self, condition_to_remove: Interned<G::EdgeCondition>) {
|
||||
pub fn remove_edges_with_condition(&mut self, condition_to_remove: Interned<G::Condition>) {
|
||||
for (edge_id, edge_opt) in self.edges_store.iter_mut() {
|
||||
let Some(edge) = edge_opt.as_mut() else { continue };
|
||||
let Some(condition) = edge.condition else { continue };
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
use crate::search::new::interner::Interned;
|
||||
|
||||
/// A set of `Vec<Interned<T>>`.
|
||||
/// A set of `Vec<Interned<T>>` implemented as a prefix tree.
|
||||
pub struct PathSet<T> {
|
||||
nodes: Vec<(Interned<T>, Self)>,
|
||||
is_end: bool,
|
||||
|
@ -6,7 +6,7 @@ use crate::{CboRoaringBitmapCodec, Result};
|
||||
|
||||
pub fn compute_docids<'ctx>(
|
||||
ctx: &mut SearchContext<'ctx>,
|
||||
edge: &ProximityCondition,
|
||||
condition: &ProximityCondition,
|
||||
universe: &RoaringBitmap,
|
||||
) -> Result<RoaringBitmap> {
|
||||
let SearchContext {
|
||||
@ -18,7 +18,7 @@ pub fn compute_docids<'ctx>(
|
||||
phrase_interner,
|
||||
term_interner,
|
||||
} = ctx;
|
||||
let pairs = match edge {
|
||||
let pairs = match condition {
|
||||
ProximityCondition::Term { term } => {
|
||||
return term_docids
|
||||
.get_query_term_docids(
|
||||
|
@ -45,11 +45,11 @@ pub enum ProximityCondition {
|
||||
pub enum ProximityGraph {}
|
||||
|
||||
impl RankingRuleGraphTrait for ProximityGraph {
|
||||
type EdgeCondition = ProximityCondition;
|
||||
type Condition = ProximityCondition;
|
||||
|
||||
fn resolve_edge_condition<'ctx>(
|
||||
fn resolve_condition<'ctx>(
|
||||
ctx: &mut SearchContext<'ctx>,
|
||||
condition: &Self::EdgeCondition,
|
||||
condition: &Self::Condition,
|
||||
universe: &RoaringBitmap,
|
||||
) -> Result<roaring::RoaringBitmap> {
|
||||
compute_docids::compute_docids(ctx, condition, universe)
|
||||
@ -57,10 +57,10 @@ impl RankingRuleGraphTrait for ProximityGraph {
|
||||
|
||||
fn build_edges<'ctx>(
|
||||
ctx: &mut SearchContext<'ctx>,
|
||||
conditions_interner: &mut DedupInterner<Self::EdgeCondition>,
|
||||
conditions_interner: &mut DedupInterner<Self::Condition>,
|
||||
source_node: &QueryNode,
|
||||
dest_node: &QueryNode,
|
||||
) -> Result<Vec<(u8, Option<Interned<Self::EdgeCondition>>)>> {
|
||||
) -> Result<Vec<(u8, Option<Interned<Self::Condition>>)>> {
|
||||
build::build_edges(ctx, conditions_interner, source_node, dest_node)
|
||||
}
|
||||
|
||||
@ -76,11 +76,11 @@ impl RankingRuleGraphTrait for ProximityGraph {
|
||||
logger.log_proximity_state(graph, paths, dead_end_path_cache, universe, distances, cost);
|
||||
}
|
||||
|
||||
fn label_for_edge_condition<'ctx>(
|
||||
fn label_for_condition<'ctx>(
|
||||
ctx: &mut SearchContext<'ctx>,
|
||||
edge: &Self::EdgeCondition,
|
||||
condition: &Self::Condition,
|
||||
) -> Result<String> {
|
||||
match edge {
|
||||
match condition {
|
||||
ProximityCondition::Term { term } => {
|
||||
let term = ctx.term_interner.get(*term);
|
||||
Ok(format!("{} : exists", ctx.word_interner.get(term.original)))
|
||||
@ -117,11 +117,11 @@ impl RankingRuleGraphTrait for ProximityGraph {
|
||||
}
|
||||
}
|
||||
|
||||
fn words_used_by_edge_condition<'ctx>(
|
||||
fn words_used_by_condition<'ctx>(
|
||||
ctx: &mut SearchContext<'ctx>,
|
||||
edge: &Self::EdgeCondition,
|
||||
condition: &Self::Condition,
|
||||
) -> Result<HashSet<Interned<String>>> {
|
||||
match edge {
|
||||
match condition {
|
||||
ProximityCondition::Term { term } => {
|
||||
let term = ctx.term_interner.get(*term);
|
||||
Ok(HashSet::from_iter(term.all_single_words_except_prefix_db()))
|
||||
@ -153,11 +153,11 @@ impl RankingRuleGraphTrait for ProximityGraph {
|
||||
}
|
||||
}
|
||||
|
||||
fn phrases_used_by_edge_condition<'ctx>(
|
||||
fn phrases_used_by_condition<'ctx>(
|
||||
ctx: &mut SearchContext<'ctx>,
|
||||
edge: &Self::EdgeCondition,
|
||||
condition: &Self::Condition,
|
||||
) -> Result<HashSet<Interned<Phrase>>> {
|
||||
match edge {
|
||||
match condition {
|
||||
ProximityCondition::Term { term } => {
|
||||
let term = ctx.term_interner.get(*term);
|
||||
Ok(HashSet::from_iter(term.all_phrases()))
|
||||
|
@ -14,19 +14,18 @@ use std::fmt::Write;
|
||||
use std::iter::FromIterator;
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Hash)]
|
||||
pub struct TypoEdge {
|
||||
pub struct TypoCondition {
|
||||
term: Interned<QueryTerm>,
|
||||
nbr_typos: u8,
|
||||
}
|
||||
|
||||
pub enum TypoGraph {}
|
||||
|
||||
impl RankingRuleGraphTrait for TypoGraph {
|
||||
type EdgeCondition = TypoEdge;
|
||||
type Condition = TypoCondition;
|
||||
|
||||
fn resolve_edge_condition<'db_cache, 'ctx>(
|
||||
fn resolve_condition<'db_cache, 'ctx>(
|
||||
ctx: &mut SearchContext<'ctx>,
|
||||
edge: &Self::EdgeCondition,
|
||||
condition: &Self::Condition,
|
||||
universe: &RoaringBitmap,
|
||||
) -> Result<RoaringBitmap> {
|
||||
let SearchContext {
|
||||
@ -47,7 +46,7 @@ impl RankingRuleGraphTrait for TypoGraph {
|
||||
word_interner,
|
||||
term_interner,
|
||||
phrase_interner,
|
||||
edge.term,
|
||||
condition.term,
|
||||
)?;
|
||||
|
||||
Ok(docids)
|
||||
@ -55,10 +54,10 @@ impl RankingRuleGraphTrait for TypoGraph {
|
||||
|
||||
fn build_edges<'ctx>(
|
||||
ctx: &mut SearchContext<'ctx>,
|
||||
conditions_interner: &mut DedupInterner<Self::EdgeCondition>,
|
||||
conditions_interner: &mut DedupInterner<Self::Condition>,
|
||||
_from_node: &QueryNode,
|
||||
to_node: &QueryNode,
|
||||
) -> Result<Vec<(u8, Option<Interned<Self::EdgeCondition>>)>> {
|
||||
) -> Result<Vec<(u8, Option<Interned<Self::Condition>>)>> {
|
||||
let SearchContext { term_interner, .. } = ctx;
|
||||
match &to_node.data {
|
||||
QueryNodeData::Term(LocatedQueryTerm { value, positions }) => {
|
||||
@ -121,10 +120,10 @@ impl RankingRuleGraphTrait for TypoGraph {
|
||||
if !new_term.is_empty() {
|
||||
edges.push((
|
||||
nbr_typos as u8 + base_cost,
|
||||
Some(conditions_interner.insert(TypoEdge {
|
||||
term: term_interner.insert(new_term),
|
||||
nbr_typos: nbr_typos as u8,
|
||||
})),
|
||||
Some(
|
||||
conditions_interner
|
||||
.insert(TypoCondition { term: term_interner.insert(new_term) }),
|
||||
),
|
||||
))
|
||||
}
|
||||
}
|
||||
@ -137,21 +136,21 @@ impl RankingRuleGraphTrait for TypoGraph {
|
||||
|
||||
fn log_state(
|
||||
graph: &RankingRuleGraph<Self>,
|
||||
paths: &[Vec<Interned<TypoEdge>>],
|
||||
paths: &[Vec<Interned<TypoCondition>>],
|
||||
dead_end_path_cache: &DeadEndPathCache<Self>,
|
||||
universe: &RoaringBitmap,
|
||||
distances: &MappedInterner<Vec<(u16, SmallBitmap<TypoEdge>)>, QueryNode>,
|
||||
distances: &MappedInterner<Vec<(u16, SmallBitmap<TypoCondition>)>, QueryNode>,
|
||||
cost: u16,
|
||||
logger: &mut dyn SearchLogger<QueryGraph>,
|
||||
) {
|
||||
logger.log_typo_state(graph, paths, dead_end_path_cache, universe, distances, cost);
|
||||
}
|
||||
|
||||
fn label_for_edge_condition<'ctx>(
|
||||
fn label_for_condition<'ctx>(
|
||||
ctx: &mut SearchContext<'ctx>,
|
||||
edge: &Self::EdgeCondition,
|
||||
condition: &Self::Condition,
|
||||
) -> Result<String> {
|
||||
let TypoEdge { term, nbr_typos: _ } = edge;
|
||||
let TypoCondition { term } = condition;
|
||||
let term = ctx.term_interner.get(*term);
|
||||
let QueryTerm {
|
||||
original: _,
|
||||
@ -203,20 +202,20 @@ impl RankingRuleGraphTrait for TypoGraph {
|
||||
Ok(s)
|
||||
}
|
||||
|
||||
fn words_used_by_edge_condition<'ctx>(
|
||||
fn words_used_by_condition<'ctx>(
|
||||
ctx: &mut SearchContext<'ctx>,
|
||||
edge: &Self::EdgeCondition,
|
||||
condition: &Self::Condition,
|
||||
) -> Result<HashSet<Interned<String>>> {
|
||||
let TypoEdge { term, .. } = edge;
|
||||
let TypoCondition { term, .. } = condition;
|
||||
let term = ctx.term_interner.get(*term);
|
||||
Ok(HashSet::from_iter(term.all_single_words_except_prefix_db()))
|
||||
}
|
||||
|
||||
fn phrases_used_by_edge_condition<'ctx>(
|
||||
fn phrases_used_by_condition<'ctx>(
|
||||
ctx: &mut SearchContext<'ctx>,
|
||||
edge: &Self::EdgeCondition,
|
||||
condition: &Self::Condition,
|
||||
) -> Result<HashSet<Interned<Phrase>>> {
|
||||
let TypoEdge { term, .. } = edge;
|
||||
let TypoCondition { term, .. } = condition;
|
||||
let term = ctx.term_interner.get(*term);
|
||||
Ok(HashSet::from_iter(term.all_phrases()))
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user