Struct Decay

Source
pub struct Decay<T: Origin> { /* private fields */ }
Expand description

Decay functions score a document with a function that decays depending on the distance of a numeric field value of the document from a user given origin. This is similar to a range query, but with smooth edges instead of boxes.

To use distance scoring on a query that has numerical fields, the user has to define an origin and a scale for each field. The origin is needed to define the “central point” from which the distance is calculated, and the scale to define the rate of decay.

Implementations§

Source§

impl<O> Decay<O>
where O: Origin,

Source

pub fn new<T>( function: DecayFunction, field: T, origin: O, scale: <O as Origin>::Scale, ) -> Self
where T: ToString,

Creates an instance of Decay

  • function - Decay function variant
  • field - Field to apply function to
  • origin - The point of origin used for calculating distance. Must be given as a number for numeric field, date for date fields and geo point for geo fields. Required for geo and numeric field. For date fields the default is now. Date math (for example now-1h) is supported for origin.
  • scale - Required for all types. Defines the distance from origin + offset at which the computed score will equal decay parameter. For geo fields: Can be defined as number+unit (1km, 12m,…​). Default unit is meters. For date fields: Can to be defined as a number+unit (“1h”, “10d”,…​). Default unit is milliseconds. For numeric field: Any number.
Source

pub fn filter<T>(self, filter: T) -> Self
where T: Into<Option<Query>>,

Add function filter

Source

pub fn weight<T>(self, weight: T) -> Self
where T: AsPrimitive<f32>,

The weight score allows you to multiply the score by the provided weight. This can sometimes be desired since boost value set on specific queries gets normalized, while for this score function it does not. The number value is of type float.

Source

pub fn offset(self, offset: <O as Origin>::Offset) -> Self

If an offset is defined, the decay function will only compute the decay function for documents with a distance greater than the defined offset.

The default is 0.

Source

pub fn decay(self, decay: f32) -> Self

The decay parameter defines how documents are scored at the distance given at scale. If no decay is defined, documents at the distance scale will be scored 0.5.

Trait Implementations§

Source§

impl<T: Clone + Origin> Clone for Decay<T>

Source§

fn clone(&self) -> Decay<T>

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<T: Debug + Origin> Debug for Decay<T>

Source§

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

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

impl From<Decay<DateTime<Utc>>> for Function

Source§

fn from(q: Decay<DateTime<Utc>>) -> Self

Converts to this type from the input type.
Source§

impl From<Decay<DateTime<Utc>>> for Option<Function>

Source§

fn from(q: Decay<DateTime<Utc>>) -> Self

Converts to this type from the input type.
Source§

impl From<Decay<GeoLocation>> for Function

Source§

fn from(q: Decay<GeoLocation>) -> Self

Converts to this type from the input type.
Source§

impl From<Decay<GeoLocation>> for Option<Function>

Source§

fn from(q: Decay<GeoLocation>) -> Self

Converts to this type from the input type.
Source§

impl From<Decay<f32>> for Function

Source§

fn from(q: Decay<f32>) -> Self

Converts to this type from the input type.
Source§

impl From<Decay<f32>> for Option<Function>

Source§

fn from(q: Decay<f32>) -> Self

Converts to this type from the input type.
Source§

impl From<Decay<f64>> for Function

Source§

fn from(q: Decay<f64>) -> Self

Converts to this type from the input type.
Source§

impl From<Decay<f64>> for Option<Function>

Source§

fn from(q: Decay<f64>) -> Self

Converts to this type from the input type.
Source§

impl From<Decay<i16>> for Function

Source§

fn from(q: Decay<i16>) -> Self

Converts to this type from the input type.
Source§

impl From<Decay<i16>> for Option<Function>

Source§

fn from(q: Decay<i16>) -> Self

Converts to this type from the input type.
Source§

impl From<Decay<i32>> for Function

Source§

fn from(q: Decay<i32>) -> Self

Converts to this type from the input type.
Source§

impl From<Decay<i32>> for Option<Function>

Source§

fn from(q: Decay<i32>) -> Self

Converts to this type from the input type.
Source§

impl From<Decay<i64>> for Function

Source§

fn from(q: Decay<i64>) -> Self

Converts to this type from the input type.
Source§

impl From<Decay<i64>> for Option<Function>

Source§

fn from(q: Decay<i64>) -> Self

Converts to this type from the input type.
Source§

impl From<Decay<i8>> for Function

Source§

fn from(q: Decay<i8>) -> Self

Converts to this type from the input type.
Source§

impl From<Decay<i8>> for Option<Function>

Source§

fn from(q: Decay<i8>) -> Self

Converts to this type from the input type.
Source§

impl From<Decay<u16>> for Function

Source§

fn from(q: Decay<u16>) -> Self

Converts to this type from the input type.
Source§

impl From<Decay<u16>> for Option<Function>

Source§

fn from(q: Decay<u16>) -> Self

Converts to this type from the input type.
Source§

impl From<Decay<u32>> for Function

Source§

fn from(q: Decay<u32>) -> Self

Converts to this type from the input type.
Source§

impl From<Decay<u32>> for Option<Function>

Source§

fn from(q: Decay<u32>) -> Self

Converts to this type from the input type.
Source§

impl From<Decay<u64>> for Function

Source§

fn from(q: Decay<u64>) -> Self

Converts to this type from the input type.
Source§

impl From<Decay<u64>> for Option<Function>

Source§

fn from(q: Decay<u64>) -> Self

Converts to this type from the input type.
Source§

impl From<Decay<u8>> for Function

Source§

fn from(q: Decay<u8>) -> Self

Converts to this type from the input type.
Source§

impl From<Decay<u8>> for Option<Function>

Source§

fn from(q: Decay<u8>) -> Self

Converts to this type from the input type.
Source§

impl<T: PartialEq + Origin> PartialEq for Decay<T>

Source§

fn eq(&self, other: &Decay<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: Origin> Serialize for Decay<T>

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<T: Origin> StructuralPartialEq for Decay<T>

Auto Trait Implementations§

§

impl<T> Freeze for Decay<T>
where T: Freeze, <T as Origin>::Scale: Freeze, <T as Origin>::Offset: Freeze,

§

impl<T> RefUnwindSafe for Decay<T>
where T: RefUnwindSafe, <T as Origin>::Scale: RefUnwindSafe, <T as Origin>::Offset: RefUnwindSafe,

§

impl<T> Send for Decay<T>
where T: Send, <T as Origin>::Scale: Send, <T as Origin>::Offset: Send,

§

impl<T> Sync for Decay<T>
where T: Sync, <T as Origin>::Scale: Sync, <T as Origin>::Offset: Sync,

§

impl<T> Unpin for Decay<T>
where T: Unpin, <T as Origin>::Scale: Unpin, <T as Origin>::Offset: Unpin,

§

impl<T> UnwindSafe for Decay<T>
where T: UnwindSafe, <T as Origin>::Scale: UnwindSafe, <T as Origin>::Offset: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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>,

Source§

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>,

Source§

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.