Skip to content

Commit bc92d04

Browse files
committed
Add more tests and comments on deprecated params
1 parent 02c3494 commit bc92d04

File tree

2 files changed

+104
-7
lines changed

2 files changed

+104
-7
lines changed

search_commands.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ type SpellCheckTerms struct {
114114
}
115115

116116
type FTExplainOptions struct {
117+
// Dialect 1,3 and 4 are deprecated since redis 8.0
117118
Dialect string
118119
}
119120

@@ -261,7 +262,8 @@ type FTAggregateOptions struct {
261262
WithCursor bool
262263
WithCursorOptions *FTAggregateWithCursor
263264
Params map[string]interface{}
264-
DialectVersion int
265+
// Dialect 1,3 and 4 are deprecated since redis 8.0
266+
DialectVersion int
265267
}
266268

267269
type FTSearchFilter struct {
@@ -293,8 +295,9 @@ type FTSearchSortBy struct {
293295
// More information about the options can be found
294296
// in the documentation for FT.SEARCH https://redis.io/docs/latest/commands/ft.search/
295297
type FTSearchOptions struct {
296-
NoContent bool
297-
Verbatim bool
298+
NoContent bool
299+
Verbatim bool
300+
// NoStopWords is deprecated since redis 8.0
298301
NoStopWords bool
299302
WithScores bool
300303
WithPayloads bool
@@ -322,8 +325,9 @@ type FTSearchOptions struct {
322325
Limit int
323326
// CountOnly sets LIMIT 0 0 to get the count - number of documents in the result set without actually returning the result set.
324327
// When using this option, the Limit and LimitOffset options are ignored.
325-
CountOnly bool
326-
Params map[string]interface{}
328+
CountOnly bool
329+
Params map[string]interface{}
330+
// Dialect 1,3 and 4 are deprecated since redis 8.0
327331
DialectVersion int
328332
}
329333

@@ -440,7 +444,8 @@ type IndexDefinition struct {
440444
type FTSpellCheckOptions struct {
441445
Distance int
442446
Terms *FTSpellCheckTerms
443-
Dialect int
447+
// Dialect 1,3 and 4 are deprecated since redis 8.0
448+
Dialect int
444449
}
445450

446451
type FTSpellCheckTerms struct {

search_test.go

Lines changed: 93 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1684,7 +1684,6 @@ var _ = Describe("RediSearch commands Resp 2", Label("search"), func() {
16841684
Expect(resUint8.Docs[0].ID).To(BeEquivalentTo("doc1"))
16851685
})
16861686

1687-
<<<<<<< HEAD
16881687
It("should fail when using a non-zero offset with a zero limit", Label("search", "ftsearch"), func() {
16891688
SkipBeforeRedisVersion(7.9, "requires Redis 8.x")
16901689
val, err := client.FTCreate(ctx, "testIdx", &redis.FTCreateOptions{}, &redis.FieldSchema{
@@ -2106,6 +2105,99 @@ var _ = Describe("RediSearch commands Resp 2", Label("search"), func() {
21062105
Expect(len(resLimit.Docs)).To(BeEquivalentTo(2))
21072106
})
21082107

2108+
It("should reject deprecated configuration keys", Label("search", "ftconfig"), func() {
2109+
SkipBeforeRedisVersion(7.9, "requires Redis 8.x")
2110+
// List of deprecated configuration keys.
2111+
deprecatedKeys := []string{
2112+
"_FREE_RESOURCE_ON_THREAD",
2113+
"_NUMERIC_COMPRESS",
2114+
"_NUMERIC_RANGES_PARENTS",
2115+
"_PRINT_PROFILE_CLOCK",
2116+
"_PRIORITIZE_INTERSECT_UNION_CHILDREN",
2117+
"BG_INDEX_SLEEP_GAP",
2118+
"CONN_PER_SHARD",
2119+
"CURSOR_MAX_IDLE",
2120+
"CURSOR_REPLY_THRESHOLD",
2121+
"DEFAULT_DIALECT",
2122+
"EXTLOAD",
2123+
"FORK_GC_CLEAN_THRESHOLD",
2124+
"FORK_GC_RETRY_INTERVAL",
2125+
"FORK_GC_RUN_INTERVAL",
2126+
"FORKGC_SLEEP_BEFORE_EXIT",
2127+
"FRISOINI",
2128+
"GC_POLICY",
2129+
"GCSCANSIZE",
2130+
"INDEX_CURSOR_LIMIT",
2131+
"MAXAGGREGATERESULTS",
2132+
"MAXDOCTABLESIZE",
2133+
"MAXPREFIXEXPANSIONS",
2134+
"MAXSEARCHRESULTS",
2135+
"MIN_OPERATION_WORKERS",
2136+
"MIN_PHONETIC_TERM_LEN",
2137+
"MINPREFIX",
2138+
"MINSTEMLEN",
2139+
"NO_MEM_POOLS",
2140+
"NOGC",
2141+
"ON_TIMEOUT",
2142+
"MULTI_TEXT_SLOP",
2143+
"PARTIAL_INDEXED_DOCS",
2144+
"RAW_DOCID_ENCODING",
2145+
"SEARCH_THREADS",
2146+
"TIERED_HNSW_BUFFER_LIMIT",
2147+
"TIMEOUT",
2148+
"TOPOLOGY_VALIDATION_TIMEOUT",
2149+
"UNION_ITERATOR_HEAP",
2150+
"VSS_MAX_RESIZE",
2151+
"WORKERS",
2152+
"WORKERS_PRIORITY_BIAS_THRESHOLD",
2153+
"MT_MODE",
2154+
"WORKER_THREADS",
2155+
}
2156+
2157+
for _, key := range deprecatedKeys {
2158+
_, err := client.FTConfigSet(ctx, key, "test_value").Result()
2159+
Expect(err).To(HaveOccurred())
2160+
}
2161+
2162+
val, err := client.ConfigGet(ctx, "*").Result()
2163+
Expect(err).NotTo(HaveOccurred())
2164+
// Since FT.CONFIG is deprecated since redis 8, use CONFIG instead with new search parameters.
2165+
keys := make([]string, 0, len(val))
2166+
for key := range val {
2167+
keys = append(keys, key)
2168+
}
2169+
Expect(keys).To(ContainElement(ContainSubstring("search")))
2170+
})
2171+
2172+
It("should return INF for MIN reducer and -INF for MAX reducer when no numeric values are present", Label("search", "ftaggregate"), func() {
2173+
SkipBeforeRedisVersion(7.9, "requires Redis 8.x")
2174+
val, err := client.FTCreate(ctx, "aggTestMinMax", &redis.FTCreateOptions{},
2175+
&redis.FieldSchema{FieldName: "grp", FieldType: redis.SearchFieldTypeText},
2176+
&redis.FieldSchema{FieldName: "n", FieldType: redis.SearchFieldTypeNumeric},
2177+
).Result()
2178+
Expect(err).NotTo(HaveOccurred())
2179+
Expect(val).To(BeEquivalentTo("OK"))
2180+
WaitForIndexing(client, "aggTestMinMax")
2181+
2182+
_, err = client.HSet(ctx, "doc1", "grp", "g1").Result()
2183+
Expect(err).NotTo(HaveOccurred())
2184+
2185+
reducers := []redis.FTAggregateReducer{
2186+
{Reducer: redis.SearchMin, Args: []interface{}{"@n"}, As: "minValue"},
2187+
{Reducer: redis.SearchMax, Args: []interface{}{"@n"}, As: "maxValue"},
2188+
}
2189+
groupBy := []redis.FTAggregateGroupBy{
2190+
{Fields: []interface{}{"@grp"}, Reduce: reducers},
2191+
}
2192+
options := &redis.FTAggregateOptions{GroupBy: groupBy}
2193+
res, err := client.FTAggregateWithArgs(ctx, "aggTestMinMax", "*", options).Result()
2194+
Expect(err).NotTo(HaveOccurred())
2195+
Expect(res.Rows).ToNot(BeEmpty())
2196+
2197+
Expect(res.Rows[0].Fields["minValue"]).To(BeEquivalentTo("inf"))
2198+
Expect(res.Rows[0].Fields["maxValue"]).To(BeEquivalentTo("-inf"))
2199+
})
2200+
21092201
})
21102202

21112203
func _assert_geosearch_result(result *redis.FTSearchResult, expectedDocIDs []string) {

0 commit comments

Comments
 (0)