Skip to content

Commit 3bc85d8

Browse files
andy-stark-redisndyakov
authored andcommitted
DOC-5102 added CountOnly search example for docs (#3345)
1 parent 7222449 commit 3bc85d8

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

doctests/home_json_example_test.go

+28
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,32 @@ func ExampleClient_search_json() {
152152
// >>> Tel Aviv
153153
// STEP_END
154154

155+
// STEP_START query2count_only
156+
citiesResult2, err := rdb.FTSearchWithArgs(
157+
ctx,
158+
"idx:users",
159+
"Paul",
160+
&redis.FTSearchOptions{
161+
Return: []redis.FTSearchReturn{
162+
{
163+
FieldName: "$.city",
164+
As: "city",
165+
},
166+
},
167+
CountOnly: true,
168+
},
169+
).Result()
170+
171+
if err != nil {
172+
panic(err)
173+
}
174+
175+
// The `Total` field has the correct number of docs found
176+
// by the query but the `Docs` slice is empty.
177+
fmt.Println(len(citiesResult2.Docs)) // >>> 0
178+
fmt.Println(citiesResult2.Total) // >>> 2
179+
// STEP_END
180+
155181
// STEP_START query3
156182
aggOptions := redis.FTAggregateOptions{
157183
GroupBy: []redis.FTAggregateGroupBy{
@@ -196,6 +222,8 @@ func ExampleClient_search_json() {
196222
// {1 [{user:3 <nil> <nil> <nil> map[$:{"age":35,"city":"Tel Aviv","email":"[email protected]","name":"Paul Zamir"}]}]}
197223
// London
198224
// Tel Aviv
225+
// 0
226+
// 2
199227
// London - 1
200228
// Tel Aviv - 2
201229
}

0 commit comments

Comments
 (0)