@@ -512,7 +512,7 @@ func (c cmdable) FTAggregate(ctx context.Context, index string, query string) *M
512
512
return cmd
513
513
}
514
514
515
- func FTAggregateQuery (query string , options * FTAggregateOptions ) AggregateQuery {
515
+ func FTAggregateQuery (query string , options * FTAggregateOptions ) ( AggregateQuery , error ) {
516
516
queryArgs := []interface {}{query }
517
517
if options != nil {
518
518
if options .Verbatim {
@@ -528,7 +528,7 @@ func FTAggregateQuery(query string, options *FTAggregateOptions) AggregateQuery
528
528
}
529
529
530
530
if options .LoadAll && options .Load != nil {
531
- panic ("FT.AGGREGATE: LOADALL and LOAD are mutually exclusive" )
531
+ return nil , fmt . Errorf ("FT.AGGREGATE: LOADALL and LOAD are mutually exclusive" )
532
532
}
533
533
if options .LoadAll {
534
534
queryArgs = append (queryArgs , "LOAD" , "*" )
@@ -584,7 +584,7 @@ func FTAggregateQuery(query string, options *FTAggregateOptions) AggregateQuery
584
584
for _ , sortBy := range options .SortBy {
585
585
sortByOptions = append (sortByOptions , sortBy .FieldName )
586
586
if sortBy .Asc && sortBy .Desc {
587
- panic ("FT.AGGREGATE: ASC and DESC are mutually exclusive" )
587
+ return nil , fmt . Errorf ("FT.AGGREGATE: ASC and DESC are mutually exclusive" )
588
588
}
589
589
if sortBy .Asc {
590
590
sortByOptions = append (sortByOptions , "ASC" )
@@ -629,7 +629,7 @@ func FTAggregateQuery(query string, options *FTAggregateOptions) AggregateQuery
629
629
queryArgs = append (queryArgs , "DIALECT" , 2 )
630
630
}
631
631
}
632
- return queryArgs
632
+ return queryArgs , nil
633
633
}
634
634
635
635
func ProcessAggregateResult (data []interface {}) (* FTAggregateResult , error ) {
@@ -731,7 +731,9 @@ func (c cmdable) FTAggregateWithArgs(ctx context.Context, index string, query st
731
731
args = append (args , "ADDSCORES" )
732
732
}
733
733
if options .LoadAll && options .Load != nil {
734
- panic ("FT.AGGREGATE: LOADALL and LOAD are mutually exclusive" )
734
+ cmd := NewAggregateCmd (ctx , args ... )
735
+ cmd .SetErr (fmt .Errorf ("FT.AGGREGATE: LOADALL and LOAD are mutually exclusive" ))
736
+ return cmd
735
737
}
736
738
if options .LoadAll {
737
739
args = append (args , "LOAD" , "*" )
@@ -784,7 +786,9 @@ func (c cmdable) FTAggregateWithArgs(ctx context.Context, index string, query st
784
786
for _ , sortBy := range options .SortBy {
785
787
sortByOptions = append (sortByOptions , sortBy .FieldName )
786
788
if sortBy .Asc && sortBy .Desc {
787
- panic ("FT.AGGREGATE: ASC and DESC are mutually exclusive" )
789
+ cmd := NewAggregateCmd (ctx , args ... )
790
+ cmd .SetErr (fmt .Errorf ("FT.AGGREGATE: ASC and DESC are mutually exclusive" ))
791
+ return cmd
788
792
}
789
793
if sortBy .Asc {
790
794
sortByOptions = append (sortByOptions , "ASC" )
@@ -932,7 +936,9 @@ func (c cmdable) FTCreate(ctx context.Context, index string, options *FTCreateOp
932
936
args = append (args , "ON" , "JSON" )
933
937
}
934
938
if options .OnHash && options .OnJSON {
935
- panic ("FT.CREATE: ON HASH and ON JSON are mutually exclusive" )
939
+ cmd := NewStatusCmd (ctx , args ... )
940
+ cmd .SetErr (fmt .Errorf ("FT.CREATE: ON HASH and ON JSON are mutually exclusive" ))
941
+ return cmd
936
942
}
937
943
if options .Prefix != nil {
938
944
args = append (args , "PREFIX" , len (options .Prefix ))
@@ -983,12 +989,16 @@ func (c cmdable) FTCreate(ctx context.Context, index string, options *FTCreateOp
983
989
}
984
990
}
985
991
if schema == nil {
986
- panic ("FT.CREATE: SCHEMA is required" )
992
+ cmd := NewStatusCmd (ctx , args ... )
993
+ cmd .SetErr (fmt .Errorf ("FT.CREATE: SCHEMA is required" ))
994
+ return cmd
987
995
}
988
996
args = append (args , "SCHEMA" )
989
997
for _ , schema := range schema {
990
998
if schema .FieldName == "" || schema .FieldType == SearchFieldTypeInvalid {
991
- panic ("FT.CREATE: SCHEMA FieldName and FieldType are required" )
999
+ cmd := NewStatusCmd (ctx , args ... )
1000
+ cmd .SetErr (fmt .Errorf ("FT.CREATE: SCHEMA FieldName and FieldType are required" ))
1001
+ return cmd
992
1002
}
993
1003
args = append (args , schema .FieldName )
994
1004
if schema .As != "" {
@@ -997,7 +1007,9 @@ func (c cmdable) FTCreate(ctx context.Context, index string, options *FTCreateOp
997
1007
args = append (args , schema .FieldType .String ())
998
1008
if schema .VectorArgs != nil {
999
1009
if schema .FieldType != SearchFieldTypeVector {
1000
- panic ("FT.CREATE: SCHEMA FieldType VECTOR is required for VectorArgs" )
1010
+ cmd := NewStatusCmd (ctx , args ... )
1011
+ cmd .SetErr (fmt .Errorf ("FT.CREATE: SCHEMA FieldType VECTOR is required for VectorArgs" ))
1012
+ return cmd
1001
1013
}
1002
1014
// Check mutual exclusivity of vector options
1003
1015
optionCount := 0
@@ -1011,12 +1023,16 @@ func (c cmdable) FTCreate(ctx context.Context, index string, options *FTCreateOp
1011
1023
optionCount ++
1012
1024
}
1013
1025
if optionCount != 1 {
1014
- panic ("FT.CREATE: SCHEMA VectorArgs must have exactly one of FlatOptions, HNSWOptions, or VamanaOptions" )
1026
+ cmd := NewStatusCmd (ctx , args ... )
1027
+ cmd .SetErr (fmt .Errorf ("FT.CREATE: SCHEMA VectorArgs must have exactly one of FlatOptions, HNSWOptions, or VamanaOptions" ))
1028
+ return cmd
1015
1029
}
1016
1030
if schema .VectorArgs .FlatOptions != nil {
1017
1031
args = append (args , "FLAT" )
1018
1032
if schema .VectorArgs .FlatOptions .Type == "" || schema .VectorArgs .FlatOptions .Dim == 0 || schema .VectorArgs .FlatOptions .DistanceMetric == "" {
1019
- panic ("FT.CREATE: Type, Dim and DistanceMetric are required for VECTOR FLAT" )
1033
+ cmd := NewStatusCmd (ctx , args ... )
1034
+ cmd .SetErr (fmt .Errorf ("FT.CREATE: Type, Dim and DistanceMetric are required for VECTOR FLAT" ))
1035
+ return cmd
1020
1036
}
1021
1037
flatArgs := []interface {}{
1022
1038
"TYPE" , schema .VectorArgs .FlatOptions .Type ,
@@ -1035,7 +1051,9 @@ func (c cmdable) FTCreate(ctx context.Context, index string, options *FTCreateOp
1035
1051
if schema .VectorArgs .HNSWOptions != nil {
1036
1052
args = append (args , "HNSW" )
1037
1053
if schema .VectorArgs .HNSWOptions .Type == "" || schema .VectorArgs .HNSWOptions .Dim == 0 || schema .VectorArgs .HNSWOptions .DistanceMetric == "" {
1038
- panic ("FT.CREATE: Type, Dim and DistanceMetric are required for VECTOR HNSW" )
1054
+ cmd := NewStatusCmd (ctx , args ... )
1055
+ cmd .SetErr (fmt .Errorf ("FT.CREATE: Type, Dim and DistanceMetric are required for VECTOR HNSW" ))
1056
+ return cmd
1039
1057
}
1040
1058
hnswArgs := []interface {}{
1041
1059
"TYPE" , schema .VectorArgs .HNSWOptions .Type ,
@@ -1061,9 +1079,11 @@ func (c cmdable) FTCreate(ctx context.Context, index string, options *FTCreateOp
1061
1079
args = append (args , hnswArgs ... )
1062
1080
}
1063
1081
if schema .VectorArgs .VamanaOptions != nil {
1064
- args = append (args , "VAMANA" )
1082
+ args = append (args , "SVS- VAMANA" )
1065
1083
if schema .VectorArgs .VamanaOptions .Type == "" || schema .VectorArgs .VamanaOptions .Dim == 0 || schema .VectorArgs .VamanaOptions .DistanceMetric == "" {
1066
- panic ("FT.CREATE: Type, Dim and DistanceMetric are required for VECTOR VAMANA" )
1084
+ cmd := NewStatusCmd (ctx , args ... )
1085
+ cmd .SetErr (fmt .Errorf ("FT.CREATE: Type, Dim and DistanceMetric are required for VECTOR VAMANA" ))
1086
+ return cmd
1067
1087
}
1068
1088
vamanaArgs := []interface {}{
1069
1089
"TYPE" , schema .VectorArgs .VamanaOptions .Type ,
@@ -1097,7 +1117,9 @@ func (c cmdable) FTCreate(ctx context.Context, index string, options *FTCreateOp
1097
1117
}
1098
1118
if schema .GeoShapeFieldType != "" {
1099
1119
if schema .FieldType != SearchFieldTypeGeoShape {
1100
- panic ("FT.CREATE: SCHEMA FieldType GEOSHAPE is required for GeoShapeFieldType" )
1120
+ cmd := NewStatusCmd (ctx , args ... )
1121
+ cmd .SetErr (fmt .Errorf ("FT.CREATE: SCHEMA FieldType GEOSHAPE is required for GeoShapeFieldType" ))
1122
+ return cmd
1101
1123
}
1102
1124
args = append (args , schema .GeoShapeFieldType )
1103
1125
}
@@ -1255,7 +1277,7 @@ func (c cmdable) FTExplainWithArgs(ctx context.Context, index string, query stri
1255
1277
// FTExplainCli - Returns the execution plan for a complex query. [Not Implemented]
1256
1278
// For more information, see https://redis.io/commands/ft.explaincli/
1257
1279
func (c cmdable ) FTExplainCli (ctx context.Context , key , path string ) error {
1258
- panic ( " not implemented" )
1280
+ return fmt . Errorf ( "FTExplainCli is not implemented" )
1259
1281
}
1260
1282
1261
1283
func parseFTInfo (data map [string ]interface {}) (FTInfoResult , error ) {
@@ -1810,7 +1832,7 @@ type SearchQuery []interface{}
1810
1832
// For more information, please refer to the Redis documentation about [FT.SEARCH].
1811
1833
//
1812
1834
// [FT.SEARCH]: (https://redis.io/commands/ft.search/)
1813
- func FTSearchQuery (query string , options * FTSearchOptions ) SearchQuery {
1835
+ func FTSearchQuery (query string , options * FTSearchOptions ) ( SearchQuery , error ) {
1814
1836
queryArgs := []interface {}{query }
1815
1837
if options != nil {
1816
1838
if options .NoContent {
@@ -1890,7 +1912,7 @@ func FTSearchQuery(query string, options *FTSearchOptions) SearchQuery {
1890
1912
for _ , sortBy := range options .SortBy {
1891
1913
queryArgs = append (queryArgs , sortBy .FieldName )
1892
1914
if sortBy .Asc && sortBy .Desc {
1893
- panic ("FT.SEARCH: ASC and DESC are mutually exclusive" )
1915
+ return nil , fmt . Errorf ("FT.SEARCH: ASC and DESC are mutually exclusive" )
1894
1916
}
1895
1917
if sortBy .Asc {
1896
1918
queryArgs = append (queryArgs , "ASC" )
@@ -1918,7 +1940,7 @@ func FTSearchQuery(query string, options *FTSearchOptions) SearchQuery {
1918
1940
queryArgs = append (queryArgs , "DIALECT" , 2 )
1919
1941
}
1920
1942
}
1921
- return queryArgs
1943
+ return queryArgs , nil
1922
1944
}
1923
1945
1924
1946
// FTSearchWithArgs - Executes a search query on an index with additional options.
@@ -2007,7 +2029,9 @@ func (c cmdable) FTSearchWithArgs(ctx context.Context, index string, query strin
2007
2029
for _ , sortBy := range options .SortBy {
2008
2030
args = append (args , sortBy .FieldName )
2009
2031
if sortBy .Asc && sortBy .Desc {
2010
- panic ("FT.SEARCH: ASC and DESC are mutually exclusive" )
2032
+ cmd := newFTSearchCmd (ctx , options , args ... )
2033
+ cmd .SetErr (fmt .Errorf ("FT.SEARCH: ASC and DESC are mutually exclusive" ))
2034
+ return cmd
2011
2035
}
2012
2036
if sortBy .Asc {
2013
2037
args = append (args , "ASC" )
0 commit comments