From bdc13f89419ca0bbaa2b2fc709cb7ea848ac1794 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6ksel=20K=C3=BC=C3=A7=C3=BCk=C5=9Fahin?= Date: Sun, 10 Nov 2024 23:26:57 +0300 Subject: [PATCH 01/17] refactor: general refactor and code cleanup --- es/base_query.go | 8 +-- es/bool_query.go | 8 +-- es/exists_query.go | 6 +-- es/match_all_query.go | 4 +- es/match_none_query.go | 6 +-- es/nested_query.go | 6 +-- es/query_string.go | 105 +++++++++++++++----------------------- es/range.go | 14 ++--- es/regexp_query.go | 14 ++--- es/regexp_query_test.go | 2 +- es/simple_query_string.go | 60 +++++++++------------- es/term_query.go | 10 ++-- es/terms_query.go | 10 ++-- 13 files changed, 110 insertions(+), 143 deletions(-) diff --git a/es/base_query.go b/es/base_query.go index 6fa4f30..7a9db7d 100644 --- a/es/base_query.go +++ b/es/base_query.go @@ -208,7 +208,7 @@ func (o Object) SourceExcludes(fields ...string) Object { // // Example usage: // -// s := Sort("age") +// s := es.Sort("age") // // s now includes a sortType with an "age" field that can be further configured. // // Parameters: @@ -241,7 +241,7 @@ func (s sortType) putInTheField(key string, value any) sortType { // // Example usage: // -// s := Sort("age").Order(Order.Desc) +// s := es.Sort("age").Order(Order.Desc) // // s now includes an "order" parameter with the value "desc". // // Parameters: @@ -262,7 +262,7 @@ func (s sortType) Order(order Order.Order) sortType { // // Example usage: // -// s := Sort("age").Mode(Mode.Avg) +// s := es.Sort("age").Mode(Mode.Avg) // // s now includes a "mode" parameter with the value "avg". // // Parameters: @@ -282,7 +282,7 @@ func (s sortType) Mode(mode Mode.Mode) sortType { // // Example usage: // -// query := es.NewQuery(...).Sort(Sort("age").Order(Order.Desc), Sort("date").Order(Order.Asc)) +// query := es.NewQuery(...).Sort(es.Sort("age").Order(Order.Desc), es.Sort("date").Order(Order.Asc)) // // query now includes a "sort" parameter with multiple sortType objects. // // Parameters: diff --git a/es/bool_query.go b/es/bool_query.go index 0e33c74..e6439ad 100644 --- a/es/bool_query.go +++ b/es/bool_query.go @@ -17,7 +17,7 @@ type ShouldType Array // // Example usage: // -// b := Bool() +// b := es.Bool() // // b is now an empty BoolType object that can be used in a query. // // Returns: @@ -36,7 +36,7 @@ func Bool() BoolType { // // Example usage: // -// b := Bool().MinimumShouldMatch(2) +// b := es.Bool().MinimumShouldMatch(2) // // b now includes a "minimum_should_match" parameter with a value of 2. // // Parameters: @@ -60,7 +60,7 @@ func (b BoolType) MinimumShouldMatch(minimumShouldMatch any) BoolType { // // Example usage: // -// b := Bool().AdjustPureNegative(true) +// b := es.Bool().AdjustPureNegative(true) // // b now includes an "adjust_pure_negative" parameter set to true. // // Parameters: @@ -84,7 +84,7 @@ func (b BoolType) AdjustPureNegative(adjustPureNegative bool) BoolType { // // Example usage: // -// b := Bool().Boost(1.5) +// b := es.Bool().Boost(1.5) // // b now includes a "boost" parameter with a value of 1.5. // // Parameters: diff --git a/es/exists_query.go b/es/exists_query.go index 87765dd..07dfd83 100644 --- a/es/exists_query.go +++ b/es/exists_query.go @@ -10,7 +10,7 @@ type existsType Object // // Example usage: // -// e := Exists("title") +// e := es.Exists("title") // // e now contains an existsType object that checks for the existence of the "title" field. // // Parameters: @@ -35,7 +35,7 @@ func Exists(key string) existsType { // // Example usage: // -// e := ExistsFunc("title", func(key string) bool { +// e := es.ExistsFunc("title", func(key string) bool { // return key != "" // }) // // e is either an existsType object or nil based on the condition. @@ -62,7 +62,7 @@ func ExistsFunc(key string, f func(key string) bool) existsType { // // Example usage: // -// e := ExistsIf("title", true) +// e := es.ExistsIf("title", true) // // e is an existsType object if the condition is true; otherwise, it is nil. // // Parameters: diff --git a/es/match_all_query.go b/es/match_all_query.go index c104b8b..c19ce18 100644 --- a/es/match_all_query.go +++ b/es/match_all_query.go @@ -10,7 +10,7 @@ type matchAllType Object // // Example usage: // -// ma := MatchAll() +// ma := es.MatchAll() // // ma now contains a matchAllType object that matches all documents. // // Returns: @@ -36,7 +36,7 @@ func (m matchAllType) putInTheField(key string, value any) matchAllType { // // Example usage: // -// ma := MatchAll().Boost(1.5) +// ma := es.MatchAll().Boost(1.5) // // ma now has a "boost" field set to 1.5 in the match_all query object. // // Parameters: diff --git a/es/match_none_query.go b/es/match_none_query.go index ec4cd38..15c5549 100644 --- a/es/match_none_query.go +++ b/es/match_none_query.go @@ -12,7 +12,7 @@ type matchNoneType Object // // Example usage: // -// mn := MatchNone("title", "es-query-builder") +// mn := es.MatchNone("title", "es-query-builder") // // mn now contains a matchNoneType object that matches no documents for the "title" field with the query "es-query-builder". // // Parameters: @@ -52,7 +52,7 @@ func (m matchNoneType) putInTheField(key string, value any) matchNoneType { // // Example usage: // -// mn := MatchNone("title", "es-query-builder").Operator("AND") +// mn := es.MatchNone("title", "es-query-builder").Operator("AND") // // mn now has an "operator" field set to "AND" in the match_none query object. // // Parameters: @@ -73,7 +73,7 @@ func (m matchNoneType) Operator(operator Operator.Operator) matchNoneType { // // Example usage: // -// mn := MatchNone("title", "es-query-builder").Boost(1.5) +// mn := es.MatchNone("title", "es-query-builder").Boost(1.5) // // mn now has a "boost" field set to 1.5 in the match_none query object. // // Parameters: diff --git a/es/nested_query.go b/es/nested_query.go index 89d3079..27a06de 100644 --- a/es/nested_query.go +++ b/es/nested_query.go @@ -12,7 +12,7 @@ type nestedType Object // // Example usage: // -// nestedQuery := Nested("comments", es.Bool().Filter(...).MustNot(...)) +// nestedQuery := es.Nested("comments", es.Bool().Filter(...).MustNot(...)) // // nestedQuery now contains a nestedType object with the specified path and query. // // Parameters: @@ -45,7 +45,7 @@ func (n nestedType) putInNested(key string, value any) nestedType { // // Example usage: // -// nested := Nested("comments", es.Term("text", "example")) +// nested := es.Nested("comments", es.Term("text", "example")) // nested = nested.InnerHits(Object{"inner": "hits"}) // // nested now has an "inner_hits" field with the specified Object in the nested query. // @@ -67,7 +67,7 @@ func (n nestedType) InnerHits(innerHits Object) nestedType { // // Example usage: // -// nested := Nested("comments", es.Term("text", "example")) +// nested := es.Nested("comments", es.Term("text", "example")) // nested = nested.ScoreMode(ScoreMode.Sum) // // nested now has a "score_mode" field with the specified ScoreMode value in the nested query. // diff --git a/es/query_string.go b/es/query_string.go index 3ca869a..7fae4db 100644 --- a/es/query_string.go +++ b/es/query_string.go @@ -10,7 +10,7 @@ type queryStringType Object // // Example usage: // -// q := QueryString("Foo AND Bar") +// q := es.QueryString("Foo AND Bar") // // q now contains a queryStringType object with a query string query. // // Parameters: @@ -39,7 +39,7 @@ func QueryString[T any](query T) queryStringType { // b := es.QueryString("value"). // DefaultField("defaultField") // -// q := QueryString("Foo Bar").DefaultField("title") +// q := es.QueryString("Foo Bar").DefaultField("title") // // q now contains a queryStringType object where the default field for the query is "title". // // Parameters: @@ -49,8 +49,7 @@ func QueryString[T any](query T) queryStringType { // // The updated queryStringType object with the new "default_field". func (q queryStringType) DefaultField(value string) queryStringType { - q.putInTheField("default_field", value) - return q + return q.putInTheField("default_field", value) } // AllowLeadingWildcard sets the option to allow leading wildcards in the queryStringType object. @@ -64,7 +63,7 @@ func (q queryStringType) DefaultField(value string) queryStringType { // b := es.QueryString("value"). // AllowLeadingWildcard(true) // -// q := QueryString("Fo* bar").AllowLeadingWildcard(true) +// q := es.QueryString("Fo* bar").AllowLeadingWildcard(true) // // q now allows leading wildcards in the query string. // // Parameters: @@ -74,8 +73,7 @@ func (q queryStringType) DefaultField(value string) queryStringType { // // The updated queryStringType object with the "allow_leading_wildcard" option set. func (q queryStringType) AllowLeadingWildcard(value bool) queryStringType { - q.putInTheField("allow_leading_wildcard", value) - return q + return q.putInTheField("allow_leading_wildcard", value) } // AnalyzeWildcard sets the option to analyze wildcard terms in the queryStringType object. @@ -89,7 +87,7 @@ func (q queryStringType) AllowLeadingWildcard(value bool) queryStringType { // b := es.QueryString("value"). // AnalyzeWildcard(true) // -// q := QueryString("Fo* bar").AnalyzeWildcard(true) +// q := es.QueryString("Fo* bar").AnalyzeWildcard(true) // // q now analyzes wildcard terms in the query string. // // Parameters: @@ -99,8 +97,7 @@ func (q queryStringType) AllowLeadingWildcard(value bool) queryStringType { // // The updated queryStringType object with the "analyze_wildcard" option set. func (q queryStringType) AnalyzeWildcard(value bool) queryStringType { - q.putInTheField("analyze_wildcard", value) - return q + return q.putInTheField("analyze_wildcard", value) } // Analyzer sets the analyzer to be used for the queryStringType object. @@ -114,7 +111,7 @@ func (q queryStringType) AnalyzeWildcard(value bool) queryStringType { // b := es.QueryString("value"). // Analyzer("custom_analyzer") // -// q := QueryString("Foo Bar").Analyzer("standard") +// q := es.QueryString("Foo Bar").Analyzer("standard") // // q now uses the "standard" analyzer for processing the query string. // // Parameters: @@ -124,8 +121,7 @@ func (q queryStringType) AnalyzeWildcard(value bool) queryStringType { // // The updated queryStringType object with the "analyzer" set. func (q queryStringType) Analyzer(value string) queryStringType { - q.putInTheField("analyzer", value) - return q + return q.putInTheField("analyzer", value) } // AutoGenerateSynonymsPhraseQuery sets the option to automatically generate phrase queries for synonyms in the queryStringType object. @@ -139,7 +135,7 @@ func (q queryStringType) Analyzer(value string) queryStringType { // b := es.QueryString("value"). // AutoGenerateSynonymsPhraseQuery(true) // -// q := QueryString("quick brown fox").AutoGenerateSynonymsPhraseQuery(true) +// q := es.QueryString("quick brown fox").AutoGenerateSynonymsPhraseQuery(true) // // q now automatically generates phrase queries for synonyms in the query string. // // Parameters: @@ -149,8 +145,7 @@ func (q queryStringType) Analyzer(value string) queryStringType { // // The updated queryStringType object with the "auto_generate_synonyms_phrase_query" option set. func (q queryStringType) AutoGenerateSynonymsPhraseQuery(value bool) queryStringType { - q.putInTheField("auto_generate_synonyms_phrase_query", value) - return q + return q.putInTheField("auto_generate_synonyms_phrase_query", value) } // Boost sets the boost factor for the queryStringType object. @@ -164,7 +159,7 @@ func (q queryStringType) AutoGenerateSynonymsPhraseQuery(value bool) queryString // b := es.QueryString("value"). // Boost(2.0) // -// q := QueryString("Foo Bar").Boost(1.5) +// q := es.QueryString("Foo Bar").Boost(1.5) // // q now has a boost factor of 1.5, increasing its relevance in the search results. // // Parameters: @@ -174,8 +169,7 @@ func (q queryStringType) AutoGenerateSynonymsPhraseQuery(value bool) queryString // // The updated queryStringType object with the "boost" value set. func (q queryStringType) Boost(value float64) queryStringType { - q.putInTheField("boost", value) - return q + return q.putInTheField("boost", value) } // DefaultOperator sets the default operator for the queryStringType object. @@ -189,7 +183,7 @@ func (q queryStringType) Boost(value float64) queryStringType { // b := es.QueryString("value"). // DefaultOperator("AND") // -// q := QueryString("Foo Bar").DefaultOperator("OR") +// q := es.QueryString("Foo Bar").DefaultOperator("OR") // // q now uses "OR" as the default operator, meaning any term can match in the query. // // Parameters: @@ -199,8 +193,7 @@ func (q queryStringType) Boost(value float64) queryStringType { // // The updated queryStringType object with the "default_operator" set. func (q queryStringType) DefaultOperator(value string) queryStringType { - q.putInTheField("default_operator", value) - return q + return q.putInTheField("default_operator", value) } // EnablePositionIncrements sets the option to enable or disable position increments in the queryStringType object. @@ -221,8 +214,7 @@ func (q queryStringType) DefaultOperator(value string) queryStringType { // // The updated queryStringType object with the "enable_position_increments" option set. func (q queryStringType) EnablePositionIncrements(value bool) queryStringType { - q.putInTheField("enable_position_increments", value) - return q + return q.putInTheField("enable_position_increments", value) } // Fields sets the fields to be searched within the queryStringType object. @@ -236,7 +228,7 @@ func (q queryStringType) EnablePositionIncrements(value bool) queryStringType { // b := es.QueryString("value"). // Fields([]string{"title", "description"}) // -// q := QueryString("Foo Bar").Fields([]string{"title", "content"}) +// q := es.QueryString("Foo Bar").Fields([]string{"title", "content"}) // // q now searches within the "title" and "content" fields. // // Parameters: @@ -246,8 +238,7 @@ func (q queryStringType) EnablePositionIncrements(value bool) queryStringType { // // The updated queryStringType object with the "fields" option set. func (q queryStringType) Fields(value []string) queryStringType { - q.putInTheField("fields", value) - return q + return q.putInTheField("fields", value) } // Fuzziness sets the fuzziness level for the queryStringType object. @@ -262,7 +253,7 @@ func (q queryStringType) Fields(value []string) queryStringType { // b := es.QueryString("value"). // Fuzziness("AUTO") // -// q := QueryString("Foo Bar").Fuzziness("2") +// q := es.QueryString("Foo Bar").Fuzziness("2") // // q now uses a fuzziness level of "2" to allow for approximate matching. // // Parameters: @@ -272,8 +263,7 @@ func (q queryStringType) Fields(value []string) queryStringType { // // The updated queryStringType object with the "fuzziness" option set. func (q queryStringType) Fuzziness(value string) queryStringType { - q.putInTheField("fuzziness", value) - return q + return q.putInTheField("fuzziness", value) } // FuzzyMaxExpansions sets the maximum number of expansions for fuzzy matching in the queryStringType object. @@ -288,7 +278,7 @@ func (q queryStringType) Fuzziness(value string) queryStringType { // b := es.QueryString("value"). // FuzzyMaxExpansions(50) // -// q := QueryString("Foo Bar").FuzzyMaxExpansions(100) +// q := es.QueryString("Foo Bar").FuzzyMaxExpansions(100) // // q now allows up to 100 expansions for fuzzy matching. // // Parameters: @@ -298,8 +288,7 @@ func (q queryStringType) Fuzziness(value string) queryStringType { // // The updated queryStringType object with the "fuzzy_max_expansions" option set. func (q queryStringType) FuzzyMaxExpansions(value int64) queryStringType { - q.putInTheField("fuzzy_max_expansions", value) - return q + return q.putInTheField("fuzzy_max_expansions", value) } // FuzzyPrefixLength sets the prefix length for fuzzy matching in the queryStringType object. @@ -314,7 +303,7 @@ func (q queryStringType) FuzzyMaxExpansions(value int64) queryStringType { // b := es.QueryString("value"). // FuzzyPrefixLength(2) // -// q := QueryString("Foo Bar").FuzzyPrefixLength(3) +// q := es.QueryString("Foo Bar").FuzzyPrefixLength(3) // // q now requires the first 3 characters to match exactly before applying fuzziness. // // Parameters: @@ -324,8 +313,7 @@ func (q queryStringType) FuzzyMaxExpansions(value int64) queryStringType { // // The updated queryStringType object with the "fuzzy_prefix_length" option set. func (q queryStringType) FuzzyPrefixLength(value int64) queryStringType { - q.putInTheField("fuzzy_prefix_length", value) - return q + return q.putInTheField("fuzzy_prefix_length", value) } // FuzzyTranspositions sets the option to allow transpositions in fuzzy matching for the queryStringType object. @@ -339,7 +327,7 @@ func (q queryStringType) FuzzyPrefixLength(value int64) queryStringType { // b := es.QueryString("value"). // FuzzyTranspositions(true) // -// q := QueryString("Foo Bar").FuzzyTranspositions(true) +// q := es.QueryString("Foo Bar").FuzzyTranspositions(true) // // q now allows transpositions in fuzzy matching. // // Parameters: @@ -349,8 +337,7 @@ func (q queryStringType) FuzzyPrefixLength(value int64) queryStringType { // // The updated queryStringType object with the "fuzzy_transpositions" option set. func (q queryStringType) FuzzyTranspositions(value bool) queryStringType { - q.putInTheField("fuzzy_transpositions", value) - return q + return q.putInTheField("fuzzy_transpositions", value) } // Lenient sets the leniency option for the queryStringType object. @@ -365,7 +352,7 @@ func (q queryStringType) FuzzyTranspositions(value bool) queryStringType { // b := es.QueryString("value"). // Lenient(true) // -// q := QueryString("Foo Bar").Lenient(true) +// q := es.QueryString("Foo Bar").Lenient(true) // // q is now lenient, allowing it to tolerate errors during the query. // // Parameters: @@ -375,8 +362,7 @@ func (q queryStringType) FuzzyTranspositions(value bool) queryStringType { // // The updated queryStringType object with the "lenient" option set. func (q queryStringType) Lenient(value bool) queryStringType { - q.putInTheField("lenient", value) - return q + return q.putInTheField("lenient", value) } // MaxDeterminizedStates sets the maximum number of determinized states for the queryStringType object. @@ -391,7 +377,7 @@ func (q queryStringType) Lenient(value bool) queryStringType { // b := es.QueryString("value"). // MaxDeterminizedStates(10000) // -// q := QueryString("Foo*").MaxDeterminizedStates(5000) +// q := es.QueryString("Foo*").MaxDeterminizedStates(5000) // // q now limits the determinized states to 5000 to control query complexity. // // Parameters: @@ -401,8 +387,7 @@ func (q queryStringType) Lenient(value bool) queryStringType { // // The updated queryStringType object with the "max_determinized_states" option set. func (q queryStringType) MaxDeterminizedStates(value int64) queryStringType { - q.putInTheField("max_determinized_states", value) - return q + return q.putInTheField("max_determinized_states", value) } // MinimumShouldMatch sets the minimum number of "should" clauses that must match for the queryStringType object. @@ -416,7 +401,7 @@ func (q queryStringType) MaxDeterminizedStates(value int64) queryStringType { // b := es.QueryString("value"). // MinimumShouldMatch("2") // -// q := QueryString("Foo Bar").MinimumShouldMatch("2") +// q := es.QueryString("Foo Bar").MinimumShouldMatch("2") // // q now requires that at least 2 of the "should" clauses match for a document to be considered a match. // // Parameters: @@ -426,8 +411,7 @@ func (q queryStringType) MaxDeterminizedStates(value int64) queryStringType { // // The updated queryStringType object with the "minimum_should_match" option set. func (q queryStringType) MinimumShouldMatch(value string) queryStringType { - q.putInTheField("minimum_should_match", value) - return q + return q.putInTheField("minimum_should_match", value) } // QuoteAnalyzer sets the analyzer to be used for quoted text in the queryStringType object. @@ -441,7 +425,7 @@ func (q queryStringType) MinimumShouldMatch(value string) queryStringType { // b := es.QueryString("value"). // QuoteAnalyzer("custom_phrase_analyzer") // -// q := QueryString("Foo Bar").QuoteAnalyzer("standard") +// q := es.QueryString("Foo Bar").QuoteAnalyzer("standard") // // q now uses the "standard" analyzer for quoted text in the query string. // // Parameters: @@ -451,8 +435,7 @@ func (q queryStringType) MinimumShouldMatch(value string) queryStringType { // // The updated queryStringType object with the "quote_analyzer" option set. func (q queryStringType) QuoteAnalyzer(value string) queryStringType { - q.putInTheField("quote_analyzer", value) - return q + return q.putInTheField("quote_analyzer", value) } // PhraseSlop sets the slop factor for phrase queries in the queryStringType object. @@ -466,7 +449,7 @@ func (q queryStringType) QuoteAnalyzer(value string) queryStringType { // b := es.QueryString("value"). // PhraseSlop(3) // -// q := QueryString("Foo Bar").PhraseSlop(2) +// q := es.QueryString("Foo Bar").PhraseSlop(2) // // q now allows a slop of 2 positions for the phrase match, accommodating slight variations in term order. // // Parameters: @@ -476,8 +459,7 @@ func (q queryStringType) QuoteAnalyzer(value string) queryStringType { // // The updated queryStringType object with the "phrase_slop" option set. func (q queryStringType) PhraseSlop(value int64) queryStringType { - q.putInTheField("phrase_slop", value) - return q + return q.putInTheField("phrase_slop", value) } // QuoteFieldSuffix sets the field suffix to be used for quoted text in the queryStringType object. @@ -490,7 +472,7 @@ func (q queryStringType) PhraseSlop(value int64) queryStringType { // b := es.QueryString("value"). // QuoteFieldSuffix("_quoted") // -// q := QueryString("Foo Bar").QuoteFieldSuffix("_phrase") +// q := es.QueryString("Foo Bar").QuoteFieldSuffix("_phrase") // // q now appends "_phrase" to the field names when processing quoted text in the query string. // // Parameters: @@ -500,8 +482,7 @@ func (q queryStringType) PhraseSlop(value int64) queryStringType { // // The updated queryStringType object with the "quote_field_suffix" option set. func (q queryStringType) QuoteFieldSuffix(value string) queryStringType { - q.putInTheField("quote_field_suffix", value) - return q + return q.putInTheField("quote_field_suffix", value) } // Rewrite sets the rewrite method for the queryStringType object. @@ -517,7 +498,7 @@ func (q queryStringType) QuoteFieldSuffix(value string) queryStringType { // b := es.QueryString("value"). // Rewrite("constant_score") // -// q := QueryString("Foo Bar").Rewrite("scoring_boolean") +// q := es.QueryString("Foo Bar").Rewrite("scoring_boolean") // // q now uses the "scoring_boolean" rewrite method for optimizing the query execution. // // Parameters: @@ -527,8 +508,7 @@ func (q queryStringType) QuoteFieldSuffix(value string) queryStringType { // // The updated queryStringType object with the "rewrite" option set. func (q queryStringType) Rewrite(value string) queryStringType { - q.putInTheField("rewrite", value) - return q + return q.putInTheField("rewrite", value) } // TimeZone sets the time zone for date and time fields in the queryStringType object. @@ -542,7 +522,7 @@ func (q queryStringType) Rewrite(value string) queryStringType { // b := es.QueryString("value"). // TimeZone("UTC") // -// q := QueryString("timestamp:[2024-01-01 TO 2024-12-31]").TimeZone("America/New_York") +// q := es.QueryString("timestamp:[2024-01-01 TO 2024-12-31]").TimeZone("America/New_York") // // q now applies the "America/New_York" time zone to date and time fields in the query string. // // Parameters: @@ -552,8 +532,7 @@ func (q queryStringType) Rewrite(value string) queryStringType { // // The updated queryStringType object with the "time_zone" option set. func (q queryStringType) TimeZone(value string) queryStringType { - q.putInTheField("time_zone", value) - return q + return q.putInTheField("time_zone", value) } func (q queryStringType) putInTheField(key string, value any) queryStringType { diff --git a/es/range.go b/es/range.go index 2f509ea..1608114 100644 --- a/es/range.go +++ b/es/range.go @@ -9,7 +9,7 @@ type rangeType Object // // Example usage: // -// r := Range("age") +// r := es.Range("age") // // r now contains a rangeType object with the specified field "age" for range queries. // // Parameters: @@ -56,7 +56,7 @@ func (r rangeType) delete(key string) rangeType { // // Example usage: // -// r := Range("age").LesserThan(20) +// r := es.Range("age").LesserThan(20) // // r now has an "lt" field set to 20 in the range query for the "age" field. // // Parameters: @@ -77,7 +77,7 @@ func (r rangeType) LesserThan(lt any) rangeType { // // Example usage: // -// r := Range("age").LesserThanOrEqual(20) +// r := es.Range("age").LesserThanOrEqual(20) // // r now has an "lte" field set to 20 in the range query for the "age" field. // // Parameters: @@ -98,7 +98,7 @@ func (r rangeType) LesserThanOrEqual(lte any) rangeType { // // Example usage: // -// r := Range("age").GreaterThan(50) +// r := es.Range("age").GreaterThan(50) // // r now has a "gt" field set to 50 in the range query for the "age" field. // // Parameters: @@ -119,7 +119,7 @@ func (r rangeType) GreaterThan(gt any) rangeType { // // Example usage: // -// r := Range("age").GreaterThanOrEqual(50) +// r := es.Range("age").GreaterThanOrEqual(50) // // r now has a "gte" field set to 50 in the range query for the "age" field. // // Parameters: @@ -140,7 +140,7 @@ func (r rangeType) GreaterThanOrEqual(gte any) rangeType { // // Example usage: // -// r := Range("date").Format("yyyy-MM-dd") +// r := es.Range("date").Format("yyyy-MM-dd") // // r now has a "format" field set to "yyyy-MM-dd" in the range query for the "date" field. // // Parameters: @@ -160,7 +160,7 @@ func (r rangeType) Format(format string) rangeType { // // Example usage: // -// r := Range("age").Boost(1.5) +// r := es.Range("age").Boost(1.5) // // r now has a "boost" field set to 1.5 in the range query for the "age" field. // // Parameters: diff --git a/es/regexp_query.go b/es/regexp_query.go index 92a13d7..61e8c95 100644 --- a/es/regexp_query.go +++ b/es/regexp_query.go @@ -10,7 +10,7 @@ type regexpType Object // // Example usage: // -// t := Regexp("endpoint", "/books/.*") +// t := es.Regexp("endpoint", "/books/.*") // // t now contains a regexpType object with a regexp query for the "endpoint" field. // // Parameters: @@ -45,7 +45,7 @@ func (r regexpType) putInTheField(key string, value any) regexpType { // Flags Enables optional operators for the regular expression. // Example usage: // -// regexp := Regexp("endpoint", "/books/.*").Flags("ALL") +// regexp := es.Regexp("endpoint", "/books/.*").Flags("ALL") // // regexp now a "flags" field set "ALL" in the regexp query object. // // Parameters: @@ -62,7 +62,7 @@ func (r regexpType) Flags(flags string) regexpType { // value with the indexed field values when set to true. // Example usage: // -// regexp := Regexp("endpoint", "/books/.*").CaseInsensitive(true) +// regexp := es.Regexp("endpoint", "/books/.*").CaseInsensitive(true) // // regexp now a "case_insensitive" field set true in the regexp query object. // // Parameters: @@ -78,7 +78,7 @@ func (r regexpType) CaseInsensitive(caseInsensitive bool) regexpType { // MaxDeterminizedStates Maximum number of automaton states required for the query. // Example usage: // -// regexp := Regexp("endpoint", "/books/.*").MaxDeterminizedStates(10000) +// regexp := es.Regexp("endpoint", "/books/.*").MaxDeterminizedStates(10000) // // regexp now a "max_determinized_states" field set 10000 in the regexp query object. // // Parameters: @@ -91,10 +91,10 @@ func (r regexpType) MaxDeterminizedStates(maxDeterminizedStates int) regexpType return r.putInTheField("max_determinized_states", maxDeterminizedStates) } -// ReWrite Method used to rewrite the query. +// Rewrite Method used to rewrite the query. // Example usage: // -// regexp := Regexp("endpoint", "/books/.*").ReWrite("a") +// regexp := es.Regexp("endpoint", "/books/.*").Rewrite("a") // // regexp now a "rewrite" field set "a" in the regexp query object. // // Parameters: @@ -103,6 +103,6 @@ func (r regexpType) MaxDeterminizedStates(maxDeterminizedStates int) regexpType // Returns: // // The updated regexp object with the "rewrite" field set to the specified value. -func (r regexpType) ReWrite(rewrite string) regexpType { +func (r regexpType) Rewrite(rewrite string) regexpType { return r.putInTheField("rewrite", rewrite) } diff --git a/es/regexp_query_test.go b/es/regexp_query_test.go index 6f4fdd5..6acba83 100644 --- a/es/regexp_query_test.go +++ b/es/regexp_query_test.go @@ -65,7 +65,7 @@ func Test_Regexp_should_create_json_with_match_all_field_inside_rewrite_query(t // Given query := es.NewQuery( es.Regexp("key", "value1"). - ReWrite("a"), + Rewrite("a"), ) // When Then diff --git a/es/simple_query_string.go b/es/simple_query_string.go index 02d4685..f87eb32 100644 --- a/es/simple_query_string.go +++ b/es/simple_query_string.go @@ -10,7 +10,7 @@ type simpleQueryStringType Object // // Example usage: // -// q := SimpleQueryString("Foo + Bar") +// q := es.SimpleQueryString("Foo + Bar") // // q now contains a simpleQueryStringType object with a simple query string query. // // Parameters: @@ -36,7 +36,7 @@ func SimpleQueryString[T any](query T) simpleQueryStringType { // // Example usage: // -// q := SimpleQueryString("Foo Bar").Fields([]string{"title", "content"}) +// q := es.SimpleQueryString("Foo Bar").Fields([]string{"title", "content"}) // // q now searches within the "title" and "content" fields. // // Parameters: @@ -46,8 +46,7 @@ func SimpleQueryString[T any](query T) simpleQueryStringType { // // The updated simpleQueryStringType object with the "fields" option set. func (q simpleQueryStringType) Fields(value []string) simpleQueryStringType { - q.putInTheField("fields", value) - return q + return q.putInTheField("fields", value) } // Analyzer sets the analyzer to be used for the simpleQueryStringType object. @@ -58,7 +57,7 @@ func (q simpleQueryStringType) Fields(value []string) simpleQueryStringType { // // Example usage: // -// q := SimpleQueryString("Foo Bar").Analyzer("standard") +// q := es.SimpleQueryString("Foo Bar").Analyzer("standard") // // q now uses the "standard" analyzer for processing the query string. // // Parameters: @@ -68,8 +67,7 @@ func (q simpleQueryStringType) Fields(value []string) simpleQueryStringType { // // The updated simpleQueryStringType object with the "analyzer" set. func (q simpleQueryStringType) Analyzer(value string) simpleQueryStringType { - q.putInTheField("analyzer", value) - return q + return q.putInTheField("analyzer", value) } // DefaultOperator sets the default operator for the simpleQueryStringType object. @@ -92,8 +90,7 @@ func (q simpleQueryStringType) Analyzer(value string) simpleQueryStringType { // // The updated simpleQueryStringType object with the "default_operator" set. func (q simpleQueryStringType) DefaultOperator(value string) simpleQueryStringType { - q.putInTheField("default_operator", value) - return q + return q.putInTheField("default_operator", value) } // MinimumShouldMatch sets the minimum number of clauses that must match for the simpleQueryStringType object. @@ -104,7 +101,7 @@ func (q simpleQueryStringType) DefaultOperator(value string) simpleQueryStringTy // // Example usage: // -// q := SimpleQueryString("Foo Bar Baz").MinimumShouldMatch("2") +// q := es.SimpleQueryString("Foo Bar Baz").MinimumShouldMatch("2") // // q now requires that at least 2 of the terms match for a document to be considered a match. // // Parameters: @@ -114,8 +111,7 @@ func (q simpleQueryStringType) DefaultOperator(value string) simpleQueryStringTy // // The updated simpleQueryStringType object with the "minimum_should_match" option set. func (q simpleQueryStringType) MinimumShouldMatch(value string) simpleQueryStringType { - q.putInTheField("minimum_should_match", value) - return q + return q.putInTheField("minimum_should_match", value) } // FuzzyMaxExpansions sets the maximum number of expansions for fuzzy matching in the simpleQueryStringType object. @@ -127,7 +123,7 @@ func (q simpleQueryStringType) MinimumShouldMatch(value string) simpleQueryStrin // // Example usage: // -// q := SimpleQueryString("Foo~").FuzzyMaxExpansions(50) +// q := es.SimpleQueryString("Foo~").FuzzyMaxExpansions(50) // // q now allows up to 50 expansions for fuzzy matching. // // Parameters: @@ -137,8 +133,7 @@ func (q simpleQueryStringType) MinimumShouldMatch(value string) simpleQueryStrin // // The updated simpleQueryStringType object with the "fuzzy_max_expansions" option set. func (q simpleQueryStringType) FuzzyMaxExpansions(value int64) simpleQueryStringType { - q.putInTheField("fuzzy_max_expansions", value) - return q + return q.putInTheField("fuzzy_max_expansions", value) } // FuzzyPrefixLength sets the prefix length for fuzzy matching in the simpleQueryStringType object. @@ -150,7 +145,7 @@ func (q simpleQueryStringType) FuzzyMaxExpansions(value int64) simpleQueryString // // Example usage: // -// q := SimpleQueryString("Foo~").FuzzyPrefixLength(2) +// q := es.SimpleQueryString("Foo~").FuzzyPrefixLength(2) // // q now requires the first 2 characters to match exactly before applying fuzziness. // // Parameters: @@ -160,8 +155,7 @@ func (q simpleQueryStringType) FuzzyMaxExpansions(value int64) simpleQueryString // // The updated simpleQueryStringType object with the "fuzzy_prefix_length" option set. func (q simpleQueryStringType) FuzzyPrefixLength(value int64) simpleQueryStringType { - q.putInTheField("fuzzy_prefix_length", value) - return q + return q.putInTheField("fuzzy_prefix_length", value) } // FuzzyTranspositions sets the option to allow transpositions in fuzzy matching for the simpleQueryStringType object. @@ -172,7 +166,7 @@ func (q simpleQueryStringType) FuzzyPrefixLength(value int64) simpleQueryStringT // // Example usage: // -// q := SimpleQueryString("Foo~").FuzzyTranspositions(true) +// q := es.SimpleQueryString("Foo~").FuzzyTranspositions(true) // // q now allows transpositions in fuzzy matching. // // Parameters: @@ -182,8 +176,7 @@ func (q simpleQueryStringType) FuzzyPrefixLength(value int64) simpleQueryStringT // // The updated simpleQueryStringType object with the "fuzzy_transpositions" option set. func (q simpleQueryStringType) FuzzyTranspositions(value bool) simpleQueryStringType { - q.putInTheField("fuzzy_transpositions", value) - return q + return q.putInTheField("fuzzy_transpositions", value) } // AnalyzeWildcard sets the option to analyze wildcard terms in the simpleQueryStringType object. @@ -194,7 +187,7 @@ func (q simpleQueryStringType) FuzzyTranspositions(value bool) simpleQueryString // // Example usage: // -// q := SimpleQueryString("Fo*").AnalyzeWildcard(true) +// q := es.SimpleQueryString("Fo*").AnalyzeWildcard(true) // // q now analyzes wildcard terms in the query string. // // Parameters: @@ -204,8 +197,7 @@ func (q simpleQueryStringType) FuzzyTranspositions(value bool) simpleQueryString // // The updated simpleQueryStringType object with the "analyze_wildcard" option set. func (q simpleQueryStringType) AnalyzeWildcard(value bool) simpleQueryStringType { - q.putInTheField("analyze_wildcard", value) - return q + return q.putInTheField("analyze_wildcard", value) } // AutoGenerateSynonymsPhraseQuery sets the option to automatically generate phrase queries for synonyms @@ -217,7 +209,7 @@ func (q simpleQueryStringType) AnalyzeWildcard(value bool) simpleQueryStringType // // Example usage: // -// q := SimpleQueryString("quick brown fox").AutoGenerateSynonymsPhraseQuery(true) +// q := es.SimpleQueryString("quick brown fox").AutoGenerateSynonymsPhraseQuery(true) // // q now automatically generates phrase queries for synonyms in the query string. // // Parameters: @@ -227,8 +219,7 @@ func (q simpleQueryStringType) AnalyzeWildcard(value bool) simpleQueryStringType // // The updated simpleQueryStringType object with the "auto_generate_synonyms_phrase_query" option set. func (q simpleQueryStringType) AutoGenerateSynonymsPhraseQuery(value bool) simpleQueryStringType { - q.putInTheField("auto_generate_synonyms_phrase_query", value) - return q + return q.putInTheField("auto_generate_synonyms_phrase_query", value) } // Flags sets the flags for the simpleQueryStringType object. @@ -238,7 +229,7 @@ func (q simpleQueryStringType) AutoGenerateSynonymsPhraseQuery(value bool) simpl // // Example usage: // -// q := SimpleQueryString("Foo Bar").Flags("AND|OR|PREFIX") +// q := es.SimpleQueryString("Foo Bar").Flags("AND|OR|PREFIX") // // q now enables AND, OR, and PREFIX features for the query. // // Parameters: @@ -249,8 +240,7 @@ func (q simpleQueryStringType) AutoGenerateSynonymsPhraseQuery(value bool) simpl // // The updated simpleQueryStringType object with the "flags" option set. func (q simpleQueryStringType) Flags(value string) simpleQueryStringType { - q.putInTheField("flags", value) - return q + return q.putInTheField("flags", value) } // Lenient sets the leniency option for the simpleQueryStringType object. @@ -262,7 +252,7 @@ func (q simpleQueryStringType) Flags(value string) simpleQueryStringType { // // Example usage: // -// q := SimpleQueryString("Foo Bar").Lenient(true) +// q := es.SimpleQueryString("Foo Bar").Lenient(true) // // q is now lenient, allowing it to tolerate errors during the query. // // Parameters: @@ -272,8 +262,7 @@ func (q simpleQueryStringType) Flags(value string) simpleQueryStringType { // // The updated simpleQueryStringType object with the "lenient" option set. func (q simpleQueryStringType) Lenient(value bool) simpleQueryStringType { - q.putInTheField("lenient", value) - return q + return q.putInTheField("lenient", value) } // QuoteFieldSuffix sets the field suffix to be used for quoted text in the simpleQueryStringType object. @@ -283,7 +272,7 @@ func (q simpleQueryStringType) Lenient(value bool) simpleQueryStringType { // // Example usage: // -// q := SimpleQueryString("Foo \"Bar Baz\"").QuoteFieldSuffix("_phrase") +// q := es.SimpleQueryString("Foo \"Bar Baz\"").QuoteFieldSuffix("_phrase") // // q now appends "_phrase" to the field names when processing quoted text in the query string. // // Parameters: @@ -293,8 +282,7 @@ func (q simpleQueryStringType) Lenient(value bool) simpleQueryStringType { // // The updated simpleQueryStringType object with the "quote_field_suffix" option set. func (q simpleQueryStringType) QuoteFieldSuffix(value string) simpleQueryStringType { - q.putInTheField("quote_field_suffix", value) - return q + return q.putInTheField("quote_field_suffix", value) } func (q simpleQueryStringType) putInTheField(key string, value any) simpleQueryStringType { diff --git a/es/term_query.go b/es/term_query.go index b0ac48b..a401409 100644 --- a/es/term_query.go +++ b/es/term_query.go @@ -10,7 +10,7 @@ type termType Object // // Example usage: // -// t := Term("category", "books") +// t := es.Term("category", "books") // // t now contains a termType object with a term query for the "category" field. // // Parameters: @@ -49,7 +49,7 @@ func (t termType) putInTheField(key string, value any) termType { // // Example usage: // -// t := Term().CaseInsensitive(true) +// t := es.Term().CaseInsensitive(true) // // t now includes a "case_insensitive" parameter set to true. // // Parameters: @@ -72,7 +72,7 @@ func (t termType) CaseInsensitive(caseInsensitive bool) termType { // // Example usage: // -// t := Term().Boost(1.5) +// t := es.Term().Boost(1.5) // // t now includes a "boost" parameter set to 1.5. // // Parameters: @@ -94,7 +94,7 @@ func (t termType) Boost(boost float64) termType { // // Example usage: // -// t := TermFunc("category", "books", func(key, value string) bool { +// t := es.TermFunc("category", "books", func(key, value string) bool { // return value != "" // }) // // t is either a termType object or nil based on the condition. @@ -122,7 +122,7 @@ func TermFunc[T any](key string, value T, f func(key string, value T) bool) term // // Example usage: // -// t := TermIf("category", "books", true) +// t := es.TermIf("category", "books", true) // // t is a termType object if the condition is true; otherwise, it is nil. // // Parameters: diff --git a/es/terms_query.go b/es/terms_query.go index ff3cd82..dc3f724 100644 --- a/es/terms_query.go +++ b/es/terms_query.go @@ -10,7 +10,7 @@ type termsType Object // // Example usage: // -// t := Terms("category", "books", "electronics") +// t := es.Terms("category", "books", "electronics") // // t now contains a termsType object with a terms query for the "category" field. // // Parameters: @@ -46,7 +46,7 @@ func (t termsType) putInTheField(key string, value any) termsType { // // Example usage: // -// t := Terms().Boost(1.5) +// t := es.Terms().Boost(1.5) // // t now includes a "boost" parameter set to 1.5. // // Parameters: @@ -69,7 +69,7 @@ func (t termsType) Boost(boost float64) termsType { // // Example usage: // -// t := TermsArray("category", []string{"books", "electronics"}) +// t := es.TermsArray("category", []string{"books", "electronics"}) // // t now contains a termsType object with a terms query for the "category" field. // // Parameters: @@ -96,7 +96,7 @@ func TermsArray[T any](key string, values []T) termsType { // // Example usage: // -// t := TermsFunc("category", []string{"books", "electronics"}, func(key string, values []string) bool { +// t := es.TermsFunc("category", []string{"books", "electronics"}, func(key string, values []string) bool { // return len(values) > 0 // }) // // t is either a termsType object or nil based on the condition. @@ -124,7 +124,7 @@ func TermsFunc[T any](key string, values []T, f func(key string, values []T) boo // // Example usage: // -// t := TermsIf("category", []string{"books", "electronics"}, true) +// t := es.TermsIf("category", []string{"books", "electronics"}, true) // // t is a termsType object if the condition is true; otherwise, it is nil. // // Parameters: From a05843f9d4154b5668d92dd73d561db9852f922d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6ksel=20K=C3=BC=C3=A7=C3=BCk=C5=9Fahin?= Date: Tue, 12 Nov 2024 16:53:01 +0300 Subject: [PATCH 02/17] refactor: refactor enums. --- es/enums/{match => }/operator/operator.go | 0 es/enums/{match => }/operator/operator_test.go | 4 ++-- es/enums/{nested => }/score-mode/score_mode.go | 0 .../{nested => }/score-mode/score_mode_test.go | 3 ++- .../zero-terms-query/zero_terms_query.go | 0 .../zero-terms-query/zero_terms_query_test.go | 4 ++-- es/match_none_query.go | 4 +++- es/match_none_query_test.go | 4 ++-- es/match_query.go | 4 ++-- es/match_query_test.go | 6 +++--- es/nested_query.go | 4 +++- es/nested_query_test.go | 4 ++-- es/query_string.go | 18 +++++++++++------- es/simple_query_string.go | 18 +++++++++++------- es/simple_query_string_test.go | 9 +++++---- 15 files changed, 48 insertions(+), 34 deletions(-) rename es/enums/{match => }/operator/operator.go (100%) rename es/enums/{match => }/operator/operator_test.go (84%) rename es/enums/{nested => }/score-mode/score_mode.go (100%) rename es/enums/{nested => }/score-mode/score_mode_test.go (86%) rename es/enums/{match => }/zero-terms-query/zero_terms_query.go (100%) rename es/enums/{match => }/zero-terms-query/zero_terms_query_test.go (84%) diff --git a/es/enums/match/operator/operator.go b/es/enums/operator/operator.go similarity index 100% rename from es/enums/match/operator/operator.go rename to es/enums/operator/operator.go diff --git a/es/enums/match/operator/operator_test.go b/es/enums/operator/operator_test.go similarity index 84% rename from es/enums/match/operator/operator_test.go rename to es/enums/operator/operator_test.go index 521d10c..0087e58 100644 --- a/es/enums/match/operator/operator_test.go +++ b/es/enums/operator/operator_test.go @@ -3,9 +3,9 @@ package operator_test import ( "testing" - "github.com/Trendyol/es-query-builder/test/assert" + Operator "github.com/Trendyol/es-query-builder/es/enums/operator" - Operator "github.com/Trendyol/es-query-builder/es/enums/match/operator" + "github.com/Trendyol/es-query-builder/test/assert" ) func Test_OperatorString(t *testing.T) { diff --git a/es/enums/nested/score-mode/score_mode.go b/es/enums/score-mode/score_mode.go similarity index 100% rename from es/enums/nested/score-mode/score_mode.go rename to es/enums/score-mode/score_mode.go diff --git a/es/enums/nested/score-mode/score_mode_test.go b/es/enums/score-mode/score_mode_test.go similarity index 86% rename from es/enums/nested/score-mode/score_mode_test.go rename to es/enums/score-mode/score_mode_test.go index c28c853..56efce8 100644 --- a/es/enums/nested/score-mode/score_mode_test.go +++ b/es/enums/score-mode/score_mode_test.go @@ -3,7 +3,8 @@ package scoremode_test import ( "testing" - scoremode "github.com/Trendyol/es-query-builder/es/enums/nested/score-mode" + "github.com/Trendyol/es-query-builder/es/enums/score-mode" + "github.com/Trendyol/es-query-builder/test/assert" ) diff --git a/es/enums/match/zero-terms-query/zero_terms_query.go b/es/enums/zero-terms-query/zero_terms_query.go similarity index 100% rename from es/enums/match/zero-terms-query/zero_terms_query.go rename to es/enums/zero-terms-query/zero_terms_query.go diff --git a/es/enums/match/zero-terms-query/zero_terms_query_test.go b/es/enums/zero-terms-query/zero_terms_query_test.go similarity index 84% rename from es/enums/match/zero-terms-query/zero_terms_query_test.go rename to es/enums/zero-terms-query/zero_terms_query_test.go index 2c65449..559eae4 100644 --- a/es/enums/match/zero-terms-query/zero_terms_query_test.go +++ b/es/enums/zero-terms-query/zero_terms_query_test.go @@ -3,9 +3,9 @@ package zerotermsquery_test import ( "testing" - "github.com/Trendyol/es-query-builder/test/assert" + ZeroTermsQuery "github.com/Trendyol/es-query-builder/es/enums/zero-terms-query" - ZeroTermsQuery "github.com/Trendyol/es-query-builder/es/enums/match/zero-terms-query" + "github.com/Trendyol/es-query-builder/test/assert" ) func Test_ZeroTermsQueryString(t *testing.T) { diff --git a/es/match_none_query.go b/es/match_none_query.go index 15c5549..84a8763 100644 --- a/es/match_none_query.go +++ b/es/match_none_query.go @@ -1,6 +1,8 @@ package es -import Operator "github.com/Trendyol/es-query-builder/es/enums/match/operator" +import ( + Operator "github.com/Trendyol/es-query-builder/es/enums/operator" +) type matchNoneType Object diff --git a/es/match_none_query_test.go b/es/match_none_query_test.go index 610133d..4265379 100644 --- a/es/match_none_query_test.go +++ b/es/match_none_query_test.go @@ -3,10 +3,10 @@ package es_test import ( "testing" + Operator "github.com/Trendyol/es-query-builder/es/enums/operator" + "github.com/Trendyol/es-query-builder/es" "github.com/Trendyol/es-query-builder/test/assert" - - Operator "github.com/Trendyol/es-query-builder/es/enums/match/operator" ) //// MatchNone //// diff --git a/es/match_query.go b/es/match_query.go index ea3d50c..f87466e 100644 --- a/es/match_query.go +++ b/es/match_query.go @@ -1,8 +1,8 @@ package es import ( - Operator "github.com/Trendyol/es-query-builder/es/enums/match/operator" - ZeroTermsQuery "github.com/Trendyol/es-query-builder/es/enums/match/zero-terms-query" + Operator "github.com/Trendyol/es-query-builder/es/enums/operator" + ZeroTermsQuery "github.com/Trendyol/es-query-builder/es/enums/zero-terms-query" ) type matchType Object diff --git a/es/match_query_test.go b/es/match_query_test.go index 83a596e..774a9a4 100644 --- a/es/match_query_test.go +++ b/es/match_query_test.go @@ -3,11 +3,11 @@ package es_test import ( "testing" + Operator "github.com/Trendyol/es-query-builder/es/enums/operator" + ZeroTermsQuery "github.com/Trendyol/es-query-builder/es/enums/zero-terms-query" + "github.com/Trendyol/es-query-builder/es" "github.com/Trendyol/es-query-builder/test/assert" - - Operator "github.com/Trendyol/es-query-builder/es/enums/match/operator" - ZeroTermsQuery "github.com/Trendyol/es-query-builder/es/enums/match/zero-terms-query" ) //// Match //// diff --git a/es/nested_query.go b/es/nested_query.go index 27a06de..841291b 100644 --- a/es/nested_query.go +++ b/es/nested_query.go @@ -1,6 +1,8 @@ package es -import ScoreMode "github.com/Trendyol/es-query-builder/es/enums/nested/score-mode" +import ( + ScoreMode "github.com/Trendyol/es-query-builder/es/enums/score-mode" +) type nestedType Object diff --git a/es/nested_query_test.go b/es/nested_query_test.go index bc62216..398d070 100644 --- a/es/nested_query_test.go +++ b/es/nested_query_test.go @@ -3,10 +3,10 @@ package es_test import ( "testing" + ScoreMode "github.com/Trendyol/es-query-builder/es/enums/score-mode" + "github.com/Trendyol/es-query-builder/es" "github.com/Trendyol/es-query-builder/test/assert" - - ScoreMode "github.com/Trendyol/es-query-builder/es/enums/nested/score-mode" ) //// Nested //// diff --git a/es/query_string.go b/es/query_string.go index 7fae4db..bac7a29 100644 --- a/es/query_string.go +++ b/es/query_string.go @@ -1,5 +1,9 @@ package es +import ( + Operator "github.com/Trendyol/es-query-builder/es/enums/operator" +) + type queryStringType Object // QueryString creates a new queryStringType object with the specified query string. @@ -175,25 +179,25 @@ func (q queryStringType) Boost(value float64) queryStringType { // DefaultOperator sets the default operator for the queryStringType object. // // This method specifies the default operator to be used between terms in the query string -// when no explicit operator is provided. The default operator can be "AND" or "OR", +// when no explicit operator is provided. The default operator can be operator.And or operator.Or, // determining whether all terms (AND) or any term (OR) must be matched in the search results. // // Example usage: // // b := es.QueryString("value"). -// DefaultOperator("AND") +// DefaultOperator(Operator.And) // -// q := es.QueryString("Foo Bar").DefaultOperator("OR") -// // q now uses "OR" as the default operator, meaning any term can match in the query. +// q := es.QueryString("Foo Bar").DefaultOperator(Operator.Or) +// // q now uses "or" as the default operator, meaning any term can match in the query. // // Parameters: -// - value: A string representing the default operator to be used ("AND" or "OR"). +// - operator: A operator.Operator representing the default operator to be used ("and" or "or"). // // Returns: // // The updated queryStringType object with the "default_operator" set. -func (q queryStringType) DefaultOperator(value string) queryStringType { - return q.putInTheField("default_operator", value) +func (q queryStringType) DefaultOperator(operator Operator.Operator) queryStringType { + return q.putInTheField("default_operator", operator) } // EnablePositionIncrements sets the option to enable or disable position increments in the queryStringType object. diff --git a/es/simple_query_string.go b/es/simple_query_string.go index f87eb32..d44783d 100644 --- a/es/simple_query_string.go +++ b/es/simple_query_string.go @@ -1,5 +1,9 @@ package es +import ( + Operator "github.com/Trendyol/es-query-builder/es/enums/operator" +) + type simpleQueryStringType Object // SimpleQueryString creates a new simpleQueryStringType object with the specified query string. @@ -73,24 +77,24 @@ func (q simpleQueryStringType) Analyzer(value string) simpleQueryStringType { // DefaultOperator sets the default operator for the simpleQueryStringType object. // // This method specifies the default operator to be used between terms in the query string -// when no explicit operator is provided. The default operator can be "AND" or "OR", -// determining whether all terms (AND) or any term (OR) must be matched in the search results. +// when no explicit operator is provided. The default operator can be operator.And or operator.Or, +// determining whether all terms (and) or any term (or) must be matched in the search results. // // Example usage: // // q := es.SimpleQueryString("Foo Bar"). -// DefaultOperator("OR") +// DefaultOperator(operator.Or) // -// q now uses "OR" as the default operator, meaning any term can match in the query. +// q now uses "or" as the default operator, meaning any term can match in the query. // // Parameters: -// - value: A string representing the default operator to be used ("AND" or "OR"). +// - operator: A operator.Operator representing the default operator to be used ("and" or "or"). // // Returns: // // The updated simpleQueryStringType object with the "default_operator" set. -func (q simpleQueryStringType) DefaultOperator(value string) simpleQueryStringType { - return q.putInTheField("default_operator", value) +func (q simpleQueryStringType) DefaultOperator(operator Operator.Operator) simpleQueryStringType { + return q.putInTheField("default_operator", operator) } // MinimumShouldMatch sets the minimum number of clauses that must match for the simpleQueryStringType object. diff --git a/es/simple_query_string_test.go b/es/simple_query_string_test.go index 9347daf..bcb2912 100644 --- a/es/simple_query_string_test.go +++ b/es/simple_query_string_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/Trendyol/es-query-builder/es" + "github.com/Trendyol/es-query-builder/es/enums/operator" "github.com/Trendyol/es-query-builder/test/assert" ) @@ -60,13 +61,13 @@ func Test_SimpleQueryString_method_should_create_simple_query_string_with_analyz func Test_SimpleQueryString_method_should_create_simple_query_string_with_default_operator(t *testing.T) { // Given When b := es.NewQuery( - es.SimpleQueryString("value").DefaultOperator("AND"), + es.SimpleQueryString("value").DefaultOperator(operator.And), ) // Then assert.NotNil(t, b) bodyJSON := assert.MarshalWithoutError(t, b) - assert.Equal(t, "{\"query\":{\"simple_query_string\":{\"default_operator\":\"AND\",\"query\":\"value\"}}}", bodyJSON) + assert.Equal(t, "{\"query\":{\"simple_query_string\":{\"default_operator\":\"and\",\"query\":\"value\"}}}", bodyJSON) } func Test_SimpleQueryString_method_should_create_simple_query_string_with_minimum_should_match(t *testing.T) { @@ -183,7 +184,7 @@ func Test_SimpleQueryString_method_should_create_simple_query_string_with_all_pa es.SimpleQueryString("value"). Fields([]string{"field1", "field2"}). Analyzer("standard"). - DefaultOperator("AND"). + DefaultOperator(operator.And). MinimumShouldMatch("2"). FuzzyMaxExpansions(50). FuzzyPrefixLength(2). @@ -202,7 +203,7 @@ func Test_SimpleQueryString_method_should_create_simple_query_string_with_all_pa "\"analyze_wildcard\":true,"+ "\"analyzer\":\"standard\","+ "\"auto_generate_synonyms_phrase_query\":true,"+ - "\"default_operator\":\"AND\","+ + "\"default_operator\":\"and\","+ "\"fields\":[\"field1\",\"field2\"],"+ "\"flags\":\"AND|OR|PREFIX\","+ "\"fuzzy_max_expansions\":50,"+ From daa1b66cf07d06a82aaa8269fc9d95dfe21af3cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6ksel=20K=C3=BC=C3=A7=C3=BCk=C5=9Fahin?= Date: Tue, 12 Nov 2024 16:58:11 +0300 Subject: [PATCH 03/17] refactor: remove Operator parameter on Match None Query --- es/match_none_query.go | 25 ------------------------- es/match_none_query_test.go | 7 ++----- 2 files changed, 2 insertions(+), 30 deletions(-) diff --git a/es/match_none_query.go b/es/match_none_query.go index 84a8763..43d1c0c 100644 --- a/es/match_none_query.go +++ b/es/match_none_query.go @@ -1,9 +1,5 @@ package es -import ( - Operator "github.com/Trendyol/es-query-builder/es/enums/operator" -) - type matchNoneType Object // MatchNone creates a new matchNoneType object with the specified field and query. @@ -46,27 +42,6 @@ func (m matchNoneType) putInTheField(key string, value any) matchNoneType { return m } -// Operator sets the "operator" field in the match_none query. -// -// This method configures the match_none query to use a specified operator (e.g., "AND" or "OR") -// for the matching process. It calls putInTheField to add or update the "operator" key -// in the match_none query object. -// -// Example usage: -// -// mn := es.MatchNone("title", "es-query-builder").Operator("AND") -// // mn now has an "operator" field set to "AND" in the match_none query object. -// -// Parameters: -// - operator: An Operator.Operator value representing the logical operator to be used in the match_none query. -// -// Returns: -// -// The updated matchNoneType object with the "operator" field set to the specified value. -func (m matchNoneType) Operator(operator Operator.Operator) matchNoneType { - return m.putInTheField("operator", operator) -} - // Boost sets the "boost" field in the match_none query. // // This method configures the match_none query to use a specified boost factor, which influences diff --git a/es/match_none_query_test.go b/es/match_none_query_test.go index 4265379..a8d0263 100644 --- a/es/match_none_query_test.go +++ b/es/match_none_query_test.go @@ -3,8 +3,6 @@ package es_test import ( "testing" - Operator "github.com/Trendyol/es-query-builder/es/enums/operator" - "github.com/Trendyol/es-query-builder/es" "github.com/Trendyol/es-query-builder/test/assert" ) @@ -29,13 +27,12 @@ func Test_MatchNone_should_create_json_with_match_none_field_inside_query(t *tes // Given query := es.NewQuery( es.MatchNone("fooBar", "lorem ipsum"). - Boost(6.19). - Operator(Operator.And), + Boost(6.19), ) // When Then assert.NotNil(t, query) bodyJSON := assert.MarshalWithoutError(t, query) // nolint:golint,lll - assert.Equal(t, "{\"query\":{\"match_none\":{\"fooBar\":{\"boost\":6.19,\"operator\":\"and\",\"query\":\"lorem ipsum\"}}}}", bodyJSON) + assert.Equal(t, "{\"query\":{\"match_none\":{\"fooBar\":{\"boost\":6.19,\"query\":\"lorem ipsum\"}}}}", bodyJSON) } From 73ec98dbdffa932dfc1b60f9a5aada86988a06a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6ksel=20K=C3=BC=C3=A7=C3=BCk=C5=9Fahin?= Date: Sat, 28 Dec 2024 17:37:27 +0300 Subject: [PATCH 04/17] feature: add boost parameter to exists, regexp simpleQueryString queries. add from, to and relation parameters to range query with rangeRelation enum --- es/enums/range-relation/range_relation.go | 38 ++++++++++ .../range-relation/range_relation_test.go | 26 +++++++ es/exists_query.go | 30 ++++++++ es/exists_query_test.go | 21 ++++++ es/range.go | 71 ++++++++++++++++++ es/range_test.go | 72 +++++++++++++++++++ es/regexp_query.go | 23 ++++++ es/regexp_query_test.go | 53 ++++++++++++++ es/simple_query_string.go | 23 ++++++ es/simple_query_string_test.go | 16 ++++- es/term_query_test.go | 2 +- 11 files changed, 373 insertions(+), 2 deletions(-) create mode 100644 es/enums/range-relation/range_relation.go create mode 100644 es/enums/range-relation/range_relation_test.go diff --git a/es/enums/range-relation/range_relation.go b/es/enums/range-relation/range_relation.go new file mode 100644 index 0000000..acc4270 --- /dev/null +++ b/es/enums/range-relation/range_relation.go @@ -0,0 +1,38 @@ +// Package range_relation provides utilities for working with range relations. +// +// RangeRelation is a string type used to specify the spatial or logical relationship +// between two ranges, such as whether one range is entirely within another, +// contains another, or intersects with another. +// +// Example usage: +// +// var relation RangeRelation = Within +// +// // Use relation in a query configuration +// +// Constants: +// - Within: Indicates that one range is entirely within another. +// - Contains: Indicates that one range entirely contains another. +// - Intersects: Indicates that the ranges overlap or intersect at least partially. +package range_relation + +// RangeRelation represents the relationship between two ranges. +// +// RangeRelation is a string type that specifies the spatial or logical relationship +// between ranges, which is commonly used in geospatial queries or similar scenarios. +type RangeRelation string + +const ( + // Within indicates that one range is entirely within another. + Within RangeRelation = "within" + + // Contains indicates that one range entirely contains another. + Contains RangeRelation = "contains" + + // Intersects indicates that the ranges overlap or intersect at least partially. + Intersects RangeRelation = "intersects" +) + +func (rangeRelation RangeRelation) String() string { + return string(rangeRelation) +} diff --git a/es/enums/range-relation/range_relation_test.go b/es/enums/range-relation/range_relation_test.go new file mode 100644 index 0000000..d00d352 --- /dev/null +++ b/es/enums/range-relation/range_relation_test.go @@ -0,0 +1,26 @@ +package range_relation_test + +import ( + "testing" + + RangeRelation "github.com/Trendyol/es-query-builder/es/enums/range-relation" + + "github.com/Trendyol/es-query-builder/test/assert" +) + +func Test_RangeRelationString(t *testing.T) { + tests := []struct { + relation RangeRelation.RangeRelation + result string + }{ + {RangeRelation.Within, "within"}, + {RangeRelation.Contains, "contains"}, + {RangeRelation.Intersects, "intersects"}, + } + + for _, test := range tests { + t.Run(test.result, func(t *testing.T) { + assert.Equal(t, test.result, test.relation.String()) + }) + } +} diff --git a/es/exists_query.go b/es/exists_query.go index 07dfd83..0b3c071 100644 --- a/es/exists_query.go +++ b/es/exists_query.go @@ -27,6 +27,36 @@ func Exists(key string) existsType { } } +func (e existsType) putInTheField(key string, value any) existsType { + if exists, ok := e["exists"].(Object); ok { + exists[key] = value + } + return e +} + +// Boost sets the "boost" parameter in an existsType query. +// +// This method allows you to specify a boost factor for the exists query, +// which influences the relevance score of matching documents. A higher +// boost value increases the importance of the query in the overall score, +// resulting in higher scores for documents that satisfy the exists condition. +// +// Example usage: +// +// e := es.Exists().Boost(2.0) +// // e now includes a "boost" parameter set to 2.0. +// +// Parameters: +// - boost: A float64 value representing the boost factor for the exists +// query. +// +// Returns: +// +// The updated existsType object with the "boost" parameter set. +func (e existsType) Boost(boost float64) existsType { + return e.putInTheField("boost", boost) +} + // ExistsFunc creates an existsType object based on a condition evaluated by a function. // // This function conditionally creates an existsType object if the provided function diff --git a/es/exists_query_test.go b/es/exists_query_test.go index 036b1c9..83a9010 100644 --- a/es/exists_query_test.go +++ b/es/exists_query_test.go @@ -35,6 +35,27 @@ func Test_Exists_method_should_create_existsType(t *testing.T) { assert.IsTypeString(t, "es.existsType", b) } +func Test_Exists_should_have_Boost_method(t *testing.T) { + // Given + exists := es.Exists("key") + + // When Then + assert.NotNil(t, exists.Boost) +} + +func Test_Exists_Boost_should_create_json_with_boost_field_inside_exists(t *testing.T) { + // Given + query := es.NewQuery( + es.Exists("type"). + Boost(3.14), + ) + + // When Then + assert.NotNil(t, query) + bodyJSON := assert.MarshalWithoutError(t, query) + assert.Equal(t, "{\"query\":{\"exists\":{\"boost\":3.14,\"field\":\"type\"}}}", bodyJSON) +} + //// ExistsFunc //// func Test_ExistsFunc_should_exist_on_es_package(t *testing.T) { diff --git a/es/range.go b/es/range.go index 1608114..ab07b69 100644 --- a/es/range.go +++ b/es/range.go @@ -1,5 +1,7 @@ package es +import RangeRelation "github.com/Trendyol/es-query-builder/es/enums/range-relation" + type rangeType Object // Range creates a new rangeType object with the specified field. @@ -172,3 +174,72 @@ func (r rangeType) Format(format string) rangeType { func (r rangeType) Boost(boost float64) rangeType { return r.putInTheField("boost", boost) } + +// From sets the "from" field for the range query. +// +// This method specifies the lower bound for the range query. The "from" field defines +// the start of the range, and documents with values greater than or equal to this +// value will be considered a match. +// +// Example usage: +// +// r := es.Range("age").From(18) +// // r now has a "from" field set to 18 in the range query for the "age" field. +// +// Parameters: +// - from: The value representing the lower bound of the range. It can be of any type +// that is valid for the field (e.g., integer, string, date). +// +// Returns: +// +// The updated rangeType object with the "from" field set to the specified value. +func (r rangeType) From(from any) rangeType { + return r.putInTheField("from", from) +} + +// To sets the "to" field for the range query. +// +// This method specifies the upper bound for the range query. The "to" field defines +// the end of the range, and documents with values less than or equal to this +// value will be considered a match. +// +// Example usage: +// +// r := es.Range("age").To(65) +// // r now has a "to" field set to 65 in the range query for the "age" field. +// +// Parameters: +// - to: The value representing the upper bound of the range. It can be of any type +// that is valid for the field (e.g., integer, string, date). +// +// Returns: +// +// The updated rangeType object with the "to" field set to the specified value. +func (r rangeType) To(to any) rangeType { + return r.putInTheField("to", to) +} + +// Relation sets the "relation" field for the range query. +// +// This method specifies the relationship between the ranges in the query. It allows +// you to define how the "from" and "to" values are related, such as whether one +// range is within another, contains it, or intersects with it. +// +// Example usage: +// +// r := es.Range("age").Relation(es.RangeRelation.Within) +// // r now has a "relation" field set to "within" in the range query for the "age" field. +// +// Parameters: +// - relation: The RangeRelation value representing the relationship between the ranges. +// It can be one of the following values: +// - Within +// - Contains +// - Intersects +// +// Returns: +// +// The updated rangeType object with the "relation" field set to the specified value. +func (r rangeType) Relation(relation RangeRelation.RangeRelation) rangeType { + return r.putInTheField("relation", relation) +} diff --git a/es/range_test.go b/es/range_test.go index 3407947..972dec1 100644 --- a/es/range_test.go +++ b/es/range_test.go @@ -1,6 +1,7 @@ package es_test import ( + range_relation "github.com/Trendyol/es-query-builder/es/enums/range-relation" "testing" "github.com/Trendyol/es-query-builder/es" @@ -171,3 +172,74 @@ func Test_Range_Boost_should_create_json_with_range_field_inside_query(t *testin // nolint:golint,lll assert.Equal(t, "{\"query\":{\"range\":{\"partition\":{\"boost\":3.2,\"gt\":112,\"lt\":765}}}}", bodyJSON) } + +func Test_Range_should_have_From_method(t *testing.T) { + // Given + r := es.Range("age") + + // When Then + assert.NotNil(t, r) + assert.NotNil(t, r.From) +} + +func Test_Range_From_should_create_json_with_range_field_inside_query(t *testing.T) { + // Given + query := es.NewQuery( + es.Range("partition"). + From(512), + ) + + // When Then + assert.NotNil(t, query) + bodyJSON := assert.MarshalWithoutError(t, query) + // nolint:golint,lll + assert.Equal(t, "{\"query\":{\"range\":{\"partition\":{\"from\":512}}}}", bodyJSON) +} + +func Test_Range_should_have_To_method(t *testing.T) { + // Given + r := es.Range("age") + + // When Then + assert.NotNil(t, r) + assert.NotNil(t, r.To) +} + +func Test_Range_To_should_create_json_with_range_field_inside_query(t *testing.T) { + // Given + query := es.NewQuery( + es.Range("partition"). + To(1024), + ) + + // When Then + assert.NotNil(t, query) + bodyJSON := assert.MarshalWithoutError(t, query) + // nolint:golint,lll + assert.Equal(t, "{\"query\":{\"range\":{\"partition\":{\"to\":1024}}}}", bodyJSON) +} + +func Test_Range_should_have_Relation_method(t *testing.T) { + // Given + r := es.Range("age") + + // When Then + assert.NotNil(t, r) + assert.NotNil(t, r.Relation) +} + +func Test_Range_Relation_should_create_json_with_range_field_inside_query(t *testing.T) { + // Given + query := es.NewQuery( + es.Range("partition"). + From(512). + To(1024). + Relation(range_relation.Within), + ) + + // When Then + assert.NotNil(t, query) + bodyJSON := assert.MarshalWithoutError(t, query) + // nolint:golint,lll + assert.Equal(t, "{\"query\":{\"range\":{\"partition\":{\"from\":512,\"relation\":\"within\",\"to\":1024}}}}", bodyJSON) +} diff --git a/es/regexp_query.go b/es/regexp_query.go index 61e8c95..a485738 100644 --- a/es/regexp_query.go +++ b/es/regexp_query.go @@ -106,3 +106,26 @@ func (r regexpType) MaxDeterminizedStates(maxDeterminizedStates int) regexpType func (r regexpType) Rewrite(rewrite string) regexpType { return r.putInTheField("rewrite", rewrite) } + +// Boost sets the "boost" parameter in a regexpType query. +// +// This method allows you to specify a boost factor for the regular expression query, +// which influences the relevance score of matching documents. A higher boost value +// increases the importance of the query in the overall score, resulting in higher +// scores for documents that match the regular expression. +// +// Example usage: +// +// r := es.Regexp().Boost(1.2) +// // r now includes a "boost" parameter set to 1.2. +// +// Parameters: +// - boost: A float64 value representing the boost factor for the regular +// expression query. +// +// Returns: +// +// The updated regexpType object with the "boost" parameter set. +func (r regexpType) Boost(boost float64) regexpType { + return r.putInTheField("boost", boost) +} diff --git a/es/regexp_query_test.go b/es/regexp_query_test.go index 6acba83..3fc6e26 100644 --- a/es/regexp_query_test.go +++ b/es/regexp_query_test.go @@ -14,6 +14,46 @@ func Test_Regexp_should_exist_on_es_package(t *testing.T) { assert.NotNil(t, es.Regexp) } +func Test_Regexp_should_have_Boost_method(t *testing.T) { + // Given + regex := es.Regexp("key", "[a-z0-9]") + + // When Then + assert.NotNil(t, regex.Boost) +} + +func Test_Regexp_should_have_Flags_method(t *testing.T) { + // Given + regex := es.Regexp("key", "[a-z0-9]") + + // When Then + assert.NotNil(t, regex.Flags) +} + +func Test_Regexp_should_have_Rewrite_method(t *testing.T) { + // Given + regex := es.Regexp("key", "[a-z0-9]") + + // When Then + assert.NotNil(t, regex.Rewrite) +} + +func Test_Regexp_should_have_CaseInsensitive_method(t *testing.T) { + // Given + regex := es.Regexp("key", "[a-z0-9]") + + // When Then + assert.NotNil(t, regex.CaseInsensitive) +} + +func Test_Regexp_should_have_MaxDeterminizedStates_method(t *testing.T) { + // Given + regex := es.Regexp("key", "[a-z0-9]") + + // When Then + assert.NotNil(t, regex.MaxDeterminizedStates) +} + func Test_Regexp_should_create_json_with_regexp_field_inside_query(t *testing.T) { // Given query := es.NewQuery( @@ -86,3 +126,16 @@ func Test_Regexp_should_create_json_with_match_all_field_inside_flags_query(t *t bodyJSON := assert.MarshalWithoutError(t, query) assert.Equal(t, "{\"query\":{\"regexp\":{\"key\":{\"flags\":\"ALL\",\"value\":\"value1\"}}}}", bodyJSON) } + +func Test_Regexp_Boost_should_create_json_with_boost_field_inside_regexp(t *testing.T) { + // Given + query := es.NewQuery( + es.Regexp("name", "[bst]ake"). + Boost(2.718), + ) + + // When Then + assert.NotNil(t, query) + bodyJSON := assert.MarshalWithoutError(t, query) + assert.Equal(t, "{\"query\":{\"regexp\":{\"name\":{\"boost\":2.718,\"value\":\"[bst]ake\"}}}}", bodyJSON) +} diff --git a/es/simple_query_string.go b/es/simple_query_string.go index d44783d..3b5eb6a 100644 --- a/es/simple_query_string.go +++ b/es/simple_query_string.go @@ -289,6 +289,29 @@ func (q simpleQueryStringType) QuoteFieldSuffix(value string) simpleQueryStringT return q.putInTheField("quote_field_suffix", value) } +// Boost sets the "boost" parameter in a simpleQueryStringType query. +// +// This method allows you to specify a boost factor for the simple query string query, +// which influences the relevance score of matching documents. A higher boost value +// increases the importance of the query in the overall score, resulting in higher +// scores for documents that match the query string conditions. +// +// Example usage: +// +// q := es.SimpleQueryString().Boost(1.8) +// // q now includes a "boost" parameter set to 1.8. +// +// Parameters: +// - boost: A float64 value representing the boost factor for the simple +// query string query. +// +// Returns: +// +// The updated simpleQueryStringType object with the "boost" parameter set. +func (q simpleQueryStringType) Boost(boost float64) simpleQueryStringType { + return q.putInTheField("boost", boost) +} + func (q simpleQueryStringType) putInTheField(key string, value any) simpleQueryStringType { for _, fieldObj := range q { if fieldObject, ok := fieldObj.(Object); ok { diff --git a/es/simple_query_string_test.go b/es/simple_query_string_test.go index bcb2912..ea7712e 100644 --- a/es/simple_query_string_test.go +++ b/es/simple_query_string_test.go @@ -178,6 +178,18 @@ func Test_SimpleQueryString_method_should_create_simple_query_string_with_quote_ assert.Equal(t, "{\"query\":{\"simple_query_string\":{\"query\":\"value\",\"quote_field_suffix\":\"_phrase\"}}}", bodyJSON) } +func Test_SimpleQueryString_method_should_create_simple_query_string_with_boost(t *testing.T) { + // Given When + b := es.NewQuery( + es.SimpleQueryString("value").Boost(3.12), + ) + + // Then + assert.NotNil(t, b) + bodyJSON := assert.MarshalWithoutError(t, b) + assert.Equal(t, "{\"query\":{\"simple_query_string\":{\"boost\":3.12,\"query\":\"value\"}}}", bodyJSON) +} + func Test_SimpleQueryString_method_should_create_simple_query_string_with_all_parameters(t *testing.T) { // Given When b := es.NewQuery( @@ -193,7 +205,8 @@ func Test_SimpleQueryString_method_should_create_simple_query_string_with_all_pa AutoGenerateSynonymsPhraseQuery(true). Flags("AND|OR|PREFIX"). Lenient(true). - QuoteFieldSuffix("_phrase"), + QuoteFieldSuffix("_phrase"). + Boost(5.19), ) // Then @@ -203,6 +216,7 @@ func Test_SimpleQueryString_method_should_create_simple_query_string_with_all_pa "\"analyze_wildcard\":true,"+ "\"analyzer\":\"standard\","+ "\"auto_generate_synonyms_phrase_query\":true,"+ + "\"boost\":5.19,"+ "\"default_operator\":\"and\","+ "\"fields\":[\"field1\",\"field2\"],"+ "\"flags\":\"AND|OR|PREFIX\","+ diff --git a/es/term_query_test.go b/es/term_query_test.go index b1eba5b..a3e1750 100644 --- a/es/term_query_test.go +++ b/es/term_query_test.go @@ -61,7 +61,7 @@ func Test_Term_should_have_Boost_method(t *testing.T) { term := es.Term("key", "value") // When Then - assert.NotNil(t, term.CaseInsensitive) + assert.NotNil(t, term.Boost) } func Test_Term_Boost_should_create_json_with_boost_field_inside_term(t *testing.T) { From d56b187607b385c94e520e1136ba9b31230a495d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6ksel=20K=C3=BC=C3=A7=C3=BCk=C5=9Fahin?= Date: Sat, 28 Dec 2024 17:42:37 +0300 Subject: [PATCH 05/17] linter: rename range relation enum's package name --- Makefile | 3 +++ es/enums/range-relation/range_relation.go | 4 ++-- es/enums/range-relation/range_relation_test.go | 2 +- es/range_test.go | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index cafd148..9b398c4 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/es/enums/range-relation/range_relation.go b/es/enums/range-relation/range_relation.go index acc4270..445da34 100644 --- a/es/enums/range-relation/range_relation.go +++ b/es/enums/range-relation/range_relation.go @@ -1,4 +1,4 @@ -// Package range_relation provides utilities for working with range relations. +// Package rangerelation provides utilities for working with range relations. // // RangeRelation is a string type used to specify the spatial or logical relationship // between two ranges, such as whether one range is entirely within another, @@ -14,7 +14,7 @@ // - Within: Indicates that one range is entirely within another. // - Contains: Indicates that one range entirely contains another. // - Intersects: Indicates that the ranges overlap or intersect at least partially. -package range_relation +package rangerelation // RangeRelation represents the relationship between two ranges. // diff --git a/es/enums/range-relation/range_relation_test.go b/es/enums/range-relation/range_relation_test.go index d00d352..2863ee5 100644 --- a/es/enums/range-relation/range_relation_test.go +++ b/es/enums/range-relation/range_relation_test.go @@ -1,4 +1,4 @@ -package range_relation_test +package rangerelation_test import ( "testing" diff --git a/es/range_test.go b/es/range_test.go index 972dec1..4d48589 100644 --- a/es/range_test.go +++ b/es/range_test.go @@ -1,9 +1,10 @@ package es_test import ( - range_relation "github.com/Trendyol/es-query-builder/es/enums/range-relation" "testing" + range_relation "github.com/Trendyol/es-query-builder/es/enums/range-relation" + "github.com/Trendyol/es-query-builder/es" "github.com/Trendyol/es-query-builder/test/assert" ) From d1581ac4d4572817b5dca1f9e6e9e64f18fb3604 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6ksel=20K=C3=BC=C3=A7=C3=BCk=C5=9Fahin?= Date: Sat, 28 Dec 2024 22:58:12 +0300 Subject: [PATCH 06/17] feature: add escape, type, fuzzy_rewrite, tie_breaker to queryStringQuery --- es/aggregations.go | 20 ++-- es/base_query.go | 20 ++-- es/enums/range-relation/range_relation.go | 33 +++---- es/enums/text-query-type/text_query_type.go | 46 +++++++++ .../text-query-type/text_query_type_test.go | 29 ++++++ es/exists_query.go | 14 +-- es/match_all_query.go | 14 +-- es/match_none_query.go | 24 ++--- es/match_query.go | 24 ++--- es/nested_query.go | 14 +-- es/query_string.go | 99 +++++++++++++++++++ es/query_string_test.go | 72 ++++++++++++-- es/range.go | 44 ++++----- es/regexp_query.go | 24 ++--- es/term_query.go | 22 ++--- es/terms_query.go | 14 +-- 16 files changed, 368 insertions(+), 145 deletions(-) create mode 100644 es/enums/text-query-type/text_query_type.go create mode 100644 es/enums/text-query-type/text_query_type_test.go diff --git a/es/aggregations.go b/es/aggregations.go index e293c35..d96b06c 100644 --- a/es/aggregations.go +++ b/es/aggregations.go @@ -179,16 +179,6 @@ 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. // // This method adds a nested aggregation under the "aggs" field with the given name. @@ -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 +} diff --git a/es/base_query.go b/es/base_query.go index 7a9db7d..730f799 100644 --- a/es/base_query.go +++ b/es/base_query.go @@ -223,16 +223,6 @@ func Sort(field string) sortType { } } -func (s sortType) putInTheField(key string, value any) sortType { - for _, fieldObj := range s { - if fieldObject, ok := fieldObj.(Object); ok { - fieldObject[key] = value - break - } - } - return s -} - // Order sets the "order" parameter in a sortType object. // // This method specifies the order in which the results should be sorted. @@ -295,3 +285,13 @@ func (o Object) Sort(sorts ...sortType) Object { o["sort"] = sorts return o } + +func (s sortType) putInTheField(key string, value any) sortType { + for _, fieldObj := range s { + if fieldObject, ok := fieldObj.(Object); ok { + fieldObject[key] = value + break + } + } + return s +} diff --git a/es/enums/range-relation/range_relation.go b/es/enums/range-relation/range_relation.go index 445da34..9774b84 100644 --- a/es/enums/range-relation/range_relation.go +++ b/es/enums/range-relation/range_relation.go @@ -1,35 +1,30 @@ -// Package rangerelation provides utilities for working with range relations. +package rangerelation + +// RangeRelation represents the relationship between two ranges in a query. // -// RangeRelation is a string type used to specify the spatial or logical relationship -// between two ranges, such as whether one range is entirely within another, -// contains another, or intersects with another. +// RangeRelation is a string type that specifies how a range interacts with another range. +// It is commonly used in range queries, especially in geospatial or numeric data contexts. +// +// Constants: +// - Within: Specifies that the range is entirely within another range. +// - Contains: Specifies that the range entirely contains another range. +// - Intersects: Specifies that the range overlaps or intersects with another range. // // Example usage: // // var relation RangeRelation = Within // -// // Use relation in a query configuration -// -// Constants: -// - Within: Indicates that one range is entirely within another. -// - Contains: Indicates that one range entirely contains another. -// - Intersects: Indicates that the ranges overlap or intersect at least partially. -package rangerelation - -// RangeRelation represents the relationship between two ranges. -// -// RangeRelation is a string type that specifies the spatial or logical relationship -// between ranges, which is commonly used in geospatial queries or similar scenarios. +// // Use relation in a range query configuration. type RangeRelation string const ( - // Within indicates that one range is entirely within another. + // Within specifies that the range is entirely within another range. Within RangeRelation = "within" - // Contains indicates that one range entirely contains another. + // Contains specifies that the range entirely contains another range. Contains RangeRelation = "contains" - // Intersects indicates that the ranges overlap or intersect at least partially. + // Intersects specifies that the range overlaps or intersects with another range. Intersects RangeRelation = "intersects" ) diff --git a/es/enums/text-query-type/text_query_type.go b/es/enums/text-query-type/text_query_type.go new file mode 100644 index 0000000..d834ade --- /dev/null +++ b/es/enums/text-query-type/text_query_type.go @@ -0,0 +1,46 @@ +package textquerytype + +// TextQueryType represents the type of text query to use in query string queries. +// +// TextQueryType is a string type that defines how the query text is analyzed and matched +// against fields in the search index. It allows specifying various query strategies +// based on the desired behavior. +// +// Constants: +// - Bestfields: Use the best matching fields for scoring. +// - Mostfields: Combine scores from all matching fields. +// - Crossfields: Treat matching fields as a single field. +// - Phrase: Match terms as a phrase. +// - Phraseprefix: Match terms as a phrase with a prefix. +// - Boolprefix: Use a boolean query with prefix matching. +// +// Example usage: +// +// var queryType TextQueryType = Bestfields +// +// // Use queryType in a query string configuration. +type TextQueryType string + +const ( + // Bestfields indicates that the best matching fields should be used for scoring. + Bestfields TextQueryType = "best_fields" + + // Mostfields indicates that the scores from all matching fields should be combined. + Mostfields TextQueryType = "most_fields" + + // Crossfields indicates that matching fields should be treated as a single field. + Crossfields TextQueryType = "cross_fields" + + // Phrase indicates that terms should be matched as a phrase. + Phrase TextQueryType = "phrase" + + // Phraseprefix indicates that terms should be matched as a phrase with a prefix. + Phraseprefix TextQueryType = "phrase_prefix" + + // Boolprefix indicates that a boolean query with prefix matching should be used. + Boolprefix TextQueryType = "bool_prefix" +) + +func (textQueryType TextQueryType) String() string { + return string(textQueryType) +} diff --git a/es/enums/text-query-type/text_query_type_test.go b/es/enums/text-query-type/text_query_type_test.go new file mode 100644 index 0000000..e8dc597 --- /dev/null +++ b/es/enums/text-query-type/text_query_type_test.go @@ -0,0 +1,29 @@ +package textquerytype_test + +import ( + "testing" + + TextQueryType "github.com/Trendyol/es-query-builder/es/enums/text-query-type" + + "github.com/Trendyol/es-query-builder/test/assert" +) + +func Test_TextQueryTypeString(t *testing.T) { + tests := []struct { + textQueryType TextQueryType.TextQueryType + result string + }{ + {TextQueryType.Bestfields, "best_fields"}, + {TextQueryType.Mostfields, "most_fields"}, + {TextQueryType.Crossfields, "cross_fields"}, + {TextQueryType.Phrase, "phrase"}, + {TextQueryType.Phraseprefix, "phrase_prefix"}, + {TextQueryType.Boolprefix, "bool_prefix"}, + } + + for _, test := range tests { + t.Run(test.result, func(t *testing.T) { + assert.Equal(t, test.result, test.textQueryType.String()) + }) + } +} diff --git a/es/exists_query.go b/es/exists_query.go index 0b3c071..0f26641 100644 --- a/es/exists_query.go +++ b/es/exists_query.go @@ -27,13 +27,6 @@ func Exists(key string) existsType { } } -func (e existsType) putInTheField(key string, value any) existsType { - if exists, ok := e["exists"].(Object); ok { - exists[key] = value - } - return e -} - // Boost sets the "boost" parameter in an existsType query. // // This method allows you to specify a boost factor for the exists query, @@ -108,3 +101,10 @@ func ExistsIf(key string, condition bool) existsType { } return Exists(key) } + +func (e existsType) putInTheField(key string, value any) existsType { + if exists, ok := e["exists"].(Object); ok { + exists[key] = value + } + return e +} diff --git a/es/match_all_query.go b/es/match_all_query.go index c19ce18..7c03ac5 100644 --- a/es/match_all_query.go +++ b/es/match_all_query.go @@ -22,13 +22,6 @@ func MatchAll() matchAllType { } } -func (m matchAllType) putInTheField(key string, value any) matchAllType { - if matchAll, ok := m["match_all"].(Object); ok { - matchAll[key] = value - } - return m -} - // Boost sets the "boost" field in the match_all query. // // This method configures the match_all query to use a specified boost factor, which influences @@ -48,3 +41,10 @@ func (m matchAllType) putInTheField(key string, value any) matchAllType { func (m matchAllType) Boost(boost float64) matchAllType { return m.putInTheField("boost", boost) } + +func (m matchAllType) putInTheField(key string, value any) matchAllType { + if matchAll, ok := m["match_all"].(Object); ok { + matchAll[key] = value + } + return m +} diff --git a/es/match_none_query.go b/es/match_none_query.go index 43d1c0c..bfc921b 100644 --- a/es/match_none_query.go +++ b/es/match_none_query.go @@ -30,18 +30,6 @@ func MatchNone[T any](key string, query T) matchNoneType { } } -func (m matchNoneType) putInTheField(key string, value any) matchNoneType { - if matchNone, ok := m["match_none"].(Object); ok { - for _, fieldObj := range matchNone { - if fieldObject, foOk := fieldObj.(Object); foOk { - fieldObject[key] = value - break - } - } - } - return m -} - // Boost sets the "boost" field in the match_none query. // // This method configures the match_none query to use a specified boost factor, which influences @@ -62,3 +50,15 @@ func (m matchNoneType) putInTheField(key string, value any) matchNoneType { func (m matchNoneType) Boost(boost float64) matchNoneType { return m.putInTheField("boost", boost) } + +func (m matchNoneType) putInTheField(key string, value any) matchNoneType { + if matchNone, ok := m["match_none"].(Object); ok { + for _, fieldObj := range matchNone { + if fieldObject, foOk := fieldObj.(Object); foOk { + fieldObject[key] = value + break + } + } + } + return m +} diff --git a/es/match_query.go b/es/match_query.go index 7b60b6e..670ab48 100644 --- a/es/match_query.go +++ b/es/match_query.go @@ -35,18 +35,6 @@ func Match[T any](key string, query T) matchType { } } -func (m matchType) putInTheField(key string, value any) matchType { - if match, ok := m["match"].(Object); ok { - for _, fieldObj := range match { - if fieldObject, foOk := fieldObj.(Object); foOk { - fieldObject[key] = value - break - } - } - } - return m -} - // Operator sets the "operator" field in the match query. // // This method configures the match query to use a specified operator (e.g., "AND" or "OR") @@ -279,3 +267,15 @@ func (m matchType) AutoGenerateSynonymsPhraseQuery(autoGenerateSynonymsPhraseQue func (m matchType) ZeroTermsQuery(zeroTermsQuery ZeroTermsQuery.ZeroTermsQuery) matchType { return m.putInTheField("zero_terms_query", zeroTermsQuery) } + +func (m matchType) putInTheField(key string, value any) matchType { + if match, ok := m["match"].(Object); ok { + for _, fieldObj := range match { + if fieldObject, foOk := fieldObj.(Object); foOk { + fieldObject[key] = value + break + } + } + } + return m +} diff --git a/es/nested_query.go b/es/nested_query.go index 841291b..b96c0a5 100644 --- a/es/nested_query.go +++ b/es/nested_query.go @@ -32,13 +32,6 @@ func Nested[T any](path string, nestedQuery T) nestedType { } } -func (n nestedType) putInNested(key string, value any) nestedType { - if nestedObject, ok := n["nested"].(Object); ok { - nestedObject[key] = value - } - return n -} - // InnerHits sets the "inner_hits" field for the nested query. // // This method specifies the inner hits for the nested query, allowing you to control @@ -82,3 +75,10 @@ func (n nestedType) InnerHits(innerHits Object) nestedType { func (n nestedType) ScoreMode(scoreMode ScoreMode.ScoreMode) nestedType { return n.putInNested("score_mode", scoreMode) } + +func (n nestedType) putInNested(key string, value any) nestedType { + if nestedObject, ok := n["nested"].(Object); ok { + nestedObject[key] = value + } + return n +} diff --git a/es/query_string.go b/es/query_string.go index bac7a29..aecd733 100644 --- a/es/query_string.go +++ b/es/query_string.go @@ -2,6 +2,7 @@ package es import ( Operator "github.com/Trendyol/es-query-builder/es/enums/operator" + TextQueryType "github.com/Trendyol/es-query-builder/es/enums/text-query-type" ) type queryStringType Object @@ -539,6 +540,104 @@ func (q queryStringType) TimeZone(value string) queryStringType { return q.putInTheField("time_zone", value) } +// Escape sets the "escape" field for the query string query. +// +// This method determines whether special characters in the query string should be escaped. +// Escaping ensures that special characters are treated literally rather than as part of +// the query syntax. +// +// Example usage: +// +// q := es.QueryString("user:admin").Escape(true) +// // q now has an "escape" field set to true in the query string query. +// +// Parameters: +// - escape: A boolean value indicating whether special characters should be escaped: +// - true: Escape special characters in the query string. +// - false: Do not escape special characters. +// +// Returns: +// +// The updated queryStringType object with the "escape" field set to the specified value. +func (q queryStringType) Escape(escape bool) queryStringType { + return q.putInTheField("escape", escape) +} + +// FuzzyRewrite sets the "fuzzy_rewrite" field for the query string query. +// +// This method specifies the rewrite method to use when executing fuzzy queries. +// The rewrite method determines how the fuzzy query is executed, such as whether +// it uses constant scoring or other advanced mechanisms. +// +// Example usage: +// +// q := es.QueryString("name:john~").FuzzyRewrite("scoring_boolean") +// // q now has a "fuzzy_rewrite" field set to "scoring_boolean" in the query string query. +// +// Parameters: +// - fuzzyRewrite: A string value specifying the rewrite method for fuzzy queries. +// Common options include: +// - "constant_score": Produces a constant score for all matching documents. +// - "scoring_boolean": Uses a scoring Boolean query for matching documents. +// - Other custom rewrite methods supported by the query engine. +// +// Returns: +// +// The updated queryStringType object with the "fuzzy_rewrite" field set to the specified value. +func (q queryStringType) FuzzyRewrite(fuzzyRewrite string) queryStringType { + return q.putInTheField("fuzzy_rewrite", fuzzyRewrite) +} + +// TieBreaker sets the "tie_breaker" field for the query string query. +// +// This method specifies the tie breaker multiplier for disjunction queries. The tie breaker +// is used to control how much influence matching terms in multiple fields have on the final score. +// It helps balance the score contribution of documents that match multiple fields. +// +// Example usage: +// +// q := es.QueryString("title:search body:query").TieBreaker(0.3) +// // q now has a "tie_breaker" field set to 0.3 in the query string query. +// +// Parameters: +// - tieBreaker: A float64 value representing the tie breaker multiplier. Common values include: +// - 0.0: Uses only the score of the best matching term (no tie breaking). +// - 1.0: Adds up the scores of all matching terms. +// - Values between 0.0 and 1.0 control the influence of additional matching terms. +// +// Returns: +// +// The updated queryStringType object with the "tie_breaker" field set to the specified value. +func (q queryStringType) TieBreaker(tieBreaker float64) queryStringType { + return q.putInTheField("tie_breaker", tieBreaker) +} + +// Type sets the "type" field for the query string query. +// +// This method specifies the text query type to use for the query. The text query type +// determines how the query text is analyzed and matched against the fields. +// +// Example usage: +// +// q := es.QueryString("description:fast").Type(es.TextQueryType.Phrase) +// // q now has a "type" field set to "phrase" in the query string query. +// +// Parameters: +// - textQueryType: A TextQueryType value representing the type of text query to use. +// Common options include: +// - TextQueryType.BestFields: Use the best matching fields for scoring. +// - TextQueryType.MostFields: Combine scores from all matching fields. +// - TextQueryType.CrossFields: Treat matching fields as a single field. +// - TextQueryType.Phrase: Match terms as a phrase. +// - TextQueryType.PhrasePrefix: Match terms as a phrase with a prefix. +// +// Returns: +// +// The updated queryStringType object with the "type" field set to the specified value. +func (q queryStringType) Type(textQueryType TextQueryType.TextQueryType) queryStringType { + return q.putInTheField("type", textQueryType) +} + func (q queryStringType) putInTheField(key string, value any) queryStringType { for _, fieldObj := range q { if fieldObject, ok := fieldObj.(Object); ok { diff --git a/es/query_string_test.go b/es/query_string_test.go index 122136a..37fdd54 100644 --- a/es/query_string_test.go +++ b/es/query_string_test.go @@ -1,6 +1,7 @@ package es_test import ( + TextQueryType "github.com/Trendyol/es-query-builder/es/enums/text-query-type" "testing" "github.com/Trendyol/es-query-builder/es" @@ -285,6 +286,54 @@ func Test_QueryString_method_should_create_query_string_with_time_zone(t *testin assert.Equal(t, "{\"query\":{\"query_string\":{\"query\":\"value\",\"time_zone\":\"value\"}}}", bodyJSON) } +func Test_QueryString_method_should_create_query_string_with_escape(t *testing.T) { + // Given When + b := es.NewQuery( + es.QueryString("value").Escape(true), + ) + + // Then + assert.NotNil(t, b) + bodyJSON := assert.MarshalWithoutError(t, b) + assert.Equal(t, "{\"query\":{\"query_string\":{\"escape\":true,\"query\":\"value\"}}}", bodyJSON) +} + +func Test_QueryString_method_should_create_query_string_with_type(t *testing.T) { + // Given When + b := es.NewQuery( + es.QueryString("value").Type(TextQueryType.Mostfields), + ) + + // Then + assert.NotNil(t, b) + bodyJSON := assert.MarshalWithoutError(t, b) + assert.Equal(t, "{\"query\":{\"query_string\":{\"query\":\"value\",\"type\":\"most_fields\"}}}", bodyJSON) +} + +func Test_QueryString_method_should_create_query_string_with_tie_breaker(t *testing.T) { + // Given When + b := es.NewQuery( + es.QueryString("value").TieBreaker(5.291), + ) + + // Then + assert.NotNil(t, b) + bodyJSON := assert.MarshalWithoutError(t, b) + assert.Equal(t, "{\"query\":{\"query_string\":{\"query\":\"value\",\"tie_breaker\":5.291}}}", bodyJSON) +} + +func Test_QueryString_method_should_create_query_string_with_fuzzy_rewrite(t *testing.T) { + // Given When + b := es.NewQuery( + es.QueryString("value").FuzzyRewrite("reWrite"), + ) + + // Then + assert.NotNil(t, b) + bodyJSON := assert.MarshalWithoutError(t, b) + assert.Equal(t, "{\"query\":{\"query_string\":{\"fuzzy_rewrite\":\"reWrite\",\"query\":\"value\"}}}", bodyJSON) +} + func Test_QueryString_method_should_create_query_string_with_all_parameters(t *testing.T) { // Given When b := es.NewQuery( @@ -303,23 +352,28 @@ func Test_QueryString_method_should_create_query_string_with_all_parameters(t *t FuzzyPrefixLength(1.0). FuzzyTranspositions(true). Lenient(true). - MaxDeterminizedStates(2).MinimumShouldMatch("value"). + MaxDeterminizedStates(2). + MinimumShouldMatch("value"). QuoteAnalyzer("value"). PhraseSlop(2). QuoteFieldSuffix("value"). Rewrite("value"). - TimeZone("value"), + TimeZone("value"). + TieBreaker(3.29). + Escape(false). + FuzzyRewrite("constant_score"). + Type(TextQueryType.Crossfields), ) // Then assert.NotNil(t, b) bodyJSON := assert.MarshalWithoutError(t, b) assert.Equal(t, "{\"query\":{\"query_string\":{\"allow_leading_wildcard\":false,\"analyze_wildcard\":true,"+ - "\"analyzer\":\"value\",\"auto_generate_synonyms_phrase_query\":true,"+ - "\"boost\":2.5,\"default_field\":\"value\",\"default_operator\":\"value\","+ - "\"enable_position_increments\":true,\"fields\":[\"field1\",\"field2\"],"+ - "\"fuzziness\":\"value\",\"fuzzy_max_expansions\":2,\"fuzzy_prefix_length\":1,"+ - "\"fuzzy_transpositions\":true,\"lenient\":true,\"max_determinized_states\":2,"+ - "\"minimum_should_match\":\"value\",\"phrase_slop\":2,\"query\":\"value\",\"quote_analyzer\":\"value\","+ - "\"quote_field_suffix\":\"value\",\"rewrite\":\"value\",\"time_zone\":\"value\"}}}", bodyJSON) + "\"analyzer\":\"value\",\"auto_generate_synonyms_phrase_query\":true,\"boost\":2.5,\"default_field\":\"value\","+ + "\"default_operator\":\"value\",\"enable_position_increments\":true,\"escape\":false,\"fields\":[\"field1\","+ + "\"field2\"],\"fuzziness\":\"value\",\"fuzzy_max_expansions\":2,\"fuzzy_prefix_length\":1,"+ + "\"fuzzy_rewrite\":\"constant_score\",\"fuzzy_transpositions\":true,\"lenient\":true,"+ + "\"max_determinized_states\":2,\"minimum_should_match\":\"value\",\"phrase_slop\":2,\"query\":\"value\","+ + "\"quote_analyzer\":\"value\",\"quote_field_suffix\":\"value\",\"rewrite\":\"value\",\"tie_breaker\":3.29,"+ + "\"time_zone\":\"value\",\"type\":\"cross_fields\"}}}", bodyJSON) } diff --git a/es/range.go b/es/range.go index ab07b69..f4ce623 100644 --- a/es/range.go +++ b/es/range.go @@ -28,28 +28,6 @@ func Range(key string) rangeType { } } -func (r rangeType) putInTheField(key string, value any) rangeType { - if rang, ok := r["range"].(Object); ok { - for field := range rang { - if fieldObject, foOk := rang[field].(Object); foOk { - fieldObject[key] = value - } - } - } - return r -} - -func (r rangeType) delete(key string) rangeType { - if rang, ok := r["range"].(Object); ok { - for field := range rang { - if fieldObject, foOk := rang[field].(Object); foOk { - delete(fieldObject, key) - } - } - } - return r -} - // LesserThan sets the "lt" (less than) field for the range query. // // This method specifies that the range query should match values that are less than @@ -243,3 +221,25 @@ func (r rangeType) To(to any) rangeType { func (r rangeType) Relation(relation RangeRelation.RangeRelation) rangeType { return r.putInTheField("relation", relation) } + +func (r rangeType) putInTheField(key string, value any) rangeType { + if rang, ok := r["range"].(Object); ok { + for field := range rang { + if fieldObject, foOk := rang[field].(Object); foOk { + fieldObject[key] = value + } + } + } + return r +} + +func (r rangeType) delete(key string) rangeType { + if rang, ok := r["range"].(Object); ok { + for field := range rang { + if fieldObject, foOk := rang[field].(Object); foOk { + delete(fieldObject, key) + } + } + } + return r +} diff --git a/es/regexp_query.go b/es/regexp_query.go index a485738..2fd048a 100644 --- a/es/regexp_query.go +++ b/es/regexp_query.go @@ -30,18 +30,6 @@ func Regexp(key string, value string) regexpType { } } -func (r regexpType) putInTheField(key string, value any) regexpType { - if regexp, ok := r["regexp"].(Object); ok { - for _, fieldObj := range regexp { - if fieldObject, foOk := fieldObj.(Object); foOk { - fieldObject[key] = value - break - } - } - } - return r -} - // Flags Enables optional operators for the regular expression. // Example usage: // @@ -129,3 +117,15 @@ func (r regexpType) Rewrite(rewrite string) regexpType { func (r regexpType) Boost(boost float64) regexpType { return r.putInTheField("boost", boost) } + +func (r regexpType) putInTheField(key string, value any) regexpType { + if regexp, ok := r["regexp"].(Object); ok { + for _, fieldObj := range regexp { + if fieldObject, foOk := fieldObj.(Object); foOk { + fieldObject[key] = value + break + } + } + } + return r +} diff --git a/es/term_query.go b/es/term_query.go index a401409..a889a2f 100644 --- a/es/term_query.go +++ b/es/term_query.go @@ -30,17 +30,6 @@ func Term[T any](key string, value T) termType { } } -func (t termType) putInTheField(key string, value any) termType { - if term, ok := t["term"].(Object); ok { - for field := range term { - if fieldObject, foOk := term[field].(Object); foOk { - fieldObject[key] = value - } - } - } - return t -} - // CaseInsensitive sets the "case_insensitive" parameter in a termType query. // // This method allows you to specify whether the term query should be case- @@ -139,3 +128,14 @@ func TermIf[T any](key string, value T, condition bool) termType { } return Term(key, value) } + +func (t termType) putInTheField(key string, value any) termType { + if term, ok := t["term"].(Object); ok { + for field := range term { + if fieldObject, foOk := term[field].(Object); foOk { + fieldObject[key] = value + } + } + } + return t +} diff --git a/es/terms_query.go b/es/terms_query.go index dc3f724..f8382ff 100644 --- a/es/terms_query.go +++ b/es/terms_query.go @@ -29,13 +29,6 @@ func Terms(key string, values ...any) termsType { } } -func (t termsType) putInTheField(key string, value any) termsType { - if terms, ok := t["terms"].(Object); ok { - terms[key] = value - } - return t -} - // Boost sets the "boost" parameter in a termsType query. // // This method allows you to specify a boost factor for the terms query, @@ -141,3 +134,10 @@ func TermsIf[T any](key string, values []T, condition bool) termsType { } return TermsArray(key, values) } + +func (t termsType) putInTheField(key string, value any) termsType { + if terms, ok := t["terms"].(Object); ok { + terms[key] = value + } + return t +} From b08c4651c0e9a422d053fbe84e74069c4b0dd56b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6ksel=20K=C3=BC=C3=A7=C3=BCk=C5=9Fahin?= Date: Sat, 28 Dec 2024 23:19:18 +0300 Subject: [PATCH 07/17] linter: fix linter --- es/query_string_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/es/query_string_test.go b/es/query_string_test.go index 37fdd54..919a6ff 100644 --- a/es/query_string_test.go +++ b/es/query_string_test.go @@ -1,9 +1,10 @@ package es_test import ( - TextQueryType "github.com/Trendyol/es-query-builder/es/enums/text-query-type" "testing" + TextQueryType "github.com/Trendyol/es-query-builder/es/enums/text-query-type" + "github.com/Trendyol/es-query-builder/es" "github.com/Trendyol/es-query-builder/test/assert" ) From 81dceabe13e6d7dc6606a584e66b5be013e9272f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6ksel=20K=C3=BC=C3=A7=C3=BCk=C5=9Fahin?= Date: Sat, 28 Dec 2024 23:29:28 +0300 Subject: [PATCH 08/17] feature: add boost and ignore_unmapped for NestedQuery --- es/nested_query.go | 42 +++++++++++++++++++++++++++++++++++++++++ es/nested_query_test.go | 40 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) diff --git a/es/nested_query.go b/es/nested_query.go index b96c0a5..13324a5 100644 --- a/es/nested_query.go +++ b/es/nested_query.go @@ -76,6 +76,48 @@ func (n nestedType) ScoreMode(scoreMode ScoreMode.ScoreMode) nestedType { return n.putInNested("score_mode", scoreMode) } +// Boost sets the "boost" field for the nested query. +// +// This method applies a boost factor to the nested query, influencing the relevance scoring +// of documents that match the query. It applies the boost to all nested fields in the query. +// +// Example usage: +// +// n := es.Nested("address").Boost(2.0) +// // n now has a "boost" field set to 2.0 in the nested query for the "address" field. +// +// Parameters: +// - boost: A float64 value representing the boost factor to be applied to the nested query. +// +// Returns: +// +// The updated nestedType object with the "boost" field set to the specified value. +func (n nestedType) Boost(boost float64) nestedType { + return n.putInNested("boost", boost) +} + +// IgnoreUnmapped sets the "ignore_unmapped" field for the nested query. +// +// This method specifies whether to ignore unmapped fields in the nested query. +// If set to true, the query will not fail if a field is not mapped in the index. +// +// Example usage: +// +// n := es.Nested("address").IgnoreUnmapped(true) +// // n now has an "ignore_unmapped" field set to true in the nested query for the "address" field. +// +// Parameters: +// - ignoreUnmapped: A boolean value indicating whether to ignore unmapped fields. +// - true: Ignore unmapped fields and prevent query failures. +// - false: Do not ignore unmapped fields (default behavior). +// +// Returns: +// +// The updated nestedType object with the "ignore_unmapped" field set to the specified value. +func (n nestedType) IgnoreUnmapped(ignoreUnmapped bool) nestedType { + return n.putInNested("ignore_unmapped", ignoreUnmapped) +} + func (n nestedType) putInNested(key string, value any) nestedType { if nestedObject, ok := n["nested"].(Object); ok { nestedObject[key] = value diff --git a/es/nested_query_test.go b/es/nested_query_test.go index 398d070..c0bb2f8 100644 --- a/es/nested_query_test.go +++ b/es/nested_query_test.go @@ -78,3 +78,43 @@ func Test_ScoreMod_should_add_score_mode_field_into_Nested(t *testing.T) { bodyJSON := assert.MarshalWithoutError(t, query) assert.Equal(t, "{\"query\":{\"nested\":{\"path\":\"nested.path\",\"query\":{},\"score_mode\":\"sum\"}}}", bodyJSON) } + +func Test_Nested_should_have_Boost_method(t *testing.T) { + // Given + n := es.Nested("path", es.Object{}) + + // When Then + assert.NotNil(t, n.Boost) +} + +func Test_Boost_should_add_boost_field_into_Nested(t *testing.T) { + // Given + query := es.NewQuery( + es.Nested("nested.path", es.Object{}).Boost(5.56), + ) + + // When Then + assert.NotNil(t, query) + bodyJSON := assert.MarshalWithoutError(t, query) + assert.Equal(t, "{\"query\":{\"nested\":{\"boost\":5.56,\"path\":\"nested.path\",\"query\":{}}}}", bodyJSON) +} + +func Test_Nested_should_have_IgnoreUnmapped_method(t *testing.T) { + // Given + n := es.Nested("path", es.Object{}) + + // When Then + assert.NotNil(t, n.IgnoreUnmapped) +} + +func Test_IgnoreUnmapped_should_add_ignore_unmapped_field_into_Nested(t *testing.T) { + // Given + query := es.NewQuery( + es.Nested("nested.path", es.Object{}).IgnoreUnmapped(true), + ) + + // When Then + assert.NotNil(t, query) + bodyJSON := assert.MarshalWithoutError(t, query) + assert.Equal(t, "{\"query\":{\"nested\":{\"ignore_unmapped\":true,\"path\":\"nested.path\",\"query\":{}}}}", bodyJSON) +} From 721c4fca2affce0242458bda6d7980cebde98f22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6ksel=20K=C3=BC=C3=A7=C3=BCk=C5=9Fahin?= Date: Fri, 3 Jan 2025 22:18:35 +0300 Subject: [PATCH 09/17] feature: add seperate inner_hits with better type safe building experience --- es/inner_hits.go | 107 ++++++++++++++++++++++++++++++++++++++++ es/inner_hits_test.go | 3 ++ es/nested_query.go | 4 +- es/nested_query_test.go | 9 +++- 4 files changed, 119 insertions(+), 4 deletions(-) create mode 100644 es/inner_hits.go create mode 100644 es/inner_hits_test.go diff --git a/es/inner_hits.go b/es/inner_hits.go new file mode 100644 index 0000000..931781c --- /dev/null +++ b/es/inner_hits.go @@ -0,0 +1,107 @@ +package es + +type innerHitsType Object + +func InnerHits() innerHitsType { + return innerHitsType{} +} + +func (ih innerHitsType) Explain(explain bool) innerHitsType { + ih["explain"] = explain + return ih +} + +func (ih innerHitsType) From(from int) innerHitsType { + ih["from"] = from + return ih +} + +func (ih innerHitsType) IgnoreUnmapped(ignoreUnmapped bool) innerHitsType { + ih["ignore_unmapped"] = ignoreUnmapped + return ih +} + +func (ih innerHitsType) Size(size int) innerHitsType { + ih["size"] = size + return ih +} + +func (ih innerHitsType) Query(queryClause any) innerHitsType { + ih["query"] = queryClause + return ih +} + +func (ih innerHitsType) Name(name string) innerHitsType { + ih["name"] = name + return ih +} + +func (ih innerHitsType) SeqNoPrimaryTerm(seqNoPrimaryTerm bool) innerHitsType { + ih["seq_no_primary_term"] = seqNoPrimaryTerm + return ih +} + +func (ih innerHitsType) Sort(sorts ...sortType) innerHitsType { + ih["sort"] = sorts + return ih +} + +func (ih innerHitsType) SourceFalse() innerHitsType { + ih["_source"] = false + return ih +} + +func (ih innerHitsType) SourceIncludes(fields ...string) innerHitsType { + if len(fields) == 0 { + return ih + } + source, ok := ih["_source"].(Object) + if !ok { + source = Object{} + } + includes, ok := source["includes"].(Array) + if !ok { + includes = Array{} + } + for i := 0; i < len(fields); i++ { + includes = append(includes, fields[i]) + } + source["includes"] = includes + ih["_source"] = source + return ih +} + +func (ih innerHitsType) SourceExcludes(fields ...string) innerHitsType { + if len(fields) == 0 { + return ih + } + source, ok := ih["_source"].(Object) + if !ok { + source = Object{} + } + excludes, exists := source["excludes"].(Array) + if !exists { + excludes = Array{} + } + for i := 0; i < len(fields); i++ { + excludes = append(excludes, fields[i]) + } + source["excludes"] = excludes + ih["_source"] = source + return ih +} + +func (ih innerHitsType) StoredFields(fields ...string) innerHitsType { + ih["stored_fields"] = fields + return ih +} + +func (ih innerHitsType) TrackScores(trackScores bool) innerHitsType { + ih["track_scores"] = trackScores + return ih +} + +func (ih innerHitsType) Version(version bool) innerHitsType { + ih["version"] = version + return ih +} diff --git a/es/inner_hits_test.go b/es/inner_hits_test.go new file mode 100644 index 0000000..a284979 --- /dev/null +++ b/es/inner_hits_test.go @@ -0,0 +1,3 @@ +package es_test + +// TODO: add detailed units test diff --git a/es/nested_query.go b/es/nested_query.go index 13324a5..2d04a1b 100644 --- a/es/nested_query.go +++ b/es/nested_query.go @@ -45,12 +45,12 @@ func Nested[T any](path string, nestedQuery T) nestedType { // // nested now has an "inner_hits" field with the specified Object in the nested query. // // Parameters: -// - innerHits: An es.Object representing the inner hits configuration for the nested query. +// - innerHits: An innerHitsType representing the inner hits configuration for the nested query. // // Returns: // // The updated nestedType object with the "inner_hits" field set to the specified value. -func (n nestedType) InnerHits(innerHits Object) nestedType { +func (n nestedType) InnerHits(innerHits innerHitsType) nestedType { return n.putInNested("inner_hits", innerHits) } diff --git a/es/nested_query_test.go b/es/nested_query_test.go index c0bb2f8..f95edd0 100644 --- a/es/nested_query_test.go +++ b/es/nested_query_test.go @@ -50,13 +50,18 @@ func Test_Nested_should_have_InnerHits_method(t *testing.T) { func Test_InnerHits_should_add_inner_hits_field_into_Nested(t *testing.T) { // Given query := es.NewQuery( - es.Nested("nested.path", es.Object{}).InnerHits(es.Object{"inner": "hits"}), + es.Nested("nested.path", es.Object{}). + InnerHits( + es.InnerHits(). + Size(1_000). + From(5_000), + ), ) // When Then assert.NotNil(t, query) bodyJSON := assert.MarshalWithoutError(t, query) - assert.Equal(t, "{\"query\":{\"nested\":{\"inner_hits\":{\"inner\":\"hits\"},\"path\":\"nested.path\",\"query\":{}}}}", bodyJSON) + assert.Equal(t, "{\"query\":{\"nested\":{\"inner_hits\":{\"from\":5000,\"size\":1000},\"path\":\"nested.path\",\"query\":{}}}}", bodyJSON) } func Test_Nested_should_have_ScoreMode_method(t *testing.T) { From 4d7391363dff0b4bd32dd3df7fe6ab1946ba66ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6ksel=20K=C3=BC=C3=A7=C3=BCk=C5=9Fahin?= Date: Sun, 5 Jan 2025 00:55:36 +0300 Subject: [PATCH 10/17] feature: add innet_hits Collapse and FieldAndFormat methods --- es/inner_hits.go | 71 +++++++-- es/inner_hits_test.go | 287 ++++++++++++++++++++++++++++++++++++- es/match_all_query_test.go | 6 +- es/match_query_test.go | 44 +++--- 4 files changed, 372 insertions(+), 36 deletions(-) diff --git a/es/inner_hits.go b/es/inner_hits.go index 931781c..cdaa175 100644 --- a/es/inner_hits.go +++ b/es/inner_hits.go @@ -2,32 +2,41 @@ package es type innerHitsType Object +type fieldAndFormatType Object + +type fieldCollapseType Object + func InnerHits() innerHitsType { return innerHitsType{} } -func (ih innerHitsType) Explain(explain bool) innerHitsType { - ih["explain"] = explain +func (ih innerHitsType) Collapse(fieldCollapse fieldCollapseType) innerHitsType { + ih["collapse"] = fieldCollapse return ih } -func (ih innerHitsType) From(from int) innerHitsType { - ih["from"] = from +func (ih innerHitsType) DocvalueFields(fieldAndFormat ...fieldAndFormatType) innerHitsType { + ih["docvalue_fields"] = fieldAndFormat return ih } -func (ih innerHitsType) IgnoreUnmapped(ignoreUnmapped bool) innerHitsType { - ih["ignore_unmapped"] = ignoreUnmapped +func (ih innerHitsType) Explain(explain bool) innerHitsType { + ih["explain"] = explain return ih } -func (ih innerHitsType) Size(size int) innerHitsType { - ih["size"] = size +func (ih innerHitsType) Fields(fields ...string) innerHitsType { + ih["fields"] = fields + return ih +} + +func (ih innerHitsType) From(from int) innerHitsType { + ih["from"] = from return ih } -func (ih innerHitsType) Query(queryClause any) innerHitsType { - ih["query"] = queryClause +func (ih innerHitsType) IgnoreUnmapped(ignoreUnmapped bool) innerHitsType { + ih["ignore_unmapped"] = ignoreUnmapped return ih } @@ -41,6 +50,11 @@ func (ih innerHitsType) SeqNoPrimaryTerm(seqNoPrimaryTerm bool) innerHitsType { return ih } +func (ih innerHitsType) Size(size int) innerHitsType { + ih["size"] = size + return ih +} + func (ih innerHitsType) Sort(sorts ...sortType) innerHitsType { ih["sort"] = sorts return ih @@ -105,3 +119,40 @@ func (ih innerHitsType) Version(version bool) innerHitsType { ih["version"] = version return ih } + +func FieldCollapse(field string) fieldCollapseType { + return fieldCollapseType{ + "field": field, + } +} + +func (fc fieldCollapseType) Collapse(fieldCollapse fieldCollapseType) fieldCollapseType { + fc["collapse"] = fieldCollapse + return fc +} + +func (fc fieldCollapseType) InnerHits(innerHits ...innerHitsType) fieldCollapseType { + fc["inner_hits"] = innerHits + return fc +} + +func (fc fieldCollapseType) MaxConcurrentGroupSearches(maxConcurrentGroupSearches int) fieldCollapseType { + fc["max_concurrent_group_searches"] = maxConcurrentGroupSearches + return fc +} + +func FieldAndFormat(field string) fieldAndFormatType { + return fieldAndFormatType{ + "field": field, + } +} + +func (fnf fieldAndFormatType) Format(format string) fieldAndFormatType { + fnf["format"] = format + return fnf +} + +func (fnf fieldAndFormatType) IncludeUnmapped(includeUnmapped bool) fieldAndFormatType { + fnf["include_unmapped"] = includeUnmapped + return fnf +} diff --git a/es/inner_hits_test.go b/es/inner_hits_test.go index a284979..c411579 100644 --- a/es/inner_hits_test.go +++ b/es/inner_hits_test.go @@ -1,3 +1,288 @@ package es_test -// TODO: add detailed units test +import ( + "github.com/Trendyol/es-query-builder/es" + "github.com/Trendyol/es-query-builder/es/enums/sort/order" + "github.com/Trendyol/es-query-builder/test/assert" + "testing" +) + +func Test_InnerHits_should_exist_on_es_package(t *testing.T) { + // Given When Then + assert.NotNil(t, es.InnerHits) +} + +func Test_InnerHits_method_should_create_innerHitsType(t *testing.T) { + // Given + ih := es.InnerHits() + + // Then + assert.NotNil(t, ih) + assert.IsTypeString(t, "es.innerHitsType", ih) +} + +func Test_FieldCollapse_should_exist_on_es_package(t *testing.T) { + // Given When Then + assert.NotNil(t, es.FieldCollapse) +} + +func Test_FieldCollapse_method_should_create_fieldCollapseType(t *testing.T) { + // Given + ih := es.FieldCollapse("name") + + // Then + assert.NotNil(t, ih) + assert.IsTypeString(t, "es.fieldCollapseType", ih) +} + +func Test_FieldAndFormat_should_exist_on_es_package(t *testing.T) { + // Given When Then + assert.NotNil(t, es.FieldAndFormat) +} + +func Test_FieldAndFormat_method_should_create_fieldAndFormatType(t *testing.T) { + // Given + ih := es.FieldAndFormat("name") + + // Then + assert.NotNil(t, ih) + assert.IsTypeString(t, "es.fieldAndFormatType", ih) +} + +func Test_InnerHits_should_have_Explain_method(t *testing.T) { + // Given + ih := es.InnerHits() + + // When Then + assert.NotNil(t, ih.Explain) +} + +func Test_InnerHits_Explain_should_create_json_with_explain_field_inside_inner_hits(t *testing.T) { + // Given + ih := es.InnerHits().Explain(true) + // When Then + assert.NotNil(t, ih) + bodyJSON := assert.MarshalWithoutError(t, ih) + assert.Equal(t, "{\"explain\":true}", bodyJSON) +} + +func Test_InnerHits_should_have_Fields_method(t *testing.T) { + // Given + ih := es.InnerHits() + + // When Then + assert.NotNil(t, ih.Fields) +} + +func Test_InnerHits_Fields_should_create_json_with_fields_field_inside_inner_hits(t *testing.T) { + // Given + ih := es.InnerHits().Fields("f1", "g2", "h3") + // When Then + assert.NotNil(t, ih) + bodyJSON := assert.MarshalWithoutError(t, ih) + assert.Equal(t, "{\"fields\":[\"f1\",\"g2\",\"h3\"]}", bodyJSON) +} + +func Test_InnerHits_should_have_Size_method(t *testing.T) { + // Given + ih := es.InnerHits() + + // When Then + assert.NotNil(t, ih.Size) +} + +func Test_InnerHits_Size_should_create_json_with_size_field_inside_inner_hits(t *testing.T) { + // Given + ih := es.InnerHits().Size(100) + // When Then + assert.NotNil(t, ih) + bodyJSON := assert.MarshalWithoutError(t, ih) + assert.Equal(t, "{\"size\":100}", bodyJSON) +} + +func Test_InnerHits_should_have_From_method(t *testing.T) { + // Given + ih := es.InnerHits() + + // When Then + assert.NotNil(t, ih.From) +} + +func Test_InnerHits_From_should_create_json_with_from_field_inside_inner_hits(t *testing.T) { + // Given + ih := es.InnerHits().From(5_000) + // When Then + assert.NotNil(t, ih) + bodyJSON := assert.MarshalWithoutError(t, ih) + assert.Equal(t, "{\"from\":5000}", bodyJSON) +} + +func Test_InnerHits_should_have_Name_method(t *testing.T) { + // Given + ih := es.InnerHits() + + // When Then + assert.NotNil(t, ih.Name) +} + +func Test_InnerHits_Name_should_create_json_with_name_field_inside_inner_hits(t *testing.T) { + // Given + ih := es.InnerHits().Name("Göksel") + // When Then + assert.NotNil(t, ih) + bodyJSON := assert.MarshalWithoutError(t, ih) + assert.Equal(t, "{\"name\":\"Göksel\"}", bodyJSON) +} + +func Test_InnerHits_should_have_SourceFalse_method(t *testing.T) { + // Given + ih := es.InnerHits() + + // When Then + assert.NotNil(t, ih.SourceFalse) +} + +func Test_InnerHits_SourceFalse_should_create_json_with_source_field_inside_inner_hits_with_false(t *testing.T) { + // Given + ih := es.InnerHits().SourceFalse() + // When Then + assert.NotNil(t, ih) + bodyJSON := assert.MarshalWithoutError(t, ih) + assert.Equal(t, "{\"_source\":false}", bodyJSON) +} + +func Test_InnerHits_should_have_SourceIncludes_method(t *testing.T) { + // Given + ih := es.InnerHits() + + // When Then + assert.NotNil(t, ih.SourceIncludes) +} + +func Test_InnerHits_SourceIncludes_should_create_json_with_source_field_inside_inner_hits(t *testing.T) { + // Given + ih := es.InnerHits().SourceIncludes("id", "name", "description") + // When Then + assert.NotNil(t, ih) + bodyJSON := assert.MarshalWithoutError(t, ih) + assert.Equal(t, "{\"_source\":{\"includes\":[\"id\",\"name\",\"description\"]}}", bodyJSON) +} + +func Test_InnerHits_should_have_SourceExcludes_method(t *testing.T) { + // Given + ih := es.InnerHits() + + // When Then + assert.NotNil(t, ih.SourceExcludes) +} + +func Test_InnerHits_SourceExcludes_should_create_json_with_source_field_inside_inner_hits(t *testing.T) { + // Given + ih := es.InnerHits().SourceExcludes("secret", "key", "partition") + // When Then + assert.NotNil(t, ih) + bodyJSON := assert.MarshalWithoutError(t, ih) + assert.Equal(t, "{\"_source\":{\"excludes\":[\"secret\",\"key\",\"partition\"]}}", bodyJSON) +} + +func Test_InnerHits_should_have_StoredFields_method(t *testing.T) { + // Given + ih := es.InnerHits() + + // When Then + assert.NotNil(t, ih.StoredFields) +} + +func Test_InnerHits_StoredFields_should_create_json_with_stored_fields_field_inside_inner_hits(t *testing.T) { + // Given + ih := es.InnerHits().StoredFields("x1", "y2", "z3") + // When Then + assert.NotNil(t, ih) + bodyJSON := assert.MarshalWithoutError(t, ih) + assert.Equal(t, "{\"stored_fields\":[\"x1\",\"y2\",\"z3\"]}", bodyJSON) +} + +func Test_InnerHits_should_have_TrackScores_method(t *testing.T) { + // Given + ih := es.InnerHits() + + // When Then + assert.NotNil(t, ih.TrackScores) +} + +func Test_InnerHits_TrackScores_should_create_json_with_track_scores_field_inside_inner_hits(t *testing.T) { + // Given + ih := es.InnerHits().TrackScores(false) + // When Then + assert.NotNil(t, ih) + bodyJSON := assert.MarshalWithoutError(t, ih) + assert.Equal(t, "{\"track_scores\":false}", bodyJSON) +} + +func Test_InnerHits_should_have_Version_method(t *testing.T) { + // Given + ih := es.InnerHits() + + // When Then + assert.NotNil(t, ih.Version) +} + +func Test_InnerHits_Version_should_create_json_with_version_field_inside_inner_hits(t *testing.T) { + // Given + ih := es.InnerHits().Version(true) + // When Then + assert.NotNil(t, ih) + bodyJSON := assert.MarshalWithoutError(t, ih) + assert.Equal(t, "{\"version\":true}", bodyJSON) +} + +func Test_InnerHits_should_have_IgnoreUnmapped_method(t *testing.T) { + // Given + ih := es.InnerHits() + + // When Then + assert.NotNil(t, ih.IgnoreUnmapped) +} + +func Test_InnerHits_IgnoreUnmapped_should_create_json_with_ignore_unmapped_field_inside_inner_hits(t *testing.T) { + // Given + ih := es.InnerHits().IgnoreUnmapped(true) + // When Then + assert.NotNil(t, ih) + bodyJSON := assert.MarshalWithoutError(t, ih) + assert.Equal(t, "{\"ignore_unmapped\":true}", bodyJSON) +} + +func Test_InnerHits_should_have_SeqNoPrimaryTerm_method(t *testing.T) { + // Given + ih := es.InnerHits() + + // When Then + assert.NotNil(t, ih.SeqNoPrimaryTerm) +} + +func Test_InnerHits_SeqNoPrimaryTerm_should_create_json_with_seq_no_primary_term_field_inside_inner_hits(t *testing.T) { + // Given + ih := es.InnerHits().SeqNoPrimaryTerm(false) + // When Then + assert.NotNil(t, ih) + bodyJSON := assert.MarshalWithoutError(t, ih) + assert.Equal(t, "{\"seq_no_primary_term\":false}", bodyJSON) +} + +func Test_InnerHits_should_have_Sort_method(t *testing.T) { + // Given + ih := es.InnerHits() + + // When Then + assert.NotNil(t, ih.Sort) +} + +func Test_InnerHits_Sort_should_create_json_with_sort_field_inside_inner_hits(t *testing.T) { + // Given + ih := es.InnerHits().Sort(es.Sort("indexedAt").Order(order.Desc)) + // When Then + assert.NotNil(t, ih) + bodyJSON := assert.MarshalWithoutError(t, ih) + assert.Equal(t, "{\"sort\":[{\"indexedAt\":{\"order\":\"desc\"}}]}", bodyJSON) +} diff --git a/es/match_all_query_test.go b/es/match_all_query_test.go index 2c677dc..d28259e 100644 --- a/es/match_all_query_test.go +++ b/es/match_all_query_test.go @@ -16,11 +16,11 @@ func Test_MatchAll_should_exist_on_es_package(t *testing.T) { func Test_MatchAll_method_should_create_matchAllType(t *testing.T) { // Given - b := es.MatchAll() + matchAll := es.MatchAll() // Then - assert.NotNil(t, b) - assert.IsTypeString(t, "es.matchAllType", b) + assert.NotNil(t, matchAll) + assert.IsTypeString(t, "es.matchAllType", matchAll) } func Test_MatchAll_should_create_json_with_match_all_field_inside_query(t *testing.T) { diff --git a/es/match_query_test.go b/es/match_query_test.go index 9421ef4..e7e37c3 100644 --- a/es/match_query_test.go +++ b/es/match_query_test.go @@ -28,10 +28,10 @@ func Test_Match_method_should_create_matchType(t *testing.T) { func Test_Match_should_have_Boost_method(t *testing.T) { // Given - term := es.Match("key", "value") + match := es.Match("key", "value") // When Then - assert.NotNil(t, term.Boost) + assert.NotNil(t, match.Boost) } func Test_Match_Boost_should_create_json_with_boost_field_inside_match(t *testing.T) { @@ -49,10 +49,10 @@ func Test_Match_Boost_should_create_json_with_boost_field_inside_match(t *testin func Test_Match_should_have_Operator_method(t *testing.T) { // Given - term := es.Match("key", "value") + match := es.Match("key", "value") // When Then - assert.NotNil(t, term.Operator) + assert.NotNil(t, match.Operator) } func Test_Match_Operator_should_create_json_with_operator_field_inside_match(t *testing.T) { @@ -70,10 +70,10 @@ func Test_Match_Operator_should_create_json_with_operator_field_inside_match(t * func Test_Match_should_have_CutoffFrequency_method(t *testing.T) { // Given - term := es.Match("key", "value") + match := es.Match("key", "value") // When Then - assert.NotNil(t, term.CutoffFrequency) + assert.NotNil(t, match.CutoffFrequency) } func Test_Match_CutoffFrequency_should_create_json_with_cutoff_frequency_field_inside_match(t *testing.T) { @@ -91,10 +91,10 @@ func Test_Match_CutoffFrequency_should_create_json_with_cutoff_frequency_field_i func Test_Match_should_have_Fuzziness_method(t *testing.T) { // Given - term := es.Match("key", "value") + match := es.Match("key", "value") // When Then - assert.NotNil(t, term.Fuzziness) + assert.NotNil(t, match.Fuzziness) } func Test_Match_Fuzziness_should_create_json_with_fuzziness_field_inside_match(t *testing.T) { @@ -112,10 +112,10 @@ func Test_Match_Fuzziness_should_create_json_with_fuzziness_field_inside_match(t func Test_Match_should_have_FuzzyRewrite_method(t *testing.T) { // Given - term := es.Match("key", "value") + match := es.Match("key", "value") // When Then - assert.NotNil(t, term.FuzzyRewrite) + assert.NotNil(t, match.FuzzyRewrite) } func Test_Match_FuzzyRewrite_should_create_json_with_fuzzy_rewrite_field_inside_match(t *testing.T) { @@ -133,10 +133,10 @@ func Test_Match_FuzzyRewrite_should_create_json_with_fuzzy_rewrite_field_inside_ func Test_Match_should_have_FuzzyTranspositions_method(t *testing.T) { // Given - term := es.Match("key", "value") + match := es.Match("key", "value") // When Then - assert.NotNil(t, term.FuzzyTranspositions) + assert.NotNil(t, match.FuzzyTranspositions) } func Test_Match_FuzzyTranspositions_should_create_json_with_fuzzy_transpositions_field_inside_match(t *testing.T) { @@ -154,10 +154,10 @@ func Test_Match_FuzzyTranspositions_should_create_json_with_fuzzy_transpositions func Test_Match_should_have_Lenient_method(t *testing.T) { // Given - term := es.Match("key", "value") + match := es.Match("key", "value") // When Then - assert.NotNil(t, term.Lenient) + assert.NotNil(t, match.Lenient) } func Test_Match_Lenient_should_create_json_with_lenient_field_inside_match(t *testing.T) { @@ -175,10 +175,10 @@ func Test_Match_Lenient_should_create_json_with_lenient_field_inside_match(t *te func Test_Match_should_have_MaxExpansions_method(t *testing.T) { // Given - term := es.Match("key", "value") + match := es.Match("key", "value") // When Then - assert.NotNil(t, term.MaxExpansions) + assert.NotNil(t, match.MaxExpansions) } func Test_Match_MaxExpansions_should_create_json_with_max_expansions_field_inside_match(t *testing.T) { @@ -196,10 +196,10 @@ func Test_Match_MaxExpansions_should_create_json_with_max_expansions_field_insid func Test_Match_should_have_PrefixLength_method(t *testing.T) { // Given - term := es.Match("key", "value") + match := es.Match("key", "value") // When Then - assert.NotNil(t, term.PrefixLength) + assert.NotNil(t, match.PrefixLength) } func Test_Match_PrefixLength_should_create_json_with_prefix_length_field_inside_match(t *testing.T) { @@ -217,10 +217,10 @@ func Test_Match_PrefixLength_should_create_json_with_prefix_length_field_inside_ func Test_Match_should_have_AutoGenerateSynonymsPhraseQuery_method(t *testing.T) { // Given - term := es.Match("key", "value") + match := es.Match("key", "value") // When Then - assert.NotNil(t, term.AutoGenerateSynonymsPhraseQuery) + assert.NotNil(t, match.AutoGenerateSynonymsPhraseQuery) } func Test_Match_AutoGenerateSynonymsPhraseQuery_should_create_json_auto_generate_synonyms_phrase_query_field_inside_match(t *testing.T) { @@ -238,10 +238,10 @@ func Test_Match_AutoGenerateSynonymsPhraseQuery_should_create_json_auto_generate func Test_Match_should_have_ZeroTermsQuery_method(t *testing.T) { // Given - term := es.Match("key", "value") + match := es.Match("key", "value") // When Then - assert.NotNil(t, term.ZeroTermsQuery) + assert.NotNil(t, match.ZeroTermsQuery) } func Test_Match_ZeroTermsQuery_should_create_json_with_zero_terms_query_field_inside_match(t *testing.T) { From 0c3979d52af8d13ad4a648c21e55fea86c928ccb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6ksel=20K=C3=BC=C3=A7=C3=BCk=C5=9Fahin?= Date: Sun, 5 Jan 2025 01:14:53 +0300 Subject: [PATCH 11/17] test: add test for inner hits --- es/inner_hits_test.go | 189 +++++++++++++++++++++++++++++++++++------- 1 file changed, 160 insertions(+), 29 deletions(-) diff --git a/es/inner_hits_test.go b/es/inner_hits_test.go index c411579..6d2739d 100644 --- a/es/inner_hits_test.go +++ b/es/inner_hits_test.go @@ -1,12 +1,15 @@ package es_test import ( + "testing" + "github.com/Trendyol/es-query-builder/es" "github.com/Trendyol/es-query-builder/es/enums/sort/order" "github.com/Trendyol/es-query-builder/test/assert" - "testing" ) +//// Inner Hits //// + func Test_InnerHits_should_exist_on_es_package(t *testing.T) { // Given When Then assert.NotNil(t, es.InnerHits) @@ -21,34 +24,6 @@ func Test_InnerHits_method_should_create_innerHitsType(t *testing.T) { assert.IsTypeString(t, "es.innerHitsType", ih) } -func Test_FieldCollapse_should_exist_on_es_package(t *testing.T) { - // Given When Then - assert.NotNil(t, es.FieldCollapse) -} - -func Test_FieldCollapse_method_should_create_fieldCollapseType(t *testing.T) { - // Given - ih := es.FieldCollapse("name") - - // Then - assert.NotNil(t, ih) - assert.IsTypeString(t, "es.fieldCollapseType", ih) -} - -func Test_FieldAndFormat_should_exist_on_es_package(t *testing.T) { - // Given When Then - assert.NotNil(t, es.FieldAndFormat) -} - -func Test_FieldAndFormat_method_should_create_fieldAndFormatType(t *testing.T) { - // Given - ih := es.FieldAndFormat("name") - - // Then - assert.NotNil(t, ih) - assert.IsTypeString(t, "es.fieldAndFormatType", ih) -} - func Test_InnerHits_should_have_Explain_method(t *testing.T) { // Given ih := es.InnerHits() @@ -286,3 +261,159 @@ func Test_InnerHits_Sort_should_create_json_with_sort_field_inside_inner_hits(t bodyJSON := assert.MarshalWithoutError(t, ih) assert.Equal(t, "{\"sort\":[{\"indexedAt\":{\"order\":\"desc\"}}]}", bodyJSON) } + +func Test_InnerHits_should_have_Collapse_method(t *testing.T) { + // Given + ih := es.InnerHits() + + // When Then + assert.NotNil(t, ih.Collapse) +} + +func Test_InnerHits_Collapse_should_create_json_with_collapse_field_inside_inner_hits(t *testing.T) { + // Given + ih := es.InnerHits().Collapse(es.FieldCollapse("yelle")) + // When Then + assert.NotNil(t, ih) + bodyJSON := assert.MarshalWithoutError(t, ih) + assert.Equal(t, "{\"collapse\":{\"field\":\"yelle\"}}", bodyJSON) +} + +func Test_InnerHits_should_have_DocvalueFields_method(t *testing.T) { + // Given + ih := es.InnerHits() + + // When Then + assert.NotNil(t, ih.DocvalueFields) +} + +func Test_InnerHits_DocvalueFields_should_create_json_with_docvalue_fields_field_inside_inner_hits(t *testing.T) { + // Given + ih := es.InnerHits().DocvalueFields( + es.FieldAndFormat("id"), + es.FieldAndFormat("name"), + es.FieldAndFormat("partition"), + ) + // When Then + assert.NotNil(t, ih) + bodyJSON := assert.MarshalWithoutError(t, ih) + assert.Equal(t, "{\"docvalue_fields\":[{\"field\":\"id\"},{\"field\":\"name\"},{\"field\":\"partition\"}]}", bodyJSON) +} + +//// Field Collapse //// + +func Test_FieldCollapse_should_exist_on_es_package(t *testing.T) { + // Given When Then + assert.NotNil(t, es.FieldCollapse) +} + +func Test_FieldCollapse_method_should_create_fieldCollapseType(t *testing.T) { + // Given + fc := es.FieldCollapse("name") + + // Then + assert.NotNil(t, fc) + assert.IsTypeString(t, "es.fieldCollapseType", fc) +} + +func Test_FieldCollapse_should_have_Collapse_method(t *testing.T) { + // Given + fc := es.FieldCollapse("id") + + // When Then + assert.NotNil(t, fc.Collapse) +} + +func Test_FieldCollapse_Collapse_should_create_json_with_collapse_field_inside_field_collapse(t *testing.T) { + // Given + fc := es.FieldCollapse("id").Collapse(es.FieldCollapse("index")) + // When Then + assert.NotNil(t, fc) + bodyJSON := assert.MarshalWithoutError(t, fc) + assert.Equal(t, "{\"collapse\":{\"field\":\"index\"},\"field\":\"id\"}", bodyJSON) +} + +func Test_FieldCollapse_should_have_InnerHits_method(t *testing.T) { + // Given + fc := es.FieldCollapse("id") + + // When Then + assert.NotNil(t, fc.InnerHits) +} + +func Test_FieldCollapse_InnerHits_should_create_json_with_inner_hits_field_inside_field_collapse(t *testing.T) { + // Given + fc := es.FieldCollapse("display").InnerHits(es.InnerHits().Fields("name", "surname")) + // When Then + assert.NotNil(t, fc) + bodyJSON := assert.MarshalWithoutError(t, fc) + assert.Equal(t, "{\"field\":\"display\",\"inner_hits\":[{\"fields\":[\"name\",\"surname\"]}]}", bodyJSON) +} + +func Test_FieldCollapse_should_have_MaxConcurrentGroupSearches_method(t *testing.T) { + // Given + fc := es.FieldCollapse("id") + + // When Then + assert.NotNil(t, fc.MaxConcurrentGroupSearches) +} + +// nolint:golint,lll +func Test_FieldCollapse_MaxConcurrentGroupSearches_should_create_json_with_max_concurrent_group_searches_field_inside_field_collapse(t *testing.T) { + // Given + fc := es.FieldCollapse("display").MaxConcurrentGroupSearches(67) + // When Then + assert.NotNil(t, fc) + bodyJSON := assert.MarshalWithoutError(t, fc) + assert.Equal(t, "{\"field\":\"display\",\"max_concurrent_group_searches\":67}", bodyJSON) +} + +//// Field And Format //// + +func Test_FieldAndFormat_should_exist_on_es_package(t *testing.T) { + // Given When Then + assert.NotNil(t, es.FieldAndFormat) +} + +func Test_FieldAndFormat_method_should_create_fieldAndFormatType(t *testing.T) { + // Given + fnf := es.FieldAndFormat("name") + + // Then + assert.NotNil(t, fnf) + assert.IsTypeString(t, "es.fieldAndFormatType", fnf) +} + +func Test_FieldAndFormat_should_have_Format_method(t *testing.T) { + // Given + fnf := es.FieldAndFormat("name") + + // When Then + assert.NotNil(t, fnf.Format) +} + +func Test_FieldAndFormat_Format_should_create_json_with_format_field_inside_field_and_format(t *testing.T) { + // Given + fnf := es.FieldAndFormat("xyz").Format("yyyy-MM-dd") + // When Then + assert.NotNil(t, fnf) + bodyJSON := assert.MarshalWithoutError(t, fnf) + assert.Equal(t, "{\"field\":\"xyz\",\"format\":\"yyyy-MM-dd\"}", bodyJSON) +} + +func Test_FieldAndFormat_should_have_IncludeUnmapped_method(t *testing.T) { + // Given + fnf := es.FieldAndFormat("name") + + // When Then + assert.NotNil(t, fnf.IncludeUnmapped) +} + +func Test_FieldAndFormat_IncludeUnmapped_should_create_json_with_include_unmapped_field_inside_field_and_format(t *testing.T) { + // Given + fnf := es.FieldAndFormat("hello").IncludeUnmapped(false) + // When Then + assert.NotNil(t, fnf) + bodyJSON := assert.MarshalWithoutError(t, fnf) + assert.Equal(t, "{\"field\":\"hello\",\"include_unmapped\":false}", bodyJSON) +} From 121ecbd308a4f3e640b2e6604ada4ac2173d6c88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6ksel=20K=C3=BC=C3=A7=C3=BCk=C5=9Fahin?= Date: Sun, 5 Jan 2025 01:19:33 +0300 Subject: [PATCH 12/17] =?UTF-8?q?test:=20make=20coverage=20=F0=9F=92=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- es/inner_hits_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/es/inner_hits_test.go b/es/inner_hits_test.go index 6d2739d..64acd13 100644 --- a/es/inner_hits_test.go +++ b/es/inner_hits_test.go @@ -143,6 +143,15 @@ func Test_InnerHits_SourceIncludes_should_create_json_with_source_field_inside_i assert.Equal(t, "{\"_source\":{\"includes\":[\"id\",\"name\",\"description\"]}}", bodyJSON) } +func Test_InnerHits_SourceIncludes_should_not_create_json_with_source_field_inside_inner_hits_when_empty(t *testing.T) { + // Given + ih := es.InnerHits().SourceIncludes() + // When Then + assert.NotNil(t, ih) + bodyJSON := assert.MarshalWithoutError(t, ih) + assert.Equal(t, "{}", bodyJSON) +} + func Test_InnerHits_should_have_SourceExcludes_method(t *testing.T) { // Given ih := es.InnerHits() @@ -160,6 +169,15 @@ func Test_InnerHits_SourceExcludes_should_create_json_with_source_field_inside_i assert.Equal(t, "{\"_source\":{\"excludes\":[\"secret\",\"key\",\"partition\"]}}", bodyJSON) } +func Test_InnerHits_SourceExcludes_should_not_create_json_with_source_field_inside_inner_hits_when_empty(t *testing.T) { + // Given + ih := es.InnerHits().SourceExcludes() + // When Then + assert.NotNil(t, ih) + bodyJSON := assert.MarshalWithoutError(t, ih) + assert.Equal(t, "{}", bodyJSON) +} + func Test_InnerHits_should_have_StoredFields_method(t *testing.T) { // Given ih := es.InnerHits() From 9784b80cdf9871f33719e8563d99fee48ad3f2b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6ksel=20K=C3=BC=C3=A7=C3=BCk=C5=9Fahin?= Date: Sun, 5 Jan 2025 01:38:16 +0300 Subject: [PATCH 13/17] doc: add godoc for inner_hits.go --- es/inner_hits.go | 415 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 415 insertions(+) diff --git a/es/inner_hits.go b/es/inner_hits.go index cdaa175..c88e5cb 100644 --- a/es/inner_hits.go +++ b/es/inner_hits.go @@ -6,65 +6,291 @@ type fieldAndFormatType Object type fieldCollapseType Object +// InnerHits initializes and returns a new instance of innerHitsType. +// +// This method creates an inner hits object, which is used to retrieve nested or +// parent-child documents matching the query. Inner hits allow you to include +// relevant sub-documents in the search response for better insights. +// +// Example usage: +// +// innerHits := es.InnerHits() +// // Use `hits` to configure and include inner hits in a query. +// +// Returns: +// +// A new instance of es.innerHitsType, ready for further configuration. func InnerHits() innerHitsType { return innerHitsType{} } +// Collapse sets the "collapse" field for the inner hits configuration. +// +// This method specifies a field-based collapsing strategy for inner hits, allowing +// you to group or collapse results based on the values of a specified field. +// +// Example usage: +// +// collapse := es.FieldCollapse("author") +// innerHits := es.InnerHits().Collapse(collapse) +// // The inner hits object now includes a "collapse" field configured for the "author" field. +// +// Parameters: +// - fieldCollapse: A es.fieldCollapseType object defining the collapsing behavior based on a specific field. +// +// Returns: +// +// The updated es.innerHitsType object with the "collapse" field set to the specified value. func (ih innerHitsType) Collapse(fieldCollapse fieldCollapseType) innerHitsType { ih["collapse"] = fieldCollapse return ih } +// DocvalueFields sets the "docvalue_fields" field for the inner hits configuration. +// +// This method specifies a list of fields and their formats to include as part of the +// inner hits results. Docvalue fields are field values stored as columnar data for +// efficient retrieval. +// +// Example usage: +// +// innerHits := es.InnerHits(). +// DocvalueFields( +// es.FieldAndFormatType("timestamp").Format("epoch_millis"), +// es.FieldAndFormatType("price"), +// ) +// // The inner hits object now includes "docvalue_fields" configured with the specified fields. +// +// Parameters: +// - fieldAndFormat: A variadic list of `es.fieldAndFormatType` objects, each defining +// a field and an optional format. +// +// Returns: +// +// The updated es.innerHitsType object with the "docvalue_fields" field set to the specified values. func (ih innerHitsType) DocvalueFields(fieldAndFormat ...fieldAndFormatType) innerHitsType { ih["docvalue_fields"] = fieldAndFormat return ih } +// Explain sets the "explain" field for the inner hits configuration. +// +// This method enables or disables the inclusion of explanation details for scoring +// in the inner hits results. When enabled, it provides detailed information about +// how the score was computed for each document. +// +// Example usage: +// +// innerHits := es.InnerHits().Explain(true) +// // The inner hits object now includes an "explain" field set to true. +// +// Parameters: +// - explain: A boolean value indicating whether to include scoring explanations. +// - true: Include explanations for scoring in the results. +// - false: Do not include explanations (default behavior). +// +// Returns: +// +// The updated es.innerHitsType object with the "explain" field set to the specified value. func (ih innerHitsType) Explain(explain bool) innerHitsType { ih["explain"] = explain return ih } +// Fields sets the "fields" field for the inner hits configuration. +// +// This method specifies a list of fields to include in the inner hits results. +// It allows selecting specific fields to be retrieved for the matched documents, +// reducing the amount of data returned. +// +// Example usage: +// +// innerHits := es.InnerHits().Fields("title", "author", "timestamp") +// // The inner hits object now includes a "fields" field with the specified field names. +// +// Parameters: +// - fields: A variadic list of strings representing the field names to include in the results. +// +// Returns: +// +// The updated es.innerHitsType object with the "fields" field set to the specified values. func (ih innerHitsType) Fields(fields ...string) innerHitsType { ih["fields"] = fields return ih } +// From sets the "from" field for the inner hits configuration. +// +// This method specifies the starting index for the inner hits results, enabling pagination. +// It determines the offset from which to begin returning hits, useful when you want to skip +// a specific number of matches. +// +// Example usage: +// +// innerHits := es.InnerHits().From(10) +// // The inner hits object now includes a "from" field set to 10. +// +// Parameters: +// - from: An integer representing the starting index for the results. +// +// Returns: +// +// The updated es.innerHitsType object with the "from" field set to the specified value. func (ih innerHitsType) From(from int) innerHitsType { ih["from"] = from return ih } +// IgnoreUnmapped sets the "ignore_unmapped" field for the inner hits configuration. +// +// This method specifies whether to ignore unmapped fields in the inner hits query. +// If set to true, the query will not fail if a field referenced in the inner hits +// is not mapped in the index. +// +// Example usage: +// +// innerHits := es.InnerHits().IgnoreUnmapped(true) +// // The inner hits object now includes an "ignore_unmapped" field set to true. +// +// Parameters: +// - ignoreUnmapped: A boolean value indicating whether to ignore unmapped fields. +// - true: Ignore unmapped fields and prevent query failures. +// - false: Do not ignore unmapped fields (default behavior). +// +// Returns: +// +// The updated es.innerHitsType object with the "ignore_unmapped" field set to the specified value. func (ih innerHitsType) IgnoreUnmapped(ignoreUnmapped bool) innerHitsType { ih["ignore_unmapped"] = ignoreUnmapped return ih } +// Name sets the "name" field for the inner hits configuration. +// +// This method assigns a custom name to the inner hits result. The name can be used +// to identify or label the inner hits in the search response, especially when multiple +// inner hits configurations are used. +// +// Example usage: +// +// innerHits := es.InnerHits().Name("nested_comments") +// // The inner hits object now includes a "name" field set to "nested_comments". +// +// Parameters: +// - name: A string representing the custom name for the inner hits. +// +// Returns: +// +// The updated es.innerHitsType object with the "name" field set to the specified value. func (ih innerHitsType) Name(name string) innerHitsType { ih["name"] = name return ih } +// SeqNoPrimaryTerm sets the "seq_no_primary_term" field for the inner hits configuration. +// +// This method specifies whether to include the sequence number and primary term of +// matched documents in the inner hits results. These values are useful for advanced use +// cases like optimistic concurrency control. +// +// Example usage: +// +// innerHits := es.InnerHits().SeqNoPrimaryTerm(true) +// // The inner hits object now includes a "seq_no_primary_term" field set to true. +// +// Parameters: +// - seqNoPrimaryTerm: A boolean value indicating whether to include the sequence number +// and primary term in the results. +// - true: Include the sequence number and primary term. +// - false: Do not include these values (default behavior). +// +// Returns: +// +// The updated es.innerHitsType object with the "seq_no_primary_term" field set to the specified value. func (ih innerHitsType) SeqNoPrimaryTerm(seqNoPrimaryTerm bool) innerHitsType { ih["seq_no_primary_term"] = seqNoPrimaryTerm return ih } +// Size sets the "size" field for the inner hits configuration. +// +// This method specifies the maximum number of inner hits to return. It controls the +// number of matched documents included in the inner hits results, allowing for fine-grained +// control over the result set size. +// +// Example usage: +// +// innerHits := es.InnerHits().Size(5) +// // The inner hits object now includes a "size" field set to 5. +// +// Parameters: +// - size: An integer representing the maximum number of inner hits to retrieve. +// +// Returns: +// +// The updated es.innerHitsType object with the "size" field set to the specified value. func (ih innerHitsType) Size(size int) innerHitsType { ih["size"] = size return ih } +// Sort sets the "sort" field for the inner hits configuration. +// +// This method specifies how to sort the inner hits results. You can provide one or more +// sorting criteria based on fields, values, or custom logic to control the order of +// the matched documents. +// +// Example usage: +// +// innerHits := es.InnerHits().Sort(es.Sort("timestamp").Order(order.Desc)) +// // The inner hits object now includes a "sort" field with the specified sorting criteria. +// +// Parameters: +// - sorts: A variadic list of es.sortType objects defining the sorting criteria. +// +// Returns: +// +// The updated es.innerHitsType object with the "sort" field set to the specified values. func (ih innerHitsType) Sort(sorts ...sortType) innerHitsType { ih["sort"] = sorts return ih } +// SourceFalse sets the "_source" field to false for the inner hits configuration. +// +// This method disables the inclusion of the _source field in the inner hits results. +// The _source field contains the original document source, and setting it to false +// prevents it from being returned, reducing the amount of data in the response. +// +// Example usage: +// +// innerHits := es.InnerHits().SourceFalse() +// // The inner hits object now includes "_source" set to false. +// +// Returns: +// +// The updated es.innerHitsType object with the "_source" field set to false. func (ih innerHitsType) SourceFalse() innerHitsType { ih["_source"] = false return ih } +// SourceIncludes sets the "includes" field for the _source configuration in the inner hits. +// +// This method specifies a list of fields to include in the inner hits results. Only +// the specified fields will be included in the _source field, and all other fields will be excluded. +// +// Example usage: +// +// innerHits := es.InnerHits().SourceIncludes("title", "author") +// // The inner hits object now includes only the "title" and "author" fields in the "_source". +// +// Parameters: +// - fields: A variadic list of field names to include in the _source field. +// +// Returns: +// +// The updated es.innerHitsType object with the "includes" field in _source set to the specified values. func (ih innerHitsType) SourceIncludes(fields ...string) innerHitsType { if len(fields) == 0 { return ih @@ -85,6 +311,22 @@ func (ih innerHitsType) SourceIncludes(fields ...string) innerHitsType { return ih } +// SourceExcludes sets the "excludes" field for the _source configuration in the inner hits. +// +// This method specifies a list of fields to exclude from the inner hits results. The excluded +// fields will not be included in the _source field, allowing you to limit the data returned. +// +// Example usage: +// +// innerHits := es.InnerHits().SourceExcludes("description", "timestamp") +// // The inner hits object now excludes the "description" and "timestamp" fields from the "_source". +// +// Parameters: +// - fields: A variadic list of field names to exclude from the _source field. +// +// Returns: +// +// The updated es.innerHitsType object with the "excludes" field in _source set to the specified values. func (ih innerHitsType) SourceExcludes(fields ...string) innerHitsType { if len(fields) == 0 { return ih @@ -105,53 +347,226 @@ func (ih innerHitsType) SourceExcludes(fields ...string) innerHitsType { return ih } +// StoredFields sets the "stored_fields" field for the inner hits configuration. +// +// This method specifies which stored fields to retrieve for the matched documents +// in the inner hits results. Only the specified stored fields will be included in +// the response, allowing you to limit the amount of data returned. +// +// Example usage: +// +// innerHits := es.InnerHits().StoredFields("title", "author") +// // The inner hits object now includes a "stored_fields" field with the specified field names. +// +// Parameters: +// - fields: A variadic list of field names to retrieve as stored fields. +// +// Returns: +// +// The updated es.innerHitsType object with the "stored_fields" field set to the specified values. func (ih innerHitsType) StoredFields(fields ...string) innerHitsType { ih["stored_fields"] = fields return ih } +// TrackScores sets the "track_scores" field for the inner hits configuration. +// +// This method specifies whether to track the relevance scores for the inner hits results. +// When set to true, the scores of the inner hits will be included in the response, which +// can be useful for sorting or filtering based on relevance. +// +// Example usage: +// +// innerHits := es.InnerHits().TrackScores(true) +// // The inner hits object now includes a "track_scores" field set to true. +// +// Parameters: +// - trackScores: A boolean value indicating whether to track the relevance scores. +// - true: Track the scores for the inner hits. +// - false: Do not track the scores (default behavior). +// +// Returns: +// +// The updated es.innerHitsType object with the "track_scores" field set to the specified value. func (ih innerHitsType) TrackScores(trackScores bool) innerHitsType { ih["track_scores"] = trackScores return ih } +// Version sets the "version" field for the inner hits configuration. +// +// This method specifies whether to include the version number of the matched documents +// in the inner hits results. Enabling this can be useful for cases where you need to +// track document versions in the response. +// +// Example usage: +// +// innerHits := es.InnerHits().Version(true) +// // The inner hits object now includes a "version" field set to true. +// +// Parameters: +// - version: A boolean value indicating whether to include the document version. +// - true: Include the version number of the matched documents. +// - false: Do not include the version (default behavior). +// +// Returns: +// +// The updated es.innerHitsType object with the "version" field set to the specified value. func (ih innerHitsType) Version(version bool) innerHitsType { ih["version"] = version return ih } +// FieldCollapse creates a field collapse configuration for sorting or grouping inner hits. +// +// This function allows you to collapse the inner hits results based on a specific field. +// It can be useful for grouping documents by field values or limiting the number of results +// per group when working with nested or parent-child queries. +// +// Example usage: +// +// collapse := es.FieldCollapse("category") +// // The fieldCollapseType object now specifies that the results should be collapsed based on the "category" field. +// +// Parameters: +// - field: A string representing the field to collapse the results by. +// +// Returns: +// +// A es.fieldCollapseType object with the "field" set to the specified value, used for collapsing results. func FieldCollapse(field string) fieldCollapseType { return fieldCollapseType{ "field": field, } } +// Collapse sets the "collapse" field for the field collapse configuration. +// +// This method allows you to apply further collapse rules to the field collapse configuration, +// such as setting multiple collapse criteria or specifying additional settings for the collapse operation. +// +// Example usage: +// +// collapse := es.FieldCollapse("category").Collapse(es.FieldCollapse("subcategory")) +// // The es.fieldCollapseType object now includes a "collapse" field specifying the collapse criteria for both "category" and "subcategory". +// +// Parameters: +// - fieldCollapse: A es.fieldCollapseType object representing the collapse configuration to apply. +// +// Returns: +// +// The updated es.fieldCollapseType object with the "collapse" field set to the specified value. func (fc fieldCollapseType) Collapse(fieldCollapse fieldCollapseType) fieldCollapseType { fc["collapse"] = fieldCollapse return fc } +// InnerHits sets the "inner_hits" field for the field collapse configuration. +// +// This method allows you to specify inner hits for the collapsed field. Inner hits provide +// the matching documents from the collapsed field, allowing you to include more details about +// the nested or parent-child documents. +// +// Example usage: +// +// collapse := es.FieldCollapse("category").InnerHits(es.InnerHits().Size(5)) +// // The es.fieldCollapseType object now includes an "inner_hits" field with the specified inner hits configuration. +// +// Parameters: +// - innerHits: A variadic list of es.innerHitsType objects representing the inner hits configuration. +// +// Returns: +// +// The updated es.fieldCollapseType object with the "inner_hits" field set to the specified values. func (fc fieldCollapseType) InnerHits(innerHits ...innerHitsType) fieldCollapseType { fc["inner_hits"] = innerHits return fc } +// MaxConcurrentGroupSearches sets the "max_concurrent_group_searches" field for the field collapse configuration. +// +// This method allows you to specify the maximum number of concurrent searches for each group of collapsed results. +// Limiting the number of concurrent searches can help optimize performance, especially when dealing with large datasets. +// +// Example usage: +// +// collapse := es.FieldCollapse("category").MaxConcurrentGroupSearches(10) +// // The es.fieldCollapseType object now includes a "max_concurrent_group_searches" field with the specified value. +// +// Parameters: +// - maxConcurrentGroupSearches: An integer representing the maximum number of concurrent searches to allow per group. +// +// Returns: +// +// The updated es.fieldCollapseType object with the "max_concurrent_group_searches" field set to the specified value. func (fc fieldCollapseType) MaxConcurrentGroupSearches(maxConcurrentGroupSearches int) fieldCollapseType { fc["max_concurrent_group_searches"] = maxConcurrentGroupSearches return fc } +// FieldAndFormat creates a field and format configuration for retrieving field values. +// +// This function allows you to specify a field along with its format in the search results. +// It can be useful for controlling how fields like dates or numbers are returned in the query response. +// +// Example usage: +// +// fieldFormat := es.FieldAndFormat("date", "yyyy-MM-dd") +// // The es.fieldAndFormatType object now specifies that the "date" field should be returned in the "yyyy-MM-dd" format. +// +// Parameters: +// - field: A string representing the field to retrieve. +// - format: A string representing the format to apply to the field value (optional). +// +// Returns: +// +// A es.fieldAndFormatType object with the "field" set to the specified value and an optional "format". func FieldAndFormat(field string) fieldAndFormatType { return fieldAndFormatType{ "field": field, } } +// Format sets the "format" field for the field and format configuration. +// +// This method allows you to specify the format for a field, such as date or number formatting, +// to control how the field's value will be returned in the query response. +// +// Example usage: +// +// fieldFormat := es.FieldAndFormat("date").Format("yyyy-MM-dd") +// // The es.fieldAndFormatType object now includes a "format" field with the specified value. +// +// Parameters: +// - format: A string representing the format to apply to the field value. +// +// Returns: +// +// The updated es.fieldAndFormatType object with the "format" field set to the specified value. func (fnf fieldAndFormatType) Format(format string) fieldAndFormatType { fnf["format"] = format return fnf } +// IncludeUnmapped sets the "include_unmapped" field for the field and format configuration. +// +// This method allows you to specify whether to include unmapped fields in the response. +// When set to true, fields that are not mapped in the index will still be included in the +// query response as null values. +// +// Example usage: +// +// fieldFormat := es.FieldAndFormat("price").IncludeUnmapped(true) +// // The es.fieldAndFormatType object now includes an "include_unmapped" field set to true. +// +// Parameters: +// - includeUnmapped: A boolean value indicating whether to include unmapped fields. +// - true: Include unmapped fields in the response. +// - false: Do not include unmapped fields (default behavior). +// +// Returns: +// +// The updated es.fieldAndFormatType object with the "include_unmapped" field set to the specified value. func (fnf fieldAndFormatType) IncludeUnmapped(includeUnmapped bool) fieldAndFormatType { fnf["include_unmapped"] = includeUnmapped return fnf From b5701a0dc605988317e83209fbdf71d505c3fd03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6ksel=20K=C3=BC=C3=A7=C3=BCk=C5=9Fahin?= Date: Sun, 5 Jan 2025 01:44:27 +0300 Subject: [PATCH 14/17] linter: fix lint error --- es/inner_hits.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/es/inner_hits.go b/es/inner_hits.go index c88e5cb..f3dbfa7 100644 --- a/es/inner_hits.go +++ b/es/inner_hits.go @@ -447,8 +447,9 @@ func FieldCollapse(field string) fieldCollapseType { // // Example usage: // -// collapse := es.FieldCollapse("category").Collapse(es.FieldCollapse("subcategory")) -// // The es.fieldCollapseType object now includes a "collapse" field specifying the collapse criteria for both "category" and "subcategory". +// collapse := es.FieldCollapse("category").Collapse(es.FieldCollapse("subcategory")) +// // The es.fieldCollapseType object now includes a "collapse" field specifying the collapse criteria +// // for both "category" and "subcategory". // // Parameters: // - fieldCollapse: A es.fieldCollapseType object representing the collapse configuration to apply. From d8a008a5667fdd87161f1d98b0f0107f9e334c0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6ksel=20K=C3=BC=C3=A7=C3=BCk=C5=9Fahin?= Date: Sun, 5 Jan 2025 03:17:25 +0300 Subject: [PATCH 15/17] doc: update go docs types --- es/aggregations.go | 60 +++++------ es/base_query.go | 40 +++---- es/bool_query.go | 44 ++++---- es/condition/if.go | 4 +- es/enums/operator/operator.go | 4 +- es/enums/zero-terms-query/zero_terms_query.go | 8 +- es/exists_query.go | 36 +++---- es/match_all_query.go | 10 +- es/match_none_query.go | 10 +- es/match_query.go | 30 +++--- es/nested_query.go | 14 +-- es/query_string.go | 102 +++++++++--------- es/query_string_test.go | 2 + es/range.go | 28 ++--- es/regexp_query.go | 20 ++-- es/simple_query_string.go | 54 +++++----- es/simple_query_string_test.go | 2 + es/term_query.go | 40 +++---- es/terms_query.go | 44 ++++---- 19 files changed, 278 insertions(+), 274 deletions(-) diff --git a/es/aggregations.go b/es/aggregations.go index d96b06c..e357bf0 100644 --- a/es/aggregations.go +++ b/es/aggregations.go @@ -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, @@ -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: // @@ -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 @@ -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{}, @@ -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{}, @@ -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{}, @@ -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{}, @@ -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{}, @@ -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{}, @@ -174,12 +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) } -// 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. // @@ -195,7 +195,7 @@ func AggCustom(agg Object) 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 { @@ -206,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: // @@ -220,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: // @@ -239,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. // @@ -258,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. // @@ -278,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{ @@ -287,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. // @@ -301,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. // @@ -320,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: @@ -340,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) } @@ -362,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: // diff --git a/es/base_query.go b/es/base_query.go index 730f799..8fd8712 100644 --- a/es/base_query.go +++ b/es/base_query.go @@ -24,7 +24,7 @@ type sortType Object // // Returns: // -// An Object containing the "query" field with the processed query clause. +// An es.Object containing the "query" field with the processed query clause. func NewQuery(queryClause any) Object { if field, ok := correctType(queryClause); ok { return Object{ @@ -54,7 +54,7 @@ func NewQuery(queryClause any) Object { // // Returns: // -// The updated Object with the "track_total_hits" parameter set. +// The updated es.Object with the "track_total_hits" parameter set. func (o Object) TrackTotalHits(value bool) Object { o["track_total_hits"] = value return o @@ -78,7 +78,7 @@ func (o Object) TrackTotalHits(value bool) Object { // // Returns: // -// The updated Object with the "size" parameter set. +// The updated es.Object with the "size" parameter set. func (o Object) Size(size int) Object { o["size"] = size return o @@ -102,7 +102,7 @@ func (o Object) Size(size int) Object { // // Returns: // -// The updated Object with the "from" parameter set. +// The updated es.Object with the "from" parameter set. func (o Object) From(from int) Object { o["from"] = from return o @@ -142,7 +142,7 @@ func (o Object) SourceFalse() Object { // // Returns: // -// The updated Object with the "_source.includes" parameter set to the specified fields. +// The updated es.Object with the "_source.includes" parameter set to the specified fields. func (o Object) SourceIncludes(fields ...string) Object { if len(fields) == 0 { return o @@ -179,7 +179,7 @@ func (o Object) SourceIncludes(fields ...string) Object { // // Returns: // -// The updated Object with the "_source.excludes" parameter set to the specified fields. +// The updated es.Object with the "_source.excludes" parameter set to the specified fields. func (o Object) SourceExcludes(fields ...string) Object { if len(fields) == 0 { return o @@ -200,33 +200,33 @@ func (o Object) SourceExcludes(fields ...string) Object { return o } -// Sort creates a new sortType object with the specified field. +// Sort creates a new es.sortType object with the specified field. // -// This function initializes a sortType object with a given field name. The +// This function initializes a es.sortType object with a given field name. The // field is used to specify the sorting criteria in the search query. The -// resulting sortType can be further configured with sorting order and mode. +// resulting es.sortType can be further configured with sorting order and mode. // // Example usage: // // s := es.Sort("age") -// // s now includes a sortType with an "age" field that can be further configured. +// // s now includes a es.sortType with an "age" field that can be further configured. // // Parameters: // - field: A string representing the field to sort by. // // Returns: // -// A sortType object with the specified field. +// A es.sortType object with the specified field. func Sort(field string) sortType { return sortType{ field: Object{}, } } -// Order sets the "order" parameter in a sortType object. +// Order sets the "order" parameter in a es.sortType object. // // This method specifies the order in which the results should be sorted. -// It configures the sortType object to sort the results in ascending or +// It configures the es.sortType object to sort the results in ascending or // descending order. // // Example usage: @@ -239,12 +239,12 @@ func Sort(field string) sortType { // // Returns: // -// The updated sortType object with the "order" parameter set. +// The updated es.sortType object with the "order" parameter set. func (s sortType) Order(order Order.Order) sortType { return s.putInTheField("order", order) } -// Mode sets the "mode" parameter in a sortType object. +// Mode sets the "mode" parameter in a es.sortType object. // // This method specifies the mode used for sorting the results. The mode // determines how sorting should be handled, such as by specifying different @@ -260,23 +260,23 @@ func (s sortType) Order(order Order.Order) sortType { // // Returns: // -// The updated sortType object with the "mode" parameter set. +// The updated es.sortType object with the "mode" parameter set. func (s sortType) Mode(mode Mode.Mode) sortType { return s.putInTheField("mode", mode) } -// Sort adds one or more sortType objects to an es.Object. +// Sort adds one or more es.sortType objects to an es.Object. // // This method allows you to specify multiple sorting criteria for the search query. -// Each sortType object defines how the results should be sorted based on different fields. +// Each es.sortType object defines how the results should be sorted based on different fields. // // Example usage: // // query := es.NewQuery(...).Sort(es.Sort("age").Order(Order.Desc), es.Sort("date").Order(Order.Asc)) -// // query now includes a "sort" parameter with multiple sortType objects. +// // query now includes a "sort" parameter with multiple es.sortType objects. // // Parameters: -// - sorts: A variadic list of sortType objects, each specifying sorting criteria. +// - sorts: A variadic list of es.sortType objects, each specifying sorting criteria. // // Returns: // diff --git a/es/bool_query.go b/es/bool_query.go index e6439ad..c949356 100644 --- a/es/bool_query.go +++ b/es/bool_query.go @@ -12,22 +12,22 @@ type ShouldType Array // 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 es.BoolType, which can be // populated later with the appropriate boolean query conditions. // // Example usage: // // b := es.Bool() -// // b is now an empty BoolType object that can be used in a query. +// // b is now an empty es.BoolType object that can be used in a query. // // Returns: // -// An empty BoolType object. +// An empty es.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 es.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 @@ -45,13 +45,13 @@ func Bool() BoolType { // // Returns: // -// The updated BoolType object with the "minimum_should_match" parameter set. +// The updated es.BoolType object with the "minimum_should_match" parameter set. func (b BoolType) MinimumShouldMatch(minimumShouldMatch any) BoolType { b["minimum_should_match"] = minimumShouldMatch return b } -// AdjustPureNegative sets the "adjust_pure_negative" parameter in a BoolType query. +// AdjustPureNegative sets the "adjust_pure_negative" parameter in a es.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 @@ -69,13 +69,13 @@ func (b BoolType) MinimumShouldMatch(minimumShouldMatch any) BoolType { // // Returns: // -// The updated BoolType object with the "adjust_pure_negative" parameter set. +// The updated es.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. +// Boost sets the "boost" parameter in a es.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 @@ -94,17 +94,17 @@ func (b BoolType) AdjustPureNegative(adjustPureNegative bool) BoolType { // // Returns: // -// The updated BoolType object with the "boost" parameter set. +// The updated es.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 es.BoolType object. // -// This method updates the "filter" section of the BoolType object by appending +// This method updates the "filter" section of the es.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 es.BoolType object. // // Example usage: // @@ -120,7 +120,7 @@ func (b BoolType) Boost(boost float64) BoolType { // // Returns: // -// The updated BoolType object with the new filter conditions added. +// The updated es.BoolType object with the new filter conditions added. func (b BoolType) Filter(items ...any) BoolType { filter, ok := b["filter"].(FilterType) if !ok { @@ -135,11 +135,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 es.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 es.BoolType object. // // Example usage: // @@ -155,7 +155,7 @@ func (b BoolType) Filter(items ...any) BoolType { // // Returns: // -// The updated BoolType object with the new conditions added to the "must" section. +// The updated es.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 { @@ -170,11 +170,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 es.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 es.BoolType object. // // Example usage: // @@ -190,7 +190,7 @@ func (b BoolType) Must(items ...any) BoolType { // // Returns: // -// The updated BoolType object with the new conditions added to the "must_not" section. +// The updated es.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 { @@ -205,11 +205,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 es.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 es.BoolType object. // // Example usage: // @@ -225,7 +225,7 @@ func (b BoolType) MustNot(items ...any) BoolType { // // Returns: // -// The updated BoolType object with the new conditions added to the "should" section. +// The updated es.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 { diff --git a/es/condition/if.go b/es/condition/if.go index 2c6410d..dbc0956 100644 --- a/es/condition/if.go +++ b/es/condition/if.go @@ -12,10 +12,10 @@ package condition // // Example usage: // -// result := If(es.Object{"key": "value"}, true) +// result := condition.If(es.Object{"key": "value"}, true) // // result is es.Object{"key": "value"} // -// result = If(es.Object{"key": "value"}, false) +// result = condition.If(es.Object{"key": "value"}, false) // // result is nil func If[T ~map[string]any | ~[]any](item T, condition bool) T { if !condition { diff --git a/es/enums/operator/operator.go b/es/enums/operator/operator.go index ea4f10a..40ae2f6 100644 --- a/es/enums/operator/operator.go +++ b/es/enums/operator/operator.go @@ -8,7 +8,7 @@ package operator // Example usage: // // match := es.Match("field", "value").Operator(Operator.And) -// // match now has the "operator" field set to "and" in the matchType object. +// // match now has the "operator" field set to "and" in the es.matchType object. // // Parameters: // - operator: An Operator value representing the logical operator to use for combining match conditions. @@ -16,7 +16,7 @@ package operator // // Returns: // -// The updated matchType object with the "operator" field set to the specified operator. +// The updated es.matchType object with the "operator" field set to the specified operator. type Operator string const ( diff --git a/es/enums/zero-terms-query/zero_terms_query.go b/es/enums/zero-terms-query/zero_terms_query.go index 2cfeed3..ace53bf 100644 --- a/es/enums/zero-terms-query/zero_terms_query.go +++ b/es/enums/zero-terms-query/zero_terms_query.go @@ -1,15 +1,15 @@ package zerotermsquery -// ZeroTermsQuery sets the "zero_terms_query" field in the matchType object. +// ZeroTermsQuery sets the "zero_terms_query" field in the es.matchType object. // // This method specifies the behavior of the match query when no terms remain after analysis, -// such as when all terms are stop words. It updates the matchType object to include the provided +// such as when all terms are stop words. It updates the es.matchType object to include the provided // zeroTermsQuery value, which determines how the query should respond in this scenario. // // Example usage: // // match := es.Match("field", "value").ZeroTermsQuery(ZeroTermsQuery.All) -// // match now has the "zero_terms_query" field set to "all" in the matchType object. +// // match now has the "zero_terms_query" field set to "all" in the es.matchType object. // // Parameters: // - zeroTermsQuery: A ZeroTermsQuery value indicating the behavior for zero-term queries. @@ -17,7 +17,7 @@ package zerotermsquery // // Returns: // -// The updated matchType object with the "zero_terms_query" field set to the specified value. +// The updated es.matchType object with the "zero_terms_query" field set to the specified value. type ZeroTermsQuery string const ( diff --git a/es/exists_query.go b/es/exists_query.go index 0f26641..52ea489 100644 --- a/es/exists_query.go +++ b/es/exists_query.go @@ -2,23 +2,23 @@ package es type existsType Object -// Exists creates a new existsType object to check if a field exists. +// Exists creates a new es.existsType object to check if a field exists. // -// This function initializes an existsType object that specifies a query to check +// This function initializes an es.existsType object that specifies a query to check // if a particular field exists in the documents. The key parameter represents // the name of the field to check for existence. // // Example usage: // // e := es.Exists("title") -// // e now contains an existsType object that checks for the existence of the "title" field. +// // e now contains an es.existsType object that checks for the existence of the "title" field. // // Parameters: // - key: A string representing the name of the field to check for existence. // // Returns: // -// An existsType object that includes the "exists" query for the specified field. +// An es.existsType object that includes the "exists" query for the specified field. func Exists(key string) existsType { return existsType{ "exists": Object{ @@ -27,7 +27,7 @@ func Exists(key string) existsType { } } -// Boost sets the "boost" parameter in an existsType query. +// Boost sets the "boost" parameter in an es.existsType query. // // This method allows you to specify a boost factor for the exists query, // which influences the relevance score of matching documents. A higher @@ -45,32 +45,32 @@ func Exists(key string) existsType { // // Returns: // -// The updated existsType object with the "boost" parameter set. +// The updated es.existsType object with the "boost" parameter set. func (e existsType) Boost(boost float64) existsType { return e.putInTheField("boost", boost) } -// ExistsFunc creates an existsType object based on a condition evaluated by a function. +// ExistsFunc creates an es.existsType object based on a condition evaluated by a function. // -// This function conditionally creates an existsType object if the provided function +// This function conditionally creates an es.existsType object if the provided function // returns true for the given key. If the function returns false, it returns nil -// instead of creating an existsType object. +// instead of creating an es.existsType object. // // Example usage: // // e := es.ExistsFunc("title", func(key string) bool { // return key != "" // }) -// // e is either an existsType object or nil based on the condition. +// // e is either an es.existsType object or nil based on the condition. // // Parameters: // - key: A string representing the name of the field to check for existence. // - f: A function that takes a key and returns a boolean indicating whether -// to create the existsType object. +// to create the es.existsType object. // // Returns: // -// An existsType object if the condition is true; otherwise, nil. +// An es.existsType object if the condition is true; otherwise, nil. func ExistsFunc(key string, f func(key string) bool) existsType { if !f(key) { return nil @@ -78,23 +78,23 @@ func ExistsFunc(key string, f func(key string) bool) existsType { return Exists(key) } -// ExistsIf creates an existsType object based on a boolean condition. +// ExistsIf creates an es.existsType object based on a boolean condition. // -// This function creates an existsType object if the provided condition is true. -// If the condition is false, it returns nil instead of creating an existsType object. +// This function creates an es.existsType object if the provided condition is true. +// If the condition is false, it returns nil instead of creating an es.existsType object. // // Example usage: // // e := es.ExistsIf("title", true) -// // e is an existsType object if the condition is true; otherwise, it is nil. +// // e is an es.existsType object if the condition is true; otherwise, it is nil. // // Parameters: // - key: A string representing the name of the field to check for existence. -// - condition: A boolean value that determines whether to create the existsType object. +// - condition: A boolean value that determines whether to create the es.existsType object. // // Returns: // -// An existsType object if the condition is true; otherwise, nil. +// An es.existsType object if the condition is true; otherwise, nil. func ExistsIf(key string, condition bool) existsType { if !condition { return nil diff --git a/es/match_all_query.go b/es/match_all_query.go index 7c03ac5..ffda166 100644 --- a/es/match_all_query.go +++ b/es/match_all_query.go @@ -2,20 +2,20 @@ package es type matchAllType Object -// MatchAll creates a new matchAllType object that matches all documents. +// MatchAll creates a new es.matchAllType object that matches all documents. // -// This function initializes a matchAllType object that is used to construct queries +// This function initializes a es.matchAllType object that is used to construct queries // that match all documents. This can be useful for scenarios where you want to ensure // that all documents are included in the results. // // Example usage: // // ma := es.MatchAll() -// // ma now contains a matchAllType object that matches all documents. +// // ma now contains a es.matchAllType object that matches all documents. // // Returns: // -// A matchAllType object with a match_all query that matches all documents. +// A es.matchAllType object with a match_all query that matches all documents. func MatchAll() matchAllType { return matchAllType{ "match_all": Object{}, @@ -37,7 +37,7 @@ func MatchAll() matchAllType { // // Returns: // -// The updated matchAllType object with the "boost" field set to the specified value. +// The updated es.matchAllType object with the "boost" field set to the specified value. func (m matchAllType) Boost(boost float64) matchAllType { return m.putInTheField("boost", boost) } diff --git a/es/match_none_query.go b/es/match_none_query.go index bfc921b..62f284d 100644 --- a/es/match_none_query.go +++ b/es/match_none_query.go @@ -2,16 +2,16 @@ package es type matchNoneType Object -// MatchNone creates a new matchNoneType object with the specified field and query. +// MatchNone creates a new es.matchNoneType object with the specified field and query. // -// This function initializes a matchNoneType object for a match_none query, where the key +// This function initializes a es.matchNoneType object for a match_none query, where the key // represents the field name and query is the value to be matched. This is used to construct // queries that explicitly match no documents for the specified value in the given field. // // Example usage: // // mn := es.MatchNone("title", "es-query-builder") -// // mn now contains a matchNoneType object that matches no documents for the "title" field with the query "es-query-builder". +// // mn now contains a es.matchNoneType object that matches no documents for the "title" field with the query "es-query-builder". // // Parameters: // - key: A string representing the field name for the match_none query. @@ -19,7 +19,7 @@ type matchNoneType Object // // Returns: // -// A matchNoneType object containing the specified match_none query. +// A es.matchNoneType object containing the specified match_none query. func MatchNone[T any](key string, query T) matchNoneType { return matchNoneType{ "match_none": Object{ @@ -46,7 +46,7 @@ func MatchNone[T any](key string, query T) matchNoneType { // // Returns: // -// The updated matchNoneType object with the "boost" field set to the specified value. +// The updated es.matchNoneType object with the "boost" field set to the specified value. func (m matchNoneType) Boost(boost float64) matchNoneType { return m.putInTheField("boost", boost) } diff --git a/es/match_query.go b/es/match_query.go index 670ab48..994ccc7 100644 --- a/es/match_query.go +++ b/es/match_query.go @@ -7,16 +7,16 @@ import ( type matchType Object -// Match creates a new matchType object with the specified field and query. +// Match creates a new es.matchType object with the specified field and query. // -// This function initializes a matchType object for a match query, where the key +// This function initializes a es.matchType object for a match query, where the key // is the field name and query is the value to search for in that field. This is used // to construct queries that match the specified value in the given field. // // Example usage: // // m := es.Match("title", "es-query-builder") -// // m now contains a matchType object that matches the query "es-query-builder" in the "title" field. +// // m now contains a es.matchType object that matches the query "es-query-builder" in the "title" field. // // Parameters: // - key: A string representing the field name for the match query. @@ -24,7 +24,7 @@ type matchType Object // // Returns: // -// A matchType object containing the specified match query. +// A es.matchType object containing the specified match query. func Match[T any](key string, query T) matchType { return matchType{ "match": Object{ @@ -50,7 +50,7 @@ func Match[T any](key string, query T) matchType { // // Returns: // -// The updated matchType object with the "operator" field set to the specified value. +// The updated es.matchType object with the "operator" field set to the specified value. func (m matchType) Operator(operator Operator.Operator) matchType { return m.putInTheField("operator", operator) } @@ -70,7 +70,7 @@ func (m matchType) Operator(operator Operator.Operator) matchType { // // Returns: // -// The updated matchType object with the "boost" field set to the specified value. +// The updated es.matchType object with the "boost" field set to the specified value. func (m matchType) Boost(boost float64) matchType { return m.putInTheField("boost", boost) } @@ -91,7 +91,7 @@ func (m matchType) Boost(boost float64) matchType { // // Returns: // -// The updated matchType object with the "cutoff_frequency" field set to the specified value. +// The updated es.matchType object with the "cutoff_frequency" field set to the specified value. func (m matchType) CutoffFrequency(cutoffFrequency float64) matchType { return m.putInTheField("cutoff_frequency", cutoffFrequency) } @@ -112,7 +112,7 @@ func (m matchType) CutoffFrequency(cutoffFrequency float64) matchType { // // Returns: // -// The updated matchType object with the "fuzziness" field set to the specified value. +// The updated es.matchType object with the "fuzziness" field set to the specified value. func (m matchType) Fuzziness(fuzziness any) matchType { return m.putInTheField("fuzziness", fuzziness) } @@ -134,7 +134,7 @@ func (m matchType) Fuzziness(fuzziness any) matchType { // // Returns: // -// The updated matchType object with the "fuzzy_rewrite" field set to the specified value. +// The updated es.matchType object with the "fuzzy_rewrite" field set to the specified value. func (m matchType) FuzzyRewrite(fuzzyRewrite string) matchType { return m.putInTheField("fuzzy_rewrite", fuzzyRewrite) } @@ -155,7 +155,7 @@ func (m matchType) FuzzyRewrite(fuzzyRewrite string) matchType { // // Returns: // -// The updated matchType object with the "fuzzy_transpositions" field set to the specified value. +// The updated es.matchType object with the "fuzzy_transpositions" field set to the specified value. func (m matchType) FuzzyTranspositions(fuzzyTranspositions bool) matchType { return m.putInTheField("fuzzy_transpositions", fuzzyTranspositions) } @@ -176,7 +176,7 @@ func (m matchType) FuzzyTranspositions(fuzzyTranspositions bool) matchType { // // Returns: // -// The updated matchType object with the "lenient" field set to the specified value. +// The updated es.matchType object with the "lenient" field set to the specified value. func (m matchType) Lenient(lenient bool) matchType { return m.putInTheField("lenient", lenient) } @@ -197,7 +197,7 @@ func (m matchType) Lenient(lenient bool) matchType { // // Returns: // -// The updated matchType object with the "max_expansions" field set to the specified value. +// The updated es.matchType object with the "max_expansions" field set to the specified value. func (m matchType) MaxExpansions(maxExpansions int) matchType { return m.putInTheField("max_expansions", maxExpansions) } @@ -219,7 +219,7 @@ func (m matchType) MaxExpansions(maxExpansions int) matchType { // // Returns: // -// The updated matchType object with the "prefix_length" field set to the specified value. +// The updated es.matchType object with the "prefix_length" field set to the specified value. func (m matchType) PrefixLength(prefixLength int) matchType { return m.putInTheField("prefix_length", prefixLength) } @@ -241,7 +241,7 @@ func (m matchType) PrefixLength(prefixLength int) matchType { // // Returns: // -// The updated matchType object with the "auto_generate_synonyms_phrase_query" field set to the specified value. +// The updated es.matchType object with the "auto_generate_synonyms_phrase_query" field set to the specified value. func (m matchType) AutoGenerateSynonymsPhraseQuery(autoGenerateSynonymsPhraseQuery bool) matchType { return m.putInTheField("auto_generate_synonyms_phrase_query", autoGenerateSynonymsPhraseQuery) } @@ -263,7 +263,7 @@ func (m matchType) AutoGenerateSynonymsPhraseQuery(autoGenerateSynonymsPhraseQue // // Returns: // -// The updated matchType object with the "zero_terms_query" field set to the specified value. +// The updated es.matchType object with the "zero_terms_query" field set to the specified value. func (m matchType) ZeroTermsQuery(zeroTermsQuery ZeroTermsQuery.ZeroTermsQuery) matchType { return m.putInTheField("zero_terms_query", zeroTermsQuery) } diff --git a/es/nested_query.go b/es/nested_query.go index 2d04a1b..c40dafb 100644 --- a/es/nested_query.go +++ b/es/nested_query.go @@ -6,7 +6,7 @@ import ( type nestedType Object -// Nested creates a new nestedType object for a nested query. +// Nested creates a new es.nestedType object for a nested query. // // This function initializes a nested query object with the specified path and query. // The path represents the field path for the nested query, and the nested query is @@ -15,7 +15,7 @@ type nestedType Object // Example usage: // // nestedQuery := es.Nested("comments", es.Bool().Filter(...).MustNot(...)) -// // nestedQuery now contains a nestedType object with the specified path and query. +// // nestedQuery now contains a es.nestedType object with the specified path and query. // // Parameters: // - path: A string representing the path for the nested query. @@ -23,7 +23,7 @@ type nestedType Object // // Returns: // -// A nestedType object with the "nested" query and specified path. +// A es.nestedType object with the "nested" query and specified path. func Nested[T any](path string, nestedQuery T) nestedType { o := NewQuery(nestedQuery) o["path"] = path @@ -45,11 +45,11 @@ func Nested[T any](path string, nestedQuery T) nestedType { // // nested now has an "inner_hits" field with the specified Object in the nested query. // // Parameters: -// - innerHits: An innerHitsType representing the inner hits configuration for the nested query. +// - innerHits: An es.innerHitsType representing the inner hits configuration for the nested query. // // Returns: // -// The updated nestedType object with the "inner_hits" field set to the specified value. +// The updated es.nestedType object with the "inner_hits" field set to the specified value. func (n nestedType) InnerHits(innerHits innerHitsType) nestedType { return n.putInNested("inner_hits", innerHits) } @@ -91,7 +91,7 @@ func (n nestedType) ScoreMode(scoreMode ScoreMode.ScoreMode) nestedType { // // Returns: // -// The updated nestedType object with the "boost" field set to the specified value. +// The updated es.nestedType object with the "boost" field set to the specified value. func (n nestedType) Boost(boost float64) nestedType { return n.putInNested("boost", boost) } @@ -113,7 +113,7 @@ func (n nestedType) Boost(boost float64) nestedType { // // Returns: // -// The updated nestedType object with the "ignore_unmapped" field set to the specified value. +// The updated es.nestedType object with the "ignore_unmapped" field set to the specified value. func (n nestedType) IgnoreUnmapped(ignoreUnmapped bool) nestedType { return n.putInNested("ignore_unmapped", ignoreUnmapped) } diff --git a/es/query_string.go b/es/query_string.go index aecd733..81a3d48 100644 --- a/es/query_string.go +++ b/es/query_string.go @@ -7,16 +7,16 @@ import ( type queryStringType Object -// QueryString creates a new queryStringType object with the specified query string. +// QueryString creates a new es.queryStringType object with the specified query string. // -// This function initializes a queryStringType object with a query string, which +// This function initializes a es.queryStringType object with a query string, which // is typically used to perform full-text search queries in Elasticsearch. The query string // can contain multiple terms and operators, allowing for complex search expressions. // // Example usage: // // q := es.QueryString("Foo AND Bar") -// // q now contains a queryStringType object with a query string query. +// // q now contains a es.queryStringType object with a query string query. // // Parameters: // - query: The query string to be used in the search. The type is generic and can be @@ -24,7 +24,7 @@ type queryStringType Object // // Returns: // -// A queryStringType object containing the specified query string. +// A es.queryStringType object containing the specified query string. func QueryString[T any](query T) queryStringType { return queryStringType{ "query_string": Object{ @@ -33,7 +33,7 @@ func QueryString[T any](query T) queryStringType { } } -// DefaultField sets the default field for the queryStringType object. +// DefaultField sets the default field for the es.queryStringType object. // // This method specifies the default field to search within if no field is explicitly mentioned // in the query string. It is useful when you want to perform a query across a single field @@ -45,19 +45,19 @@ func QueryString[T any](query T) queryStringType { // DefaultField("defaultField") // // q := es.QueryString("Foo Bar").DefaultField("title") -// // q now contains a queryStringType object where the default field for the query is "title". +// // q now contains a es.queryStringType object where the default field for the query is "title". // // Parameters: // - value: A string representing the field name to be used as the default field in the query. // // Returns: // -// The updated queryStringType object with the new "default_field". +// The updated es.queryStringType object with the new "default_field". func (q queryStringType) DefaultField(value string) queryStringType { return q.putInTheField("default_field", value) } -// AllowLeadingWildcard sets the option to allow leading wildcards in the queryStringType object. +// AllowLeadingWildcard sets the option to allow leading wildcards in the es.queryStringType object. // // This method enables or disables the use of leading wildcards in the query string. // When set to true, wildcard queries can begin with a wildcard character (* or ?), @@ -76,12 +76,12 @@ func (q queryStringType) DefaultField(value string) queryStringType { // // Returns: // -// The updated queryStringType object with the "allow_leading_wildcard" option set. +// The updated es.queryStringType object with the "allow_leading_wildcard" option set. func (q queryStringType) AllowLeadingWildcard(value bool) queryStringType { return q.putInTheField("allow_leading_wildcard", value) } -// AnalyzeWildcard sets the option to analyze wildcard terms in the queryStringType object. +// AnalyzeWildcard sets the option to analyze wildcard terms in the es.queryStringType object. // // This method determines whether wildcard terms in the query string should be analyzed. // When set to true, wildcard terms (* and ?) will be analyzed by the analyzer defined @@ -100,12 +100,12 @@ func (q queryStringType) AllowLeadingWildcard(value bool) queryStringType { // // Returns: // -// The updated queryStringType object with the "analyze_wildcard" option set. +// The updated es.queryStringType object with the "analyze_wildcard" option set. func (q queryStringType) AnalyzeWildcard(value bool) queryStringType { return q.putInTheField("analyze_wildcard", value) } -// Analyzer sets the analyzer to be used for the queryStringType object. +// Analyzer sets the analyzer to be used for the es.queryStringType object. // // This method specifies the analyzer that should be applied to the query string. // Analyzers are used to process the text, such as tokenizing and normalizing it, @@ -124,12 +124,12 @@ func (q queryStringType) AnalyzeWildcard(value bool) queryStringType { // // Returns: // -// The updated queryStringType object with the "analyzer" set. +// The updated es.queryStringType object with the "analyzer" set. func (q queryStringType) Analyzer(value string) queryStringType { return q.putInTheField("analyzer", value) } -// AutoGenerateSynonymsPhraseQuery sets the option to automatically generate phrase queries for synonyms in the queryStringType object. +// AutoGenerateSynonymsPhraseQuery sets the option to automatically generate phrase queries for synonyms in the es.queryStringType object. // // This method enables or disables the automatic generation of phrase queries for synonyms in the query string. // When set to true, Elasticsearch will automatically create phrase queries for terms that have synonyms, @@ -148,12 +148,12 @@ func (q queryStringType) Analyzer(value string) queryStringType { // // Returns: // -// The updated queryStringType object with the "auto_generate_synonyms_phrase_query" option set. +// The updated es.queryStringType object with the "auto_generate_synonyms_phrase_query" option set. func (q queryStringType) AutoGenerateSynonymsPhraseQuery(value bool) queryStringType { return q.putInTheField("auto_generate_synonyms_phrase_query", value) } -// Boost sets the boost factor for the queryStringType object. +// Boost sets the boost factor for the es.queryStringType object. // // This method specifies the boost value to increase or decrease the relevance of the query. // A higher boost value increases the relevance score of the query, making it more likely @@ -172,12 +172,12 @@ func (q queryStringType) AutoGenerateSynonymsPhraseQuery(value bool) queryString // // Returns: // -// The updated queryStringType object with the "boost" value set. +// The updated es.queryStringType object with the "boost" value set. func (q queryStringType) Boost(value float64) queryStringType { return q.putInTheField("boost", value) } -// DefaultOperator sets the default operator for the queryStringType object. +// DefaultOperator sets the default operator for the es.queryStringType object. // // This method specifies the default operator to be used between terms in the query string // when no explicit operator is provided. The default operator can be operator.And or operator.Or, @@ -196,12 +196,12 @@ func (q queryStringType) Boost(value float64) queryStringType { // // Returns: // -// The updated queryStringType object with the "default_operator" set. +// The updated es.queryStringType object with the "default_operator" set. func (q queryStringType) DefaultOperator(operator Operator.Operator) queryStringType { return q.putInTheField("default_operator", operator) } -// EnablePositionIncrements sets the option to enable or disable position increments in the queryStringType object. +// EnablePositionIncrements sets the option to enable or disable position increments in the es.queryStringType object. // // This method determines whether to account for position increments when analyzing the query string. // When set to true, position increments are taken into account, which can improve the accuracy of @@ -217,12 +217,12 @@ func (q queryStringType) DefaultOperator(operator Operator.Operator) queryString // // Returns: // -// The updated queryStringType object with the "enable_position_increments" option set. +// The updated es.queryStringType object with the "enable_position_increments" option set. func (q queryStringType) EnablePositionIncrements(value bool) queryStringType { return q.putInTheField("enable_position_increments", value) } -// Fields sets the fields to be searched within the queryStringType object. +// Fields sets the fields to be searched within the es.queryStringType object. // // This method specifies a list of fields that the query string should search. // If multiple fields are provided, the query will search across all of them, @@ -241,12 +241,12 @@ func (q queryStringType) EnablePositionIncrements(value bool) queryStringType { // // Returns: // -// The updated queryStringType object with the "fields" option set. +// The updated es.queryStringType object with the "fields" option set. func (q queryStringType) Fields(value []string) queryStringType { return q.putInTheField("fields", value) } -// Fuzziness sets the fuzziness level for the queryStringType object. +// Fuzziness sets the fuzziness level for the es.queryStringType object. // // This method specifies the fuzziness level for the query, allowing for approximate // matching of terms. Fuzziness is particularly useful for handling misspellings or @@ -266,12 +266,12 @@ func (q queryStringType) Fields(value []string) queryStringType { // // Returns: // -// The updated queryStringType object with the "fuzziness" option set. +// The updated es.queryStringType object with the "fuzziness" option set. func (q queryStringType) Fuzziness(value string) queryStringType { return q.putInTheField("fuzziness", value) } -// FuzzyMaxExpansions sets the maximum number of expansions for fuzzy matching in the queryStringType object. +// FuzzyMaxExpansions sets the maximum number of expansions for fuzzy matching in the es.queryStringType object. // // This method specifies the maximum number of terms that the query will expand to // when performing fuzzy matching. This setting controls the number of variations @@ -291,12 +291,12 @@ func (q queryStringType) Fuzziness(value string) queryStringType { // // Returns: // -// The updated queryStringType object with the "fuzzy_max_expansions" option set. +// The updated es.queryStringType object with the "fuzzy_max_expansions" option set. func (q queryStringType) FuzzyMaxExpansions(value int64) queryStringType { return q.putInTheField("fuzzy_max_expansions", value) } -// FuzzyPrefixLength sets the prefix length for fuzzy matching in the queryStringType object. +// FuzzyPrefixLength sets the prefix length for fuzzy matching in the es.queryStringType object. // // This method specifies the length of the initial characters that must match exactly // before applying any fuzziness in the query. Increasing the prefix length can improve @@ -316,12 +316,12 @@ func (q queryStringType) FuzzyMaxExpansions(value int64) queryStringType { // // Returns: // -// The updated queryStringType object with the "fuzzy_prefix_length" option set. +// The updated es.queryStringType object with the "fuzzy_prefix_length" option set. func (q queryStringType) FuzzyPrefixLength(value int64) queryStringType { return q.putInTheField("fuzzy_prefix_length", value) } -// FuzzyTranspositions sets the option to allow transpositions in fuzzy matching for the queryStringType object. +// FuzzyTranspositions sets the option to allow transpositions in fuzzy matching for the es.queryStringType object. // // This method enables or disables the allowance of transpositions (swapping of adjacent characters) // in fuzzy matching. When set to true, terms that are similar but have transposed characters @@ -340,12 +340,12 @@ func (q queryStringType) FuzzyPrefixLength(value int64) queryStringType { // // Returns: // -// The updated queryStringType object with the "fuzzy_transpositions" option set. +// The updated es.queryStringType object with the "fuzzy_transpositions" option set. func (q queryStringType) FuzzyTranspositions(value bool) queryStringType { return q.putInTheField("fuzzy_transpositions", value) } -// Lenient sets the leniency option for the queryStringType object. +// Lenient sets the leniency option for the es.queryStringType object. // // This method determines whether the query should be lenient when encountering // errors, such as analyzing incompatible fields. When set to true, the query will @@ -365,12 +365,12 @@ func (q queryStringType) FuzzyTranspositions(value bool) queryStringType { // // Returns: // -// The updated queryStringType object with the "lenient" option set. +// The updated es.queryStringType object with the "lenient" option set. func (q queryStringType) Lenient(value bool) queryStringType { return q.putInTheField("lenient", value) } -// MaxDeterminizedStates sets the maximum number of determinized states for the queryStringType object. +// MaxDeterminizedStates sets the maximum number of determinized states for the es.queryStringType object. // // This method specifies the maximum number of states that can be determinized when expanding // wildcard, prefix, and other complex queries into a finite automaton. Limiting this number @@ -390,12 +390,12 @@ func (q queryStringType) Lenient(value bool) queryStringType { // // Returns: // -// The updated queryStringType object with the "max_determinized_states" option set. +// The updated es.queryStringType object with the "max_determinized_states" option set. func (q queryStringType) MaxDeterminizedStates(value int64) queryStringType { return q.putInTheField("max_determinized_states", value) } -// MinimumShouldMatch sets the minimum number of "should" clauses that must match for the queryStringType object. +// MinimumShouldMatch sets the minimum number of "should" clauses that must match for the es.queryStringType object. // // This method specifies the minimum number of optional ("should") clauses that must match in order // for a document to be considered a match. This can be expressed as an absolute number or a percentage, @@ -414,12 +414,12 @@ func (q queryStringType) MaxDeterminizedStates(value int64) queryStringType { // // Returns: // -// The updated queryStringType object with the "minimum_should_match" option set. +// The updated es.queryStringType object with the "minimum_should_match" option set. func (q queryStringType) MinimumShouldMatch(value string) queryStringType { return q.putInTheField("minimum_should_match", value) } -// QuoteAnalyzer sets the analyzer to be used for quoted text in the queryStringType object. +// QuoteAnalyzer sets the analyzer to be used for quoted text in the es.queryStringType object. // // This method specifies the analyzer that should be applied to terms within quotes in the query string. // When a query contains quoted text, this analyzer will be used to process that portion of the query, @@ -438,12 +438,12 @@ func (q queryStringType) MinimumShouldMatch(value string) queryStringType { // // Returns: // -// The updated queryStringType object with the "quote_analyzer" option set. +// The updated es.queryStringType object with the "quote_analyzer" option set. func (q queryStringType) QuoteAnalyzer(value string) queryStringType { return q.putInTheField("quote_analyzer", value) } -// PhraseSlop sets the slop factor for phrase queries in the queryStringType object. +// PhraseSlop sets the slop factor for phrase queries in the es.queryStringType object. // // This method specifies the allowed number of positions (or "slop") that terms in a phrase query can be // moved around while still being considered a match. A higher slop value allows for more flexibility @@ -462,12 +462,12 @@ func (q queryStringType) QuoteAnalyzer(value string) queryStringType { // // Returns: // -// The updated queryStringType object with the "phrase_slop" option set. +// The updated es.queryStringType object with the "phrase_slop" option set. func (q queryStringType) PhraseSlop(value int64) queryStringType { return q.putInTheField("phrase_slop", value) } -// QuoteFieldSuffix sets the field suffix to be used for quoted text in the queryStringType object. +// QuoteFieldSuffix sets the field suffix to be used for quoted text in the es.queryStringType object. // // This method specifies a suffix to be appended to the field names when analyzing quoted text in the query string. // This is useful for applying different analyzers or field mappings to quoted phrases compared to unquoted terms. @@ -485,12 +485,12 @@ func (q queryStringType) PhraseSlop(value int64) queryStringType { // // Returns: // -// The updated queryStringType object with the "quote_field_suffix" option set. +// The updated es.queryStringType object with the "quote_field_suffix" option set. func (q queryStringType) QuoteFieldSuffix(value string) queryStringType { return q.putInTheField("quote_field_suffix", value) } -// Rewrite sets the rewrite method for the queryStringType object. +// Rewrite sets the rewrite method for the es.queryStringType object. // // This method specifies the rewrite method to be used for rewriting the query string. Rewrite methods // are used to transform the query into a more optimized form for execution, which can affect both @@ -511,12 +511,12 @@ func (q queryStringType) QuoteFieldSuffix(value string) queryStringType { // // Returns: // -// The updated queryStringType object with the "rewrite" option set. +// The updated es.queryStringType object with the "rewrite" option set. func (q queryStringType) Rewrite(value string) queryStringType { return q.putInTheField("rewrite", value) } -// TimeZone sets the time zone for date and time fields in the queryStringType object. +// TimeZone sets the time zone for date and time fields in the es.queryStringType object. // // This method specifies the time zone to be applied when parsing and interpreting date and time values // in the query string. Setting the correct time zone ensures accurate date range queries and comparisons, @@ -535,7 +535,7 @@ func (q queryStringType) Rewrite(value string) queryStringType { // // Returns: // -// The updated queryStringType object with the "time_zone" option set. +// The updated es.queryStringType object with the "time_zone" option set. func (q queryStringType) TimeZone(value string) queryStringType { return q.putInTheField("time_zone", value) } @@ -558,7 +558,7 @@ func (q queryStringType) TimeZone(value string) queryStringType { // // Returns: // -// The updated queryStringType object with the "escape" field set to the specified value. +// The updated es.queryStringType object with the "escape" field set to the specified value. func (q queryStringType) Escape(escape bool) queryStringType { return q.putInTheField("escape", escape) } @@ -583,7 +583,7 @@ func (q queryStringType) Escape(escape bool) queryStringType { // // Returns: // -// The updated queryStringType object with the "fuzzy_rewrite" field set to the specified value. +// The updated es.queryStringType object with the "fuzzy_rewrite" field set to the specified value. func (q queryStringType) FuzzyRewrite(fuzzyRewrite string) queryStringType { return q.putInTheField("fuzzy_rewrite", fuzzyRewrite) } @@ -607,7 +607,7 @@ func (q queryStringType) FuzzyRewrite(fuzzyRewrite string) queryStringType { // // Returns: // -// The updated queryStringType object with the "tie_breaker" field set to the specified value. +// The updated es.queryStringType object with the "tie_breaker" field set to the specified value. func (q queryStringType) TieBreaker(tieBreaker float64) queryStringType { return q.putInTheField("tie_breaker", tieBreaker) } @@ -633,7 +633,7 @@ func (q queryStringType) TieBreaker(tieBreaker float64) queryStringType { // // Returns: // -// The updated queryStringType object with the "type" field set to the specified value. +// The updated es.queryStringType object with the "type" field set to the specified value. func (q queryStringType) Type(textQueryType TextQueryType.TextQueryType) queryStringType { return q.putInTheField("type", textQueryType) } diff --git a/es/query_string_test.go b/es/query_string_test.go index 919a6ff..e4fc1a2 100644 --- a/es/query_string_test.go +++ b/es/query_string_test.go @@ -9,6 +9,8 @@ import ( "github.com/Trendyol/es-query-builder/test/assert" ) +//// Query String //// + func Test_QueryString_should_exist_on_es_package(t *testing.T) { // Given When assert.NotNil(t, es.QueryString[any]) diff --git a/es/range.go b/es/range.go index f4ce623..932cd33 100644 --- a/es/range.go +++ b/es/range.go @@ -4,22 +4,22 @@ import RangeRelation "github.com/Trendyol/es-query-builder/es/enums/range-relati type rangeType Object -// Range creates a new rangeType object with the specified field. +// Range creates a new es.rangeType object with the specified field. // -// This function initializes a rangeType object for specifying range queries. The key represents -// the field name, and the rangeType object is used to define the range conditions for that field. +// This function initializes a es.rangeType object for specifying range queries. The key represents +// the field name, and the es.rangeType object is used to define the range conditions for that field. // // Example usage: // // r := es.Range("age") -// // r now contains a rangeType object with the specified field "age" for range queries. +// // r now contains a es.rangeType object with the specified field "age" for range queries. // // Parameters: // - key: A string representing the field name for the range query. // // Returns: // -// A rangeType object with the specified field ready for defining range conditions. +// A es.rangeType object with the specified field ready for defining range conditions. func Range(key string) rangeType { return rangeType{ "range": Object{ @@ -44,7 +44,7 @@ func Range(key string) rangeType { // // Returns: // -// The updated rangeType object with the "lt" field set to the specified value. +// The updated es.rangeType object with the "lt" field set to the specified value. func (r rangeType) LesserThan(lt any) rangeType { return r.putInTheField("lt", lt).delete("lte") } @@ -65,7 +65,7 @@ func (r rangeType) LesserThan(lt any) rangeType { // // Returns: // -// The updated rangeType object with the "lte" field set to the specified value. +// The updated es.rangeType object with the "lte" field set to the specified value. func (r rangeType) LesserThanOrEqual(lte any) rangeType { return r.putInTheField("lte", lte).delete("lt") } @@ -86,7 +86,7 @@ func (r rangeType) LesserThanOrEqual(lte any) rangeType { // // Returns: // -// The updated rangeType object with the "gt" field set to the specified value. +// The updated es.rangeType object with the "gt" field set to the specified value. func (r rangeType) GreaterThan(gt any) rangeType { return r.putInTheField("gt", gt).delete("gte") } @@ -107,7 +107,7 @@ func (r rangeType) GreaterThan(gt any) rangeType { // // Returns: // -// The updated rangeType object with the "gte" field set to the specified value. +// The updated es.rangeType object with the "gte" field set to the specified value. func (r rangeType) GreaterThanOrEqual(gte any) rangeType { return r.putInTheField("gte", gte).delete("gt") } @@ -128,7 +128,7 @@ func (r rangeType) GreaterThanOrEqual(gte any) rangeType { // // Returns: // -// The updated rangeType object with the "format" field set to the specified value. +// The updated es.rangeType object with the "format" field set to the specified value. func (r rangeType) Format(format string) rangeType { return r.putInTheField("format", format) } @@ -148,7 +148,7 @@ func (r rangeType) Format(format string) rangeType { // // Returns: // -// The updated rangeType object with the "boost" field set to the specified value. +// The updated es.rangeType object with the "boost" field set to the specified value. func (r rangeType) Boost(boost float64) rangeType { return r.putInTheField("boost", boost) } @@ -170,7 +170,7 @@ func (r rangeType) Boost(boost float64) rangeType { // // Returns: // -// The updated rangeType object with the "from" field set to the specified value. +// The updated es.rangeType object with the "from" field set to the specified value. func (r rangeType) From(from any) rangeType { return r.putInTheField("from", from) } @@ -192,7 +192,7 @@ func (r rangeType) From(from any) rangeType { // // Returns: // -// The updated rangeType object with the "to" field set to the specified value. +// The updated es.rangeType object with the "to" field set to the specified value. func (r rangeType) To(to any) rangeType { return r.putInTheField("to", to) } @@ -217,7 +217,7 @@ func (r rangeType) To(to any) rangeType { // // Returns: // -// The updated rangeType object with the "relation" field set to the specified value. +// The updated es.rangeType object with the "relation" field set to the specified value. func (r rangeType) Relation(relation RangeRelation.RangeRelation) rangeType { return r.putInTheField("relation", relation) } diff --git a/es/regexp_query.go b/es/regexp_query.go index 2fd048a..2584904 100644 --- a/es/regexp_query.go +++ b/es/regexp_query.go @@ -2,16 +2,16 @@ package es type regexpType Object -// Regexp creates a new regexpType object with the specified key-value pair. +// Regexp creates a new es.regexpType object with the specified key-value pair. // -// This function initializes a regexpType object with a single regexp query, where the +// This function initializes a es.regexpType object with a single regexp query, where the // key is the field name and the value is the regexp to search for. This is typically // used to construct a regexp query in search queries. // // Example usage: // // t := es.Regexp("endpoint", "/books/.*") -// // t now contains a regexpType object with a regexp query for the "endpoint" field. +// // t now contains a es.regexpType object with a regexp query for the "endpoint" field. // // Parameters: // - key: A string representing the field name for the regexp query. @@ -19,7 +19,7 @@ type regexpType Object // // Returns: // -// A regexpType object containing the specified regexp query. +// A es.regexpType object containing the specified regexp query. func Regexp(key string, value string) regexpType { return regexpType{ "regexp": Object{ @@ -41,7 +41,7 @@ func Regexp(key string, value string) regexpType { // // Returns: // -// The updated regexp object with the "flags" field set to the specified value. +// The updated es.regexpType object with the "flags" field set to the specified value. func (r regexpType) Flags(flags string) regexpType { return r.putInTheField("flags", flags) } @@ -58,7 +58,7 @@ func (r regexpType) Flags(flags string) regexpType { // // Returns: // -// The updated regexp object with the "case_insensitive" field set to the specified value. +// The updated es.regexpType object with the "case_insensitive" field set to the specified value. func (r regexpType) CaseInsensitive(caseInsensitive bool) regexpType { return r.putInTheField("case_insensitive", caseInsensitive) } @@ -74,7 +74,7 @@ func (r regexpType) CaseInsensitive(caseInsensitive bool) regexpType { // // Returns: // -// The updated regexp object with the "max_determinized_states" field set to the specified value. +// The updated es.regexpType object with the "max_determinized_states" field set to the specified value. func (r regexpType) MaxDeterminizedStates(maxDeterminizedStates int) regexpType { return r.putInTheField("max_determinized_states", maxDeterminizedStates) } @@ -90,12 +90,12 @@ func (r regexpType) MaxDeterminizedStates(maxDeterminizedStates int) regexpType // // Returns: // -// The updated regexp object with the "rewrite" field set to the specified value. +// The updated es.regexpType object with the "rewrite" field set to the specified value. func (r regexpType) Rewrite(rewrite string) regexpType { return r.putInTheField("rewrite", rewrite) } -// Boost sets the "boost" parameter in a regexpType query. +// Boost sets the "boost" parameter in a es.regexpType query. // // This method allows you to specify a boost factor for the regular expression query, // which influences the relevance score of matching documents. A higher boost value @@ -113,7 +113,7 @@ func (r regexpType) Rewrite(rewrite string) regexpType { // // Returns: // -// The updated regexpType object with the "boost" parameter set. +// The updated es.regexpType object with the "boost" parameter set. func (r regexpType) Boost(boost float64) regexpType { return r.putInTheField("boost", boost) } diff --git a/es/simple_query_string.go b/es/simple_query_string.go index 3b5eb6a..c02abca 100644 --- a/es/simple_query_string.go +++ b/es/simple_query_string.go @@ -6,16 +6,16 @@ import ( type simpleQueryStringType Object -// SimpleQueryString creates a new simpleQueryStringType object with the specified query string. +// SimpleQueryString creates a new es.simpleQueryStringType object with the specified query string. // -// This function initializes a simpleQueryStringType object with a simple query string, which +// This function initializes a es.simpleQueryStringType object with a simple query string, which // is typically used to perform simple text search queries in Elasticsearch. The query string // can contain multiple terms and operators, allowing for basic search expressions. // // Example usage: // // q := es.SimpleQueryString("Foo + Bar") -// // q now contains a simpleQueryStringType object with a simple query string query. +// // q now contains a es.simpleQueryStringType object with a simple query string query. // // Parameters: // - query: The query string to be used in the search. The type is generic and can be @@ -23,7 +23,7 @@ type simpleQueryStringType Object // // Returns: // -// A simpleQueryStringType object containing the specified query string. +// A es.simpleQueryStringType object containing the specified query string. func SimpleQueryString[T any](query T) simpleQueryStringType { return simpleQueryStringType{ "simple_query_string": Object{ @@ -32,7 +32,7 @@ func SimpleQueryString[T any](query T) simpleQueryStringType { } } -// Fields sets the fields to be searched within the simpleQueryStringType object. +// Fields sets the fields to be searched within the es.simpleQueryStringType object. // // This method specifies a list of fields that the query string should search. // If multiple fields are provided, the query will search across all of them, @@ -48,7 +48,7 @@ func SimpleQueryString[T any](query T) simpleQueryStringType { // // Returns: // -// The updated simpleQueryStringType object with the "fields" option set. +// The updated es.simpleQueryStringType object with the "fields" option set. func (q simpleQueryStringType) Fields(value []string) simpleQueryStringType { return q.putInTheField("fields", value) } @@ -69,12 +69,12 @@ func (q simpleQueryStringType) Fields(value []string) simpleQueryStringType { // // Returns: // -// The updated simpleQueryStringType object with the "analyzer" set. +// The updated es.simpleQueryStringType object with the "analyzer" set. func (q simpleQueryStringType) Analyzer(value string) simpleQueryStringType { return q.putInTheField("analyzer", value) } -// DefaultOperator sets the default operator for the simpleQueryStringType object. +// DefaultOperator sets the default operator for the es.simpleQueryStringType object. // // This method specifies the default operator to be used between terms in the query string // when no explicit operator is provided. The default operator can be operator.And or operator.Or, @@ -92,12 +92,12 @@ func (q simpleQueryStringType) Analyzer(value string) simpleQueryStringType { // // Returns: // -// The updated simpleQueryStringType object with the "default_operator" set. +// The updated es.simpleQueryStringType object with the "default_operator" set. func (q simpleQueryStringType) DefaultOperator(operator Operator.Operator) simpleQueryStringType { return q.putInTheField("default_operator", operator) } -// MinimumShouldMatch sets the minimum number of clauses that must match for the simpleQueryStringType object. +// MinimumShouldMatch sets the minimum number of clauses that must match for the es.simpleQueryStringType object. // // This method specifies the minimum number of clauses that must match in order // for a document to be considered a match. This can be expressed as an absolute number or a percentage, @@ -113,12 +113,12 @@ func (q simpleQueryStringType) DefaultOperator(operator Operator.Operator) simpl // // Returns: // -// The updated simpleQueryStringType object with the "minimum_should_match" option set. +// The updated es.simpleQueryStringType object with the "minimum_should_match" option set. func (q simpleQueryStringType) MinimumShouldMatch(value string) simpleQueryStringType { return q.putInTheField("minimum_should_match", value) } -// FuzzyMaxExpansions sets the maximum number of expansions for fuzzy matching in the simpleQueryStringType object. +// FuzzyMaxExpansions sets the maximum number of expansions for fuzzy matching in the es.simpleQueryStringType object. // // This method specifies the maximum number of terms that the query will expand to // when performing fuzzy matching. This setting controls the number of variations @@ -135,12 +135,12 @@ func (q simpleQueryStringType) MinimumShouldMatch(value string) simpleQueryStrin // // Returns: // -// The updated simpleQueryStringType object with the "fuzzy_max_expansions" option set. +// The updated es.simpleQueryStringType object with the "fuzzy_max_expansions" option set. func (q simpleQueryStringType) FuzzyMaxExpansions(value int64) simpleQueryStringType { return q.putInTheField("fuzzy_max_expansions", value) } -// FuzzyPrefixLength sets the prefix length for fuzzy matching in the simpleQueryStringType object. +// FuzzyPrefixLength sets the prefix length for fuzzy matching in the es.simpleQueryStringType object. // // This method specifies the length of the initial characters that must match exactly // before applying any fuzziness in the query. Increasing the prefix length can improve @@ -157,12 +157,12 @@ func (q simpleQueryStringType) FuzzyMaxExpansions(value int64) simpleQueryString // // Returns: // -// The updated simpleQueryStringType object with the "fuzzy_prefix_length" option set. +// The updated es.simpleQueryStringType object with the "fuzzy_prefix_length" option set. func (q simpleQueryStringType) FuzzyPrefixLength(value int64) simpleQueryStringType { return q.putInTheField("fuzzy_prefix_length", value) } -// FuzzyTranspositions sets the option to allow transpositions in fuzzy matching for the simpleQueryStringType object. +// FuzzyTranspositions sets the option to allow transpositions in fuzzy matching for the es.simpleQueryStringType object. // // This method enables or disables the allowance of transpositions (swapping of adjacent characters) // in fuzzy matching. When set to true, terms that are similar but have transposed characters @@ -178,7 +178,7 @@ func (q simpleQueryStringType) FuzzyPrefixLength(value int64) simpleQueryStringT // // Returns: // -// The updated simpleQueryStringType object with the "fuzzy_transpositions" option set. +// The updated es.simpleQueryStringType object with the "fuzzy_transpositions" option set. func (q simpleQueryStringType) FuzzyTranspositions(value bool) simpleQueryStringType { return q.putInTheField("fuzzy_transpositions", value) } @@ -199,7 +199,7 @@ func (q simpleQueryStringType) FuzzyTranspositions(value bool) simpleQueryString // // Returns: // -// The updated simpleQueryStringType object with the "analyze_wildcard" option set. +// The updated es.simpleQueryStringType object with the "analyze_wildcard" option set. func (q simpleQueryStringType) AnalyzeWildcard(value bool) simpleQueryStringType { return q.putInTheField("analyze_wildcard", value) } @@ -221,12 +221,12 @@ func (q simpleQueryStringType) AnalyzeWildcard(value bool) simpleQueryStringType // // Returns: // -// The updated simpleQueryStringType object with the "auto_generate_synonyms_phrase_query" option set. +// The updated es.simpleQueryStringType object with the "auto_generate_synonyms_phrase_query" option set. func (q simpleQueryStringType) AutoGenerateSynonymsPhraseQuery(value bool) simpleQueryStringType { return q.putInTheField("auto_generate_synonyms_phrase_query", value) } -// Flags sets the flags for the simpleQueryStringType object. +// Flags sets the flags for the es.simpleQueryStringType object. // // This method specifies which features of the simple_query_string query should be enabled. // It allows fine-grained control over the query's behavior by enabling or disabling specific features. @@ -242,12 +242,12 @@ func (q simpleQueryStringType) AutoGenerateSynonymsPhraseQuery(value bool) simpl // // Returns: // -// The updated simpleQueryStringType object with the "flags" option set. +// The updated es.simpleQueryStringType object with the "flags" option set. func (q simpleQueryStringType) Flags(value string) simpleQueryStringType { return q.putInTheField("flags", value) } -// Lenient sets the leniency option for the simpleQueryStringType object. +// Lenient sets the leniency option for the es.simpleQueryStringType object. // // This method determines whether the query should be lenient when encountering // errors, such as analyzing incompatible fields. When set to true, the query will @@ -264,12 +264,12 @@ func (q simpleQueryStringType) Flags(value string) simpleQueryStringType { // // Returns: // -// The updated simpleQueryStringType object with the "lenient" option set. +// The updated es.simpleQueryStringType object with the "lenient" option set. func (q simpleQueryStringType) Lenient(value bool) simpleQueryStringType { return q.putInTheField("lenient", value) } -// QuoteFieldSuffix sets the field suffix to be used for quoted text in the simpleQueryStringType object. +// QuoteFieldSuffix sets the field suffix to be used for quoted text in the es.simpleQueryStringType object. // // This method specifies a suffix to be appended to the field names when analyzing quoted text in the query string. // This is useful for applying different analyzers or field mappings to quoted phrases compared to unquoted terms. @@ -284,12 +284,12 @@ func (q simpleQueryStringType) Lenient(value bool) simpleQueryStringType { // // Returns: // -// The updated simpleQueryStringType object with the "quote_field_suffix" option set. +// The updated es.simpleQueryStringType object with the "quote_field_suffix" option set. func (q simpleQueryStringType) QuoteFieldSuffix(value string) simpleQueryStringType { return q.putInTheField("quote_field_suffix", value) } -// Boost sets the "boost" parameter in a simpleQueryStringType query. +// Boost sets the "boost" parameter in a es.simpleQueryStringType query. // // This method allows you to specify a boost factor for the simple query string query, // which influences the relevance score of matching documents. A higher boost value @@ -307,7 +307,7 @@ func (q simpleQueryStringType) QuoteFieldSuffix(value string) simpleQueryStringT // // Returns: // -// The updated simpleQueryStringType object with the "boost" parameter set. +// The updated es.simpleQueryStringType object with the "boost" parameter set. func (q simpleQueryStringType) Boost(boost float64) simpleQueryStringType { return q.putInTheField("boost", boost) } diff --git a/es/simple_query_string_test.go b/es/simple_query_string_test.go index ea7712e..0542ba5 100644 --- a/es/simple_query_string_test.go +++ b/es/simple_query_string_test.go @@ -8,6 +8,8 @@ import ( "github.com/Trendyol/es-query-builder/test/assert" ) +//// Simple Query String //// + func Test_SimpleQueryString_should_exist_on_es_package(t *testing.T) { // Given When assert.NotNil(t, es.SimpleQueryString[any]) diff --git a/es/term_query.go b/es/term_query.go index a889a2f..7e0e2bf 100644 --- a/es/term_query.go +++ b/es/term_query.go @@ -2,16 +2,16 @@ package es type termType Object -// Term creates a new termType object with the specified key-value pair. +// Term creates a new es.termType object with the specified key-value pair. // -// This function initializes a termType object with a single term query, where the +// This function initializes a es.termType object with a single term query, where the // key is the field name and the value is the term to search for. This is typically // used to construct a term query in search queries. // // Example usage: // // t := es.Term("category", "books") -// // t now contains a termType object with a term query for the "category" field. +// // t now contains a es.termType object with a term query for the "category" field. // // Parameters: // - key: A string representing the field name for the term query. @@ -19,7 +19,7 @@ type termType Object // // Returns: // -// A termType object containing the specified term query. +// A es.termType object containing the specified term query. func Term[T any](key string, value T) termType { return termType{ "term": Object{ @@ -30,7 +30,7 @@ func Term[T any](key string, value T) termType { } } -// CaseInsensitive sets the "case_insensitive" parameter in a termType query. +// CaseInsensitive sets the "case_insensitive" parameter in a es.termType query. // // This method allows you to specify whether the term query should be case- // insensitive. When set to true, the term matching will ignore case, @@ -47,12 +47,12 @@ func Term[T any](key string, value T) termType { // // Returns: // -// The updated termType object with the "case_insensitive" parameter set. +// The updated es.termType object with the "case_insensitive" parameter set. func (t termType) CaseInsensitive(caseInsensitive bool) termType { return t.putInTheField("case_insensitive", caseInsensitive) } -// Boost sets the "boost" parameter in a termType query. +// Boost sets the "boost" parameter in a es.termType query. // // This method allows you to specify a boost factor for the term query, // which influences the relevance score of matching documents. A higher @@ -70,33 +70,33 @@ func (t termType) CaseInsensitive(caseInsensitive bool) termType { // // Returns: // -// The updated termType object with the "boost" parameter set. +// The updated es.termType object with the "boost" parameter set. func (t termType) Boost(boost float64) termType { return t.putInTheField("boost", boost) } -// TermFunc creates a termType object based on a condition evaluated by a function. +// TermFunc creates a es.termType object based on a condition evaluated by a function. // -// This function conditionally creates a termType object if the provided function +// This function conditionally creates a es.termType object if the provided function // returns true for the given key-value pair. If the function returns false, it -// returns nil instead of creating a termType object. +// returns nil instead of creating a es.termType object. // // Example usage: // // t := es.TermFunc("category", "books", func(key, value string) bool { // return value != "" // }) -// // t is either a termType object or nil based on the condition. +// // t is either a es.termType object or nil based on the condition. // // Parameters: // - key: A string representing the field name for the term query. // - value: The value to be searched for in the specified field. The type is generic. // - f: A function that takes a key and value, and returns a boolean indicating -// whether to create the termType object. +// whether to create the es.termType object. // // Returns: // -// A termType object if the condition is true; otherwise, nil. +// A es.termType object if the condition is true; otherwise, nil. func TermFunc[T any](key string, value T, f func(key string, value T) bool) termType { if !f(key, value) { return nil @@ -104,24 +104,24 @@ func TermFunc[T any](key string, value T, f func(key string, value T) bool) term return Term(key, value) } -// TermIf creates a termType object based on a boolean condition. +// TermIf creates a es.termType object based on a boolean condition. // -// This function creates a termType object if the provided condition is true. If -// the condition is false, it returns nil instead of creating a termType object. +// This function creates a es.termType object if the provided condition is true. If +// the condition is false, it returns nil instead of creating a es.termType object. // // Example usage: // // t := es.TermIf("category", "books", true) -// // t is a termType object if the condition is true; otherwise, it is nil. +// // t is a es.termType object if the condition is true; otherwise, it is nil. // // Parameters: // - key: A string representing the field name for the term query. // - value: The value to be searched for in the specified field. The type is generic. -// - condition: A boolean value that determines whether to create the termType object. +// - condition: A boolean value that determines whether to create the es.termType object. // // Returns: // -// A termType object if the condition is true; otherwise, nil. +// A es.termType object if the condition is true; otherwise, nil. func TermIf[T any](key string, value T, condition bool) termType { if !condition { return nil diff --git a/es/terms_query.go b/es/terms_query.go index f8382ff..c17d1c3 100644 --- a/es/terms_query.go +++ b/es/terms_query.go @@ -2,16 +2,16 @@ package es type termsType Object -// Terms creates a new termsType object with the specified key and values. +// Terms creates a new es.termsType object with the specified key and values. // -// This function initializes a termsType object for a terms query, where the key +// This function initializes a es.termsType object for a terms query, where the key // is the field name and values is a variadic list of terms to search for in that field. // This is used to construct queries that match any of the specified terms. // // Example usage: // // t := es.Terms("category", "books", "electronics") -// // t now contains a termsType object with a terms query for the "category" field. +// // t now contains a es.termsType object with a terms query for the "category" field. // // Parameters: // - key: A string representing the field name for the terms query. @@ -20,7 +20,7 @@ type termsType Object // // Returns: // -// A termsType object containing the specified terms query. +// A es.termsType object containing the specified terms query. func Terms(key string, values ...any) termsType { return termsType{ "terms": Object{ @@ -29,7 +29,7 @@ func Terms(key string, values ...any) termsType { } } -// Boost sets the "boost" parameter in a termsType query. +// Boost sets the "boost" parameter in a es.termsType query. // // This method allows you to specify a boost factor for the terms query, // which influences the relevance score of documents matching any of the @@ -48,14 +48,14 @@ func Terms(key string, values ...any) termsType { // // Returns: // -// The updated termsType object with the "boost" parameter set. +// The updated es.termsType object with the "boost" parameter set. func (t termsType) Boost(boost float64) termsType { return t.putInTheField("boost", boost) } -// TermsArray creates a new termsType object with the specified key and values as a slice. +// TermsArray creates a new es.termsType object with the specified key and values as a slice. // -// This function initializes a termsType object for a terms query, where the key +// This function initializes a es.termsType object for a terms query, where the key // is the field name and values is a slice of terms to search for in that field. // This is useful for cases where the terms are provided as a slice instead of // a variadic list. @@ -63,7 +63,7 @@ func (t termsType) Boost(boost float64) termsType { // Example usage: // // t := es.TermsArray("category", []string{"books", "electronics"}) -// // t now contains a termsType object with a terms query for the "category" field. +// // t now contains a es.termsType object with a terms query for the "category" field. // // Parameters: // - key: A string representing the field name for the terms query. @@ -72,7 +72,7 @@ func (t termsType) Boost(boost float64) termsType { // // Returns: // -// A termsType object containing the specified terms query. +// A es.termsType object containing the specified terms query. func TermsArray[T any](key string, values []T) termsType { return termsType{ "terms": Object{ @@ -81,28 +81,28 @@ func TermsArray[T any](key string, values []T) termsType { } } -// TermsFunc creates a termsType object based on a condition evaluated by a function. +// TermsFunc creates a es.termsType object based on a condition evaluated by a function. // -// This function conditionally creates a termsType object if the provided function +// This function conditionally creates a es.termsType object if the provided function // returns true for the given key and values. If the function returns false, it -// returns nil instead of creating a termsType object. +// returns nil instead of creating a es.termsType object. // // Example usage: // // t := es.TermsFunc("category", []string{"books", "electronics"}, func(key string, values []string) bool { // return len(values) > 0 // }) -// // t is either a termsType object or nil based on the condition. +// // t is either a es.termsType object or nil based on the condition. // // Parameters: // - key: A string representing the field name for the terms query. // - values: A slice of values to be searched for in the specified field. // - f: A function that takes a key and values, and returns a boolean indicating -// whether to create the termsType object. +// whether to create the es.termsType object. // // Returns: // -// A termsType object if the condition is true; otherwise, nil. +// A es.termsType object if the condition is true; otherwise, nil. func TermsFunc[T any](key string, values []T, f func(key string, values []T) bool) termsType { if !f(key, values) { return nil @@ -110,24 +110,24 @@ func TermsFunc[T any](key string, values []T, f func(key string, values []T) boo return TermsArray(key, values) } -// TermsIf creates a termsType object based on a boolean condition. +// TermsIf creates a es.termsType object based on a boolean condition. // -// This function creates a termsType object if the provided condition is true. If -// the condition is false, it returns nil instead of creating a termsType object. +// This function creates a es.termsType object if the provided condition is true. If +// the condition is false, it returns nil instead of creating a es.termsType object. // // Example usage: // // t := es.TermsIf("category", []string{"books", "electronics"}, true) -// // t is a termsType object if the condition is true; otherwise, it is nil. +// // t is a es.termsType object if the condition is true; otherwise, it is nil. // // Parameters: // - key: A string representing the field name for the terms query. // - values: A slice of values to be searched for in the specified field. -// - condition: A boolean value that determines whether to create the termsType object. +// - condition: A boolean value that determines whether to create the es.termsType object. // // Returns: // -// A termsType object if the condition is true; otherwise, nil. +// A es.termsType object if the condition is true; otherwise, nil. func TermsIf[T any](key string, values []T, condition bool) termsType { if !condition { return nil From a899fef442e7e56de8863bc243f552f0845737df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6ksel=20K=C3=BC=C3=A7=C3=BCk=C5=9Fahin?= Date: Sun, 5 Jan 2025 13:05:41 +0300 Subject: [PATCH 16/17] chore: organize imports --- es/aggregations_test.go | 4 ++-- es/base_query_test.go | 6 +++--- es/enums/score-mode/score_mode_test.go | 14 +++++++------- es/enums/sort/mode/mode_test.go | 4 ++-- es/enums/sort/order/order_test.go | 4 ++-- es/inner_hits_test.go | 5 +++-- es/nested_query.go | 4 +--- es/range_test.go | 4 ++-- es/simple_query_string.go | 4 +--- es/simple_query_string_test.go | 7 ++++--- example/example.go | 5 +++-- internal/testing/elasticsearch_repository.go | 4 ++-- internal/testing/regexp_query_test.go | 1 + internal/testing/suite_test.go | 6 +++--- 14 files changed, 36 insertions(+), 36 deletions(-) diff --git a/es/aggregations_test.go b/es/aggregations_test.go index 48f7e1e..2714f0c 100644 --- a/es/aggregations_test.go +++ b/es/aggregations_test.go @@ -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 //// diff --git a/es/base_query_test.go b/es/base_query_test.go index 847216a..a7fb9ca 100644 --- a/es/base_query_test.go +++ b/es/base_query_test.go @@ -4,11 +4,11 @@ import ( "reflect" "testing" - "github.com/Trendyol/es-query-builder/es" - "github.com/Trendyol/es-query-builder/test/assert" - Mode "github.com/Trendyol/es-query-builder/es/enums/sort/mode" 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" ) //// NewQuery //// diff --git a/es/enums/score-mode/score_mode_test.go b/es/enums/score-mode/score_mode_test.go index 56efce8..2383e64 100644 --- a/es/enums/score-mode/score_mode_test.go +++ b/es/enums/score-mode/score_mode_test.go @@ -3,21 +3,21 @@ package scoremode_test import ( "testing" - "github.com/Trendyol/es-query-builder/es/enums/score-mode" + ScoreMode "github.com/Trendyol/es-query-builder/es/enums/score-mode" "github.com/Trendyol/es-query-builder/test/assert" ) func Test_ScoreModeString(t *testing.T) { tests := []struct { - mode scoremode.ScoreMode + mode ScoreMode.ScoreMode result string }{ - {scoremode.Avg, "avg"}, - {scoremode.Max, "max"}, - {scoremode.Min, "min"}, - {scoremode.None, "none"}, - {scoremode.Sum, "sum"}, + {ScoreMode.Avg, "avg"}, + {ScoreMode.Max, "max"}, + {ScoreMode.Min, "min"}, + {ScoreMode.None, "none"}, + {ScoreMode.Sum, "sum"}, } for _, test := range tests { diff --git a/es/enums/sort/mode/mode_test.go b/es/enums/sort/mode/mode_test.go index 570deb7..1f811a4 100644 --- a/es/enums/sort/mode/mode_test.go +++ b/es/enums/sort/mode/mode_test.go @@ -3,9 +3,9 @@ package mode_test import ( "testing" - "github.com/Trendyol/es-query-builder/test/assert" - Mode "github.com/Trendyol/es-query-builder/es/enums/sort/mode" + + "github.com/Trendyol/es-query-builder/test/assert" ) func Test_ModeString(t *testing.T) { diff --git a/es/enums/sort/order/order_test.go b/es/enums/sort/order/order_test.go index 4f39ea8..273f15e 100644 --- a/es/enums/sort/order/order_test.go +++ b/es/enums/sort/order/order_test.go @@ -3,9 +3,9 @@ package order_test import ( "testing" - "github.com/Trendyol/es-query-builder/test/assert" - Order "github.com/Trendyol/es-query-builder/es/enums/sort/order" + + "github.com/Trendyol/es-query-builder/test/assert" ) func TestOrderString(t *testing.T) { diff --git a/es/inner_hits_test.go b/es/inner_hits_test.go index 64acd13..dde88d7 100644 --- a/es/inner_hits_test.go +++ b/es/inner_hits_test.go @@ -3,8 +3,9 @@ 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/es/enums/sort/order" "github.com/Trendyol/es-query-builder/test/assert" ) @@ -273,7 +274,7 @@ func Test_InnerHits_should_have_Sort_method(t *testing.T) { func Test_InnerHits_Sort_should_create_json_with_sort_field_inside_inner_hits(t *testing.T) { // Given - ih := es.InnerHits().Sort(es.Sort("indexedAt").Order(order.Desc)) + ih := es.InnerHits().Sort(es.Sort("indexedAt").Order(Order.Desc)) // When Then assert.NotNil(t, ih) bodyJSON := assert.MarshalWithoutError(t, ih) diff --git a/es/nested_query.go b/es/nested_query.go index c40dafb..e9d631b 100644 --- a/es/nested_query.go +++ b/es/nested_query.go @@ -1,8 +1,6 @@ package es -import ( - ScoreMode "github.com/Trendyol/es-query-builder/es/enums/score-mode" -) +import ScoreMode "github.com/Trendyol/es-query-builder/es/enums/score-mode" type nestedType Object diff --git a/es/range_test.go b/es/range_test.go index 4d48589..0e6b7da 100644 --- a/es/range_test.go +++ b/es/range_test.go @@ -3,7 +3,7 @@ package es_test import ( "testing" - range_relation "github.com/Trendyol/es-query-builder/es/enums/range-relation" + RangeRelation "github.com/Trendyol/es-query-builder/es/enums/range-relation" "github.com/Trendyol/es-query-builder/es" "github.com/Trendyol/es-query-builder/test/assert" @@ -235,7 +235,7 @@ func Test_Range_Relation_should_create_json_with_range_field_inside_query(t *tes es.Range("partition"). From(512). To(1024). - Relation(range_relation.Within), + Relation(RangeRelation.Within), ) // When Then diff --git a/es/simple_query_string.go b/es/simple_query_string.go index c02abca..caa09ef 100644 --- a/es/simple_query_string.go +++ b/es/simple_query_string.go @@ -1,8 +1,6 @@ package es -import ( - Operator "github.com/Trendyol/es-query-builder/es/enums/operator" -) +import Operator "github.com/Trendyol/es-query-builder/es/enums/operator" type simpleQueryStringType Object diff --git a/es/simple_query_string_test.go b/es/simple_query_string_test.go index 0542ba5..7513531 100644 --- a/es/simple_query_string_test.go +++ b/es/simple_query_string_test.go @@ -3,8 +3,9 @@ package es_test import ( "testing" + Operator "github.com/Trendyol/es-query-builder/es/enums/operator" + "github.com/Trendyol/es-query-builder/es" - "github.com/Trendyol/es-query-builder/es/enums/operator" "github.com/Trendyol/es-query-builder/test/assert" ) @@ -63,7 +64,7 @@ func Test_SimpleQueryString_method_should_create_simple_query_string_with_analyz func Test_SimpleQueryString_method_should_create_simple_query_string_with_default_operator(t *testing.T) { // Given When b := es.NewQuery( - es.SimpleQueryString("value").DefaultOperator(operator.And), + es.SimpleQueryString("value").DefaultOperator(Operator.And), ) // Then @@ -198,7 +199,7 @@ func Test_SimpleQueryString_method_should_create_simple_query_string_with_all_pa es.SimpleQueryString("value"). Fields([]string{"field1", "field2"}). Analyzer("standard"). - DefaultOperator(operator.And). + DefaultOperator(Operator.And). MinimumShouldMatch("2"). FuzzyMaxExpansions(50). FuzzyPrefixLength(2). diff --git a/example/example.go b/example/example.go index 5a5000a..d369318 100644 --- a/example/example.go +++ b/example/example.go @@ -6,8 +6,9 @@ import ( "fmt" "log" + Order "github.com/Trendyol/es-query-builder/es/enums/sort/order" + "github.com/Trendyol/es-query-builder/es" - "github.com/Trendyol/es-query-builder/es/enums/sort/order" ) func mockGetDocumentsEs(query string) (string, error) { @@ -97,7 +98,7 @@ func buildQuery(id int) es.Object { es.Terms("type", "DOC", "FILE"), )). Size(45). - Sort(es.Sort("name").Order(order.Asc)). + Sort(es.Sort("name").Order(Order.Asc)). SourceIncludes("id", "type", "indexedAt", "chapters") return query diff --git a/internal/testing/elasticsearch_repository.go b/internal/testing/elasticsearch_repository.go index 7b534a8..b35320c 100644 --- a/internal/testing/elasticsearch_repository.go +++ b/internal/testing/elasticsearch_repository.go @@ -7,10 +7,10 @@ import ( "net/http" "strings" + "integration-tests/constants" + "github.com/elastic/go-elasticsearch/v8" "github.com/elastic/go-elasticsearch/v8/esapi" - - "integration-tests/constants" ) type elasticsearchRepository struct { diff --git a/internal/testing/regexp_query_test.go b/internal/testing/regexp_query_test.go index 497b5f2..cd0c990 100644 --- a/internal/testing/regexp_query_test.go +++ b/internal/testing/regexp_query_test.go @@ -2,6 +2,7 @@ package testing import ( "encoding/json" + "github.com/Trendyol/es-query-builder/es" "github.com/bayraktugrul/go-await" "github.com/stretchr/testify/assert" diff --git a/internal/testing/suite_test.go b/internal/testing/suite_test.go index 9fbc363..7f2ddfb 100644 --- a/internal/testing/suite_test.go +++ b/internal/testing/suite_test.go @@ -7,13 +7,13 @@ import ( "strings" "testing" + "integration-tests/constants" + "integration-tests/container" + "github.com/elastic/elastic-transport-go/v8/elastictransport" "github.com/elastic/go-elasticsearch/v8" "github.com/elastic/go-elasticsearch/v8/esapi" "github.com/stretchr/testify/suite" - - "integration-tests/constants" - "integration-tests/container" ) func TestSuite(t *testing.T) { From 4703fd0ae02f9f015db71e85e9483376c8e921c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6ksel=20K=C3=BC=C3=A7=C3=BCk=C5=9Fahin?= Date: Thu, 16 Jan 2025 19:14:46 +0300 Subject: [PATCH 17/17] documentation: fix vovel sound grammer --- es/base_query.go | 10 +++++----- es/bool_query.go | 8 ++++---- es/inner_hits.go | 8 ++++---- es/match_all_query.go | 6 +++--- es/match_none_query.go | 6 +++--- es/match_query.go | 6 +++--- es/nested_query.go | 4 ++-- es/query_string.go | 8 ++++---- es/range.go | 6 +++--- es/regexp_query.go | 8 ++++---- es/simple_query_string.go | 8 ++++---- es/term_query.go | 30 +++++++++++++++--------------- es/terms_query.go | 34 +++++++++++++++++----------------- 13 files changed, 71 insertions(+), 71 deletions(-) diff --git a/es/base_query.go b/es/base_query.go index 8fd8712..4516cba 100644 --- a/es/base_query.go +++ b/es/base_query.go @@ -202,28 +202,28 @@ func (o Object) SourceExcludes(fields ...string) Object { // Sort creates a new es.sortType object with the specified field. // -// This function initializes a es.sortType object with a given field name. The +// This function initializes an es.sortType object with a given field name. The // field is used to specify the sorting criteria in the search query. The // resulting es.sortType can be further configured with sorting order and mode. // // Example usage: // // s := es.Sort("age") -// // s now includes a es.sortType with an "age" field that can be further configured. +// // s now includes an es.sortType with an "age" field that can be further configured. // // Parameters: // - field: A string representing the field to sort by. // // Returns: // -// A es.sortType object with the specified field. +// An es.sortType object with the specified field. func Sort(field string) sortType { return sortType{ field: Object{}, } } -// Order sets the "order" parameter in a es.sortType object. +// Order sets the "order" parameter in an es.sortType object. // // This method specifies the order in which the results should be sorted. // It configures the es.sortType object to sort the results in ascending or @@ -244,7 +244,7 @@ func (s sortType) Order(order Order.Order) sortType { return s.putInTheField("order", order) } -// Mode sets the "mode" parameter in a es.sortType object. +// Mode sets the "mode" parameter in an es.sortType object. // // This method specifies the mode used for sorting the results. The mode // determines how sorting should be handled, such as by specifying different diff --git a/es/bool_query.go b/es/bool_query.go index c949356..04146b8 100644 --- a/es/bool_query.go +++ b/es/bool_query.go @@ -12,7 +12,7 @@ type ShouldType Array // Bool creates and returns an empty BoolType object. // -// This function is typically used to initialize a es.BoolType, which can be +// This function is typically used to initialize an es.BoolType, which can be // populated later with the appropriate boolean query conditions. // // Example usage: @@ -27,7 +27,7 @@ func Bool() BoolType { return BoolType{} } -// MinimumShouldMatch sets the "minimum_should_match" parameter in a es.BoolType query. +// MinimumShouldMatch sets the "minimum_should_match" parameter in an es.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 @@ -51,7 +51,7 @@ func (b BoolType) MinimumShouldMatch(minimumShouldMatch any) BoolType { return b } -// AdjustPureNegative sets the "adjust_pure_negative" parameter in a es.BoolType query. +// AdjustPureNegative sets the "adjust_pure_negative" parameter in an es.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 @@ -75,7 +75,7 @@ func (b BoolType) AdjustPureNegative(adjustPureNegative bool) BoolType { return b } -// Boost sets the "boost" parameter in a es.BoolType query. +// Boost sets the "boost" parameter in an es.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 diff --git a/es/inner_hits.go b/es/inner_hits.go index f3dbfa7..cb745d9 100644 --- a/es/inner_hits.go +++ b/es/inner_hits.go @@ -36,7 +36,7 @@ func InnerHits() innerHitsType { // // The inner hits object now includes a "collapse" field configured for the "author" field. // // Parameters: -// - fieldCollapse: A es.fieldCollapseType object defining the collapsing behavior based on a specific field. +// - fieldCollapse: An es.fieldCollapseType object defining the collapsing behavior based on a specific field. // // Returns: // @@ -433,7 +433,7 @@ func (ih innerHitsType) Version(version bool) innerHitsType { // // Returns: // -// A es.fieldCollapseType object with the "field" set to the specified value, used for collapsing results. +// An es.fieldCollapseType object with the "field" set to the specified value, used for collapsing results. func FieldCollapse(field string) fieldCollapseType { return fieldCollapseType{ "field": field, @@ -452,7 +452,7 @@ func FieldCollapse(field string) fieldCollapseType { // // for both "category" and "subcategory". // // Parameters: -// - fieldCollapse: A es.fieldCollapseType object representing the collapse configuration to apply. +// - fieldCollapse: An es.fieldCollapseType object representing the collapse configuration to apply. // // Returns: // @@ -521,7 +521,7 @@ func (fc fieldCollapseType) MaxConcurrentGroupSearches(maxConcurrentGroupSearche // // Returns: // -// A es.fieldAndFormatType object with the "field" set to the specified value and an optional "format". +// An es.fieldAndFormatType object with the "field" set to the specified value and an optional "format". func FieldAndFormat(field string) fieldAndFormatType { return fieldAndFormatType{ "field": field, diff --git a/es/match_all_query.go b/es/match_all_query.go index ffda166..fe64dee 100644 --- a/es/match_all_query.go +++ b/es/match_all_query.go @@ -4,18 +4,18 @@ type matchAllType Object // MatchAll creates a new es.matchAllType object that matches all documents. // -// This function initializes a es.matchAllType object that is used to construct queries +// This function initializes an es.matchAllType object that is used to construct queries // that match all documents. This can be useful for scenarios where you want to ensure // that all documents are included in the results. // // Example usage: // // ma := es.MatchAll() -// // ma now contains a es.matchAllType object that matches all documents. +// // ma now contains an es.matchAllType object that matches all documents. // // Returns: // -// A es.matchAllType object with a match_all query that matches all documents. +// An es.matchAllType object with a match_all query that matches all documents. func MatchAll() matchAllType { return matchAllType{ "match_all": Object{}, diff --git a/es/match_none_query.go b/es/match_none_query.go index 62f284d..ebdf1fe 100644 --- a/es/match_none_query.go +++ b/es/match_none_query.go @@ -4,14 +4,14 @@ type matchNoneType Object // MatchNone creates a new es.matchNoneType object with the specified field and query. // -// This function initializes a es.matchNoneType object for a match_none query, where the key +// This function initializes an es.matchNoneType object for a match_none query, where the key // represents the field name and query is the value to be matched. This is used to construct // queries that explicitly match no documents for the specified value in the given field. // // Example usage: // // mn := es.MatchNone("title", "es-query-builder") -// // mn now contains a es.matchNoneType object that matches no documents for the "title" field with the query "es-query-builder". +// // mn now contains an es.matchNoneType object that matches no documents for the "title" field with the query "es-query-builder". // // Parameters: // - key: A string representing the field name for the match_none query. @@ -19,7 +19,7 @@ type matchNoneType Object // // Returns: // -// A es.matchNoneType object containing the specified match_none query. +// An es.matchNoneType object containing the specified match_none query. func MatchNone[T any](key string, query T) matchNoneType { return matchNoneType{ "match_none": Object{ diff --git a/es/match_query.go b/es/match_query.go index 994ccc7..7b292b3 100644 --- a/es/match_query.go +++ b/es/match_query.go @@ -9,14 +9,14 @@ type matchType Object // Match creates a new es.matchType object with the specified field and query. // -// This function initializes a es.matchType object for a match query, where the key +// This function initializes an es.matchType object for a match query, where the key // is the field name and query is the value to search for in that field. This is used // to construct queries that match the specified value in the given field. // // Example usage: // // m := es.Match("title", "es-query-builder") -// // m now contains a es.matchType object that matches the query "es-query-builder" in the "title" field. +// // m now contains an es.matchType object that matches the query "es-query-builder" in the "title" field. // // Parameters: // - key: A string representing the field name for the match query. @@ -24,7 +24,7 @@ type matchType Object // // Returns: // -// A es.matchType object containing the specified match query. +// An es.matchType object containing the specified match query. func Match[T any](key string, query T) matchType { return matchType{ "match": Object{ diff --git a/es/nested_query.go b/es/nested_query.go index e9d631b..c12260f 100644 --- a/es/nested_query.go +++ b/es/nested_query.go @@ -13,7 +13,7 @@ type nestedType Object // Example usage: // // nestedQuery := es.Nested("comments", es.Bool().Filter(...).MustNot(...)) -// // nestedQuery now contains a es.nestedType object with the specified path and query. +// // nestedQuery now contains an es.nestedType object with the specified path and query. // // Parameters: // - path: A string representing the path for the nested query. @@ -21,7 +21,7 @@ type nestedType Object // // Returns: // -// A es.nestedType object with the "nested" query and specified path. +// a es.nestedType object with the "nested" query and specified path. func Nested[T any](path string, nestedQuery T) nestedType { o := NewQuery(nestedQuery) o["path"] = path diff --git a/es/query_string.go b/es/query_string.go index 81a3d48..7ea03fd 100644 --- a/es/query_string.go +++ b/es/query_string.go @@ -9,14 +9,14 @@ type queryStringType Object // QueryString creates a new es.queryStringType object with the specified query string. // -// This function initializes a es.queryStringType object with a query string, which +// This function initializes an es.queryStringType object with a query string, which // is typically used to perform full-text search queries in Elasticsearch. The query string // can contain multiple terms and operators, allowing for complex search expressions. // // Example usage: // // q := es.QueryString("Foo AND Bar") -// // q now contains a es.queryStringType object with a query string query. +// // q now contains an es.queryStringType object with a query string query. // // Parameters: // - query: The query string to be used in the search. The type is generic and can be @@ -24,7 +24,7 @@ type queryStringType Object // // Returns: // -// A es.queryStringType object containing the specified query string. +// An es.queryStringType object containing the specified query string. func QueryString[T any](query T) queryStringType { return queryStringType{ "query_string": Object{ @@ -45,7 +45,7 @@ func QueryString[T any](query T) queryStringType { // DefaultField("defaultField") // // q := es.QueryString("Foo Bar").DefaultField("title") -// // q now contains a es.queryStringType object where the default field for the query is "title". +// // q now contains an es.queryStringType object where the default field for the query is "title". // // Parameters: // - value: A string representing the field name to be used as the default field in the query. diff --git a/es/range.go b/es/range.go index 2552d1d..7eeb1cb 100644 --- a/es/range.go +++ b/es/range.go @@ -6,20 +6,20 @@ type rangeType Object // Range creates a new es.rangeType object with the specified field. // -// This function initializes a es.rangeType object for specifying range queries. The key represents +// This function initializes an es.rangeType object for specifying range queries. The key represents // the field name, and the es.rangeType object is used to define the range conditions for that field. // // Example usage: // // r := es.Range("age") -// // r now contains a es.rangeType object with the specified field "age" for range queries. +// // r now contains an es.rangeType object with the specified field "age" for range queries. // // Parameters: // - key: A string representing the field name for the range query. // // Returns: // -// A es.rangeType object with the specified field ready for defining range conditions. +// An es.rangeType object with the specified field ready for defining range conditions. func Range(key string) rangeType { return rangeType{ "range": Object{ diff --git a/es/regexp_query.go b/es/regexp_query.go index 2584904..4dbc854 100644 --- a/es/regexp_query.go +++ b/es/regexp_query.go @@ -4,14 +4,14 @@ type regexpType Object // Regexp creates a new es.regexpType object with the specified key-value pair. // -// This function initializes a es.regexpType object with a single regexp query, where the +// This function initializes an es.regexpType object with a single regexp query, where the // key is the field name and the value is the regexp to search for. This is typically // used to construct a regexp query in search queries. // // Example usage: // // t := es.Regexp("endpoint", "/books/.*") -// // t now contains a es.regexpType object with a regexp query for the "endpoint" field. +// // t now contains an es.regexpType object with a regexp query for the "endpoint" field. // // Parameters: // - key: A string representing the field name for the regexp query. @@ -19,7 +19,7 @@ type regexpType Object // // Returns: // -// A es.regexpType object containing the specified regexp query. +// An es.regexpType object containing the specified regexp query. func Regexp(key string, value string) regexpType { return regexpType{ "regexp": Object{ @@ -95,7 +95,7 @@ func (r regexpType) Rewrite(rewrite string) regexpType { return r.putInTheField("rewrite", rewrite) } -// Boost sets the "boost" parameter in a es.regexpType query. +// Boost sets the "boost" parameter in an es.regexpType query. // // This method allows you to specify a boost factor for the regular expression query, // which influences the relevance score of matching documents. A higher boost value diff --git a/es/simple_query_string.go b/es/simple_query_string.go index caa09ef..511f9f0 100644 --- a/es/simple_query_string.go +++ b/es/simple_query_string.go @@ -6,14 +6,14 @@ type simpleQueryStringType Object // SimpleQueryString creates a new es.simpleQueryStringType object with the specified query string. // -// This function initializes a es.simpleQueryStringType object with a simple query string, which +// This function initializes an es.simpleQueryStringType object with a simple query string, which // is typically used to perform simple text search queries in Elasticsearch. The query string // can contain multiple terms and operators, allowing for basic search expressions. // // Example usage: // // q := es.SimpleQueryString("Foo + Bar") -// // q now contains a es.simpleQueryStringType object with a simple query string query. +// // q now contains an es.simpleQueryStringType object with a simple query string query. // // Parameters: // - query: The query string to be used in the search. The type is generic and can be @@ -21,7 +21,7 @@ type simpleQueryStringType Object // // Returns: // -// A es.simpleQueryStringType object containing the specified query string. +// An es.simpleQueryStringType object containing the specified query string. func SimpleQueryString[T any](query T) simpleQueryStringType { return simpleQueryStringType{ "simple_query_string": Object{ @@ -287,7 +287,7 @@ func (q simpleQueryStringType) QuoteFieldSuffix(value string) simpleQueryStringT return q.putInTheField("quote_field_suffix", value) } -// Boost sets the "boost" parameter in a es.simpleQueryStringType query. +// Boost sets the "boost" parameter in an es.simpleQueryStringType query. // // This method allows you to specify a boost factor for the simple query string query, // which influences the relevance score of matching documents. A higher boost value diff --git a/es/term_query.go b/es/term_query.go index 7e0e2bf..0751cce 100644 --- a/es/term_query.go +++ b/es/term_query.go @@ -4,14 +4,14 @@ type termType Object // Term creates a new es.termType object with the specified key-value pair. // -// This function initializes a es.termType object with a single term query, where the +// This function initializes an es.termType object with a single term query, where the // key is the field name and the value is the term to search for. This is typically // used to construct a term query in search queries. // // Example usage: // // t := es.Term("category", "books") -// // t now contains a es.termType object with a term query for the "category" field. +// // t now contains an es.termType object with a term query for the "category" field. // // Parameters: // - key: A string representing the field name for the term query. @@ -19,7 +19,7 @@ type termType Object // // Returns: // -// A es.termType object containing the specified term query. +// An es.termType object containing the specified term query. func Term[T any](key string, value T) termType { return termType{ "term": Object{ @@ -30,7 +30,7 @@ func Term[T any](key string, value T) termType { } } -// CaseInsensitive sets the "case_insensitive" parameter in a es.termType query. +// CaseInsensitive sets the "case_insensitive" parameter in an es.termType query. // // This method allows you to specify whether the term query should be case- // insensitive. When set to true, the term matching will ignore case, @@ -52,7 +52,7 @@ func (t termType) CaseInsensitive(caseInsensitive bool) termType { return t.putInTheField("case_insensitive", caseInsensitive) } -// Boost sets the "boost" parameter in a es.termType query. +// Boost sets the "boost" parameter in an es.termType query. // // This method allows you to specify a boost factor for the term query, // which influences the relevance score of matching documents. A higher @@ -75,18 +75,18 @@ func (t termType) Boost(boost float64) termType { return t.putInTheField("boost", boost) } -// TermFunc creates a es.termType object based on a condition evaluated by a function. +// TermFunc creates an es.termType object based on a condition evaluated by a function. // -// This function conditionally creates a es.termType object if the provided function +// This function conditionally creates an es.termType object if the provided function // returns true for the given key-value pair. If the function returns false, it -// returns nil instead of creating a es.termType object. +// returns nil instead of creating an es.termType object. // // Example usage: // // t := es.TermFunc("category", "books", func(key, value string) bool { // return value != "" // }) -// // t is either a es.termType object or nil based on the condition. +// // t is either an es.termType object or nil based on the condition. // // Parameters: // - key: A string representing the field name for the term query. @@ -96,7 +96,7 @@ func (t termType) Boost(boost float64) termType { // // Returns: // -// A es.termType object if the condition is true; otherwise, nil. +// An es.termType object if the condition is true; otherwise, nil. func TermFunc[T any](key string, value T, f func(key string, value T) bool) termType { if !f(key, value) { return nil @@ -104,15 +104,15 @@ func TermFunc[T any](key string, value T, f func(key string, value T) bool) term return Term(key, value) } -// TermIf creates a es.termType object based on a boolean condition. +// TermIf creates an es.termType object based on a boolean condition. // -// This function creates a es.termType object if the provided condition is true. If -// the condition is false, it returns nil instead of creating a es.termType object. +// This function creates an es.termType object if the provided condition is true. If +// the condition is false, it returns nil instead of creating an es.termType object. // // Example usage: // // t := es.TermIf("category", "books", true) -// // t is a es.termType object if the condition is true; otherwise, it is nil. +// // t is an es.termType object if the condition is true; otherwise, it is nil. // // Parameters: // - key: A string representing the field name for the term query. @@ -121,7 +121,7 @@ func TermFunc[T any](key string, value T, f func(key string, value T) bool) term // // Returns: // -// A es.termType object if the condition is true; otherwise, nil. +// An es.termType object if the condition is true; otherwise, nil. func TermIf[T any](key string, value T, condition bool) termType { if !condition { return nil diff --git a/es/terms_query.go b/es/terms_query.go index c17d1c3..5702d63 100644 --- a/es/terms_query.go +++ b/es/terms_query.go @@ -4,14 +4,14 @@ type termsType Object // Terms creates a new es.termsType object with the specified key and values. // -// This function initializes a es.termsType object for a terms query, where the key +// This function initializes an es.termsType object for a terms query, where the key // is the field name and values is a variadic list of terms to search for in that field. // This is used to construct queries that match any of the specified terms. // // Example usage: // // t := es.Terms("category", "books", "electronics") -// // t now contains a es.termsType object with a terms query for the "category" field. +// // t now contains an es.termsType object with a terms query for the "category" field. // // Parameters: // - key: A string representing the field name for the terms query. @@ -20,7 +20,7 @@ type termsType Object // // Returns: // -// A es.termsType object containing the specified terms query. +// An es.termsType object containing the specified terms query. func Terms(key string, values ...any) termsType { return termsType{ "terms": Object{ @@ -29,7 +29,7 @@ func Terms(key string, values ...any) termsType { } } -// Boost sets the "boost" parameter in a es.termsType query. +// Boost sets the "boost" parameter in an es.termsType query. // // This method allows you to specify a boost factor for the terms query, // which influences the relevance score of documents matching any of the @@ -55,7 +55,7 @@ func (t termsType) Boost(boost float64) termsType { // TermsArray creates a new es.termsType object with the specified key and values as a slice. // -// This function initializes a es.termsType object for a terms query, where the key +// This function initializes an es.termsType object for a terms query, where the key // is the field name and values is a slice of terms to search for in that field. // This is useful for cases where the terms are provided as a slice instead of // a variadic list. @@ -63,7 +63,7 @@ func (t termsType) Boost(boost float64) termsType { // Example usage: // // t := es.TermsArray("category", []string{"books", "electronics"}) -// // t now contains a es.termsType object with a terms query for the "category" field. +// // t now contains an es.termsType object with a terms query for the "category" field. // // Parameters: // - key: A string representing the field name for the terms query. @@ -72,7 +72,7 @@ func (t termsType) Boost(boost float64) termsType { // // Returns: // -// A es.termsType object containing the specified terms query. +// An es.termsType object containing the specified terms query. func TermsArray[T any](key string, values []T) termsType { return termsType{ "terms": Object{ @@ -81,18 +81,18 @@ func TermsArray[T any](key string, values []T) termsType { } } -// TermsFunc creates a es.termsType object based on a condition evaluated by a function. +// TermsFunc creates an es.termsType object based on a condition evaluated by a function. // -// This function conditionally creates a es.termsType object if the provided function +// This function conditionally creates an es.termsType object if the provided function // returns true for the given key and values. If the function returns false, it -// returns nil instead of creating a es.termsType object. +// returns nil instead of creating an es.termsType object. // // Example usage: // // t := es.TermsFunc("category", []string{"books", "electronics"}, func(key string, values []string) bool { // return len(values) > 0 // }) -// // t is either a es.termsType object or nil based on the condition. +// // t is either an es.termsType object or nil based on the condition. // // Parameters: // - key: A string representing the field name for the terms query. @@ -102,7 +102,7 @@ func TermsArray[T any](key string, values []T) termsType { // // Returns: // -// A es.termsType object if the condition is true; otherwise, nil. +// An es.termsType object if the condition is true; otherwise, nil. func TermsFunc[T any](key string, values []T, f func(key string, values []T) bool) termsType { if !f(key, values) { return nil @@ -110,15 +110,15 @@ func TermsFunc[T any](key string, values []T, f func(key string, values []T) boo return TermsArray(key, values) } -// TermsIf creates a es.termsType object based on a boolean condition. +// TermsIf creates an es.termsType object based on a boolean condition. // -// This function creates a es.termsType object if the provided condition is true. If -// the condition is false, it returns nil instead of creating a es.termsType object. +// This function creates an es.termsType object if the provided condition is true. If +// the condition is false, it returns nil instead of creating an es.termsType object. // // Example usage: // // t := es.TermsIf("category", []string{"books", "electronics"}, true) -// // t is a es.termsType object if the condition is true; otherwise, it is nil. +// // t is an es.termsType object if the condition is true; otherwise, it is nil. // // Parameters: // - key: A string representing the field name for the terms query. @@ -127,7 +127,7 @@ func TermsFunc[T any](key string, values []T, f func(key string, values []T) boo // // Returns: // -// A es.termsType object if the condition is true; otherwise, nil. +// An es.termsType object if the condition is true; otherwise, nil. func TermsIf[T any](key string, values []T, condition bool) termsType { if !condition { return nil