Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
289 changes: 220 additions & 69 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion external/epsearchast/v3/aliases.go → aliases.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package epsearchast_v3
package epsearchast

import "regexp"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package epsearchast_v3
package epsearchast

import (
"github.com/stretchr/testify/require"
Expand Down
6 changes: 3 additions & 3 deletions external/epsearchast/v3/ast.go → ast.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Package epsearchast_v3 implements structs and functions for working with the EP-Internal-Search-AST-v3 header.
package epsearchast_v3
// Package epsearchast implements structs and functions for working with the EP-Internal-Search-AST-v3 header.
package epsearchast

import (
"encoding/json"
Expand Down Expand Up @@ -102,7 +102,7 @@ func GetAst(jsonTxt string) (*AstNode, error) {

// The AstVisitor interface provides a way of specifying a [Visitor] for visiting an AST.
//
// This interface is clunky to use for conversions or when you need to return state, and you should use [epsearchast_v3.ReduceAst] instead.
// This interface is clunky to use for conversions or when you need to return state, and you should use [epsearchast.ReduceAst] instead.
// In particular because the return values are restricted to error, you need to manage and combine the state yourself, which can be more annoying than necessary.
//
// [Visitor]: https://en.wikipedia.org/wiki/Visitor_pattern
Expand Down
2 changes: 1 addition & 1 deletion external/epsearchast/v3/ast_test.go → ast_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package epsearchast_v3
package epsearchast

import (
"github.com/stretchr/testify/require"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package epsearchast_v3
package epsearchast

import (
"fmt"
Expand Down
168 changes: 162 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
volumes:
mongo-community:
mongo-community-search:

services:
postgres:
image: postgres:15.0-bullseye
ports:
- '20001:5432'
- '127.0.0.1:20001:5432'
environment:
POSTGRES_PASSWORD: admin
POSTGRES_USER: admin
Expand All @@ -13,12 +17,12 @@ services:
timeout: 5s
retries: 5
mongo:
image: mongo:7.0
image: mongodb/mongodb-community-server:8.2.1-ubi8
ports:
- '20002:27017'
- '127.0.0.1:20002:27017'
environment:
MONGO_INITDB_ROOT_USERNAME: admin
MONGO_INITDB_ROOT_PASSWORD: admin
MONGODB_INITDB_ROOT_USERNAME: admin
MONGODB_INITDB_ROOT_PASSWORD: admin
healthcheck:
test: [ "CMD-SHELL", "echo 'db.runCommand({ ping: 1 })' | mongosh mongodb://localhost:27017/test_db --quiet" ]
interval: 10s
Expand All @@ -28,7 +32,7 @@ services:
elasticsearch:
image: elasticsearch:7.17.25
ports:
- '20003:9200'
- '127.0.0.1:20003:9200'
environment:
discovery.type: single-node
ES_JAVA_OPTS: "-Xms1024m -Xmx1024m"
Expand All @@ -38,3 +42,155 @@ services:
timeout: 5s
retries: 5


mongo-community:
container_name: search-ast-helper-mongo-community
hostname: mongo-community
extra_hosts:
# We override the hostname for mongo to point to localhost.
# Because in the init mode mongo is only available to localhost.
# But we need the replicaset to be configured with a name other containers can see.
# https://github.com/docker-library/mongo/issues/339#issuecomment-2253159258
- "mongo-community:127.0.0.1"
#image: mongodb/mongodb-community-server:8.2.1-ubi8
image: mongo:8.2.1
command:
- "--bind_ip_all"
- "--replSet"
- "rs0"
- "--setParameter"
- "mongotHost=mongo-community-search:27027"
- "--setParameter"
- "searchIndexManagementHostAndPort=mongo-community-search:27027"
- "--setParameter"
- "skipAuthenticationToSearchIndexManagementServer=false"
- "--setParameter"
- "useGrpcForSearch=true"
- "--keyFile"
- "/keyfile"
- "--auth"
ports:
- '127.0.0.1:20004:27017'
volumes:
- mongo-community:/data/db:delegated
configs:
- source: mongo-rs-config.js
target: /docker-entrypoint-initdb.d/mongo-rs-config.js
- source: mongo-user-config.js
target: /docker-entrypoint-initdb.d/mongo-user-config.js
- source: keyfile
target: /keyfile
mode: 0400
uid: "999"
gid: "999"
healthcheck:
test: >
mongosh --quiet "localhost/test" --eval 'quit(db.runCommand({ ping: 1 }).ok ? 0 : 2)'
interval: 10s
timeout: 5s
retries: 10
start_period: 40s

mongo-community-search:
container_name: search-ast-helper-mongo-community-search
hostname: mongo-community-search
image: mongodb/mongodb-community-search:0.55.0
ports:
- '127.0.0.1:20005:27027'
volumes:
- mongo-community-search:/data/mongot:delegated
configs:
- source: config.default.yml
target: /mongot-community/config.default.yml
- source: passwordFile
target: /etc/mongot/secrets/passwordFile
mode: 0400
uid: "999"
gid: "999"
stop_grace_period: 1s
depends_on:
mongo-community:
condition: service_healthy



configs:
mongo-rs-config.js:
# language=javascript
content: |
print("\n\n\nStarting Replica Set Configuration\n\n\n");
rs.initiate({
_id: "rs0",
members: [
{ _id: 0, host: `mongo-community:27017` }
]
});

while (!rs.status().members.some(m => m.stateStr === "PRIMARY")) {
print("Waiting for primary...");
sleep(1000); // sleep 1 second
}

print("\n\n\nReplica Set Configuration Completed\n\n\n");

mongo-user-config.js:
# language=javascript
content: |
print("\n\n\nCreating Users\n\n\n");
var db = db.getSiblingDB("admin");
db.createUser(
{
user: "admin",
pwd: "admin",
mechanisms: ["SCRAM-SHA-256"],
roles: [
{
role: "root",
db: "admin"
}
]
},
{
w: "majority",
wtimeout: 5000
}
);

db.createUser(
{
user: "search",
pwd: "search",
mechanisms: ["SCRAM-SHA-256"],
roles: [ "searchCoordinator" ]
}
);

print("\n\n\nUsers created\n\n\n");
keyfile:
content: |
helloworld
passwordFile:
content: "search"
config.default.yml:
# language=yaml
content: |
syncSource:
replicaSet:
hostAndPort: "mongo-community:27017"
username: "search"
passwordFile: "/etc/mongot/secrets/passwordFile"
tls: false
storage:
dataPath: "/data/mongot"
server:
grpc:
address: "0.0.0.0:27027"
tls:
mode: "disabled"
metrics:
enabled: true
address: "0.0.0.0:9946"
healthCheck:
address: "0.0.0.0:8080"
logging:
verbosity: INFO
2 changes: 1 addition & 1 deletion external/epsearchast/v3/errors.go → errors.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package epsearchast_v3
package epsearchast

import "fmt"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package epsearchast_v3_es
package astes

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

"github.com/elasticpath/epcc-search-ast-helper"
)

type JsonObject map[string]any
Expand Down Expand Up @@ -150,7 +151,7 @@ func sortByDecreasingLength(groupKeys []string) {
})
}

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

func (d DefaultEsQueryBuilder) PostVisitAnd(rs []*JsonObject) (*JsonObject, error) {
return &JsonObject{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package epsearchast_v3_es
package astes

import (
"bytes"
"encoding/json"
"fmt"
epsearchast_v3 "github.com/elasticpath/epcc-search-ast-helper/external/epsearchast/v3"
"io/ioutil"
"net/http"
"os"
"testing"

"github.com/elasticpath/epcc-search-ast-helper"
)

const esBaseURL = "http://localhost:20003"
Expand All @@ -24,7 +25,7 @@ type testStruct struct {

func (t *testStruct) String() string {

ast, err := epsearchast_v3.GetAst(t.filter)
ast, err := epsearchast.GetAst(t.filter)

if err != nil {
panic(fmt.Sprintf("Failed to get filter: %s)", err))
Expand Down Expand Up @@ -1048,12 +1049,12 @@ func TestSmokeTestElasticSearchWithFilters(t *testing.T) {
}

// Build Elasticsearch query
ast, err := epsearchast_v3.GetAst(tc.filter)
ast, err := epsearchast.GetAst(tc.filter)
if err != nil {
t.Fatalf("Failed to parse filter: %v", err)
}

var qb epsearchast_v3.SemanticReducer[JsonObject] = DefaultEsQueryBuilder{
var qb epsearchast.SemanticReducer[JsonObject] = DefaultEsQueryBuilder{
OpTypeToFieldNames: map[string]*OperatorTypeToMultiFieldName{
"key_value_field.description": {
Wildcard: "key_value_field.description.wildcard",
Expand Down Expand Up @@ -1082,7 +1083,7 @@ func TestSmokeTestElasticSearchWithFilters(t *testing.T) {
DefaultFuzziness: "AUTO",
}

query, err := epsearchast_v3.SemanticReduceAst(ast, qb)
query, err := epsearchast.SemanticReduceAst(ast, qb)
if err != nil {
t.Fatalf("Failed to reduce AST: %v", err)
}
Expand Down
Loading
Loading