@@ -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
@@ -490,6 +497,15 @@ func FTAggregateQuery(query string, options *FTAggregateOptions) AggregateQuery
490
497
if options .Verbatim {
491
498
queryArgs = append (queryArgs , "VERBATIM" )
492
499
}
500
+
501
+ if options .Scorer != "" {
502
+ queryArgs = append (queryArgs , "SCORER" , options .Scorer )
503
+ }
504
+
505
+ if options .AddScores {
506
+ queryArgs = append (queryArgs , "ADDSCORES" )
507
+ }
508
+
493
509
if options .LoadAll && options .Load != nil {
494
510
panic ("FT.AGGREGATE: LOADALL and LOAD are mutually exclusive" )
495
511
}
@@ -505,9 +521,18 @@ func FTAggregateQuery(query string, options *FTAggregateOptions) AggregateQuery
505
521
}
506
522
}
507
523
}
524
+
508
525
if options .Timeout > 0 {
509
526
queryArgs = append (queryArgs , "TIMEOUT" , options .Timeout )
510
527
}
528
+
529
+ for _ , apply := range options .Apply {
530
+ queryArgs = append (queryArgs , "APPLY" , apply .Field )
531
+ if apply .As != "" {
532
+ queryArgs = append (queryArgs , "AS" , apply .As )
533
+ }
534
+ }
535
+
511
536
if options .GroupBy != nil {
512
537
for _ , groupBy := range options .GroupBy {
513
538
queryArgs = append (queryArgs , "GROUPBY" , len (groupBy .Fields ))
@@ -549,12 +574,6 @@ func FTAggregateQuery(query string, options *FTAggregateOptions) AggregateQuery
549
574
if options .SortByMax > 0 {
550
575
queryArgs = append (queryArgs , "MAX" , options .SortByMax )
551
576
}
552
- for _ , apply := range options .Apply {
553
- queryArgs = append (queryArgs , "APPLY" , apply .Field )
554
- if apply .As != "" {
555
- queryArgs = append (queryArgs , "AS" , apply .As )
556
- }
557
- }
558
577
if options .LimitOffset > 0 {
559
578
queryArgs = append (queryArgs , "LIMIT" , options .LimitOffset )
560
579
}
@@ -581,6 +600,7 @@ func FTAggregateQuery(query string, options *FTAggregateOptions) AggregateQuery
581
600
queryArgs = append (queryArgs , key , value )
582
601
}
583
602
}
603
+
584
604
if options .DialectVersion > 0 {
585
605
queryArgs = append (queryArgs , "DIALECT" , options .DialectVersion )
586
606
}
@@ -661,11 +681,12 @@ func (cmd *AggregateCmd) readReply(rd *proto.Reader) (err error) {
661
681
data , err := rd .ReadSlice ()
662
682
if err != nil {
663
683
cmd .err = err
664
- return nil
684
+ return err
665
685
}
666
686
cmd .val , err = ProcessAggregateResult (data )
667
687
if err != nil {
668
688
cmd .err = err
689
+ return err
669
690
}
670
691
return nil
671
692
}
@@ -681,6 +702,12 @@ func (c cmdable) FTAggregateWithArgs(ctx context.Context, index string, query st
681
702
if options .Verbatim {
682
703
args = append (args , "VERBATIM" )
683
704
}
705
+ if options .Scorer != "" {
706
+ args = append (args , "SCORER" , options .Scorer )
707
+ }
708
+ if options .AddScores {
709
+ args = append (args , "ADDSCORES" )
710
+ }
684
711
if options .LoadAll && options .Load != nil {
685
712
panic ("FT.AGGREGATE: LOADALL and LOAD are mutually exclusive" )
686
713
}
@@ -699,6 +726,12 @@ func (c cmdable) FTAggregateWithArgs(ctx context.Context, index string, query st
699
726
if options .Timeout > 0 {
700
727
args = append (args , "TIMEOUT" , options .Timeout )
701
728
}
729
+ for _ , apply := range options .Apply {
730
+ args = append (args , "APPLY" , apply .Field )
731
+ if apply .As != "" {
732
+ args = append (args , "AS" , apply .As )
733
+ }
734
+ }
702
735
if options .GroupBy != nil {
703
736
for _ , groupBy := range options .GroupBy {
704
737
args = append (args , "GROUPBY" , len (groupBy .Fields ))
@@ -740,12 +773,6 @@ func (c cmdable) FTAggregateWithArgs(ctx context.Context, index string, query st
740
773
if options .SortByMax > 0 {
741
774
args = append (args , "MAX" , options .SortByMax )
742
775
}
743
- for _ , apply := range options .Apply {
744
- args = append (args , "APPLY" , apply .Field )
745
- if apply .As != "" {
746
- args = append (args , "AS" , apply .As )
747
- }
748
- }
749
776
if options .LimitOffset > 0 {
750
777
args = append (args , "LIMIT" , options .LimitOffset )
751
778
}
@@ -1693,7 +1720,8 @@ func (cmd *FTSearchCmd) readReply(rd *proto.Reader) (err error) {
1693
1720
1694
1721
// FTSearch - Executes a search query on an index.
1695
1722
// The 'index' parameter specifies the index to search, and the 'query' parameter specifies the search query.
1696
- // For more information, please refer to the Redis documentation:
1723
+ // For more information, please refer to the Redis documentation about [FT.SEARCH].
1724
+ //
1697
1725
// [FT.SEARCH]: (https://redis.io/commands/ft.search/)
1698
1726
func (c cmdable ) FTSearch (ctx context.Context , index string , query string ) * FTSearchCmd {
1699
1727
args := []interface {}{"FT.SEARCH" , index , query }
@@ -1704,6 +1732,12 @@ func (c cmdable) FTSearch(ctx context.Context, index string, query string) *FTSe
1704
1732
1705
1733
type SearchQuery []interface {}
1706
1734
1735
+ // FTSearchQuery - Executes a search query on an index with additional options.
1736
+ // The 'index' parameter specifies the index to search, the 'query' parameter specifies the search query,
1737
+ // and the 'options' parameter specifies additional options for the search.
1738
+ // For more information, please refer to the Redis documentation about [FT.SEARCH].
1739
+ //
1740
+ // [FT.SEARCH]: (https://redis.io/commands/ft.search/)
1707
1741
func FTSearchQuery (query string , options * FTSearchOptions ) SearchQuery {
1708
1742
queryArgs := []interface {}{query }
1709
1743
if options != nil {
@@ -1816,7 +1850,8 @@ func FTSearchQuery(query string, options *FTSearchOptions) SearchQuery {
1816
1850
// FTSearchWithArgs - Executes a search query on an index with additional options.
1817
1851
// The 'index' parameter specifies the index to search, the 'query' parameter specifies the search query,
1818
1852
// and the 'options' parameter specifies additional options for the search.
1819
- // For more information, please refer to the Redis documentation:
1853
+ // For more information, please refer to the Redis documentation about [FT.SEARCH].
1854
+ //
1820
1855
// [FT.SEARCH]: (https://redis.io/commands/ft.search/)
1821
1856
func (c cmdable ) FTSearchWithArgs (ctx context.Context , index string , query string , options * FTSearchOptions ) * FTSearchCmd {
1822
1857
args := []interface {}{"FT.SEARCH" , index , query }
@@ -1908,7 +1943,7 @@ func (c cmdable) FTSearchWithArgs(ctx context.Context, index string, query strin
1908
1943
}
1909
1944
}
1910
1945
if options .SortByWithCount {
1911
- args = append (args , "WITHCOUT " )
1946
+ args = append (args , "WITHCOUNT " )
1912
1947
}
1913
1948
}
1914
1949
if options .LimitOffset >= 0 && options .Limit > 0 {
0 commit comments