diff --git a/quesma/ast/query_basic_visitor.go b/quesma/ast/query_basic_visitor.go deleted file mode 100644 index 3f2c4064d..000000000 --- a/quesma/ast/query_basic_visitor.go +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright Quesma, licensed under the Elastic License 2.0. -// SPDX-License-Identifier: Elastic-2.0 -package ast - -import "github.com/elastic/go-elasticsearch/v8/typedapi/types" - -type QueryBasicVisitor struct { - QueryVisitor -} - -func (QueryBasicVisitor) PreVisitQuery(q *types.Query, path []string) {} -func (QueryBasicVisitor) PostVisitQuery(q *types.Query, path []string) {} -func (QueryBasicVisitor) PreVisitBool(b *types.BoolQuery, path []string) {} -func (QueryBasicVisitor) PostVisitBool(b *types.BoolQuery, path []string) {} -func (QueryBasicVisitor) PreVisitBoostingQuery(b *types.BoostingQuery, path []string) {} -func (QueryBasicVisitor) PostVisitBoostingQuery(b *types.BoostingQuery, path []string) {} -func (QueryBasicVisitor) PreVisitTypeQuery(t *types.TypeQuery, path []string) {} -func (QueryBasicVisitor) PostVisitTypeQuery(t *types.TypeQuery, path []string) {} -func (QueryBasicVisitor) PreVisitCommonTermsQuery(ctq *types.CommonTermsQuery, field string, path []string) { -} -func (QueryBasicVisitor) PostVisitCommonTermsQuery(ctq *types.CommonTermsQuery, field string, path []string) { -} -func (QueryBasicVisitor) PostVisitCombinedFieldsQuery(ctq *types.CombinedFieldsQuery, path []string) { -} -func (QueryBasicVisitor) PreVisitTerm(t *types.TermQuery, field string, path []string) {} -func (QueryBasicVisitor) PostVisitTerm(t *types.TermQuery, field string, path []string) {} -func (QueryBasicVisitor) PreVisitConstantScoreQuery(csq *types.ConstantScoreQuery, path []string) {} -func (QueryBasicVisitor) PostVisitConstantScoreQuery(csq *types.ConstantScoreQuery, path []string) {} -func (QueryBasicVisitor) PreVisitDisMaxQuery(dmq *types.DisMaxQuery, path []string) {} -func (QueryBasicVisitor) PostVisitDisMaxQuery(dmq *types.DisMaxQuery, path []string) {} -func (QueryBasicVisitor) PreVisitDistanceFeatureQuery(dfq types.DistanceFeatureQuery, path []string) { -} -func (QueryBasicVisitor) PostVisitDistanceFeatureQuery(dfq types.DistanceFeatureQuery, path []string) { -} -func (QueryBasicVisitor) PreVisitExistsQuery(eq *types.ExistsQuery, path []string) {} -func (QueryBasicVisitor) PostVisitExistsQuery(eq *types.ExistsQuery, path []string) {} -func (QueryBasicVisitor) PreVisitMatchQuery(mq *types.MatchQuery, field string, path []string) {} -func (QueryBasicVisitor) PostVisitMatchQuery(mq *types.MatchQuery, field string, path []string) {} -func (QueryBasicVisitor) PreVisitMatchAllQuery(mq *types.MatchAllQuery, path []string) {} -func (QueryBasicVisitor) PostVisitMatchAllQuery(mq *types.MatchAllQuery, path []string) {} -func (QueryBasicVisitor) PreVisitMatchBoolPrefixQuery(mq *types.MatchBoolPrefixQuery, field string, path []string) { -} -func (QueryBasicVisitor) PostVisitMatchBoolPrefixQuery(mq *types.MatchBoolPrefixQuery, field string, path []string) { -} diff --git a/quesma/ast/query_traversal_test.go b/quesma/ast/query_traversal_test.go deleted file mode 100644 index 57df7cd2a..000000000 --- a/quesma/ast/query_traversal_test.go +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright Quesma, licensed under the Elastic License 2.0. -// SPDX-License-Identifier: Elastic-2.0 -package ast - -import ( - "github.com/elastic/go-elasticsearch/v8/typedapi/types" - "github.com/goccy/go-json" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "testing" -) - -const queryContent = `{ - "query": { - "bool": { - "must": [ - { "term": { "field1": "value1" }}, - { - "bool": { - "should": [ - { "term": { "field2": "value2" }}, - { "term": { "field3": "value3" }} - ] - } - } - ] - } - } -}` - -type QueryCountingVisitor struct { - boolQueriesCounter int - termQueriesCounter int - QueryVisitor -} - -func (v *QueryCountingVisitor) PreVisitBool(b *types.BoolQuery, path []string) { - v.boolQueriesCounter++ -} -func (v *QueryCountingVisitor) PreVisitTerm(t *types.TermQuery, field string, path []string) { - v.termQueriesCounter++ -} - -func Test_queryTraversal(t *testing.T) { - body := []byte(queryContent) - query := &types.Query{} - err := json.Unmarshal(body, query) - require.NoError(t, err) - path := []string{} - visitor := &QueryCountingVisitor{QueryVisitor: QueryBasicVisitor{}} - queryTraverser := QueryTraverser{Debug: true, PathMatched: false} - queryTraverser.TraverseQuery(query, visitor, path) - assert.Equal(t, 2, visitor.boolQueriesCounter) - assert.Equal(t, 3, visitor.termQueriesCounter) -} diff --git a/quesma/ast/query_traverse.go b/quesma/ast/query_traverse.go deleted file mode 100644 index 2f4f3d5a3..000000000 --- a/quesma/ast/query_traverse.go +++ /dev/null @@ -1,215 +0,0 @@ -// Copyright Quesma, licensed under the Elastic License 2.0. -// SPDX-License-Identifier: Elastic-2.0 -package ast - -import ( - "github.com/elastic/go-elasticsearch/v8/typedapi/types" -) - -type QueryTraverser struct { - Debug bool - PathMatched bool -} - -func (qt *QueryTraverser) TraverseBooleanQuery(b *types.BoolQuery, v QueryVisitor, path []string) { - if b == nil { - return - } - v.PreVisitBool(b, path) - for _, q := range b.Filter { - if qt.Debug { - path = append(path, "filter", "*") - } - qt.TraverseQuery(&q, v, path) - if qt.Debug { - path = path[:len(path)-2] - } - } - for _, q := range b.Should { - if qt.Debug { - path = append(path, "should", "*") - } - qt.TraverseQuery(&q, v, path) - if qt.Debug { - path = path[:len(path)-2] - } - } - for _, q := range b.Must { - if qt.Debug { - path = append(path, "must", "*") - } - qt.TraverseQuery(&q, v, path) - if qt.Debug { - path = path[:len(path)-2] - } - } - for _, q := range b.MustNot { - if qt.Debug { - path = append(path, "must_not", "*") - } - qt.TraverseQuery(&q, v, path) - if qt.Debug { - path = path[:len(path)-2] - } - } - v.PostVisitBool(b, path) -} - -func (qt *QueryTraverser) TraverseCombinedFieldsQuery(cfq *types.CombinedFieldsQuery, v QueryVisitor, path []string) { - if cfq == nil { - return - } - v.PreVisitCombinedFieldsQuery(cfq, path) - v.PostVisitCombinedFieldsQuery(cfq, path) -} - -func (qt *QueryTraverser) TraverseTypeQuery(t *types.TypeQuery, v QueryVisitor, path []string) { - if t == nil { - return - } - v.PreVisitTypeQuery(t, path) - v.PostVisitTypeQuery(t, path) -} - -func (qt *QueryTraverser) TraverseBoostingQuery(b *types.BoostingQuery, v QueryVisitor, path []string) { - if b == nil { - return - } - v.PreVisitBoostingQuery(b, path) - qt.TraverseQuery(b.Positive, v, path) - qt.TraverseQuery(b.Negative, v, path) - v.PostVisitBoostingQuery(b, path) -} - -func (qt *QueryTraverser) TraverseCommonTermsQuery(ctq *types.CommonTermsQuery, field string, v QueryVisitor, path []string) { - if ctq == nil { - return - } - v.PreVisitCommonTermsQuery(ctq, field, path) - v.PostVisitCommonTermsQuery(ctq, field, path) -} - -func (qt *QueryTraverser) TraverseTermQuery(t *types.TermQuery, field string, v QueryVisitor, path []string) { - if t == nil { - return - } - if qt.Debug { - path = append(path, "term", field) - } - v.PreVisitTerm(t, field, path) - v.PostVisitTerm(t, field, path) - if qt.Debug { - path = path[:len(path)-2] - _ = path - } -} - -func (qt *QueryTraverser) TraverseConstantScoreQuery(csq *types.ConstantScoreQuery, v QueryVisitor, path []string) { - if csq == nil { - return - } - v.PreVisitConstantScoreQuery(csq, path) - qt.TraverseQuery(csq.Filter, v, path) - v.PostVisitConstantScoreQuery(csq, path) -} - -func (qt *QueryTraverser) TraverseDistanceFeatureQuery(dfq types.DistanceFeatureQuery, v QueryVisitor, path []string) { - if dfq == nil { - return - } - v.PreVisitDistanceFeatureQuery(dfq, path) - v.PostVisitDistanceFeatureQuery(dfq, path) - -} - -func (qt *QueryTraverser) TraverseDismaxQuery(dq *types.DisMaxQuery, v QueryVisitor, path []string) { - if dq == nil { - return - } - v.PreVisitDisMaxQuery(dq, path) - for _, q := range dq.Queries { - qt.TraverseQuery(&q, v, path) - } - v.PostVisitDisMaxQuery(dq, path) -} - -func (*QueryTraverser) TraverseExistsQuery(eq *types.ExistsQuery, v QueryVisitor, path []string) { - if eq == nil { - return - } - - v.PreVisitExistsQuery(eq, path) - v.PostVisitExistsQuery(eq, path) -} - -func (*QueryTraverser) TraverseMatchQuery(mq *types.MatchQuery, field string, v QueryVisitor, path []string) { - if mq == nil { - return - } - v.PreVisitMatchQuery(mq, field, path) - v.PostVisitMatchQuery(mq, field, path) -} - -func (qt *QueryTraverser) TraverseMatchAllQuery(mq *types.MatchAllQuery, v QueryVisitor, path []string) { - if mq == nil { - return - } - v.PreVisitMatchAllQuery(mq, path) - v.PostVisitMatchAllQuery(mq, path) -} - -func (qt *QueryTraverser) TraverseMatchBoolPrefixQuery(mbpq *types.MatchBoolPrefixQuery, field string, v QueryVisitor, path []string) { - if mbpq == nil { - return - } - v.PreVisitMatchBoolPrefixQuery(mbpq, field, path) - v.PostVisitMatchBoolPrefixQuery(mbpq, field, path) -} - -func (qt *QueryTraverser) TraverseQuery(q *types.Query, v QueryVisitor, path []string) { - if q == nil { - return - } - if qt.Debug && !qt.PathMatched { - path = append(path, "query") - qt.PathMatched = true - } - v.PreVisitQuery(q, path) - if qt.Debug { - path = append(path, "bool") - } - qt.TraverseBooleanQuery(q.Bool, v, path) - if qt.Debug { - path = path[:len(path)-1] - } - for field, commonTermsQ := range q.Common { - qt.TraverseCommonTermsQuery(&commonTermsQ, field, v, path) - } - qt.TraverseTypeQuery(q.Type, v, path) - qt.TraverseBoostingQuery(q.Boosting, v, path) - qt.TraverseDismaxQuery(q.DisMax, v, path) - qt.TraverseCombinedFieldsQuery(q.CombinedFields, v, path) - qt.TraverseConstantScoreQuery(q.ConstantScore, v, path) - - qt.TraverseDistanceFeatureQuery(q.DistanceFeature, v, path) - - qt.TraverseExistsQuery(q.Exists, v, path) - - for field, matchQ := range q.Match { - qt.TraverseMatchQuery(&matchQ, field, v, path) - } - qt.TraverseMatchAllQuery(q.MatchAll, v, path) - - for field, matchBoolPrefixQ := range q.MatchBoolPrefix { - qt.TraverseMatchBoolPrefixQuery(&matchBoolPrefixQ, field, v, path) - } - for field, termQ := range q.Term { - qt.TraverseTermQuery(&termQ, field, v, path) - } - - v.PostVisitQuery(q, path) - if qt.Debug { - path = path[:len(path)-1] - _ = path - } -} diff --git a/quesma/ast/query_visitor.go b/quesma/ast/query_visitor.go deleted file mode 100644 index 3e8ba2383..000000000 --- a/quesma/ast/query_visitor.go +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright Quesma, licensed under the Elastic License 2.0. -// SPDX-License-Identifier: Elastic-2.0 -package ast - -import "github.com/elastic/go-elasticsearch/v8/typedapi/types" - -type QueryVisitor interface { - PreVisitQuery(q *types.Query, path []string) - PostVisitQuery(q *types.Query, path []string) - PreVisitBool(b *types.BoolQuery, path []string) - PostVisitBool(b *types.BoolQuery, path []string) - PreVisitBoostingQuery(b *types.BoostingQuery, path []string) - PostVisitBoostingQuery(b *types.BoostingQuery, path []string) - PreVisitTypeQuery(t *types.TypeQuery, path []string) - PostVisitTypeQuery(t *types.TypeQuery, path []string) - PreVisitCommonTermsQuery(ctq *types.CommonTermsQuery, field string, path []string) - PostVisitCommonTermsQuery(ctq *types.CommonTermsQuery, field string, path []string) - PreVisitCombinedFieldsQuery(ctq *types.CombinedFieldsQuery, path []string) - PostVisitCombinedFieldsQuery(ctq *types.CombinedFieldsQuery, path []string) - PreVisitTerm(t *types.TermQuery, field string, path []string) - PostVisitTerm(t *types.TermQuery, field string, path []string) - PreVisitConstantScoreQuery(csq *types.ConstantScoreQuery, path []string) - PostVisitConstantScoreQuery(csq *types.ConstantScoreQuery, path []string) - PreVisitDisMaxQuery(dmq *types.DisMaxQuery, path []string) - PostVisitDisMaxQuery(dmq *types.DisMaxQuery, path []string) - PreVisitDistanceFeatureQuery(dfq types.DistanceFeatureQuery, path []string) - PostVisitDistanceFeatureQuery(dfq types.DistanceFeatureQuery, path []string) - PreVisitExistsQuery(eq *types.ExistsQuery, path []string) - PostVisitExistsQuery(eq *types.ExistsQuery, path []string) - PreVisitMatchQuery(mq *types.MatchQuery, field string, path []string) - PostVisitMatchQuery(mq *types.MatchQuery, field string, path []string) - PreVisitMatchAllQuery(mq *types.MatchAllQuery, path []string) - PostVisitMatchAllQuery(mq *types.MatchAllQuery, path []string) - PreVisitMatchBoolPrefixQuery(mq *types.MatchBoolPrefixQuery, field string, path []string) - PostVisitMatchBoolPrefixQuery(mq *types.MatchBoolPrefixQuery, field string, path []string) -} diff --git a/quesma/go.mod b/quesma/go.mod index c618fbf08..2cb0924aa 100644 --- a/quesma/go.mod +++ b/quesma/go.mod @@ -66,7 +66,6 @@ require ( github.com/andybalholm/brotli v1.1.1 // indirect github.com/antlr4-go/antlr/v4 v4.13.1 github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect - github.com/elastic/go-elasticsearch/v8 v8.16.0 github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/go-faster/city v1.0.1 // indirect github.com/go-faster/errors v0.7.1 // indirect diff --git a/quesma/go.sum b/quesma/go.sum index ac677fa5e..5e696e0a3 100644 --- a/quesma/go.sum +++ b/quesma/go.sum @@ -29,8 +29,6 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/elastic/go-elasticsearch/v8 v8.16.0 h1:f7bR+iBz8GTAVhwyFO3hm4ixsz2eMaEy0QroYnXV3jE= -github.com/elastic/go-elasticsearch/v8 v8.16.0/go.mod h1:lGMlgKIbYoRvay3xWBeKahAiJOgmFDsjZC39nmO3H64= github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= github.com/go-faster/city v1.0.1 h1:4WAxSZ3V2Ws4QRDrscLEDcibJY8uf41H6AhXDrNDcGw=