Struct elasticsearch_dsl::search::queries::specialized::DistanceFeatureQuery
source · [−]pub struct DistanceFeatureQuery<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", GeoPoint::coordinates(12.0, 13.0), 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: Origin> DistanceFeatureQuery<O>
impl<O: Origin> DistanceFeatureQuery<O>
sourcepub fn boost<B>(self, boost: B) -> Self where
B: TryInto<Boost>,
pub fn boost<B>(self, boost: B) -> Self where
B: TryInto<Boost>,
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 + Origin> Clone for DistanceFeatureQuery<O>
impl<O: Clone + Origin> Clone for DistanceFeatureQuery<O>
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 + Origin> Debug for DistanceFeatureQuery<O>
impl<O: Debug + Origin> Debug for DistanceFeatureQuery<O>
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<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 Queries
impl From<DistanceFeatureQuery<DateTime<Utc>>> for Queries
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<GeoPoint>> for Query
impl From<DistanceFeatureQuery<GeoPoint>> for Query
sourcefn from(q: DistanceFeatureQuery<GeoPoint>) -> Self
fn from(q: DistanceFeatureQuery<GeoPoint>) -> Self
Converts to this type from the input type.
sourceimpl From<DistanceFeatureQuery<GeoPoint>> for Option<Query>
impl From<DistanceFeatureQuery<GeoPoint>> for Option<Query>
sourcefn from(q: DistanceFeatureQuery<GeoPoint>) -> Self
fn from(q: DistanceFeatureQuery<GeoPoint>) -> Self
Converts to this type from the input type.
sourceimpl From<DistanceFeatureQuery<GeoPoint>> for Queries
impl From<DistanceFeatureQuery<GeoPoint>> for Queries
sourcefn from(q: DistanceFeatureQuery<GeoPoint>) -> Self
fn from(q: DistanceFeatureQuery<GeoPoint>) -> Self
Converts to this type from the input type.
sourceimpl PartialEq<DistanceFeatureQuery<GeoPoint>> for Query
impl PartialEq<DistanceFeatureQuery<GeoPoint>> for Query
sourceimpl<O: PartialEq + Origin> PartialEq<DistanceFeatureQuery<O>> for DistanceFeatureQuery<O>
impl<O: PartialEq + Origin> PartialEq<DistanceFeatureQuery<O>> for DistanceFeatureQuery<O>
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<GeoPoint>
impl PartialEq<Query> for DistanceFeatureQuery<GeoPoint>
sourceimpl<O: Origin> Serialize for DistanceFeatureQuery<O> where
O: Serialize,
impl<O: Origin> Serialize for DistanceFeatureQuery<O> where
O: Serialize,
impl<O: Origin> StructuralPartialEq for DistanceFeatureQuery<O>
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