Skip to content

Commit

Permalink
Resolves #50 - Use correct acronym for ES
Browse files Browse the repository at this point in the history
  • Loading branch information
steve-r-west committed Nov 29, 2024
1 parent 64f8175 commit 9a94979
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 51 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -400,13 +400,13 @@ The following examples shows how to generate a Elastic Search Query with this li
```go
package example
import epsearchast_v3 "github.com/elasticpath/epcc-search-ast-helper/external/epsearchast/v3"
import epsearchast_v3_els "github.com/elasticpath/epcc-search-ast-helper/external/epsearchast/v3/els"
import epsearchast_v3_es "github.com/elasticpath/epcc-search-ast-helper/external/epsearchast/v3/els"

func Example(ast *epsearchast_v3.AstNode, tenantBoundaryId string) (string, error) {
// Not Shown: Validation

// Create query builder
var qb epsearchast_v3.SemanticReducer[epsearchast_v3_els.JsonObject] = epsearchast_v3_els.LowerCaseEmail{}
var qb epsearchast_v3.SemanticReducer[epsearchast_v3_es.JsonObject] = epsearchast_v3_es.LowerCaseEmail{}

// Create Query Object
queryObj, err := epsearchast_v3.SemanticReduceAst(ast, qb)
Expand All @@ -419,7 +419,7 @@ func Example(ast *epsearchast_v3.AstNode, tenantBoundaryId string) (string, err
}

type LowerCaseEmail struct {
epsearchast_v3_els.DefaultElsQueryBuilder
epsearchast_v3_es.DefaultEsQueryBuilder
}

func (l *LowerCaseEmail) VisitEq(first, second string) (*bson.D, error) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package epsearchast_v3_els
package epsearchast_v3_es

import (
epsearchast_v3 "github.com/elasticpath/epcc-search-ast-helper/external/epsearchast/v3"
"strings"
)

type DefaultElsQueryBuilder struct {
type DefaultEsQueryBuilder struct {
OpTypeToFieldNames map[string]*OperatorTypeToMultiFieldName
}

Expand All @@ -31,41 +31,41 @@ type OperatorTypeToMultiFieldName struct {
Wildcard string
}

var _ epsearchast_v3.SemanticReducer[JsonObject] = (*DefaultElsQueryBuilder)(nil)
var _ epsearchast_v3.SemanticReducer[JsonObject] = (*DefaultEsQueryBuilder)(nil)

func (d DefaultElsQueryBuilder) PostVisitAnd(rs []*JsonObject) (*JsonObject, error) {
func (d DefaultEsQueryBuilder) PostVisitAnd(rs []*JsonObject) (*JsonObject, error) {
return (*JsonObject)(&map[string]interface{}{
"bool": map[string]interface{}{
"must": rs,
},
}), nil
}

func (d DefaultElsQueryBuilder) VisitIn(args ...string) (*JsonObject, error) {
func (d DefaultEsQueryBuilder) VisitIn(args ...string) (*JsonObject, error) {
return (*JsonObject)(&map[string]interface{}{
"terms": map[string]interface{}{
d.getFieldMapping(args[0]).Equality: args[1:],
},
}), nil
}

func (d DefaultElsQueryBuilder) VisitEq(first, second string) (*JsonObject, error) {
func (d DefaultEsQueryBuilder) VisitEq(first, second string) (*JsonObject, error) {
return (*JsonObject)(&map[string]interface{}{
"term": map[string]interface{}{
d.getFieldMapping(first).Equality: second,
},
}), nil
}

func (d DefaultElsQueryBuilder) VisitContains(first, second string) (*JsonObject, error) {
func (d DefaultEsQueryBuilder) VisitContains(first, second string) (*JsonObject, error) {
return (*JsonObject)(&map[string]interface{}{
"term": map[string]interface{}{
d.getFieldMapping(first).Array: second,
},
}), nil
}

func (d DefaultElsQueryBuilder) VisitText(first, second string) (*JsonObject, error) {
func (d DefaultEsQueryBuilder) VisitText(first, second string) (*JsonObject, error) {
return (*JsonObject)(&map[string]interface{}{
"match": map[string]interface{}{
d.getFieldMapping(first).Text: second,
Expand All @@ -75,7 +75,7 @@ func (d DefaultElsQueryBuilder) VisitText(first, second string) (*JsonObject, er

// Useful doc: https://www.elastic.co/guide/en/elasticsearch/reference/7.17/query-dsl-range-query.html

func (d DefaultElsQueryBuilder) VisitLe(first, second string) (*JsonObject, error) {
func (d DefaultEsQueryBuilder) VisitLe(first, second string) (*JsonObject, error) {
return (*JsonObject)(&map[string]interface{}{
"range": map[string]interface{}{
d.getFieldMapping(first).Relational: map[string]interface{}{
Expand All @@ -85,7 +85,7 @@ func (d DefaultElsQueryBuilder) VisitLe(first, second string) (*JsonObject, erro
}), nil
}

func (d DefaultElsQueryBuilder) VisitLt(first, second string) (*JsonObject, error) {
func (d DefaultEsQueryBuilder) VisitLt(first, second string) (*JsonObject, error) {
return (*JsonObject)(&map[string]interface{}{
"range": map[string]interface{}{
d.getFieldMapping(first).Relational: map[string]interface{}{
Expand All @@ -95,7 +95,7 @@ func (d DefaultElsQueryBuilder) VisitLt(first, second string) (*JsonObject, erro
}), nil
}

func (d DefaultElsQueryBuilder) VisitGe(first, second string) (*JsonObject, error) {
func (d DefaultEsQueryBuilder) VisitGe(first, second string) (*JsonObject, error) {
return (*JsonObject)(&map[string]interface{}{
"range": map[string]interface{}{
d.getFieldMapping(first).Relational: map[string]interface{}{
Expand All @@ -105,7 +105,7 @@ func (d DefaultElsQueryBuilder) VisitGe(first, second string) (*JsonObject, erro
}), nil
}

func (d DefaultElsQueryBuilder) VisitGt(first, second string) (*JsonObject, error) {
func (d DefaultEsQueryBuilder) VisitGt(first, second string) (*JsonObject, error) {
return (*JsonObject)(&map[string]interface{}{
"range": map[string]interface{}{
d.getFieldMapping(first).Relational: map[string]interface{}{
Expand All @@ -115,7 +115,7 @@ func (d DefaultElsQueryBuilder) VisitGt(first, second string) (*JsonObject, erro
}), nil
}

func (d DefaultElsQueryBuilder) VisitLike(first, second string) (*JsonObject, error) {
func (d DefaultEsQueryBuilder) VisitLike(first, second string) (*JsonObject, error) {
return (*JsonObject)(&map[string]interface{}{
"wildcard": map[string]interface{}{
d.getFieldMapping(first).Wildcard: map[string]interface{}{
Expand All @@ -126,7 +126,7 @@ func (d DefaultElsQueryBuilder) VisitLike(first, second string) (*JsonObject, er
}), nil
}

func (d DefaultElsQueryBuilder) VisitILike(first, second string) (*JsonObject, error) {
func (d DefaultEsQueryBuilder) VisitILike(first, second string) (*JsonObject, error) {
return (*JsonObject)(&map[string]interface{}{
"wildcard": map[string]interface{}{
d.getFieldMapping(first).Wildcard: map[string]interface{}{
Expand All @@ -137,7 +137,7 @@ func (d DefaultElsQueryBuilder) VisitILike(first, second string) (*JsonObject, e
}), nil
}

func (d DefaultElsQueryBuilder) VisitIsNull(first string) (*JsonObject, error) {
func (d DefaultEsQueryBuilder) VisitIsNull(first string) (*JsonObject, error) {
return (*JsonObject)(&map[string]interface{}{
"bool": map[string]interface{}{
"must_not": map[string]interface{}{
Expand All @@ -150,7 +150,7 @@ func (d DefaultElsQueryBuilder) VisitIsNull(first string) (*JsonObject, error) {
}

// getFieldMapping returns the field name to use for a given operator type, the struct is always guaranteed to return f, if nothing was set.
func (d DefaultElsQueryBuilder) getFieldMapping(f string) *OperatorTypeToMultiFieldName {
func (d DefaultEsQueryBuilder) getFieldMapping(f string) *OperatorTypeToMultiFieldName {
var o *OperatorTypeToMultiFieldName

if d.OpTypeToFieldNames[f] == nil {
Expand Down Expand Up @@ -196,7 +196,7 @@ func (d DefaultElsQueryBuilder) getFieldMapping(f string) *OperatorTypeToMultiFi
return o
}

func (d DefaultElsQueryBuilder) EscapeWildcardString(s string) string {
func (d DefaultEsQueryBuilder) EscapeWildcardString(s string) string {
str := strings.ReplaceAll(s, "?", `\?`)
str = strings.ReplaceAll(str, "*", `\*`)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package epsearchast_v3_els
package epsearchast_v3_es

import (
"bytes"
Expand Down Expand Up @@ -239,7 +239,7 @@ func TestSmokeTestElasticSearchWithFilters(t *testing.T) {
t.Fatalf("Failed to parse filter: %v", err)
}

var qb epsearchast_v3.SemanticReducer[JsonObject] = DefaultElsQueryBuilder{}
var qb epsearchast_v3.SemanticReducer[JsonObject] = DefaultEsQueryBuilder{}
query, err := epsearchast_v3.SemanticReduceAst(ast, qb)
if err != nil {
t.Fatalf("Failed to reduce AST: %v", err)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package epsearchast_v3_els_test
package epsearchast_v3_es_test

import (
"encoding/json"
"fmt"
epsearchast_v3 "github.com/elasticpath/epcc-search-ast-helper/external/epsearchast/v3"
epsearchast_v3_els "github.com/elasticpath/epcc-search-ast-helper/external/epsearchast/v3/els"
epsearchast_v3_es "github.com/elasticpath/epcc-search-ast-helper/external/epsearchast/v3/es"
"github.com/stretchr/testify/require"
"strings"
"testing"
Expand Down Expand Up @@ -32,7 +32,7 @@ func TestSimpleBinaryEqOperatorGeneratesCorrectQuery(t *testing.T) {
astNode, err := epsearchast_v3.GetAst(jsonTxt)
require.NoError(t, err)

var qb epsearchast_v3.SemanticReducer[epsearchast_v3_els.JsonObject] = epsearchast_v3_els.DefaultElsQueryBuilder{}
var qb epsearchast_v3.SemanticReducer[epsearchast_v3_es.JsonObject] = epsearchast_v3_es.DefaultEsQueryBuilder{}

// Execute SUT
query, err := epsearchast_v3.SemanticReduceAst(astNode, qb)
Expand Down Expand Up @@ -67,8 +67,8 @@ func TestSimpleBinaryEqOperatorGeneratesCorrectQueryWithFieldOverride(t *testing
astNode, err := epsearchast_v3.GetAst(jsonTxt)
require.NoError(t, err)

var qb epsearchast_v3.SemanticReducer[epsearchast_v3_els.JsonObject] = epsearchast_v3_els.DefaultElsQueryBuilder{
OpTypeToFieldNames: map[string]*epsearchast_v3_els.OperatorTypeToMultiFieldName{
var qb epsearchast_v3.SemanticReducer[epsearchast_v3_es.JsonObject] = epsearchast_v3_es.DefaultEsQueryBuilder{
OpTypeToFieldNames: map[string]*epsearchast_v3_es.OperatorTypeToMultiFieldName{
"email": {
Equality: "email.keyword",
},
Expand Down Expand Up @@ -110,7 +110,7 @@ func TestSimpleBinaryLeOperatorGeneratesCorrectQuery(t *testing.T) {
astNode, err := epsearchast_v3.GetAst(jsonTxt)
require.NoError(t, err)

var qb epsearchast_v3.SemanticReducer[epsearchast_v3_els.JsonObject] = epsearchast_v3_els.DefaultElsQueryBuilder{}
var qb epsearchast_v3.SemanticReducer[epsearchast_v3_es.JsonObject] = epsearchast_v3_es.DefaultEsQueryBuilder{}

// Execute SUT
query, err := epsearchast_v3.SemanticReduceAst(astNode, qb)
Expand Down Expand Up @@ -147,8 +147,8 @@ func TestSimpleBinaryLeOperatorGeneratesCorrectQueryWithFieldOverride(t *testing
astNode, err := epsearchast_v3.GetAst(jsonTxt)
require.NoError(t, err)

var qb epsearchast_v3.SemanticReducer[epsearchast_v3_els.JsonObject] = epsearchast_v3_els.DefaultElsQueryBuilder{
OpTypeToFieldNames: map[string]*epsearchast_v3_els.OperatorTypeToMultiFieldName{
var qb epsearchast_v3.SemanticReducer[epsearchast_v3_es.JsonObject] = epsearchast_v3_es.DefaultEsQueryBuilder{
OpTypeToFieldNames: map[string]*epsearchast_v3_es.OperatorTypeToMultiFieldName{
"amount": {
Relational: "amount.range",
},
Expand Down Expand Up @@ -190,7 +190,7 @@ func TestSimpleBinaryLtOperatorGeneratesCorrectQuery(t *testing.T) {
astNode, err := epsearchast_v3.GetAst(jsonTxt)
require.NoError(t, err)

var qb epsearchast_v3.SemanticReducer[epsearchast_v3_els.JsonObject] = epsearchast_v3_els.DefaultElsQueryBuilder{}
var qb epsearchast_v3.SemanticReducer[epsearchast_v3_es.JsonObject] = epsearchast_v3_es.DefaultEsQueryBuilder{}

// Execute SUT
query, err := epsearchast_v3.SemanticReduceAst(astNode, qb)
Expand Down Expand Up @@ -227,8 +227,8 @@ func TestSimpleBinaryLtOperatorGeneratesCorrectQueryWithFieldOverride(t *testing
astNode, err := epsearchast_v3.GetAst(jsonTxt)
require.NoError(t, err)

var qb epsearchast_v3.SemanticReducer[epsearchast_v3_els.JsonObject] = epsearchast_v3_els.DefaultElsQueryBuilder{
OpTypeToFieldNames: map[string]*epsearchast_v3_els.OperatorTypeToMultiFieldName{
var qb epsearchast_v3.SemanticReducer[epsearchast_v3_es.JsonObject] = epsearchast_v3_es.DefaultEsQueryBuilder{
OpTypeToFieldNames: map[string]*epsearchast_v3_es.OperatorTypeToMultiFieldName{
"amount": {
Relational: "amount.range",
},
Expand Down Expand Up @@ -270,7 +270,7 @@ func TestSimpleBinaryGtOperatorGeneratesCorrectQuery(t *testing.T) {
astNode, err := epsearchast_v3.GetAst(jsonTxt)
require.NoError(t, err)

var qb epsearchast_v3.SemanticReducer[epsearchast_v3_els.JsonObject] = epsearchast_v3_els.DefaultElsQueryBuilder{}
var qb epsearchast_v3.SemanticReducer[epsearchast_v3_es.JsonObject] = epsearchast_v3_es.DefaultEsQueryBuilder{}

// Execute SUT
query, err := epsearchast_v3.SemanticReduceAst(astNode, qb)
Expand Down Expand Up @@ -307,8 +307,8 @@ func TestSimpleBinaryGtOperatorGeneratesCorrectQueryWithFieldOverride(t *testing
astNode, err := epsearchast_v3.GetAst(jsonTxt)
require.NoError(t, err)

var qb epsearchast_v3.SemanticReducer[epsearchast_v3_els.JsonObject] = epsearchast_v3_els.DefaultElsQueryBuilder{
OpTypeToFieldNames: map[string]*epsearchast_v3_els.OperatorTypeToMultiFieldName{
var qb epsearchast_v3.SemanticReducer[epsearchast_v3_es.JsonObject] = epsearchast_v3_es.DefaultEsQueryBuilder{
OpTypeToFieldNames: map[string]*epsearchast_v3_es.OperatorTypeToMultiFieldName{
"amount": {
Relational: "amount.range",
},
Expand Down Expand Up @@ -350,7 +350,7 @@ func TestSimpleBinaryGEOperatorGeneratesCorrectQuery(t *testing.T) {
astNode, err := epsearchast_v3.GetAst(jsonTxt)
require.NoError(t, err)

var qb epsearchast_v3.SemanticReducer[epsearchast_v3_els.JsonObject] = epsearchast_v3_els.DefaultElsQueryBuilder{}
var qb epsearchast_v3.SemanticReducer[epsearchast_v3_es.JsonObject] = epsearchast_v3_es.DefaultEsQueryBuilder{}

// Execute SUT
query, err := epsearchast_v3.SemanticReduceAst(astNode, qb)
Expand Down Expand Up @@ -387,8 +387,8 @@ func TestSimpleBinaryGEOperatorGeneratesCorrectQueryWithFieldOverride(t *testing
astNode, err := epsearchast_v3.GetAst(jsonTxt)
require.NoError(t, err)

var qb epsearchast_v3.SemanticReducer[epsearchast_v3_els.JsonObject] = epsearchast_v3_els.DefaultElsQueryBuilder{
OpTypeToFieldNames: map[string]*epsearchast_v3_els.OperatorTypeToMultiFieldName{
var qb epsearchast_v3.SemanticReducer[epsearchast_v3_es.JsonObject] = epsearchast_v3_es.DefaultEsQueryBuilder{
OpTypeToFieldNames: map[string]*epsearchast_v3_es.OperatorTypeToMultiFieldName{
"amount": {
Relational: "amount.range",
},
Expand Down Expand Up @@ -431,7 +431,7 @@ func TestSimpleBinaryLikeOperatorGeneratesCorrectQuery(t *testing.T) {
astNode, err := epsearchast_v3.GetAst(jsonTxt)
require.NoError(t, err)

var qb epsearchast_v3.SemanticReducer[epsearchast_v3_els.JsonObject] = epsearchast_v3_els.DefaultElsQueryBuilder{}
var qb epsearchast_v3.SemanticReducer[epsearchast_v3_es.JsonObject] = epsearchast_v3_es.DefaultEsQueryBuilder{}

// Execute SUT
query, err := epsearchast_v3.SemanticReduceAst(astNode, qb)
Expand Down Expand Up @@ -469,8 +469,8 @@ func TestSimpleBinaryLikeOperatorGeneratesCorrectQueryWithFieldOverride(t *testi
astNode, err := epsearchast_v3.GetAst(jsonTxt)
require.NoError(t, err)

var qb epsearchast_v3.SemanticReducer[epsearchast_v3_els.JsonObject] = epsearchast_v3_els.DefaultElsQueryBuilder{
OpTypeToFieldNames: map[string]*epsearchast_v3_els.OperatorTypeToMultiFieldName{
var qb epsearchast_v3.SemanticReducer[epsearchast_v3_es.JsonObject] = epsearchast_v3_es.DefaultEsQueryBuilder{
OpTypeToFieldNames: map[string]*epsearchast_v3_es.OperatorTypeToMultiFieldName{
"email": {
Wildcard: "email.keyword",
},
Expand Down Expand Up @@ -530,7 +530,7 @@ func TestSimpleBinaryLikeOperatorGeneratesCorrectQueryWithWildcards(t *testing.T
astNode, err := epsearchast_v3.GetAst(jsonTxt)
require.NoError(t, err)

var qb epsearchast_v3.SemanticReducer[epsearchast_v3_els.JsonObject] = epsearchast_v3_els.DefaultElsQueryBuilder{}
var qb epsearchast_v3.SemanticReducer[epsearchast_v3_es.JsonObject] = epsearchast_v3_es.DefaultEsQueryBuilder{}

// Execute SUT
query, err := epsearchast_v3.SemanticReduceAst(astNode, qb)
Expand Down Expand Up @@ -596,8 +596,8 @@ func TestSimpleRecursiveStructure(t *testing.T) {
astNode, err := epsearchast_v3.GetAst(jsonTxt)
require.NoError(t, err)

var qb epsearchast_v3.SemanticReducer[epsearchast_v3_els.JsonObject] = epsearchast_v3_els.DefaultElsQueryBuilder{
OpTypeToFieldNames: map[string]*epsearchast_v3_els.OperatorTypeToMultiFieldName{
var qb epsearchast_v3.SemanticReducer[epsearchast_v3_es.JsonObject] = epsearchast_v3_es.DefaultEsQueryBuilder{
OpTypeToFieldNames: map[string]*epsearchast_v3_es.OperatorTypeToMultiFieldName{
"status": {
Equality: "status.keyword",
},
Expand Down Expand Up @@ -637,7 +637,7 @@ func TestSimpleBinaryTextOperatorGeneratesCorrectQuery(t *testing.T) {
astNode, err := epsearchast_v3.GetAst(jsonTxt)
require.NoError(t, err)

var qb epsearchast_v3.SemanticReducer[epsearchast_v3_els.JsonObject] = epsearchast_v3_els.DefaultElsQueryBuilder{}
var qb epsearchast_v3.SemanticReducer[epsearchast_v3_es.JsonObject] = epsearchast_v3_es.DefaultEsQueryBuilder{}

// Execute SUT
query, err := epsearchast_v3.SemanticReduceAst(astNode, qb)
Expand Down Expand Up @@ -672,8 +672,8 @@ func TestSimpleBinaryTextOperatorGeneratesCorrectQueryWithFieldOverride(t *testi
astNode, err := epsearchast_v3.GetAst(jsonTxt)
require.NoError(t, err)

var qb epsearchast_v3.SemanticReducer[epsearchast_v3_els.JsonObject] = epsearchast_v3_els.DefaultElsQueryBuilder{
OpTypeToFieldNames: map[string]*epsearchast_v3_els.OperatorTypeToMultiFieldName{
var qb epsearchast_v3.SemanticReducer[epsearchast_v3_es.JsonObject] = epsearchast_v3_es.DefaultEsQueryBuilder{
OpTypeToFieldNames: map[string]*epsearchast_v3_es.OperatorTypeToMultiFieldName{
"description": {
Text: "description.text",
},
Expand Down Expand Up @@ -716,7 +716,7 @@ func TestSimpleUnaryIsNullOperatorGeneratesCorrectQuery(t *testing.T) {
astNode, err := epsearchast_v3.GetAst(jsonTxt)
require.NoError(t, err)

var qb epsearchast_v3.SemanticReducer[epsearchast_v3_els.JsonObject] = epsearchast_v3_els.DefaultElsQueryBuilder{}
var qb epsearchast_v3.SemanticReducer[epsearchast_v3_es.JsonObject] = epsearchast_v3_es.DefaultEsQueryBuilder{}

// Execute SUT
query, err := epsearchast_v3.SemanticReduceAst(astNode, qb)
Expand Down Expand Up @@ -754,8 +754,8 @@ func TestSimpleUnaryIsNullOperatorGeneratesCorrectQueryWithFieldOverride(t *test
astNode, err := epsearchast_v3.GetAst(jsonTxt)
require.NoError(t, err)

var qb epsearchast_v3.SemanticReducer[epsearchast_v3_els.JsonObject] = epsearchast_v3_els.DefaultElsQueryBuilder{
OpTypeToFieldNames: map[string]*epsearchast_v3_els.OperatorTypeToMultiFieldName{
var qb epsearchast_v3.SemanticReducer[epsearchast_v3_es.JsonObject] = epsearchast_v3_es.DefaultEsQueryBuilder{
OpTypeToFieldNames: map[string]*epsearchast_v3_es.OperatorTypeToMultiFieldName{
"sort_order": {
Equality: "sort_order.keyword",
},
Expand Down

0 comments on commit 9a94979

Please sign in to comment.