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

General refactor and add missing parameters #22

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
bdc13f8
refactor: general refactor and code cleanup
GokselKUCUKSAHIN Nov 10, 2024
a05843f
refactor: refactor enums.
GokselKUCUKSAHIN Nov 12, 2024
daa1b66
refactor: remove Operator parameter on Match None Query
GokselKUCUKSAHIN Nov 12, 2024
4e1ff33
Merge branch 'main' into refactor/general-refactor
GokselKUCUKSAHIN Nov 12, 2024
73ec98d
feature: add boost parameter to exists, regexp simpleQueryString quer…
GokselKUCUKSAHIN Dec 28, 2024
d56b187
linter: rename range relation enum's package name
GokselKUCUKSAHIN Dec 28, 2024
d1581ac
feature: add escape, type, fuzzy_rewrite, tie_breaker to queryStringQ…
GokselKUCUKSAHIN Dec 28, 2024
b08c465
linter: fix linter
GokselKUCUKSAHIN Dec 28, 2024
81dceab
feature: add boost and ignore_unmapped for NestedQuery
GokselKUCUKSAHIN Dec 28, 2024
721c4fc
feature: add seperate inner_hits with better type safe building exper…
GokselKUCUKSAHIN Jan 3, 2025
c6cba3a
Merge branch 'main' into refactor/general-refactor
GokselKUCUKSAHIN Jan 4, 2025
4d73913
feature: add innet_hits Collapse and FieldAndFormat methods
GokselKUCUKSAHIN Jan 4, 2025
0c3979d
test: add test for inner hits
GokselKUCUKSAHIN Jan 4, 2025
121ecbd
test: make coverage 💯
GokselKUCUKSAHIN Jan 4, 2025
9784b80
doc: add godoc for inner_hits.go
GokselKUCUKSAHIN Jan 4, 2025
b5701a0
linter: fix lint error
GokselKUCUKSAHIN Jan 4, 2025
d8a008a
doc: update go docs types
GokselKUCUKSAHIN Jan 5, 2025
a899fef
chore: organize imports
GokselKUCUKSAHIN Jan 5, 2025
7996bcd
Merge branch 'main' into refactor/general-refactor
GokselKUCUKSAHIN Jan 16, 2025
4703fd0
documentation: fix vovel sound grammer
GokselKUCUKSAHIN Jan 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ run-test:
linter:
golangci-lint run -c .golangci.yml --timeout=5m -v --fix

fixfieldalignment:
fieldalignment --fix ./...

unit-test-pretty:
go test ./... -count=1 -v -json | gotestfmt

Expand Down
80 changes: 40 additions & 40 deletions es/aggregations.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type aggTermType Object
//
// Returns:
//
// An aggTermType object with the "field" set to the provided value.
// An es.aggTermType object with the "field" set to the provided value.
func AggTerm(field string) aggTermType {
return aggTermType{
"field": field,
Expand All @@ -31,7 +31,7 @@ func AggTerm(field string) aggTermType {
// Missing sets the "missing" value for an aggregation term.
//
// This method specifies a value to be used when the field is missing in documents.
// It updates the aggTermType object to handle missing values in the aggregation.
// It updates the es.aggTermType object to handle missing values in the aggregation.
//
// Example usage:
//
Expand All @@ -43,7 +43,7 @@ func AggTerm(field string) aggTermType {
//
// Returns:
//
// The updated aggTermType object with the "missing" field set to the specified value.
// The updated es.aggTermType object with the "missing" field set to the specified value.
func (aggTerm aggTermType) Missing(missing string) aggTermType {
aggTerm["missing"] = missing
return aggTerm
Expand All @@ -61,7 +61,7 @@ func (aggTerm aggTermType) Missing(missing string) aggTermType {
//
// Returns:
//
// An aggsType object with the "terms" field initialized.
// An es.aggsType object with the "terms" field initialized.
func AggTerms() aggsType {
return aggsType{
"terms": Object{},
Expand All @@ -80,7 +80,7 @@ func AggTerms() aggsType {
//
// Returns:
//
// An aggsType object with the "multi_terms" field initialized.
// An es.aggsType object with the "multi_terms" field initialized.
func AggMultiTerms() aggsType {
return aggsType{
"multi_terms": Object{},
Expand All @@ -99,7 +99,7 @@ func AggMultiTerms() aggsType {
//
// Returns:
//
// An aggsType object with the "nested" field initialized.
// An es.aggsType object with the "nested" field initialized.
func AggNested() aggsType {
return aggsType{
"nested": Object{},
Expand All @@ -117,7 +117,7 @@ func AggNested() aggsType {
//
// Returns:
//
// An aggsType object with the "max" field initialized.
// An es.aggsType object with the "max" field initialized.
func AggMax() aggsType {
return aggsType{
"max": Object{},
Expand All @@ -135,7 +135,7 @@ func AggMax() aggsType {
//
// Returns:
//
// An aggsType object with the "min" field initialized.
// An es.aggsType object with the "min" field initialized.
func AggMin() aggsType {
return aggsType{
"min": Object{},
Expand All @@ -153,7 +153,7 @@ func AggMin() aggsType {
//
// Returns:
//
// An aggsType object with the "avg" field initialized.
// An es.aggsType object with the "avg" field initialized.
func AggAvg() aggsType {
return aggsType{
"avg": Object{},
Expand All @@ -174,22 +174,12 @@ func AggAvg() aggsType {
//
// Returns:
//
// An aggsType object initialized with the provided custom aggregation.
// An es.aggsType object initialized with the provided custom aggregation.
func AggCustom(agg Object) aggsType {
return aggsType(agg)
}

func (agg aggsType) putInTheField(key string, value any) aggsType {
for _, fieldObj := range agg {
if fieldObject, ok := fieldObj.(Object); ok {
fieldObject[key] = value
break
}
}
return agg
}

// Aggs adds a nested aggregation to the aggsType object.
// Aggs adds a nested aggregation to the es.aggsType object.
//
// This method adds a nested aggregation under the "aggs" field with the given name.
//
Expand All @@ -205,7 +195,7 @@ func (agg aggsType) putInTheField(key string, value any) aggsType {
//
// Returns:
//
// The updated aggsType object with the nested aggregation added.
// The updated es.aggsType object with the nested aggregation added.
func (agg aggsType) Aggs(name string, nestedAgg aggsType) aggsType {
aggs, ok := agg["aggs"].(Object)
if !ok {
Expand All @@ -216,9 +206,9 @@ func (agg aggsType) Aggs(name string, nestedAgg aggsType) aggsType {
return agg
}

// Field sets the "field" value in the aggsType object.
// Field sets the "field" value in the es.aggsType object.
//
// This method specifies the field to aggregate on in the aggsType object.
// This method specifies the field to aggregate on in the es.aggsType object.
//
// Example usage:
//
Expand All @@ -230,14 +220,14 @@ func (agg aggsType) Aggs(name string, nestedAgg aggsType) aggsType {
//
// Returns:
//
// The updated aggsType object with the "field" set to the specified value.
// The updated es.aggsType object with the "field" set to the specified value.
func (agg aggsType) Field(field string) aggsType {
return agg.putInTheField("field", field)
}

// Path sets the "path" value in the aggsType object.
// Path sets the "path" value in the es.aggsType object.
//
// This method specifies the nested path for the aggregation in the aggsType object.
// This method specifies the nested path for the aggregation in the es.aggsType object.
//
// Example usage:
//
Expand All @@ -249,12 +239,12 @@ func (agg aggsType) Field(field string) aggsType {
//
// Returns:
//
// The updated aggsType object with the "path" set to the specified value.
// The updated es.aggsType object with the "path" set to the specified value.
func (agg aggsType) Path(path string) aggsType {
return agg.putInTheField("path", path)
}

// Size sets the "size" value in the aggsType object.
// Size sets the "size" value in the es.aggsType object.
//
// This method specifies the number of terms to return in the aggregation result.
//
Expand All @@ -268,12 +258,12 @@ func (agg aggsType) Path(path string) aggsType {
//
// Returns:
//
// The updated aggsType object with the "size" field set to the specified value.
// The updated es.aggsType object with the "size" field set to the specified value.
func (agg aggsType) Size(size int) aggsType {
return agg.putInTheField("size", size)
}

// Order sets the "order" field in the aggsType object.
// Order sets the "order" field in the es.aggsType object.
//
// This method specifies the sorting order for the aggregation results.
//
Expand All @@ -288,7 +278,7 @@ func (agg aggsType) Size(size int) aggsType {
//
// Returns:
//
// The updated aggsType object with the "order" field set to the specified value.
// The updated es.aggsType object with the "order" field set to the specified value.
func (agg aggsType) Order(field string, order Order.Order) aggsType {
return agg.putInTheField("order",
Object{
Expand All @@ -297,7 +287,7 @@ func (agg aggsType) Order(field string, order Order.Order) aggsType {
)
}

// Include sets the "include" field in the aggsType object.
// Include sets the "include" field in the es.aggsType object.
//
// This method specifies a pattern to include in the aggregation results.
//
Expand All @@ -311,12 +301,12 @@ func (agg aggsType) Order(field string, order Order.Order) aggsType {
//
// Returns:
//
// The updated aggsType object with the "include" field set to the specified value.
// The updated es.aggsType object with the "include" field set to the specified value.
func (agg aggsType) Include(include string) aggsType {
return agg.putInTheField("include", include)
}

// Exclude sets the "exclude" field in the aggsType object.
// Exclude sets the "exclude" field in the es.aggsType object.
//
// This method specifies a pattern to exclude from the aggregation results.
//
Expand All @@ -330,14 +320,14 @@ func (agg aggsType) Include(include string) aggsType {
//
// Returns:
//
// The updated aggsType object with the "exclude" field set to the specified value.
// The updated es.aggsType object with the "exclude" field set to the specified value.
func (agg aggsType) Exclude(exclude string) aggsType {
return agg.putInTheField("exclude", exclude)
}

// Terms sets the "terms" field in the aggsType object.
//
// This method adds a list of aggregation terms to the "terms" field of the aggsType object.
// This method adds a list of aggregation terms to the "terms" field of the es.aggsType object.
// It allows specifying multiple term aggregations for the aggregation query.
//
// Example usage:
Expand All @@ -350,11 +340,11 @@ func (agg aggsType) Exclude(exclude string) aggsType {
// // agg now has the "terms" field containing the provided term aggregations.
//
// Parameters:
// - terms: A variadic list of aggTermType objects representing the term aggregations.
// - terms: A variadic list of es.aggTermType objects representing the term aggregations.
//
// Returns:
//
// The updated aggsType object with the "terms" field set to the provided term aggregations.
// The updated es.aggsType object with the "terms" field set to the provided term aggregations.
func (agg aggsType) Terms(terms ...aggTermType) aggsType {
return agg.putInTheField("terms", terms)
}
Expand All @@ -372,7 +362,7 @@ func (agg aggsType) Terms(terms ...aggTermType) aggsType {
//
// Parameters:
// - name: The name to associate with the nested aggregation.
// - agg: The aggsType object representing the nested aggregation.
// - agg: The es.aggsType object representing the nested aggregation.
//
// Returns:
//
Expand All @@ -386,3 +376,13 @@ func (o Object) Aggs(name string, agg aggsType) Object {
o["aggs"] = aggs
return o
}

func (agg aggsType) putInTheField(key string, value any) aggsType {
for _, fieldObj := range agg {
if fieldObject, ok := fieldObj.(Object); ok {
fieldObject[key] = value
break
}
}
return agg
}
4 changes: 2 additions & 2 deletions es/aggregations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package es_test
import (
"testing"

Order "github.com/Trendyol/es-query-builder/es/enums/sort/order"

"github.com/Trendyol/es-query-builder/es"
"github.com/Trendyol/es-query-builder/test/assert"

Order "github.com/Trendyol/es-query-builder/es/enums/sort/order"
)

//// AGGS ////
Expand Down
Loading
Loading