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");
Implementations§
Source§impl<O> DistanceFeatureQuery<O>where
O: Origin + Serialize,
impl<O> DistanceFeatureQuery<O>where
O: Origin + Serialize,
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,
impl<O> DistanceFeatureQuery<O>where
O: Origin,
Sourcepub fn boost<T>(self, boost: T) -> Selfwhere
T: AsPrimitive<f32>,
pub fn boost<T>(self, boost: T) -> Selfwhere
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§
Source§impl<O> Clone for DistanceFeatureQuery<O>where
O: Origin + Clone,
impl<O> Clone for DistanceFeatureQuery<O>where
O: Origin + Clone,
Source§fn clone(&self) -> DistanceFeatureQuery<O>
fn clone(&self) -> DistanceFeatureQuery<O>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<O> Debug for DistanceFeatureQuery<O>where
O: Origin + Debug,
impl<O> Debug for DistanceFeatureQuery<O>where
O: Origin + Debug,
Source§impl From<DistanceFeatureQuery<GeoLocation>> for Option<Query>
impl From<DistanceFeatureQuery<GeoLocation>> for Option<Query>
Source§fn from(q: DistanceFeatureQuery<GeoLocation>) -> Self
fn from(q: DistanceFeatureQuery<GeoLocation>) -> Self
Source§impl From<DistanceFeatureQuery<GeoLocation>> for Query
impl From<DistanceFeatureQuery<GeoLocation>> for Query
Source§fn from(q: DistanceFeatureQuery<GeoLocation>) -> Self
fn from(q: DistanceFeatureQuery<GeoLocation>) -> Self
Source§impl IntoIterator for DistanceFeatureQuery<DateTime<Utc>>
impl IntoIterator for DistanceFeatureQuery<DateTime<Utc>>
Source§type IntoIter = IntoIter<<DistanceFeatureQuery<DateTime<Utc>> as IntoIterator>::Item>
type IntoIter = IntoIter<<DistanceFeatureQuery<DateTime<Utc>> as IntoIterator>::Item>
Source§impl IntoIterator for DistanceFeatureQuery<GeoLocation>
impl IntoIterator for DistanceFeatureQuery<GeoLocation>
Source§type Item = DistanceFeatureQuery<GeoLocation>
type Item = DistanceFeatureQuery<GeoLocation>
Source§type IntoIter = IntoIter<<DistanceFeatureQuery<GeoLocation> as IntoIterator>::Item>
type IntoIter = IntoIter<<DistanceFeatureQuery<GeoLocation> as IntoIterator>::Item>
Source§impl PartialEq<DistanceFeatureQuery<DateTime<Utc>>> for Query
impl PartialEq<DistanceFeatureQuery<DateTime<Utc>>> for Query
Source§impl PartialEq<DistanceFeatureQuery<GeoLocation>> for Query
impl PartialEq<DistanceFeatureQuery<GeoLocation>> for Query
Source§fn eq(&self, other: &DistanceFeatureQuery<GeoLocation>) -> bool
fn eq(&self, other: &DistanceFeatureQuery<GeoLocation>) -> bool
self
and other
values to be equal, and is used by ==
.