Skip to content

Commit

Permalink
Implement post filter (#219)
Browse files Browse the repository at this point in the history
  • Loading branch information
buinauskas committed Jun 29, 2023
1 parent 11799e4 commit d875f59
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
13 changes: 13 additions & 0 deletions src/search/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ pub struct Search {

#[serde(skip_serializing_if = "ShouldSkip::should_skip")]
docvalue_fields: Set<String>,

#[serde(skip_serializing_if = "ShouldSkip::should_skip")]
post_filter: Option<Query>,
}

impl Search {
Expand Down Expand Up @@ -144,6 +147,16 @@ impl Search {
self
}

/// When you use the `post_filter` parameter to filter search results, the search hits are filtered after the
/// aggregations are calculated. A post filter has no impact on the aggregation results.
pub fn post_filter<Q>(mut self, post_filter: Q) -> Self
where
Q: Into<Query>,
{
self.post_filter = Some(post_filter.into());
self
}

/// A collection of sorting fields
pub fn sort<T>(mut self, sort: T) -> Self
where
Expand Down
9 changes: 6 additions & 3 deletions src/util/assert_serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ where
#[cfg(test)]
pub(crate) fn assert_serialize_query<T>(subject: T, expectation: serde_json::Value)
where
T: Into<crate::Query>,
T: Into<crate::Query> + Clone,
{
let subject = crate::Search::new().query(subject);
let expectation = json!({ "query": expectation });
let subject = crate::Search::new()
.query(subject.clone())
.post_filter(subject);

let expectation = json!({ "query": expectation, "post_filter": expectation });

assert_serialize(subject, expectation)
}
Expand Down

0 comments on commit d875f59

Please sign in to comment.