Skip to content

Commit

Permalink
Merge pull request #10 from Trendyol/feature/bool-access-modifier-change
Browse files Browse the repository at this point in the history
feature: change access modifiers of boolTypes.
  • Loading branch information
bayraktugrul authored Sep 17, 2024
2 parents a7a8931 + a280dd9 commit 33c21f7
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 52 deletions.
84 changes: 42 additions & 42 deletions es/bool_query.go
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
package es

type boolType Object
type BoolType Object

type filterType Array
type FilterType Array

type mustType Array
type MustType Array

type mustNotType Array
type MustNotType Array

type shouldType Array
type ShouldType Array

// Bool creates and returns an empty boolType object.
// Bool creates and returns an empty BoolType object.
//
// This function is typically used to initialize a boolType, which can be
// This function is typically used to initialize a BoolType, which can be
// populated later with the appropriate boolean query conditions.
//
// Example usage:
//
// b := Bool()
// // b is now an empty boolType object that can be used in a query.
// // b is now an empty BoolType object that can be used in a query.
//
// Returns:
//
// An empty boolType object.
func Bool() boolType {
return boolType{}
// An empty BoolType object.
func Bool() BoolType {
return BoolType{}
}

// MinimumShouldMatch sets the "minimum_should_match" parameter in a boolType query.
// MinimumShouldMatch sets the "minimum_should_match" parameter in a BoolType query.
//
// This method allows you to specify the minimum number of "should" clauses
// that must match in a boolean query. The "minimum_should_match" parameter
Expand All @@ -45,13 +45,13 @@ func Bool() boolType {
//
// Returns:
//
// The updated boolType object with the "minimum_should_match" parameter set.
func (b boolType) MinimumShouldMatch(minimumShouldMatch int) boolType {
// The updated BoolType object with the "minimum_should_match" parameter set.
func (b BoolType) MinimumShouldMatch(minimumShouldMatch int) BoolType {
b["minimum_should_match"] = minimumShouldMatch
return b
}

// Boost sets the "boost" parameter in a boolType query.
// Boost sets the "boost" parameter in a BoolType query.
//
// This method allows you to assign a boost value to a boolean query, which
// can be used to increase or decrease the relevance score of the query's
Expand All @@ -70,17 +70,17 @@ func (b boolType) MinimumShouldMatch(minimumShouldMatch int) boolType {
//
// Returns:
//
// The updated boolType object with the "boost" parameter set.
func (b boolType) Boost(boost float64) boolType {
// The updated BoolType object with the "boost" parameter set.
func (b BoolType) Boost(boost float64) BoolType {
b["boost"] = boost
return b
}

// Filter adds one or more filter conditions to the boolType object.
// Filter adds one or more filter conditions to the BoolType object.
//
// This method updates the "filter" section of the boolType object by appending
// This method updates the "filter" section of the BoolType object by appending
// the specified filter conditions. It accepts a variadic number of filter conditions,
// checks their types, and adds them to the "filter" array in the boolType object.
// checks their types, and adds them to the "filter" array in the BoolType object.
//
// Example usage:
//
Expand All @@ -96,11 +96,11 @@ func (b boolType) Boost(boost float64) boolType {
//
// Returns:
//
// The updated boolType object with the new filter conditions added.
func (b boolType) Filter(items ...any) boolType {
filter, ok := b["filter"].(filterType)
// The updated BoolType object with the new filter conditions added.
func (b BoolType) Filter(items ...any) BoolType {
filter, ok := b["filter"].(FilterType)
if !ok {
filter = filterType{}
filter = FilterType{}
}
for i := 0; i < len(items); i++ {
if field, fOk := correctType(items[i]); fOk {
Expand All @@ -111,11 +111,11 @@ func (b boolType) Filter(items ...any) boolType {
return b
}

// Must adds one or more conditions to the "must" section of the boolType object.
// Must adds one or more conditions to the "must" section of the BoolType object.
//
// This method updates the "must" section by appending the specified conditions.
// It accepts a variadic number of conditions, checks their types, and adds them to
// the "must" array in the boolType object.
// the "must" array in the BoolType object.
//
// Example usage:
//
Expand All @@ -131,11 +131,11 @@ func (b boolType) Filter(items ...any) boolType {
//
// Returns:
//
// The updated boolType object with the new conditions added to the "must" section.
func (b boolType) Must(items ...any) boolType {
must, ok := b["must"].(mustType)
// The updated BoolType object with the new conditions added to the "must" section.
func (b BoolType) Must(items ...any) BoolType {
must, ok := b["must"].(MustType)
if !ok {
must = mustType{}
must = MustType{}
}
for i := 0; i < len(items); i++ {
if field, fOk := correctType(items[i]); fOk {
Expand All @@ -146,11 +146,11 @@ func (b boolType) Must(items ...any) boolType {
return b
}

// MustNot adds one or more conditions to the "must_not" section of the boolType object.
// MustNot adds one or more conditions to the "must_not" section of the BoolType object.
//
// This method updates the "must_not" section by appending the specified conditions.
// It accepts a variadic number of conditions, checks their types, and adds them to
// the "must_not" array in the boolType object.
// the "must_not" array in the BoolType object.
//
// Example usage:
//
Expand All @@ -166,11 +166,11 @@ func (b boolType) Must(items ...any) boolType {
//
// Returns:
//
// The updated boolType object with the new conditions added to the "must_not" section.
func (b boolType) MustNot(items ...any) boolType {
mustNot, ok := b["must_not"].(mustNotType)
// The updated BoolType object with the new conditions added to the "must_not" section.
func (b BoolType) MustNot(items ...any) BoolType {
mustNot, ok := b["must_not"].(MustNotType)
if !ok {
mustNot = mustNotType{}
mustNot = MustNotType{}
}
for i := 0; i < len(items); i++ {
if field, fOk := correctType(items[i]); fOk {
Expand All @@ -181,11 +181,11 @@ func (b boolType) MustNot(items ...any) boolType {
return b
}

// Should adds one or more conditions to the "should" section of the boolType object.
// Should adds one or more conditions to the "should" section of the BoolType object.
//
// This method updates the "should" section by appending the specified conditions.
// It accepts a variadic number of conditions, checks their types, and adds them to
// the "should" array in the boolType object.
// the "should" array in the BoolType object.
//
// Example usage:
//
Expand All @@ -201,11 +201,11 @@ func (b boolType) MustNot(items ...any) boolType {
//
// Returns:
//
// The updated boolType object with the new conditions added to the "should" section.
func (b boolType) Should(items ...any) boolType {
should, ok := b["should"].(shouldType)
// The updated BoolType object with the new conditions added to the "should" section.
func (b BoolType) Should(items ...any) BoolType {
should, ok := b["should"].(ShouldType)
if !ok {
should = shouldType{}
should = ShouldType{}
}
for i := 0; i < len(items); i++ {
if field, fOk := correctType(items[i]); fOk {
Expand Down
18 changes: 9 additions & 9 deletions es/bool_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func Test_Bool_method_should_create_boolType(t *testing.T) {

// Then
assert.NotNil(t, b)
assert.IsTypeString(t, "es.boolType", b)
assert.IsTypeString(t, "es.BoolType", b)
}

func Test_Bool_should_have_MinimumShouldMatch_method(t *testing.T) {
Expand Down Expand Up @@ -108,7 +108,7 @@ func Test_Filter_method_should_return_boolType(t *testing.T) {

// Then
assert.NotNil(t, filter)
assert.IsTypeString(t, "es.boolType", filter)
assert.IsTypeString(t, "es.BoolType", filter)
}

func Test_Filter_method_should_add_filter_if_doesnt_exist_before(t *testing.T) {
Expand Down Expand Up @@ -138,7 +138,7 @@ func Test_Filter_method_should_hold_items(t *testing.T) {

// Then
assert.True(t, exists)
assert.IsTypeString(t, "es.filterType", filter)
assert.IsTypeString(t, "es.FilterType", filter)

bodyJSON := assert.MarshalWithoutError(t, b)
assert.Equal(t, "{\"filter\":[{\"term\":{\"id\":12345}}]}", bodyJSON)
Expand All @@ -155,7 +155,7 @@ func Test_Must_method_should_return_boolType(t *testing.T) {

// Then
assert.NotNil(t, must)
assert.IsTypeString(t, "es.boolType", must)
assert.IsTypeString(t, "es.BoolType", must)
}

func Test_Must_method_should_add_must_if_doesnt_exist_before(t *testing.T) {
Expand Down Expand Up @@ -185,7 +185,7 @@ func Test_Must_method_should_hold_items(t *testing.T) {

// Then
assert.True(t, exists)
assert.IsTypeString(t, "es.mustType", must)
assert.IsTypeString(t, "es.MustType", must)

bodyJSON := assert.MarshalWithoutError(t, b)
assert.Equal(t, "{\"must\":[{\"term\":{\"id\":12345}}]}", bodyJSON)
Expand All @@ -202,7 +202,7 @@ func Test_MustNot_method_should_return_boolType(t *testing.T) {

// Then
assert.NotNil(t, mustNot)
assert.IsTypeString(t, "es.boolType", mustNot)
assert.IsTypeString(t, "es.BoolType", mustNot)
}

func Test_MustNot_method_should_add_must_not_if_doesnt_exist_before(t *testing.T) {
Expand Down Expand Up @@ -232,7 +232,7 @@ func Test_MustNot_method_should_hold_items(t *testing.T) {

// Then
assert.True(t, exists)
assert.IsTypeString(t, "es.mustNotType", mustNot)
assert.IsTypeString(t, "es.MustNotType", mustNot)

bodyJSON := assert.MarshalWithoutError(t, b)
assert.Equal(t, "{\"must_not\":[{\"term\":{\"id\":12345}}]}", bodyJSON)
Expand All @@ -249,7 +249,7 @@ func Test_Should_method_should_return_boolType(t *testing.T) {

// Then
assert.NotNil(t, should)
assert.IsTypeString(t, "es.boolType", should)
assert.IsTypeString(t, "es.BoolType", should)
}

func Test_Should_method_should_add_should_if_doesnt_exist_before(t *testing.T) {
Expand Down Expand Up @@ -279,7 +279,7 @@ func Test_Should_method_should_hold_items(t *testing.T) {

// Then
assert.True(t, exists)
assert.IsTypeString(t, "es.shouldType", should)
assert.IsTypeString(t, "es.ShouldType", should)

bodyJSON := assert.MarshalWithoutError(t, b)
assert.Equal(t, "{\"should\":[{\"term\":{\"id\":12345}}]}", bodyJSON)
Expand Down
2 changes: 1 addition & 1 deletion es/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func correctType(b any) (any, bool) {
return Object{}, false
}
switch b.(type) {
case boolType:
case BoolType:
return Object{"bool": b}, true
case rangeType:
return Object{"range": b}, true
Expand Down

0 comments on commit 33c21f7

Please sign in to comment.