pub struct ICUTransformTokenFilter { /* private fields */ }
Available on crate feature icu only.
Expand description

This TokenFilter allow to transform text into another, for example, to performe transliteration. See ICU documentation

use tantivy_analysis_contrib::icu::{Direction, ICUTransformTokenFilter};

let token_filter = ICUTransformTokenFilter::new(
    "Any-Latin; NFD; [:Nonspacing Mark:] Remove; Lower;  NFC".to_string(),
    None,
    Direction::Forward
)?;

§Example

Here is an example of transform that converts greek letters into latin letters

use tantivy::tokenizer::{RawTokenizer, TextAnalyzer, Token};
use tantivy_analysis_contrib::icu::{Direction, ICUTransformTokenFilter};

let mut tmp = TextAnalyzer::builder(RawTokenizer::default())
   .filter(ICUTransformTokenFilter::new(
      "Greek-Latin".to_string(),
      None,
      Direction::Forward
   )?)
   .build();
let mut token_stream = tmp.token_stream("Αλφαβητικός Κατάλογος");

let token = token_stream.next().expect("A token should be present.");
assert_eq!(token.text, "Alphabētikós Katálogos".to_string());

assert_eq!(None, token_stream.next());

Implementations§

source§

impl ICUTransformTokenFilter

source

pub fn new( compound_id: String, rules: Option<String>, direction: Direction ) -> Result<Self, Error>

Construct a new transform filter.

# Parameters :

Trait Implementations§

source§

impl Clone for ICUTransformTokenFilter

source§

fn clone(&self) -> ICUTransformTokenFilter

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for ICUTransformTokenFilter

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl TokenFilter for ICUTransformTokenFilter

§

type Tokenizer<T: Tokenizer> = ICUTransformFilterWrapper<T>

The Tokenizer type returned by this filter, typically parametrized by the underlying Tokenizer.
source§

fn transform<T: Tokenizer>(self, token_stream: T) -> Self::Tokenizer<T>

Wraps a Tokenizer and returns a new one.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.