Skip to content

Commit 0e402d8

Browse files
committed
Checkpoint
1 parent 878cd6f commit 0e402d8

File tree

4 files changed

+31
-84
lines changed

4 files changed

+31
-84
lines changed

README.md

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -639,8 +639,8 @@ func Example(ast *epsearchast_v3.AstNode, collection *mongo.Collection, tenantBo
639639

640640
The following operators are currently supported:
641641
- `text` - Full-text search with analyzers
642-
- `eq` - Exact case-sensitive equality matching (supports string and UUID fields)
643-
- `in` - Multiple value exact matching (supports string and UUID fields)
642+
- `eq` - Exact case-sensitive equality matching (string fields only)
643+
- `in` - Multiple value exact matching (string fields only)
644644
- `like` - Case-sensitive wildcard matching
645645
- `ilike` - Case-insensitive wildcard matching
646646
- `gt` - Greater than (lexicographic comparison for strings)
@@ -696,17 +696,12 @@ To support `like` and `ilike` operators with proper case sensitivity handling, y
696696
{
697697
"type": "token"
698698
}
699-
],
700-
"id": {
701-
"type": "token"
702-
}
699+
]
703700
}
704701
}
705702
}
706703
```
707704

708-
**Note on UUID Fields**: MongoDB Atlas Search (cloud) supports a dedicated `uuid` field type, but `token` type works for UUID string values in both Atlas Search and MongoDB Community Search editions. The query builder treats both the same way.
709-
710705
**Query Builder Configuration:**
711706

712707
The `FieldToMultiAnalyzers` map specifies which multi-analyzer to use for each field:
@@ -728,15 +723,15 @@ This allows you to mix fields with and without multi-analyzer support in the sam
728723
##### Limitations
729724

730725
1. The following operators are not yet implemented: `contains`, `contains_any`, `contains_all`, `is_null`
731-
2. Range operators (`gt`, `ge`, `lt`, `le`) perform lexicographic comparison on string fields. For numeric comparisons, ensure fields are indexed with appropriate numeric types
732-
3. Atlas Search requires proper [search index configuration](https://www.mongodb.com/docs/atlas/atlas-search/create-index/) with appropriate field types:
726+
2. The following field types are not currently supported: UUID fields, Date fields, Numeric fields (numbers are compared as strings)
727+
3. Range operators (`gt`, `ge`, `lt`, `le`) perform lexicographic comparison on string fields only
728+
4. Atlas Search requires proper [search index configuration](https://www.mongodb.com/docs/atlas/atlas-search/create-index/) with appropriate field types:
733729
- String fields used with `like`/`ilike` should be indexed with multi-analyzers as shown above
734730
- String fields used with `eq`/`in` should be indexed with `token` type
735731
- String fields used with range operators (`gt`/`ge`/`lt`/`le`) work with `token` type for lexicographic comparison
736-
- UUID fields should be indexed with `token` type
737732
- Text fields should be indexed with `string` type and an appropriate analyzer
738-
4. Unlike regular MongoDB queries, Atlas Search queries use the aggregation pipeline with the `$search` stage
739-
5. Additional filters (like tenant boundaries) should be added as separate `$match` stages in the pipeline
733+
5. Unlike regular MongoDB queries, Atlas Search queries use the aggregation pipeline with the `$search` stage
734+
6. Additional filters (like tenant boundaries) should be added as separate `$match` stages in the pipeline
740735

741736
### FAQ
742737

docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ services:
7070
- "/keyfile"
7171
- "--auth"
7272
ports:
73-
- '20004:27017'
73+
- '127.0.0.1:20004:27017'
7474
volumes:
7575
- mongo-community:/data/db:delegated
7676
configs:
@@ -96,7 +96,7 @@ services:
9696
hostname: mongo-community-search
9797
image: mongodb/mongodb-community-search:0.55.0
9898
ports:
99-
- 20005:27027
99+
- '127.0.0.1:20005:27027'
100100
volumes:
101101
- mongo-community-search:/data/mongot:delegated
102102
configs:

mongo/mongo_atlas_search_query_builder.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
package epsearchast_v3_mongo
1+
package astmongo
22

33
import (
44
"fmt"
55
"strings"
66

7-
epsearchast_v3 "github.com/elasticpath/epcc-search-ast-helper/external/epsearchast/v3"
8-
"go.mongodb.org/mongo-driver/bson"
7+
"github.com/elasticpath/epcc-search-ast-helper"
8+
"go.mongodb.org/mongo-driver/v2/bson"
99
)
1010

1111
type DefaultAtlasSearchQueryBuilder struct {
@@ -27,7 +27,7 @@ type StringMultiAnalyzers struct {
2727
WildcardCaseSensitive string
2828
}
2929

30-
var _ epsearchast_v3.SemanticReducer[bson.D] = (*DefaultAtlasSearchQueryBuilder)(nil)
30+
var _ epsearchast.SemanticReducer[bson.D] = (*DefaultAtlasSearchQueryBuilder)(nil)
3131

3232
func (d DefaultAtlasSearchQueryBuilder) PostVisitAnd(rs []*bson.D) (*bson.D, error) {
3333
// https://www.mongodb.com/docs/atlas/atlas-search/compound/

mongo/mongo_atlas_search_query_builder_int_test.go

Lines changed: 17 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
package epsearchast_v3_mongo
1+
package astmongo
22

33
import (
44
"context"
55
"fmt"
66
"testing"
77
"time"
88

9-
epsearchast_v3 "github.com/elasticpath/epcc-search-ast-helper/external/epsearchast/v3"
10-
"go.mongodb.org/mongo-driver/bson"
11-
"go.mongodb.org/mongo-driver/mongo"
12-
"go.mongodb.org/mongo-driver/mongo/options"
9+
"github.com/elasticpath/epcc-search-ast-helper"
10+
"go.mongodb.org/mongo-driver/v2/bson"
11+
"go.mongodb.org/mongo-driver/v2/mongo"
12+
"go.mongodb.org/mongo-driver/v2/mongo/options"
1313
)
1414

1515
func TestSmokeTestAtlasSearchWithFilters(t *testing.T) {
@@ -19,7 +19,7 @@ func TestSmokeTestAtlasSearchWithFilters(t *testing.T) {
1919

2020
// Connect to Atlas Search enabled MongoDB
2121
ctx := context.Background()
22-
atlasClient, err := mongo.Connect(ctx, options.Client().ApplyURI("mongodb://admin:admin@localhost:20004/?replicaSet=rs0&directConnection=true"))
22+
atlasClient, err := mongo.Connect(options.Client().ApplyURI("mongodb://admin:admin@localhost:20004/?replicaSet=rs0&directConnection=true"))
2323
if err != nil {
2424
t.Fatalf("Failed to connect to MongoDB Atlas Search: %v", err)
2525
}
@@ -36,19 +36,22 @@ func TestSmokeTestAtlasSearchWithFilters(t *testing.T) {
3636
"nullable_string_field": nil,
3737
"text_field": "Developers like IDEs",
3838
"uuid_field": "550e8400-e29b-41d4-a716-446655440001",
39+
"date_field": time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC),
3940
},
4041
bson.M{
4142
"string_field": "test2 test2",
4243
"array_field": []string{"c c", "d d"},
4344
"nullable_string_field": "yay yay",
4445
"text_field": "I like Development Environments",
4546
"uuid_field": "550e8400-e29b-41d4-a716-446655440002",
47+
"date_field": time.Date(2024, 6, 15, 0, 0, 0, 0, time.UTC),
4648
},
4749
bson.M{
4850
"string_field": "test3 test3",
4951
"array_field": []string{"c c"},
5052
"text_field": "Vim is the best",
5153
"uuid_field": "550e8400-e29b-41d4-a716-446655440003",
54+
"date_field": time.Date(2024, 12, 31, 0, 0, 0, 0, time.UTC),
5255
},
5356
}
5457

@@ -339,60 +342,6 @@ func TestSmokeTestAtlasSearchWithFilters(t *testing.T) {
339342
}`,
340343
count: 2,
341344
},
342-
{
343-
// Test EQ on UUID field - exact match
344-
//language=JSON
345-
filter: `{
346-
"type": "EQ",
347-
"args": ["uuid_field", "550e8400-e29b-41d4-a716-446655440001"]
348-
}`,
349-
count: 1,
350-
},
351-
{
352-
// Test EQ on UUID field - different UUID
353-
//language=JSON
354-
filter: `{
355-
"type": "EQ",
356-
"args": ["uuid_field", "550e8400-e29b-41d4-a716-446655440002"]
357-
}`,
358-
count: 1,
359-
},
360-
{
361-
// Test EQ on UUID field - non-existent UUID
362-
//language=JSON
363-
filter: `{
364-
"type": "EQ",
365-
"args": ["uuid_field", "550e8400-e29b-41d4-a716-446655440099"]
366-
}`,
367-
count: 0,
368-
},
369-
{
370-
// Test IN on UUID field - multiple values
371-
//language=JSON
372-
filter: `{
373-
"type": "IN",
374-
"args": ["uuid_field", "550e8400-e29b-41d4-a716-446655440001", "550e8400-e29b-41d4-a716-446655440002"]
375-
}`,
376-
count: 2,
377-
},
378-
{
379-
// Test IN on UUID field - single value
380-
//language=JSON
381-
filter: `{
382-
"type": "IN",
383-
"args": ["uuid_field", "550e8400-e29b-41d4-a716-446655440003"]
384-
}`,
385-
count: 1,
386-
},
387-
{
388-
// Test IN on UUID field - no matches
389-
//language=JSON
390-
filter: `{
391-
"type": "IN",
392-
"args": ["uuid_field", "550e8400-e29b-41d4-a716-446655440099", "550e8400-e29b-41d4-a716-446655440098"]
393-
}`,
394-
count: 0,
395-
},
396345
{
397346
// Test GT on string field - lexicographic comparison
398347
//language=JSON
@@ -530,9 +479,12 @@ func TestSmokeTestAtlasSearchWithFilters(t *testing.T) {
530479
},
531480
}},
532481
// uuid_field: indexed as token for equals and in operations
533-
// Note: token type works for UUID string values
534482
{"uuid_field", bson.D{
535-
{"type", "token"},
483+
{"type", "uuid"},
484+
}},
485+
// date_field: indexed as token for range and equality operations
486+
{"date_field", bson.D{
487+
{"type", "date"},
536488
}},
537489
}},
538490
}},
@@ -565,7 +517,7 @@ func TestSmokeTestAtlasSearchWithFilters(t *testing.T) {
565517

566518
// Create query builder
567519
// Configure multi-analyzers for fields that support LIKE/ILIKE
568-
var qb epsearchast_v3.SemanticReducer[bson.D] = DefaultAtlasSearchQueryBuilder{
520+
var qb epsearchast.SemanticReducer[bson.D] = DefaultAtlasSearchQueryBuilder{
569521
FieldToMultiAnalyzers: map[string]*StringMultiAnalyzers{
570522
"string_field": {
571523
WildcardCaseInsensitive: "keywordAnalyzer",
@@ -579,12 +531,12 @@ func TestSmokeTestAtlasSearchWithFilters(t *testing.T) {
579531
}
580532

581533
// Create Query Object
582-
ast, err := epsearchast_v3.GetAst(tc.filter)
534+
ast, err := epsearchast.GetAst(tc.filter)
583535
if err != nil {
584536
t.Fatalf("Failed to get filter: %v", err)
585537
}
586538

587-
query, err := epsearchast_v3.SemanticReduceAst(ast, qb)
539+
query, err := epsearchast.SemanticReduceAst(ast, qb)
588540

589541
if err != nil {
590542
t.Fatalf("Failed to reduce AST: %v", err)

0 commit comments

Comments
 (0)