mirror of
https://github.com/redis/go-redis.git
synced 2025-10-23 08:08:28 +03:00
fix(search): return results even if doc is empty (#3457)
* 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 * fix(doctest): fix assertions in doctests
This commit is contained in:
@@ -199,11 +199,11 @@ func ExampleClient_geoindex() {
|
|||||||
// OK
|
// OK
|
||||||
// OK
|
// OK
|
||||||
// OK
|
// OK
|
||||||
// {1 [{product:46885 <nil> <nil> <nil> map[$:{"city":"Denver","description":"Navy Blue Slippers","location":"-104.991531, 39.742043","price":45.99}]}]}
|
// {1 [{product:46885 <nil> <nil> <nil> map[$:{"city":"Denver","description":"Navy Blue Slippers","location":"-104.991531, 39.742043","price":45.99}] <nil>}]}
|
||||||
// OK
|
// OK
|
||||||
// OK
|
// OK
|
||||||
// OK
|
// OK
|
||||||
// OK
|
// OK
|
||||||
// OK
|
// OK
|
||||||
// {1 [{shape:4 <nil> <nil> <nil> map[$:[{"geom":"POINT (2 2)","name":"Purple Point"}]]}]}
|
// {1 [{shape:4 <nil> <nil> <nil> map[$:[{"geom":"POINT (2 2)","name":"Purple Point"}]] <nil>}]}
|
||||||
}
|
}
|
||||||
|
@@ -219,7 +219,7 @@ func ExampleClient_search_json() {
|
|||||||
// STEP_END
|
// STEP_END
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// {1 [{user:3 <nil> <nil> <nil> map[$:{"age":35,"city":"Tel Aviv","email":"paul.zamir@example.com","name":"Paul Zamir"}]}]}
|
// {1 [{user:3 <nil> <nil> <nil> map[$:{"age":35,"city":"Tel Aviv","email":"paul.zamir@example.com","name":"Paul Zamir"}] <nil>}]}
|
||||||
// London
|
// London
|
||||||
// Tel Aviv
|
// Tel Aviv
|
||||||
// 0
|
// 0
|
||||||
@@ -329,5 +329,5 @@ func ExampleClient_search_hash() {
|
|||||||
// STEP_END
|
// STEP_END
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// {1 [{huser:3 <nil> <nil> <nil> map[age:35 city:Tel Aviv email:paul.zamir@example.com name:Paul Zamir]}]}
|
// {1 [{huser:3 <nil> <nil> <nil> map[age:35 city:Tel Aviv email:paul.zamir@example.com name:Paul Zamir] <nil>}]}
|
||||||
}
|
}
|
||||||
|
@@ -257,6 +257,6 @@ func ExampleClient_search_qs() {
|
|||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// Documents found: 10
|
// Documents found: 10
|
||||||
// {1 [{bicycle:0 <nil> <nil> <nil> map[$:{"brand":"Velorim","condition":"new","description":"Small and powerful, the Jigger is the best ride for the smallest of tikes! This is the tiniest kids’ pedal bike on the market available without a coaster brake, the Jigger is the vehicle of choice for the rare tenacious little rider raring to go.","model":"Jigger","price":270}]}]}
|
// {1 [{bicycle:0 <nil> <nil> <nil> map[$:{"brand":"Velorim","condition":"new","description":"Small and powerful, the Jigger is the best ride for the smallest of tikes! This is the tiniest kids’ pedal bike on the market available without a coaster brake, the Jigger is the vehicle of choice for the rare tenacious little rider raring to go.","model":"Jigger","price":270}] <nil>}]}
|
||||||
// {1 [{bicycle:4 <nil> <nil> <nil> map[$:{"brand":"Noka Bikes","condition":"used","description":"Whether you want to try your hand at XC racing or are looking for a lively trail bike that's just as inspiring on the climbs as it is over rougher ground, the Wilder is one heck of a bike built specifically for short women. Both the frames and components have been tweaked to include a women’s saddle, different bars and unique colourway.","model":"Kahuna","price":3200}]}]}
|
// {1 [{bicycle:4 <nil> <nil> <nil> map[$:{"brand":"Noka Bikes","condition":"used","description":"Whether you want to try your hand at XC racing or are looking for a lively trail bike that's just as inspiring on the climbs as it is over rougher ground, the Wilder is one heck of a bike built specifically for short women. Both the frames and components have been tweaked to include a women’s saddle, different bars and unique colourway.","model":"Kahuna","price":3200}] <nil>}]}
|
||||||
}
|
}
|
||||||
|
@@ -474,6 +474,7 @@ type Document struct {
|
|||||||
Payload *string
|
Payload *string
|
||||||
SortKey *string
|
SortKey *string
|
||||||
Fields map[string]string
|
Fields map[string]string
|
||||||
|
Error error
|
||||||
}
|
}
|
||||||
|
|
||||||
type AggregateQuery []interface{}
|
type AggregateQuery []interface{}
|
||||||
@@ -1654,7 +1655,13 @@ func parseFTSearch(data []interface{}, noContent, withScores, withPayloads, with
|
|||||||
if i < len(data) {
|
if i < len(data) {
|
||||||
fields, ok := data[i].([]interface{})
|
fields, ok := data[i].([]interface{})
|
||||||
if !ok {
|
if !ok {
|
||||||
return FTSearchResult{}, fmt.Errorf("invalid document fields format")
|
if data[i] == proto.Nil || data[i] == nil {
|
||||||
|
doc.Error = proto.Nil
|
||||||
|
doc.Fields = map[string]string{}
|
||||||
|
fields = []interface{}{}
|
||||||
|
} else {
|
||||||
|
return FTSearchResult{}, fmt.Errorf("invalid document fields format")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for j := 0; j < len(fields); j += 2 {
|
for j := 0; j < len(fields); j += 2 {
|
||||||
|
Reference in New Issue
Block a user