mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-07-29 18:04:47 +00:00
Renaming Edge -> Condition
This commit is contained in:
@ -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()))
|
||||
}
|
||||
|
Reference in New Issue
Block a user