TrgmExpressionMethods

Trait TrgmExpressionMethods 

Source
pub trait TrgmExpressionMethods: Expression + Sized
where Self::SqlType: TrgmTextType,
{ // Provided methods fn similar_to<T>(self, other: T) -> Similar<Self, T::Expression> where T: AsExpression<Text> { ... } fn word_similar_to<T>( self, other: T, ) -> WordSimilarRight<Self, T::Expression> where T: AsExpression<Text> { ... } fn strict_word_similar_to<T>( self, other: T, ) -> StrictWordSimilarRight<Self, T::Expression> where T: AsExpression<Text> { ... } fn distance<T>(self, other: T) -> Distance<Self, T::Expression> where T: AsExpression<Text> { ... } fn word_distance<T>( self, other: T, ) -> WordDistanceRight<Self, T::Expression> where T: AsExpression<Text> { ... } fn strict_word_distance<T>( self, other: T, ) -> StrictWordDistanceRight<Self, T::Expression> where T: AsExpression<Text> { ... } }
Available on crate feature diesel only.
Expand description

Extension trait for text expressions to provide pg_trgm operators.

This trait is implemented for all Diesel expressions that return Text or Nullable<Text>.

Provided Methods§

Source

fn similar_to<T>(self, other: T) -> Similar<Self, T::Expression>
where T: AsExpression<Text>,

Checks if this expression is similar to the given text using trigram matching.

Uses the % operator. Returns true if similarity exceeds the threshold.

§Example
use pgtrgm::TrgmExpressionMethods;

users.filter(name.similar_to("john"))
Source

fn word_similar_to<T>(self, other: T) -> WordSimilarRight<Self, T::Expression>
where T: AsExpression<Text>,

Checks if this expression contains a word similar to the given text.

Uses the %> operator.

Source

fn strict_word_similar_to<T>( self, other: T, ) -> StrictWordSimilarRight<Self, T::Expression>
where T: AsExpression<Text>,

Checks if this expression contains a word strictly similar to the given text.

Uses the %>> operator with strict word boundaries.

Source

fn distance<T>(self, other: T) -> Distance<Self, T::Expression>
where T: AsExpression<Text>,

Returns the trigram distance between this expression and the given text.

Uses the <-> operator. Distance is 1 - similarity, so lower is better. Useful for ordering results by similarity.

§Example
use pgtrgm::TrgmExpressionMethods;

users.order_by(name.distance("john"))
Source

fn word_distance<T>(self, other: T) -> WordDistanceRight<Self, T::Expression>
where T: AsExpression<Text>,

Returns the word similarity distance.

Uses the <->> operator.

Source

fn strict_word_distance<T>( self, other: T, ) -> StrictWordDistanceRight<Self, T::Expression>
where T: AsExpression<Text>,

Returns the strict word similarity distance.

Uses the <->>> operator.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§