Skip to content
Merged
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
12 changes: 12 additions & 0 deletions redisearch/aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,18 @@ func (a *AggregateQuery) Limit(offset int, num int) *AggregateQuery {
return a
}

//Load document fields from the document HASH objects (if they are not in the sortables)
func (a *AggregateQuery) Load( Properties []string) *AggregateQuery {
nproperties := len(Properties)
if nproperties > 0 {
a.AggregatePlan = a.AggregatePlan.Add("LOAD", nproperties)
for _, property := range Properties {
a.AggregatePlan = a.AggregatePlan.Add(fmt.Sprintf( "@%s", property ))
}
}
return a
}

//Adds a GROUPBY clause to the aggregate plan
func (a *AggregateQuery) GroupBy(group GroupBy) *AggregateQuery {
a.AggregatePlan = a.AggregatePlan.AddFlat(group.Serialize())
Expand Down
55 changes: 55 additions & 0 deletions redisearch/aggregate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,3 +523,58 @@ func TestAggregateQuery_CursorHasResults(t *testing.T) {
})
}
}

func TestAggregateQuery_Load(t *testing.T) {
type fields struct {
Query *redisearch.Query
AggregatePlan redis.Args
Paging *redisearch.Paging
Max int
WithSchema bool
Verbatim bool
WithCursor bool
Cursor *redisearch.Cursor
}
type args struct {
Properties []string
}
tests := []struct {
name string
fields fields
args args
want redis.Args
}{
{"TestAggregateQuery_Load_1",
fields{nil, redis.Args{}, nil, 0, false, false, false, nil},
args{[]string{"field1"}},
redis.Args{"*", "LOAD", 1, "@field1"},
},
{"TestAggregateQuery_Load_2",
fields{nil, redis.Args{}, nil, 0, false, false, false, nil},
args{[]string{"field1", "field2", "field3", "field4"}},
redis.Args{"*", "LOAD", 4, "@field1", "@field2", "@field3", "@field4"},
},
{"TestAggregateQuery_Load_Empty",
fields{nil, redis.Args{}, nil, 0, false, false, false, nil},
args{[]string{}},
redis.Args{"*"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
a := &redisearch.AggregateQuery{
Query: tt.fields.Query,
AggregatePlan: tt.fields.AggregatePlan,
Paging: tt.fields.Paging,
Max: tt.fields.Max,
WithSchema: tt.fields.WithSchema,
Verbatim: tt.fields.Verbatim,
WithCursor: tt.fields.WithCursor,
Cursor: tt.fields.Cursor,
}
if got := a.Load(tt.args.Properties).Serialize(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("Load() = %v, want %v", got, tt.want)
}
})
}
}