Struct DistanceFeatureQuery

Source
pub struct DistanceFeatureQuery<O>
where O: Origin,
{ /* private fields */ }
Expand description

Boosts the relevance score of documents closer to a provided origin date or point. For example, you can use this query to give more weight to documents closer to a certain date or location.

You can use the distance_feature query to find the nearest neighbors to a location. You can also use the query in a bool search’s should filter to add boosted relevance scores to the bool query’s scores.

How the distance_feature query calculates relevance scores

The distance_feature query dynamically calculates the distance between the origin value and a document’s field values. It then uses this distance as a feature to boost the relevance-scores of closer documents.

The distance_feature query calculates a document’s relevance score as follows:

relevance score = boost * pivot / (pivot + distance)

The distance is the absolute difference between the origin value and a document’s field value.

Skip non-competitive hits

Unlike the function_score query or other ways to change relevance scores , the distance_feature query efficiently skips non-competitive hits when the track_total_hits parameter is not true.

To create distance feature query date query:

Query::distance_feature("test", Utc.with_ymd_and_hms(2014, 7, 8, 9, 1, 0).unwrap(), Time::Days(7))
    .boost(1.5)
    .name("test");

To create distance feature query geo query:

Query::distance_feature("test", GeoLocation::new(-71.34, 40.12), Distance::Kilometers(15))
    .boost(1.5)
    .name("test");

Distance Feature is built to allow only valid origin and pivot values, the following won’t compile:

Query::distance_feature("test", Utc.with_ymd_and_hms(2014, 7, 8, 9, 1, 0).unwrap(), Distance::Kilometers(15))
    .boost(1.5)
    .name("test");

https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-distance-feature-query.html

Implementations§

Source§

impl<O> DistanceFeatureQuery<O>
where O: Origin + Serialize,

Source

pub fn serialize<__S>( __self: &DistanceFeatureQuery<O>, __serializer: __S, ) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Source§

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

Source

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

Floating point number used to decrease or increase the relevance scores of a query. Defaults to 1.0.

You can use the boost parameter to adjust relevance scores for searches containing two or more queries.

Boost values are relative to the default value of 1.0. A boost value between 0 and 1.0 decreases the relevance score. A value greater than 1.0 increases the relevance score.

Source

pub fn name<S>(self, name: S) -> Self
where S: ToString,

You can use named queries to track which queries matched returned documents. If named queries are used, the response includes a matched_queries property for each hit.

https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html#named-queries

Trait Implementations§

Source§

impl<O> Clone for DistanceFeatureQuery<O>
where O: Origin + Clone,

Source§

fn clone(&self) -> DistanceFeatureQuery<O>

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<O> Debug for DistanceFeatureQuery<O>
where O: Origin + Debug,

Source§

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

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

impl From<DistanceFeatureQuery<DateTime<Utc>>> for Option<Query>

Source§

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

Converts to this type from the input type.
Source§

impl From<DistanceFeatureQuery<DateTime<Utc>>> for Query

Source§

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

Converts to this type from the input type.
Source§

impl From<DistanceFeatureQuery<GeoLocation>> for Option<Query>

Source§

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

Converts to this type from the input type.
Source§

impl From<DistanceFeatureQuery<GeoLocation>> for Query

Source§

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

Converts to this type from the input type.
Source§

impl IntoIterator for DistanceFeatureQuery<DateTime<Utc>>

Source§

type Item = DistanceFeatureQuery<DateTime<Utc>>

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<<DistanceFeatureQuery<DateTime<Utc>> as IntoIterator>::Item>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl IntoIterator for DistanceFeatureQuery<GeoLocation>

Source§

type Item = DistanceFeatureQuery<GeoLocation>

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<<DistanceFeatureQuery<GeoLocation> as IntoIterator>::Item>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl PartialEq<DistanceFeatureQuery<DateTime<Utc>>> for Query

Source§

fn eq(&self, other: &DistanceFeatureQuery<DateTime<Utc>>) -> 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 PartialEq<DistanceFeatureQuery<GeoLocation>> for Query

Source§

fn eq(&self, other: &DistanceFeatureQuery<GeoLocation>) -> 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 PartialEq<Query> for DistanceFeatureQuery<DateTime<Utc>>

Source§

fn eq(&self, other: &Query) -> 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 PartialEq<Query> for DistanceFeatureQuery<GeoLocation>

Source§

fn eq(&self, other: &Query) -> 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<O> PartialEq for DistanceFeatureQuery<O>
where O: Origin + PartialEq,

Source§

fn eq(&self, other: &DistanceFeatureQuery<O>) -> 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 DistanceFeatureQuery<DateTime<Utc>>

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 Serialize for DistanceFeatureQuery<GeoLocation>

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<O> StructuralPartialEq for DistanceFeatureQuery<O>
where O: Origin,

Auto Trait Implementations§

§

impl<O> Freeze for DistanceFeatureQuery<O>
where O: Freeze, <O as Origin>::Pivot: Freeze,

§

impl<O> RefUnwindSafe for DistanceFeatureQuery<O>
where O: RefUnwindSafe, <O as Origin>::Pivot: RefUnwindSafe,

§

impl<O> Send for DistanceFeatureQuery<O>
where O: Send, <O as Origin>::Pivot: Send,

§

impl<O> Sync for DistanceFeatureQuery<O>
where O: Sync, <O as Origin>::Pivot: Sync,

§

impl<O> Unpin for DistanceFeatureQuery<O>
where O: Unpin, <O as Origin>::Pivot: Unpin,

§

impl<O> UnwindSafe for DistanceFeatureQuery<O>
where O: UnwindSafe, <O as Origin>::Pivot: 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.