Skip to content

fix FT.SEARCH RETURN [] #2421

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/search/lib/commands/PROFILE_SEARCH.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -21,9 +21,9 @@ export function transformArguments(

type ProfileSearchRawReply = ProfileRawReply<SearchRawReply>;

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])
};
}
8 changes: 6 additions & 2 deletions packages/search/lib/commands/SEARCH.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,18 +267,22 @@ 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(
await client.ft.search('index', '*', {
RETURN: []
}),
{
total: 1,
total: 2,
documents: [{
id: '1',
value: Object.create(null)
}, {
id: '2',
value: Object.create(null)
}]
}
);
Expand Down
5 changes: 2 additions & 3 deletions packages/search/lib/commands/SEARCH.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ export function transformArguments(

export type SearchRawReply = Array<any>;

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++])
});
}

Expand All @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions packages/search/lib/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,10 @@ export function pushSearchOptions(
args.push('DIALECT', options.DIALECT.toString());
}

if (options?.RETURN?.length === 0) {
args.preserve = true;
}

return args;
}

Expand Down