Struct elasticsearch_dsl::search::queries::specialized::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.ymd(2014, 7, 8).and_hms(9, 1, 0), 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.ymd(2014, 7, 8).and_hms(9, 1, 0), Distance::Kilometers(15))
.boost(1.5)
.name("test");
Implementations
sourceimpl<O> DistanceFeatureQuery<O> where
O: Origin,
impl<O> DistanceFeatureQuery<O> where
O: Origin,
sourcepub fn boost<T>(self, boost: T) -> Self where
T: AsPrimitive<f32>,
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.
Trait Implementations
sourceimpl<O: Clone> Clone for DistanceFeatureQuery<O> where
O: Origin,
impl<O: Clone> Clone for DistanceFeatureQuery<O> where
O: Origin,
sourcefn clone(&self) -> DistanceFeatureQuery<O>
fn clone(&self) -> DistanceFeatureQuery<O>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl<O: Debug> Debug for DistanceFeatureQuery<O> where
O: Origin,
impl<O: Debug> Debug for DistanceFeatureQuery<O> where
O: Origin,
sourceimpl From<DistanceFeatureQuery<DateTime<Utc>>> for Option<Query>
impl From<DistanceFeatureQuery<DateTime<Utc>>> for Option<Query>
sourcefn from(q: DistanceFeatureQuery<DateTime<Utc>>) -> Self
fn from(q: DistanceFeatureQuery<DateTime<Utc>>) -> Self
Converts to this type from the input type.
sourceimpl From<DistanceFeatureQuery<DateTime<Utc>>> for Query
impl From<DistanceFeatureQuery<DateTime<Utc>>> for Query
sourcefn from(q: DistanceFeatureQuery<DateTime<Utc>>) -> Self
fn from(q: DistanceFeatureQuery<DateTime<Utc>>) -> Self
Converts to this type from the input type.
sourceimpl From<DistanceFeatureQuery<GeoLocation>> for Option<Query>
impl From<DistanceFeatureQuery<GeoLocation>> for Option<Query>
sourcefn from(q: DistanceFeatureQuery<GeoLocation>) -> Self
fn from(q: DistanceFeatureQuery<GeoLocation>) -> Self
Converts to this type from the input type.
sourceimpl From<DistanceFeatureQuery<GeoLocation>> for Query
impl From<DistanceFeatureQuery<GeoLocation>> for Query
sourcefn from(q: DistanceFeatureQuery<GeoLocation>) -> Self
fn from(q: DistanceFeatureQuery<GeoLocation>) -> Self
Converts to this type from the input type.
sourceimpl IntoIterator for DistanceFeatureQuery<DateTime<Utc>>
impl IntoIterator for DistanceFeatureQuery<DateTime<Utc>>
type Item = DistanceFeatureQuery<DateTime<Utc>>
type Item = DistanceFeatureQuery<DateTime<Utc>>
The type of the elements being iterated over.
type IntoIter = IntoIter<<DistanceFeatureQuery<DateTime<Utc>> as IntoIterator>::Item>
type IntoIter = IntoIter<<DistanceFeatureQuery<DateTime<Utc>> as IntoIterator>::Item>
Which kind of iterator are we turning this into?
sourceimpl IntoIterator for DistanceFeatureQuery<GeoLocation>
impl IntoIterator for DistanceFeatureQuery<GeoLocation>
type Item = DistanceFeatureQuery<GeoLocation>
type Item = DistanceFeatureQuery<GeoLocation>
The type of the elements being iterated over.
type IntoIter = IntoIter<<DistanceFeatureQuery<GeoLocation> as IntoIterator>::Item>
type IntoIter = IntoIter<<DistanceFeatureQuery<GeoLocation> as IntoIterator>::Item>
Which kind of iterator are we turning this into?
sourceimpl PartialEq<DistanceFeatureQuery<GeoLocation>> for Query
impl PartialEq<DistanceFeatureQuery<GeoLocation>> for Query
sourcefn eq(&self, other: &DistanceFeatureQuery<GeoLocation>) -> bool
fn eq(&self, other: &DistanceFeatureQuery<GeoLocation>) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourceimpl<O: PartialEq> PartialEq<DistanceFeatureQuery<O>> for DistanceFeatureQuery<O> where
O: Origin,
impl<O: PartialEq> PartialEq<DistanceFeatureQuery<O>> for DistanceFeatureQuery<O> where
O: Origin,
sourcefn eq(&self, other: &DistanceFeatureQuery<O>) -> bool
fn eq(&self, other: &DistanceFeatureQuery<O>) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &DistanceFeatureQuery<O>) -> bool
fn ne(&self, other: &DistanceFeatureQuery<O>) -> bool
This method tests for !=
.
sourceimpl PartialEq<Query> for DistanceFeatureQuery<GeoLocation>
impl PartialEq<Query> for DistanceFeatureQuery<GeoLocation>
sourceimpl Serialize for DistanceFeatureQuery<DateTime<Utc>>
impl Serialize for DistanceFeatureQuery<DateTime<Utc>>
sourceimpl Serialize for DistanceFeatureQuery<GeoLocation>
impl Serialize for DistanceFeatureQuery<GeoLocation>
impl<O> StructuralPartialEq for DistanceFeatureQuery<O> where
O: Origin,
Auto Trait Implementations
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more