pub struct MatchingEngine { /* private fields */ }Expand description
Event matcher engine.
The engine is immutable after construction and cheap to clone (it
owns only a MatchConfig). Construct one and call its methods from any
thread.
use event_matcher::{MatchConfig, MatchingEngine};
let engine_a = MatchingEngine::default_config();
let engine_b = MatchingEngine::new(MatchConfig::strict());Implementations§
Source§impl MatchingEngine
impl MatchingEngine
Sourcepub fn new(config: MatchConfig) -> Self
pub fn new(config: MatchConfig) -> Self
Construct an engine with the given configuration.
Sourcepub fn default_config() -> Self
pub fn default_config() -> Self
Construct an engine with MatchConfig::default.
Sourcepub fn match_events(&self, event1: &Event, event2: &Event) -> MatchResult
pub fn match_events(&self, event1: &Event, event2: &Event) -> MatchResult
Compare two events probabilistically and return a MatchResult.
The score is the weight-renormalised sum of every component that scored on both records. Missing fields are skipped, not penalised.
use event_matcher::{MatchingEngine, Event};
let e = Event::builder()
.name("RustConf 2024")
.start_date("2024-09-10T09:00:00Z")
.build();
let result = MatchingEngine::default_config().match_events(&e, &e);
assert!(result.is_match);
assert!(result.score > 0.99);Sourcepub fn match_one_to_many(
&self,
query: &Event,
candidates: &[Event],
) -> Vec<MatchResult>
pub fn match_one_to_many( &self, query: &Event, candidates: &[Event], ) -> Vec<MatchResult>
Score a single query against many candidates. Returns one
MatchResult per candidate, in the same order as the input slice.
use event_matcher::{MatchingEngine, Event};
let query = Event::builder().name("RustConf 2024").build();
let candidates = vec![
Event::builder().name("RustConf 2024").build(),
Event::builder().name("GoConf 2024").build(),
];
let results = MatchingEngine::default_config().match_one_to_many(&query, &candidates);
assert_eq!(results.len(), 2);
assert!(results[0].is_match);
assert!(!results[1].is_match);Sourcepub fn rank_one_to_many(
&self,
query: &Event,
candidates: &[Event],
) -> Vec<(usize, MatchResult)>
pub fn rank_one_to_many( &self, query: &Event, candidates: &[Event], ) -> Vec<(usize, MatchResult)>
Score and rank: return (original_index, MatchResult) tuples
sorted by descending score. Ties are broken by ascending original
index, so the result is deterministic.
Sourcepub fn deterministic_match(&self, event1: &Event, event2: &Event) -> bool
pub fn deterministic_match(&self, event1: &Event, event2: &Event) -> bool
Compare two events deterministically and return a single boolean.
Returns true iff either:
- the events share any
(scheme, value)pair in theirevent_idslists, OR - both have a primary
namethat normalises to the same value AND both have astart_datethat parses to the same instant.
use event_matcher::{MatchingEngine, Event, EventId, EventIdScheme};
let id = EventId::new(EventIdScheme::Eventbrite, "123456789").unwrap();
let a = Event::builder().name("RustConf 2024").add_event_id(id.clone()).build();
let b = Event::builder().name("RC '24").add_event_id(id).build();
assert!(MatchingEngine::default_config().deterministic_match(&a, &b));Auto Trait Implementations§
impl Freeze for MatchingEngine
impl RefUnwindSafe for MatchingEngine
impl Send for MatchingEngine
impl Sync for MatchingEngine
impl Unpin for MatchingEngine
impl UnsafeUnpin for MatchingEngine
impl UnwindSafe for MatchingEngine
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more