RediSearch / redisearch-go

Go client for RediSearch
https://redisearch.io
BSD 3-Clause "New" or "Revised" License
288 stars 65 forks source link

The cap of Document slice returned by the Search method should be the variable total. #148

Closed xjplke closed 2 years ago

xjplke commented 2 years ago

https://github.com/RediSearch/redisearch-go/blob/7a5af817fbc0755cc59c366e487c7a480788b963/redisearch/client.go#L115 The cap of Document slice returned by the search method should be the variable total.

    if total, err = redis.Int(res[0], nil); err != nil {
        return
    }

        // docs = make([]Document, 0, len(res)-1)
    docs = make([]Document, 0, total)

This does not result in serious errors.

But I think len(res)-1 is not in line with the programmer's intention.

gkorland commented 2 years ago

@xjplke it shouldn't be total since total represent the total amount of results while the actual amount of results can be limited by LIMIT, but it seems like the right code should be:

docs = make([]Document, 0, len(res)/2)
xjplke commented 2 years ago

@xjplke it shouldn't be total since total represent the total amount of results while the actual amount of results can be limited by LIMIT, but it seems like the right code should be:

docs = make([]Document, 0, len(res)/2)

Yes, you are right. I missed the impact of LIMIT.