Skip to content
Snippets Groups Projects
Commit 8fc4f2d4 authored by Alena Petraki's avatar Alena Petraki
Browse files

Merge branch 'master' into feature/PRXS-1619-AsyncSyncMethods

parents 5a42d06f cdfe0757
No related branches found
No related tags found
No related merge requests found
......@@ -57,16 +57,11 @@ func convertToMongo(ctx context.Context, tree *parser.Tree, env map[string]inter
}
c := &compiler{tree: tree, env: env, config: config, identifierRenameFn: identifierRenameFn}
v := c.compile(tree.Node)
switch e := v.(type) {
case bson.M:
b = e
case string:
b = bson.M{"$text": bson.M{"$search": e}}
default:
err = fmt.Errorf("invalid expression")
v, ok := c.compile(tree.Node).(bson.M)
if !ok || v == nil {
return nil, fmt.Errorf("invalid expression")
}
return
return v, nil
}
type compiler struct {
......
......@@ -50,10 +50,15 @@ func TestConvertToMongo(t *testing.T) {
{"time", fmt.Sprintf("d > Time.Time('%s')", now.Format(time.RFC3339)), nil, bson.M{"d": bson.M{"$gt": tm}}, false},
{"in", "In(s, [1,2,3])", nil, bson.M{"s": bson.M{"$in": []interface{}{1, 2, 3}}}, false},
{"in", "In(s, 1)", nil, bson.M{"s": bson.M{"$in": []interface{}{1}}}, false},
{"text search or id", "id", nil, nil, true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotB, err := ConvertToMongo(ctx, tt.eval, tt.env, nil)
if tt.wantErr {
require.Error(t, err)
return
}
require.NoError(t, err)
assert.Equal(t, tt.wantB, gotB)
})
......@@ -72,7 +77,7 @@ func BenchmarkConvertToMongo(b *testing.B) {
//fmt.Println(len(exp))
for i := 0; i < b.N; i++ {
ConvertToMongo(ctx, exp, nil, nil, expr.Patch(&testVisitor{}))
_, _ = ConvertToMongo(ctx, exp, nil, nil, expr.Patch(&testVisitor{}))
}
}
......
......@@ -54,6 +54,7 @@ type PreSaver interface {
type Filter struct {
ID []string
Data []*filter.Filter
// DEPRECATED Use Q instead
Search string // Поиск, одновременно поддерживается только один запрос
Q []string
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment