Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement indices boost and min score #119

Merged
merged 2 commits into from Jan 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "elasticsearch-dsl"
version = "0.2.2"
version = "0.2.3"
authors = ["Boost <boost@vinted.com>"]
edition = "2018"
description = "Strongly typed Elasticsearch DSL"
Expand Down
35 changes: 35 additions & 0 deletions src/search/request.rs
Expand Up @@ -11,6 +11,12 @@ pub struct Search {
#[serde(skip_serializing_if = "ShouldSkip::should_skip")]
runtime_mappings: BTreeMap<String, RuntimeMapping>,

#[serde(skip_serializing_if = "ShouldSkip::should_skip")]
indices_boost: Vec<KeyValuePair<String, Boost>>,

#[serde(skip_serializing_if = "ShouldSkip::should_skip")]
min_score: Option<f32>,

#[serde(skip_serializing_if = "ShouldSkip::should_skip")]
_source: Option<SourceFilter>,

Expand Down Expand Up @@ -57,6 +63,35 @@ impl Search {
self
}

/// Allows to configure different boost level per index when searching
/// across more than one indices. This is very handy when hits coming from
/// one index matter more than hits coming from another index (think social
/// graph where each user has an index).
pub fn indices_boost<F, B>(mut self, field: F, boost: B) -> Self
where
F: ToString,
B: TryInto<Boost>,
{
if let Ok(boost) = boost.try_into() {
self.indices_boost
.push(KeyValuePair::new(field.to_string(), boost));
}
self
}

/// Exclude documents which have a `_score` less than the minimum specified
/// in `min_score`
///
/// Note, most times, this does not make much sense, but is provided for
/// advanced use cases
pub fn min_score<F>(mut self, min_score: F) -> Self
where
F: Into<f32>,
{
self.min_score = Some(min_score.into());
self
}

/// Indicates which source fields are returned for matching documents
pub fn source<S>(mut self, source: S) -> Self
where
Expand Down