@@ -240,13 +240,20 @@ type FTAggregateWithCursor struct {
240240}
241241
242242type 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
250257 Apply []FTAggregateApply
251258 LimitOffset int
252259 Limit int
@@ -483,6 +490,15 @@ func FTAggregateQuery(query string, options *FTAggregateOptions) AggregateQuery
483490 if options .Verbatim {
484491 queryArgs = append (queryArgs , "VERBATIM" )
485492 }
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+
486502 if options .LoadAll && options .Load != nil {
487503 panic ("FT.AGGREGATE: LOADALL and LOAD are mutually exclusive" )
488504 }
@@ -498,9 +514,18 @@ func FTAggregateQuery(query string, options *FTAggregateOptions) AggregateQuery
498514 }
499515 }
500516 }
517+
501518 if options .Timeout > 0 {
502519 queryArgs = append (queryArgs , "TIMEOUT" , options .Timeout )
503520 }
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+
504529 if options .GroupBy != nil {
505530 for _ , groupBy := range options .GroupBy {
506531 queryArgs = append (queryArgs , "GROUPBY" , len (groupBy .Fields ))
@@ -542,12 +567,6 @@ func FTAggregateQuery(query string, options *FTAggregateOptions) AggregateQuery
542567 if options .SortByMax > 0 {
543568 queryArgs = append (queryArgs , "MAX" , options .SortByMax )
544569 }
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- }
551570 if options .LimitOffset > 0 {
552571 queryArgs = append (queryArgs , "LIMIT" , options .LimitOffset )
553572 }
@@ -574,6 +593,7 @@ func FTAggregateQuery(query string, options *FTAggregateOptions) AggregateQuery
574593 queryArgs = append (queryArgs , key , value )
575594 }
576595 }
596+
577597 if options .DialectVersion > 0 {
578598 queryArgs = append (queryArgs , "DIALECT" , options .DialectVersion )
579599 }
@@ -654,11 +674,12 @@ func (cmd *AggregateCmd) readReply(rd *proto.Reader) (err error) {
654674 data , err := rd .ReadSlice ()
655675 if err != nil {
656676 cmd .err = err
657- return nil
677+ return err
658678 }
659679 cmd .val , err = ProcessAggregateResult (data )
660680 if err != nil {
661681 cmd .err = err
682+ return err
662683 }
663684 return nil
664685}
@@ -674,6 +695,12 @@ func (c cmdable) FTAggregateWithArgs(ctx context.Context, index string, query st
674695 if options .Verbatim {
675696 args = append (args , "VERBATIM" )
676697 }
698+ if options .Scorer != "" {
699+ args = append (args , "SCORER" , options .Scorer )
700+ }
701+ if options .AddScores {
702+ args = append (args , "ADDSCORES" )
703+ }
677704 if options .LoadAll && options .Load != nil {
678705 panic ("FT.AGGREGATE: LOADALL and LOAD are mutually exclusive" )
679706 }
@@ -692,6 +719,12 @@ func (c cmdable) FTAggregateWithArgs(ctx context.Context, index string, query st
692719 if options .Timeout > 0 {
693720 args = append (args , "TIMEOUT" , options .Timeout )
694721 }
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+ }
695728 if options .GroupBy != nil {
696729 for _ , groupBy := range options .GroupBy {
697730 args = append (args , "GROUPBY" , len (groupBy .Fields ))
@@ -733,12 +766,6 @@ func (c cmdable) FTAggregateWithArgs(ctx context.Context, index string, query st
733766 if options .SortByMax > 0 {
734767 args = append (args , "MAX" , options .SortByMax )
735768 }
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- }
742769 if options .LimitOffset > 0 {
743770 args = append (args , "LIMIT" , options .LimitOffset )
744771 }
@@ -1674,7 +1701,8 @@ func (cmd *FTSearchCmd) readReply(rd *proto.Reader) (err error) {
16741701
16751702// FTSearch - Executes a search query on an index.
16761703// 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+ //
16781706// [FT.SEARCH]: (https://redis.io/commands/ft.search/)
16791707func (c cmdable ) FTSearch (ctx context.Context , index string , query string ) * FTSearchCmd {
16801708 args := []interface {}{"FT.SEARCH" , index , query }
@@ -1685,6 +1713,12 @@ func (c cmdable) FTSearch(ctx context.Context, index string, query string) *FTSe
16851713
16861714type SearchQuery []interface {}
16871715
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/)
16881722func FTSearchQuery (query string , options * FTSearchOptions ) SearchQuery {
16891723 queryArgs := []interface {}{query }
16901724 if options != nil {
@@ -1797,7 +1831,8 @@ func FTSearchQuery(query string, options *FTSearchOptions) SearchQuery {
17971831// FTSearchWithArgs - Executes a search query on an index with additional options.
17981832// The 'index' parameter specifies the index to search, the 'query' parameter specifies the search query,
17991833// 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+ //
18011836// [FT.SEARCH]: (https://redis.io/commands/ft.search/)
18021837func (c cmdable ) FTSearchWithArgs (ctx context.Context , index string , query string , options * FTSearchOptions ) * FTSearchCmd {
18031838 args := []interface {}{"FT.SEARCH" , index , query }
@@ -1889,7 +1924,7 @@ func (c cmdable) FTSearchWithArgs(ctx context.Context, index string, query strin
18891924 }
18901925 }
18911926 if options .SortByWithCount {
1892- args = append (args , "WITHCOUT " )
1927+ args = append (args , "WITHCOUNT " )
18931928 }
18941929 }
18951930 if options .LimitOffset >= 0 && options .Limit > 0 {
0 commit comments