Skip to content

Commit

Permalink
ref redis#2419 - fix FT.SEARCH RETURN []
Browse files Browse the repository at this point in the history
  • Loading branch information
leibale authored Feb 23, 2023
1 parent 1be8422 commit fcdaa87
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
6 changes: 5 additions & 1 deletion packages/search/lib/commands/SEARCH.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -279,6 +280,9 @@ describe('SEARCH', () => {
documents: [{
id: '1',
value: Object.create(null)
}, {
id: '2',
value: Object.create(null)
}]
}
);
Expand Down
11 changes: 6 additions & 5 deletions packages/search/lib/commands/SEARCH.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,23 @@ export function transformArguments(
query: string,
options?: SearchOptions
): RedisCommandArguments {
return pushSearchOptions(
const args = pushSearchOptions(
['FT.SEARCH', index, query],
options
);

args.preserve = options?.RETURN.length === 0;
}

export type SearchRawReply = Array<any>;

export function transformReply(reply: SearchRawReply): SearchReply {
export function transformReply(reply: SearchRawReply, hasDocuments: boolean): SearchReply {
const documents = [];
let i = 1;
while (i < reply.length) {
documents.push({
id: reply[i++],
value: documentValue(reply[i++])
value: hasDocuments ? documentValue(reply[i++]) : null
});
}

Expand All @@ -88,8 +90,7 @@ 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) {
const key = tuples[i++],
Expand Down

0 comments on commit fcdaa87

Please sign in to comment.