diff --git a/packages/search/lib/commands/PROFILE_SEARCH.ts b/packages/search/lib/commands/PROFILE_SEARCH.ts index 8040ccb5e05..94fba8a6a54 100644 --- a/packages/search/lib/commands/PROFILE_SEARCH.ts +++ b/packages/search/lib/commands/PROFILE_SEARCH.ts @@ -9,7 +9,7 @@ export function transformArguments( query: string, options?: ProfileOptions & SearchOptions ): RedisCommandArguments { - const args = ['FT.PROFILE', index, 'SEARCH']; + let args: RedisCommandArguments = ['FT.PROFILE', index, 'SEARCH']; if (options?.LIMITED) { args.push('LIMITED'); @@ -21,9 +21,9 @@ export function transformArguments( type ProfileSearchRawReply = ProfileRawReply; -export function transformReply(reply: ProfileSearchRawReply): ProfileReply { +export function transformReply(reply: ProfileSearchRawReply, withoutDocuments: boolean): ProfileReply { return { - results: transformSearchReply(reply[0]), + results: transformSearchReply(reply[0], withoutDocuments), profile: transformProfile(reply[1]) }; } diff --git a/packages/search/lib/commands/SEARCH.spec.ts b/packages/search/lib/commands/SEARCH.spec.ts index a5d8ae9e6c4..47c82cf892b 100644 --- a/packages/search/lib/commands/SEARCH.spec.ts +++ b/packages/search/lib/commands/SEARCH.spec.ts @@ -267,7 +267,8 @@ describe('SEARCH', () => { client.ft.create('index', { field: SchemaFieldTypes.NUMERIC }), - client.hSet('1', 'field', '1') + client.hSet('1', 'field', '1'), + client.hSet('2', 'field', '2') ]); assert.deepEqual( @@ -275,10 +276,13 @@ describe('SEARCH', () => { RETURN: [] }), { - total: 1, + total: 2, documents: [{ id: '1', value: Object.create(null) + }, { + id: '2', + value: Object.create(null) }] } ); diff --git a/packages/search/lib/commands/SEARCH.ts b/packages/search/lib/commands/SEARCH.ts index bed06e22c36..fbccb25058b 100644 --- a/packages/search/lib/commands/SEARCH.ts +++ b/packages/search/lib/commands/SEARCH.ts @@ -70,13 +70,13 @@ export function transformArguments( export type SearchRawReply = Array; -export function transformReply(reply: SearchRawReply): SearchReply { +export function transformReply(reply: SearchRawReply, withoutDocuments: boolean): SearchReply { const documents = []; let i = 1; while (i < reply.length) { documents.push({ id: reply[i++], - value: documentValue(reply[i++]) + value: withoutDocuments ? Object.create(null) : documentValue(reply[i++]) }); } @@ -88,7 +88,6 @@ export function transformReply(reply: SearchRawReply): SearchReply { function documentValue(tuples: any) { const message = Object.create(null); - if (tuples === undefined) return message; let i = 0; while (i < tuples.length) { diff --git a/packages/search/lib/commands/index.ts b/packages/search/lib/commands/index.ts index 74a49cb1bba..d56db7bdbbe 100644 --- a/packages/search/lib/commands/index.ts +++ b/packages/search/lib/commands/index.ts @@ -506,6 +506,10 @@ export function pushSearchOptions( args.push('DIALECT', options.DIALECT.toString()); } + if (options?.RETURN?.length === 0) { + args.preserve = true; + } + return args; }