Skip to content

Commit 990cadb

Browse files
committed
Add clone method to hybrid search commands
1 parent c646288 commit 990cadb

File tree

1 file changed

+105
-0
lines changed

1 file changed

+105
-0
lines changed

search_commands.go

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2302,6 +2302,111 @@ func (cmd *FTHybridCmd) readReply(rd *proto.Reader) (err error) {
23022302
return nil
23032303
}
23042304

2305+
func (cmd *FTHybridCmd) Clone() Cmder {
2306+
val := FTHybridResult{
2307+
TotalResults: cmd.val.TotalResults,
2308+
ExecutionTime: cmd.val.ExecutionTime,
2309+
}
2310+
if cmd.val.Results != nil {
2311+
val.Results = make([]map[string]interface{}, len(cmd.val.Results))
2312+
for i, result := range cmd.val.Results {
2313+
val.Results[i] = make(map[string]interface{}, len(result))
2314+
for k, v := range result {
2315+
val.Results[i][k] = v
2316+
}
2317+
}
2318+
}
2319+
if cmd.val.Warnings != nil {
2320+
val.Warnings = make([]string, len(cmd.val.Warnings))
2321+
copy(val.Warnings, cmd.val.Warnings)
2322+
}
2323+
2324+
var cursorVal *FTHybridCursorResult
2325+
if cmd.cursorVal != nil {
2326+
cursorVal = &FTHybridCursorResult{
2327+
SearchCursorID: cmd.cursorVal.SearchCursorID,
2328+
VsimCursorID: cmd.cursorVal.VsimCursorID,
2329+
}
2330+
}
2331+
2332+
var options *FTHybridOptions
2333+
if cmd.options != nil {
2334+
options = &FTHybridOptions{
2335+
CountExpressions: cmd.options.CountExpressions,
2336+
Load: cmd.options.Load,
2337+
Filter: cmd.options.Filter,
2338+
LimitOffset: cmd.options.LimitOffset,
2339+
Limit: cmd.options.Limit,
2340+
ExplainScore: cmd.options.ExplainScore,
2341+
Timeout: cmd.options.Timeout,
2342+
WithCursor: cmd.options.WithCursor,
2343+
}
2344+
// Clone slices and maps
2345+
if cmd.options.SearchExpressions != nil {
2346+
options.SearchExpressions = make([]FTHybridSearchExpression, len(cmd.options.SearchExpressions))
2347+
copy(options.SearchExpressions, cmd.options.SearchExpressions)
2348+
}
2349+
if cmd.options.VectorExpressions != nil {
2350+
options.VectorExpressions = make([]FTHybridVectorExpression, len(cmd.options.VectorExpressions))
2351+
copy(options.VectorExpressions, cmd.options.VectorExpressions)
2352+
}
2353+
if cmd.options.Combine != nil {
2354+
options.Combine = &FTHybridCombineOptions{
2355+
Method: cmd.options.Combine.Method,
2356+
Count: cmd.options.Combine.Count,
2357+
Window: cmd.options.Combine.Window,
2358+
Constant: cmd.options.Combine.Constant,
2359+
Alpha: cmd.options.Combine.Alpha,
2360+
Beta: cmd.options.Combine.Beta,
2361+
YieldScoreAs: cmd.options.Combine.YieldScoreAs,
2362+
}
2363+
}
2364+
if cmd.options.GroupBy != nil {
2365+
options.GroupBy = &FTHybridGroupBy{
2366+
Count: cmd.options.GroupBy.Count,
2367+
ReduceFunc: cmd.options.GroupBy.ReduceFunc,
2368+
ReduceCount: cmd.options.GroupBy.ReduceCount,
2369+
}
2370+
if cmd.options.GroupBy.Fields != nil {
2371+
options.GroupBy.Fields = make([]string, len(cmd.options.GroupBy.Fields))
2372+
copy(options.GroupBy.Fields, cmd.options.GroupBy.Fields)
2373+
}
2374+
if cmd.options.GroupBy.ReduceParams != nil {
2375+
options.GroupBy.ReduceParams = make([]interface{}, len(cmd.options.GroupBy.ReduceParams))
2376+
copy(options.GroupBy.ReduceParams, cmd.options.GroupBy.ReduceParams)
2377+
}
2378+
}
2379+
if cmd.options.Apply != nil {
2380+
options.Apply = make([]FTHybridApply, len(cmd.options.Apply))
2381+
copy(options.Apply, cmd.options.Apply)
2382+
}
2383+
if cmd.options.SortBy != nil {
2384+
options.SortBy = make([]FTSearchSortBy, len(cmd.options.SortBy))
2385+
copy(options.SortBy, cmd.options.SortBy)
2386+
}
2387+
if cmd.options.Params != nil {
2388+
options.Params = make(map[string]interface{}, len(cmd.options.Params))
2389+
for k, v := range cmd.options.Params {
2390+
options.Params[k] = v
2391+
}
2392+
}
2393+
if cmd.options.WithCursorOptions != nil {
2394+
options.WithCursorOptions = &FTHybridWithCursor{
2395+
MaxIdle: cmd.options.WithCursorOptions.MaxIdle,
2396+
Count: cmd.options.WithCursorOptions.Count,
2397+
}
2398+
}
2399+
}
2400+
2401+
return &FTHybridCmd{
2402+
baseCmd: cmd.cloneBaseCmd(),
2403+
val: val,
2404+
cursorVal: cursorVal,
2405+
options: options,
2406+
withCursor: cmd.withCursor,
2407+
}
2408+
}
2409+
23052410
// FTSearch - Executes a search query on an index.
23062411
// The 'index' parameter specifies the index to search, and the 'query' parameter specifies the search query.
23072412
// For more information, please refer to the Redis documentation about [FT.SEARCH].

0 commit comments

Comments
 (0)