pub struct EdgeNgramTokenFilter { /* private fields */ }
Available on crate feature
commons
only.Expand description
Token filter that produce ngram
from the start of the token.
For example, Quick
will generate
Q
, Qu
, Qui
, Quic
, …etc.
It is configure with two parameters:
- min edge-ngram: the number of maximum characters (e.g. with min=3,
Quick
will generateQui
,Quic
andQuick
). It must be greater than 0. - max edge-ngram: the number of maximum characters (e.g. with max=3,
Quick
will generateQ
,Qu
andQui
. It is optional, and there is no maximum then it will generate up to the end of the token.
§Example
use std::num::NonZeroUsize;
use tantivy::tokenizer::{WhitespaceTokenizer, TextAnalyzer, Token};
use tantivy_analysis_contrib::commons::EdgeNgramTokenFilter;
let mut tmp = TextAnalyzer::builder(WhitespaceTokenizer::default())
.filter(EdgeNgramTokenFilter::new(NonZeroUsize::new(2).unwrap(), NonZeroUsize::new(4), false)?)
.build();
let mut token_stream = tmp.token_stream("Quick");
let token = token_stream.next().expect("A token should be present.");
assert_eq!(token.text, "Qu".to_string());
let token = token_stream.next().expect("A token should be present.");
assert_eq!(token.text, "Qui".to_string());
let token = token_stream.next().expect("A token should be present.");
assert_eq!(token.text, "Quic".to_string());
assert_eq!(None, token_stream.next());
This token filter is useful to do a “starts with” therefor a “search as you type”.
It is also easy to have an efficient “ends with” by adding the ReverseTokenFilter before the edge ngram filter.
§How to use it
To use it, you should have another pipeline at search time that does not include the edge-ngram filter. Otherwise, you’ll get irrelevant results. Please see the example in source repository for a way to do it.
Implementations§
source§impl EdgeNgramTokenFilter
impl EdgeNgramTokenFilter
sourcepub fn new(
min: NonZeroUsize,
max: Option<NonZeroUsize>,
keep_original_token: bool
) -> Result<Self, EdgeNgramError>
pub fn new( min: NonZeroUsize, max: Option<NonZeroUsize>, keep_original_token: bool ) -> Result<Self, EdgeNgramError>
Trait Implementations§
source§impl Clone for EdgeNgramTokenFilter
impl Clone for EdgeNgramTokenFilter
source§fn clone(&self) -> EdgeNgramTokenFilter
fn clone(&self) -> EdgeNgramTokenFilter
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for EdgeNgramTokenFilter
impl Debug for EdgeNgramTokenFilter
source§impl From<NonZero<usize>> for EdgeNgramTokenFilter
impl From<NonZero<usize>> for EdgeNgramTokenFilter
source§fn from(ngram: NonZeroUsize) -> Self
fn from(ngram: NonZeroUsize) -> Self
Converts to this type from the input type.
source§impl Hash for EdgeNgramTokenFilter
impl Hash for EdgeNgramTokenFilter
source§impl Ord for EdgeNgramTokenFilter
impl Ord for EdgeNgramTokenFilter
source§fn cmp(&self, other: &EdgeNgramTokenFilter) -> Ordering
fn cmp(&self, other: &EdgeNgramTokenFilter) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
source§impl PartialEq for EdgeNgramTokenFilter
impl PartialEq for EdgeNgramTokenFilter
source§fn eq(&self, other: &EdgeNgramTokenFilter) -> bool
fn eq(&self, other: &EdgeNgramTokenFilter) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd for EdgeNgramTokenFilter
impl PartialOrd for EdgeNgramTokenFilter
source§fn partial_cmp(&self, other: &EdgeNgramTokenFilter) -> Option<Ordering>
fn partial_cmp(&self, other: &EdgeNgramTokenFilter) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moresource§impl TokenFilter for EdgeNgramTokenFilter
impl TokenFilter for EdgeNgramTokenFilter
impl Copy for EdgeNgramTokenFilter
impl Eq for EdgeNgramTokenFilter
impl StructuralPartialEq for EdgeNgramTokenFilter
Auto Trait Implementations§
impl Freeze for EdgeNgramTokenFilter
impl RefUnwindSafe for EdgeNgramTokenFilter
impl Send for EdgeNgramTokenFilter
impl Sync for EdgeNgramTokenFilter
impl Unpin for EdgeNgramTokenFilter
impl UnwindSafe for EdgeNgramTokenFilter
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
Mutably borrows from an owned value. Read more