pub struct QueryRewriter { /* private fields */ }Expand description
Query rewriter engine
Implementations§
Source§impl QueryRewriter
impl QueryRewriter
Sourcepub fn new(config: QueryRewriterConfig) -> Self
pub fn new(config: QueryRewriterConfig) -> Self
Create a new query rewriter with the given configuration.
Sourcepub fn add_rule(&mut self, rule: RewriteRule) -> Result<(), String>
pub fn add_rule(&mut self, rule: RewriteRule) -> Result<(), String>
Add a rewrite rule. Returns an error if the max rules limit is reached.
Sourcepub fn add_synonym(&mut self, word: &str, synonym: &str, boost: f64)
pub fn add_synonym(&mut self, word: &str, synonym: &str, boost: f64)
Add a synonym mapping with a boost factor.
Sourcepub fn add_stop_word(&mut self, word: &str)
pub fn add_stop_word(&mut self, word: &str)
Add a stop word.
Sourcepub fn rewrite(&mut self, query: &str) -> RewriteResult
pub fn rewrite(&mut self, query: &str) -> RewriteResult
Rewrite a query, applying all enabled rules, synonym expansion, stemming, and stop word removal.
Sourcepub fn tokenize(query: &str) -> Vec<String>
pub fn tokenize(query: &str) -> Vec<String>
Tokenize a query string: split on whitespace, lowercase, remove non-alphanumeric chars.
Sourcepub fn apply_stemming(word: &str) -> String
pub fn apply_stemming(word: &str) -> String
Simple suffix-stripping stemmer (Porter-like). Handles: -ing, -ed, -ly, -tion, -ness, -ment
Sourcepub fn is_stop_word(&self, word: &str) -> bool
pub fn is_stop_word(&self, word: &str) -> bool
Check if a word is a stop word.
Sourcepub fn expand_synonyms(&self, term: &str) -> Vec<(String, f64)>
pub fn expand_synonyms(&self, term: &str) -> Vec<(String, f64)>
Expand a term into its synonyms with associated boost values.
Sourcepub fn rules_count(&self) -> usize
pub fn rules_count(&self) -> usize
Return the number of rules.
Sourcepub fn remove_rule(&mut self, pattern: &str) -> bool
pub fn remove_rule(&mut self, pattern: &str) -> bool
Remove all rules matching the given pattern. Returns true if any were removed.
Sourcepub fn clear_rules(&mut self)
pub fn clear_rules(&mut self)
Clear all rules.
Sourcepub fn stats(&self) -> &QueryRewriterStats
pub fn stats(&self) -> &QueryRewriterStats
Get current statistics.
Sourcepub fn normalize_query(query: &str) -> String
pub fn normalize_query(query: &str) -> String
Normalize a query: lowercase, trim, collapse multiple whitespace into single space.
Auto Trait Implementations§
impl Freeze for QueryRewriter
impl RefUnwindSafe for QueryRewriter
impl Send for QueryRewriter
impl Sync for QueryRewriter
impl Unpin for QueryRewriter
impl UnsafeUnpin for QueryRewriter
impl UnwindSafe for QueryRewriter
Blanket Implementations§
impl<T> Allocation for T
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.