@@ -240,13 +240,20 @@ type FTAggregateWithCursor struct {
240
240
}
241
241
242
242
type FTAggregateOptions struct {
243
- Verbatim bool
244
- LoadAll bool
245
- Load []FTAggregateLoad
246
- Timeout int
247
- GroupBy []FTAggregateGroupBy
248
- SortBy []FTAggregateSortBy
249
- SortByMax int
243
+ Verbatim bool
244
+ LoadAll bool
245
+ Load []FTAggregateLoad
246
+ Timeout int
247
+ GroupBy []FTAggregateGroupBy
248
+ SortBy []FTAggregateSortBy
249
+ SortByMax int
250
+ // Scorer is used to set scoring function, if not set passed, a default will be used.
251
+ // The default scorer depends on the Redis version:
252
+ // - `BM25` for Redis >= 8
253
+ // - `TFIDF` for Redis < 8
254
+ Scorer string
255
+ // AddScores is available in Redis CE 8
256
+ AddScores bool
250
257
Apply []FTAggregateApply
251
258
LimitOffset int
252
259
Limit int
@@ -483,6 +490,15 @@ func FTAggregateQuery(query string, options *FTAggregateOptions) AggregateQuery
483
490
if options .Verbatim {
484
491
queryArgs = append (queryArgs , "VERBATIM" )
485
492
}
493
+
494
+ if options .Scorer != "" {
495
+ queryArgs = append (queryArgs , "SCORER" , options .Scorer )
496
+ }
497
+
498
+ if options .AddScores {
499
+ queryArgs = append (queryArgs , "ADDSCORES" )
500
+ }
501
+
486
502
if options .LoadAll && options .Load != nil {
487
503
panic ("FT.AGGREGATE: LOADALL and LOAD are mutually exclusive" )
488
504
}
@@ -498,9 +514,18 @@ func FTAggregateQuery(query string, options *FTAggregateOptions) AggregateQuery
498
514
}
499
515
}
500
516
}
517
+
501
518
if options .Timeout > 0 {
502
519
queryArgs = append (queryArgs , "TIMEOUT" , options .Timeout )
503
520
}
521
+
522
+ for _ , apply := range options .Apply {
523
+ queryArgs = append (queryArgs , "APPLY" , apply .Field )
524
+ if apply .As != "" {
525
+ queryArgs = append (queryArgs , "AS" , apply .As )
526
+ }
527
+ }
528
+
504
529
if options .GroupBy != nil {
505
530
for _ , groupBy := range options .GroupBy {
506
531
queryArgs = append (queryArgs , "GROUPBY" , len (groupBy .Fields ))
@@ -542,12 +567,6 @@ func FTAggregateQuery(query string, options *FTAggregateOptions) AggregateQuery
542
567
if options .SortByMax > 0 {
543
568
queryArgs = append (queryArgs , "MAX" , options .SortByMax )
544
569
}
545
- for _ , apply := range options .Apply {
546
- queryArgs = append (queryArgs , "APPLY" , apply .Field )
547
- if apply .As != "" {
548
- queryArgs = append (queryArgs , "AS" , apply .As )
549
- }
550
- }
551
570
if options .LimitOffset > 0 {
552
571
queryArgs = append (queryArgs , "LIMIT" , options .LimitOffset )
553
572
}
@@ -574,6 +593,7 @@ func FTAggregateQuery(query string, options *FTAggregateOptions) AggregateQuery
574
593
queryArgs = append (queryArgs , key , value )
575
594
}
576
595
}
596
+
577
597
if options .DialectVersion > 0 {
578
598
queryArgs = append (queryArgs , "DIALECT" , options .DialectVersion )
579
599
}
@@ -654,11 +674,12 @@ func (cmd *AggregateCmd) readReply(rd *proto.Reader) (err error) {
654
674
data , err := rd .ReadSlice ()
655
675
if err != nil {
656
676
cmd .err = err
657
- return nil
677
+ return err
658
678
}
659
679
cmd .val , err = ProcessAggregateResult (data )
660
680
if err != nil {
661
681
cmd .err = err
682
+ return err
662
683
}
663
684
return nil
664
685
}
@@ -674,6 +695,12 @@ func (c cmdable) FTAggregateWithArgs(ctx context.Context, index string, query st
674
695
if options .Verbatim {
675
696
args = append (args , "VERBATIM" )
676
697
}
698
+ if options .Scorer != "" {
699
+ args = append (args , "SCORER" , options .Scorer )
700
+ }
701
+ if options .AddScores {
702
+ args = append (args , "ADDSCORES" )
703
+ }
677
704
if options .LoadAll && options .Load != nil {
678
705
panic ("FT.AGGREGATE: LOADALL and LOAD are mutually exclusive" )
679
706
}
@@ -692,6 +719,12 @@ func (c cmdable) FTAggregateWithArgs(ctx context.Context, index string, query st
692
719
if options .Timeout > 0 {
693
720
args = append (args , "TIMEOUT" , options .Timeout )
694
721
}
722
+ for _ , apply := range options .Apply {
723
+ args = append (args , "APPLY" , apply .Field )
724
+ if apply .As != "" {
725
+ args = append (args , "AS" , apply .As )
726
+ }
727
+ }
695
728
if options .GroupBy != nil {
696
729
for _ , groupBy := range options .GroupBy {
697
730
args = append (args , "GROUPBY" , len (groupBy .Fields ))
@@ -733,12 +766,6 @@ func (c cmdable) FTAggregateWithArgs(ctx context.Context, index string, query st
733
766
if options .SortByMax > 0 {
734
767
args = append (args , "MAX" , options .SortByMax )
735
768
}
736
- for _ , apply := range options .Apply {
737
- args = append (args , "APPLY" , apply .Field )
738
- if apply .As != "" {
739
- args = append (args , "AS" , apply .As )
740
- }
741
- }
742
769
if options .LimitOffset > 0 {
743
770
args = append (args , "LIMIT" , options .LimitOffset )
744
771
}
@@ -1674,7 +1701,8 @@ func (cmd *FTSearchCmd) readReply(rd *proto.Reader) (err error) {
1674
1701
1675
1702
// FTSearch - Executes a search query on an index.
1676
1703
// The 'index' parameter specifies the index to search, and the 'query' parameter specifies the search query.
1677
- // For more information, please refer to the Redis documentation:
1704
+ // For more information, please refer to the Redis documentation about [FT.SEARCH].
1705
+ //
1678
1706
// [FT.SEARCH]: (https://redis.io/commands/ft.search/)
1679
1707
func (c cmdable ) FTSearch (ctx context.Context , index string , query string ) * FTSearchCmd {
1680
1708
args := []interface {}{"FT.SEARCH" , index , query }
@@ -1685,6 +1713,12 @@ func (c cmdable) FTSearch(ctx context.Context, index string, query string) *FTSe
1685
1713
1686
1714
type SearchQuery []interface {}
1687
1715
1716
+ // FTSearchQuery - Executes a search query on an index with additional options.
1717
+ // The 'index' parameter specifies the index to search, the 'query' parameter specifies the search query,
1718
+ // and the 'options' parameter specifies additional options for the search.
1719
+ // For more information, please refer to the Redis documentation about [FT.SEARCH].
1720
+ //
1721
+ // [FT.SEARCH]: (https://redis.io/commands/ft.search/)
1688
1722
func FTSearchQuery (query string , options * FTSearchOptions ) SearchQuery {
1689
1723
queryArgs := []interface {}{query }
1690
1724
if options != nil {
@@ -1797,7 +1831,8 @@ func FTSearchQuery(query string, options *FTSearchOptions) SearchQuery {
1797
1831
// FTSearchWithArgs - Executes a search query on an index with additional options.
1798
1832
// The 'index' parameter specifies the index to search, the 'query' parameter specifies the search query,
1799
1833
// and the 'options' parameter specifies additional options for the search.
1800
- // For more information, please refer to the Redis documentation:
1834
+ // For more information, please refer to the Redis documentation about [FT.SEARCH].
1835
+ //
1801
1836
// [FT.SEARCH]: (https://redis.io/commands/ft.search/)
1802
1837
func (c cmdable ) FTSearchWithArgs (ctx context.Context , index string , query string , options * FTSearchOptions ) * FTSearchCmd {
1803
1838
args := []interface {}{"FT.SEARCH" , index , query }
@@ -1889,7 +1924,7 @@ func (c cmdable) FTSearchWithArgs(ctx context.Context, index string, query strin
1889
1924
}
1890
1925
}
1891
1926
if options .SortByWithCount {
1892
- args = append (args , "WITHCOUT " )
1927
+ args = append (args , "WITHCOUNT " )
1893
1928
}
1894
1929
}
1895
1930
if options .LimitOffset >= 0 && options .Limit > 0 {
0 commit comments