Struct FieldValueFactor

Source
pub struct FieldValueFactor { /* private fields */ }
Expand description

The field_value_factor function allows you to use a field from a document to influence the score. It’s similar to using the script_score function, however, it avoids the overhead of scripting. If used on a multi-valued field, only the first value of the field is used in calculations.

As an example, imagine you have a document indexed with a numeric my-int field and wish to influence the score of a document with this field, an example doing so would look like:

FieldValueFactor::new("my-int")
    .factor(1.2)
    .modifier(FieldValueFactorModifier::Sqrt)
    .missing(1.0)

Which will translate into the following formula for scoring:

sqrt(1.2 * doc['my-int'].value)

Implementations§

Source§

impl FieldValueFactor

Source

pub fn new<T>(field: T) -> Self
where T: ToString,

Creates an instance of FieldValueFactor

  • field - Field to be extracted from the document.
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 factor(self, factor: f32) -> Self

Factor to multiply the field value with

Source

pub fn modifier(self, modifier: FieldValueFactorModifier) -> Self

Modifier to apply to the field value

Source

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

Value used if the document doesn’t have that field. The modifier and factor are still applied to it as though it were read from the document

Trait Implementations§

Source§

impl Clone for FieldValueFactor

Source§

fn clone(&self) -> FieldValueFactor

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 FieldValueFactor

Source§

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

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

impl From<FieldValueFactor> for Function

Source§

fn from(q: FieldValueFactor) -> Self

Converts to this type from the input type.
Source§

impl From<FieldValueFactor> for Option<Function>

Source§

fn from(q: FieldValueFactor) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for FieldValueFactor

Source§

fn eq(&self, other: &FieldValueFactor) -> 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 Serialize for FieldValueFactor

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 StructuralPartialEq for FieldValueFactor

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