From 9cfefa68964d09d0b1d2c6a4ccbbfad13a051ef3 Mon Sep 17 00:00:00 2001 From: Nedyalko Dyakov <1547186+ndyakov@users.noreply.github.com> Date: Thu, 31 Jul 2025 15:21:05 +0300 Subject: [PATCH] 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 --- doctests/geo_index_test.go | 4 ++-- doctests/home_json_example_test.go | 4 ++-- doctests/search_quickstart_test.go | 4 ++-- search_commands.go | 9 ++++++++- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/doctests/geo_index_test.go b/doctests/geo_index_test.go index c497b722..2e944274 100644 --- a/doctests/geo_index_test.go +++ b/doctests/geo_index_test.go @@ -199,11 +199,11 @@ func ExampleClient_geoindex() { // OK // OK // OK - // {1 [{product:46885 map[$:{"city":"Denver","description":"Navy Blue Slippers","location":"-104.991531, 39.742043","price":45.99}]}]} + // {1 [{product:46885 map[$:{"city":"Denver","description":"Navy Blue Slippers","location":"-104.991531, 39.742043","price":45.99}] }]} // OK // OK // OK // OK // OK - // {1 [{shape:4 map[$:[{"geom":"POINT (2 2)","name":"Purple Point"}]]}]} + // {1 [{shape:4 map[$:[{"geom":"POINT (2 2)","name":"Purple Point"}]] }]} } diff --git a/doctests/home_json_example_test.go b/doctests/home_json_example_test.go index f32bf8d1..d2af4d73 100644 --- a/doctests/home_json_example_test.go +++ b/doctests/home_json_example_test.go @@ -219,7 +219,7 @@ func ExampleClient_search_json() { // STEP_END // Output: - // {1 [{user:3 map[$:{"age":35,"city":"Tel Aviv","email":"paul.zamir@example.com","name":"Paul Zamir"}]}]} + // {1 [{user:3 map[$:{"age":35,"city":"Tel Aviv","email":"paul.zamir@example.com","name":"Paul Zamir"}] }]} // London // Tel Aviv // 0 @@ -329,5 +329,5 @@ func ExampleClient_search_hash() { // STEP_END // Output: - // {1 [{huser:3 map[age:35 city:Tel Aviv email:paul.zamir@example.com name:Paul Zamir]}]} + // {1 [{huser:3 map[age:35 city:Tel Aviv email:paul.zamir@example.com name:Paul Zamir] }]} } diff --git a/doctests/search_quickstart_test.go b/doctests/search_quickstart_test.go index ce5033bc..a41c9c5c 100644 --- a/doctests/search_quickstart_test.go +++ b/doctests/search_quickstart_test.go @@ -257,6 +257,6 @@ func ExampleClient_search_qs() { // Output: // Documents found: 10 - // {1 [{bicycle:0 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:4 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:0 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:4 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}] }]} } diff --git a/search_commands.go b/search_commands.go index b31baaa7..6552f553 100644 --- a/search_commands.go +++ b/search_commands.go @@ -474,6 +474,7 @@ type Document struct { Payload *string SortKey *string Fields map[string]string + Error error } type AggregateQuery []interface{} @@ -1654,7 +1655,13 @@ func parseFTSearch(data []interface{}, noContent, withScores, withPayloads, with if i < len(data) { fields, ok := data[i].([]interface{}) 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 {