Skip to content

Commit

Permalink
feature: add adjust_pure_negative flag into bool query
Browse files Browse the repository at this point in the history
  • Loading branch information
GokselKUCUKSAHIN committed Oct 26, 2024
1 parent 1a08d8e commit 0d5b6e5
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
24 changes: 24 additions & 0 deletions es/bool_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,30 @@ func (b BoolType) MinimumShouldMatch(minimumShouldMatch int) BoolType {
return b
}

// AdjustPureNegative sets the "adjust_pure_negative" parameter in a BoolType query.
//
// This method allows you to specify whether pure negative queries should be
// adjusted or not. When set to true, the query will be adjusted to include
// pure negative queries, which can influence the matching behavior of the
// boolean query.
//
// Example usage:
//
// b := Bool().AdjustPureNegative(true)
// // b now includes an "adjust_pure_negative" parameter set to true.
//
// Parameters:
// - adjustPureNegative: A boolean value indicating whether to adjust
// pure negative queries in the boolean query.
//
// Returns:
//
// The updated BoolType object with the "adjust_pure_negative" parameter set.
func (b BoolType) AdjustPureNegative(adjustPureNegative bool) BoolType {
b["adjust_pure_negative"] = adjustPureNegative
return b
}

// Boost sets the "boost" parameter in a BoolType query.
//
// This method allows you to assign a boost value to a boolean query, which
Expand Down
21 changes: 21 additions & 0 deletions es/bool_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,27 @@ func Test_Bool_MinimumShouldMatch_should_create_json_with_minimum_should_match_f
assert.Equal(t, "{\"query\":{\"bool\":{\"minimum_should_match\":7}}}", bodyJSON)
}

func Test_Bool_should_have_AdjustPureNegative_method(t *testing.T) {
// Given
b := es.Bool()

// When Then
assert.NotNil(t, b.AdjustPureNegative)
}

func Test_Bool_AdjustPureNegative_should_create_json_with_adjust_pure_negative_field_inside_bool(t *testing.T) {
// Given
query := es.NewQuery(
es.Bool().
AdjustPureNegative(false),
)

// When Then
assert.NotNil(t, query)
bodyJSON := assert.MarshalWithoutError(t, query)
assert.Equal(t, "{\"query\":{\"bool\":{\"adjust_pure_negative\":false}}}", bodyJSON)
}

func Test_Bool_should_have_Boost_method(t *testing.T) {
// Given
b := es.Bool()
Expand Down

0 comments on commit 0d5b6e5

Please sign in to comment.