From 54b3e178f9943ae24362cb99c8d91ac865cae8b4 Mon Sep 17 00:00:00 2001 From: Shaya Potter Date: Mon, 29 Jul 2024 16:22:38 +0300 Subject: [PATCH] add addscores to aggregate search command (#2799) * add addscores to aggregate search command * change `true` to `boolean` --------- Co-authored-by: Leibale Eidelman --- packages/search/lib/commands/AGGREGATE.spec.ts | 7 +++++++ packages/search/lib/commands/AGGREGATE.ts | 9 +++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/search/lib/commands/AGGREGATE.spec.ts b/packages/search/lib/commands/AGGREGATE.spec.ts index d1e4565339a..5b34d7dc16f 100644 --- a/packages/search/lib/commands/AGGREGATE.spec.ts +++ b/packages/search/lib/commands/AGGREGATE.spec.ts @@ -19,6 +19,13 @@ describe('AGGREGATE', () => { ); }); + it('with ADDSCORES', () => { + assert.deepEqual( + transformArguments('index', '*', { ADDSCORES: true }), + ['FT.AGGREGATE', 'index', '*', 'ADDSCORES'] + ); + }); + describe('with LOAD', () => { describe('single', () => { describe('without alias', () => { diff --git a/packages/search/lib/commands/AGGREGATE.ts b/packages/search/lib/commands/AGGREGATE.ts index 950d959243a..0cab9b25d48 100644 --- a/packages/search/lib/commands/AGGREGATE.ts +++ b/packages/search/lib/commands/AGGREGATE.ts @@ -119,7 +119,8 @@ type LoadField = PropertyName | { } export interface AggregateOptions { - VERBATIM?: true; + VERBATIM?: boolean; + ADDSCORES?: boolean; LOAD?: LoadField | Array; STEPS?: Array; PARAMS?: Params; @@ -150,6 +151,10 @@ export function pushAggregatehOptions( args.push('VERBATIM'); } + if (options?.ADDSCORES) { + args.push('ADDSCORES'); + } + if (options?.LOAD) { args.push('LOAD'); pushArgumentsWithLength(args, () => { @@ -308,4 +313,4 @@ export function transformReply(rawReply: AggregateRawReply): AggregateReply { total: rawReply[0], results }; -} \ No newline at end of file +}