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
16 changes: 10 additions & 6 deletions redisearch/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package redisearch
import (
"errors"
"fmt"
"github.com/gomodule/redigo/redis"
"log"
"reflect"
"strconv"
"strings"
"log"
"github.com/gomodule/redigo/redis"
)

// Options are flags passed to the the abstract Index call, which receives them as interface{}, allowing
Expand Down Expand Up @@ -399,7 +399,7 @@ func (i *Client) Aggregate(q *AggregateQuery) (aggregateReply [][]string, total
hasCursor := q.WithCursor
validCursor := q.CursorHasResults()
var res []interface{} = nil
if ! validCursor {
if !validCursor {
args := redis.Args{i.name}
args = append(args, q.Serialize()...)
res, err = redis.Values(conn.Do("FT.AGGREGATE", args...))
Expand All @@ -411,9 +411,11 @@ func (i *Client) Aggregate(q *AggregateQuery) (aggregateReply [][]string, total
return
}
// has no cursor
if ! hasCursor {
if !hasCursor {
total = len(res) - 1
if total > 1 {
// there is a case when only 1 data from aggregate, it returns nothing
// then set total > 0 so the data will be return
if total > 0 {
aggregateReply = ProcessAggResponse(res[1:])
}
// has cursor
Expand All @@ -427,7 +429,9 @@ func (i *Client) Aggregate(q *AggregateQuery) (aggregateReply [][]string, total
return aggregateReply, total, err
}
total = len(partialResults) - 1
if total > 1 {
// there is a case when only 1 data from aggregate, it returns nothing
// then set total > 0 so the data will be return
if total > 0 {
aggregateReply = ProcessAggResponse(partialResults[1:])
}
}
Expand Down
11 changes: 6 additions & 5 deletions redisearch/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ type SortingKey struct {

func NewSortingKeyDir(field string, ascending bool) *SortingKey {
return &SortingKey{
Field: field,
Field: field,
Ascending: ascending,
}
}

func (s SortingKey) Serialize() redis.Args {
args := redis.Args{ s.Field }
args := redis.Args{s.Field}
if s.Ascending {
args = args.Add("ASC")
} else {
Expand Down Expand Up @@ -98,15 +98,16 @@ type Paging struct {
func NewPaging(offset int, num int) *Paging {
return &Paging{
Offset: offset,
Num: num,
Num: num,
}
}

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

if q.SortBy != nil {
args = args.Add("SORTBY").AddFlat( q.SortBy.Serialize() )
args = args.Add("SORTBY").AddFlat(q.SortBy.Serialize())
}

if q.HighlightOpts != nil {
Expand Down