Skip to content

Commit 2ad24bb

Browse files
committed
Merge branch 'master' of https://github.com/RediSearch/redisearch-go into extend.coverage
2 parents 7c3434d + e440655 commit 2ad24bb

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

redisearch/client.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ package redisearch
33
import (
44
"errors"
55
"fmt"
6+
"github.com/gomodule/redigo/redis"
7+
"log"
68
"reflect"
79
"strconv"
810
"strings"
9-
"log"
10-
"github.com/gomodule/redigo/redis"
1111
)
1212

1313
// Options are flags passed to the the abstract Index call, which receives them as interface{}, allowing
@@ -399,7 +399,7 @@ func (i *Client) Aggregate(q *AggregateQuery) (aggregateReply [][]string, total
399399
hasCursor := q.WithCursor
400400
validCursor := q.CursorHasResults()
401401
var res []interface{} = nil
402-
if ! validCursor {
402+
if !validCursor {
403403
args := redis.Args{i.name}
404404
args = append(args, q.Serialize()...)
405405
res, err = redis.Values(conn.Do("FT.AGGREGATE", args...))
@@ -411,9 +411,11 @@ func (i *Client) Aggregate(q *AggregateQuery) (aggregateReply [][]string, total
411411
return
412412
}
413413
// has no cursor
414-
if ! hasCursor {
414+
if !hasCursor {
415415
total = len(res) - 1
416-
if total > 1 {
416+
// there is a case when only 1 data from aggregate, it returns nothing
417+
// then set total > 0 so the data will be return
418+
if total > 0 {
417419
aggregateReply = ProcessAggResponse(res[1:])
418420
}
419421
// has cursor
@@ -427,7 +429,9 @@ func (i *Client) Aggregate(q *AggregateQuery) (aggregateReply [][]string, total
427429
return aggregateReply, total, err
428430
}
429431
total = len(partialResults) - 1
430-
if total > 1 {
432+
// there is a case when only 1 data from aggregate, it returns nothing
433+
// then set total > 0 so the data will be return
434+
if total > 0 {
431435
aggregateReply = ProcessAggResponse(partialResults[1:])
432436
}
433437
}

redisearch/query.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ type SortingKey struct {
3838

3939
func NewSortingKeyDir(field string, ascending bool) *SortingKey {
4040
return &SortingKey{
41-
Field: field,
41+
Field: field,
4242
Ascending: ascending,
4343
}
4444
}
4545

4646
func (s SortingKey) Serialize() redis.Args {
47-
args := redis.Args{ s.Field }
47+
args := redis.Args{s.Field}
4848
if s.Ascending {
4949
args = args.Add("ASC")
5050
} else {
@@ -98,15 +98,16 @@ type Paging struct {
9898
func NewPaging(offset int, num int) *Paging {
9999
return &Paging{
100100
Offset: offset,
101-
Num: num,
101+
Num: num,
102102
}
103103
}
104104

105105
func (p Paging) serialize() redis.Args {
106106
args := redis.Args{}
107107
// only serialize something if it's different than the default
108108
// The default is 0 10
109-
if p.Offset != DefaultOffset || p.Num != DefaultNum {
109+
// when either offset or num is default number, then need to set limit too
110+
if !(p.Offset == DefaultOffset && p.Num == DefaultNum) {
110111
args = args.Add("LIMIT", p.Offset, p.Num)
111112
}
112113
return args
@@ -166,7 +167,7 @@ func (q Query) serialize() redis.Args {
166167
}
167168

168169
if q.SortBy != nil {
169-
args = args.Add("SORTBY").AddFlat( q.SortBy.Serialize() )
170+
args = args.Add("SORTBY").AddFlat(q.SortBy.Serialize())
170171
}
171172

172173
if q.HighlightOpts != nil {

0 commit comments

Comments
 (0)