Skip to content

Commit f3e61b4

Browse files
committed
fix(search): return results even if doc is empty
"If a relevant key expires while a query is running, an attempt to load the key's value will return a null array. However, the key is still counted in the total number of results." - Redis Search return documentation
1 parent 5aca9c2 commit f3e61b4

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

search_commands.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,7 @@ type Document struct {
474474
Payload *string
475475
SortKey *string
476476
Fields map[string]string
477+
Error error
477478
}
478479

479480
type AggregateQuery []interface{}
@@ -1654,7 +1655,13 @@ func parseFTSearch(data []interface{}, noContent, withScores, withPayloads, with
16541655
if i < len(data) {
16551656
fields, ok := data[i].([]interface{})
16561657
if !ok {
1657-
return FTSearchResult{}, fmt.Errorf("invalid document fields format")
1658+
if data[i] == proto.Nil || data[i] == nil {
1659+
doc.Error = proto.Nil
1660+
doc.Fields = map[string]string{}
1661+
fields = []interface{}{}
1662+
} else {
1663+
return FTSearchResult{}, fmt.Errorf("invalid document fields format")
1664+
}
16581665
}
16591666

16601667
for j := 0; j < len(fields); j += 2 {

0 commit comments

Comments
 (0)