Skip to content

Commit 26e057e

Browse files
authored
fix FT.SEARCH RETURN [] (#2421)
* ref #2419 - fix FT.SEARCH RETURN [] * fix transformReply * fix PROFILE SEARCH as well * fix PROFILE SEARCH preserve * move preserve login to `pushSearchOptions` * attach preserve only if true * fix RETURN: [] test
1 parent 0f28dad commit 26e057e

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

packages/search/lib/commands/PROFILE_SEARCH.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export function transformArguments(
99
query: string,
1010
options?: ProfileOptions & SearchOptions
1111
): RedisCommandArguments {
12-
const args = ['FT.PROFILE', index, 'SEARCH'];
12+
let args: RedisCommandArguments = ['FT.PROFILE', index, 'SEARCH'];
1313

1414
if (options?.LIMITED) {
1515
args.push('LIMITED');
@@ -21,9 +21,9 @@ export function transformArguments(
2121

2222
type ProfileSearchRawReply = ProfileRawReply<SearchRawReply>;
2323

24-
export function transformReply(reply: ProfileSearchRawReply): ProfileReply {
24+
export function transformReply(reply: ProfileSearchRawReply, withoutDocuments: boolean): ProfileReply {
2525
return {
26-
results: transformSearchReply(reply[0]),
26+
results: transformSearchReply(reply[0], withoutDocuments),
2727
profile: transformProfile(reply[1])
2828
};
2929
}

packages/search/lib/commands/SEARCH.spec.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -267,18 +267,22 @@ describe('SEARCH', () => {
267267
client.ft.create('index', {
268268
field: SchemaFieldTypes.NUMERIC
269269
}),
270-
client.hSet('1', 'field', '1')
270+
client.hSet('1', 'field', '1'),
271+
client.hSet('2', 'field', '2')
271272
]);
272273

273274
assert.deepEqual(
274275
await client.ft.search('index', '*', {
275276
RETURN: []
276277
}),
277278
{
278-
total: 1,
279+
total: 2,
279280
documents: [{
280281
id: '1',
281282
value: Object.create(null)
283+
}, {
284+
id: '2',
285+
value: Object.create(null)
282286
}]
283287
}
284288
);

packages/search/lib/commands/SEARCH.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ export function transformArguments(
7070

7171
export type SearchRawReply = Array<any>;
7272

73-
export function transformReply(reply: SearchRawReply): SearchReply {
73+
export function transformReply(reply: SearchRawReply, withoutDocuments: boolean): SearchReply {
7474
const documents = [];
7575
let i = 1;
7676
while (i < reply.length) {
7777
documents.push({
7878
id: reply[i++],
79-
value: documentValue(reply[i++])
79+
value: withoutDocuments ? Object.create(null) : documentValue(reply[i++])
8080
});
8181
}
8282

@@ -88,7 +88,6 @@ export function transformReply(reply: SearchRawReply): SearchReply {
8888

8989
function documentValue(tuples: any) {
9090
const message = Object.create(null);
91-
if (tuples === undefined) return message;
9291

9392
let i = 0;
9493
while (i < tuples.length) {

packages/search/lib/commands/index.ts

+4
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,10 @@ export function pushSearchOptions(
506506
args.push('DIALECT', options.DIALECT.toString());
507507
}
508508

509+
if (options?.RETURN?.length === 0) {
510+
args.preserve = true;
511+
}
512+
509513
return args;
510514
}
511515

0 commit comments

Comments
 (0)