You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
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
This commit is contained in:
@@ -9,7 +9,7 @@ export function transformArguments(
|
|||||||
query: string,
|
query: string,
|
||||||
options?: ProfileOptions & SearchOptions
|
options?: ProfileOptions & SearchOptions
|
||||||
): RedisCommandArguments {
|
): RedisCommandArguments {
|
||||||
const args = ['FT.PROFILE', index, 'SEARCH'];
|
let args: RedisCommandArguments = ['FT.PROFILE', index, 'SEARCH'];
|
||||||
|
|
||||||
if (options?.LIMITED) {
|
if (options?.LIMITED) {
|
||||||
args.push('LIMITED');
|
args.push('LIMITED');
|
||||||
@@ -21,9 +21,9 @@ export function transformArguments(
|
|||||||
|
|
||||||
type ProfileSearchRawReply = ProfileRawReply<SearchRawReply>;
|
type ProfileSearchRawReply = ProfileRawReply<SearchRawReply>;
|
||||||
|
|
||||||
export function transformReply(reply: ProfileSearchRawReply): ProfileReply {
|
export function transformReply(reply: ProfileSearchRawReply, withoutDocuments: boolean): ProfileReply {
|
||||||
return {
|
return {
|
||||||
results: transformSearchReply(reply[0]),
|
results: transformSearchReply(reply[0], withoutDocuments),
|
||||||
profile: transformProfile(reply[1])
|
profile: transformProfile(reply[1])
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@@ -267,7 +267,8 @@ describe('SEARCH', () => {
|
|||||||
client.ft.create('index', {
|
client.ft.create('index', {
|
||||||
field: SchemaFieldTypes.NUMERIC
|
field: SchemaFieldTypes.NUMERIC
|
||||||
}),
|
}),
|
||||||
client.hSet('1', 'field', '1')
|
client.hSet('1', 'field', '1'),
|
||||||
|
client.hSet('2', 'field', '2')
|
||||||
]);
|
]);
|
||||||
|
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
@@ -275,10 +276,13 @@ describe('SEARCH', () => {
|
|||||||
RETURN: []
|
RETURN: []
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
total: 1,
|
total: 2,
|
||||||
documents: [{
|
documents: [{
|
||||||
id: '1',
|
id: '1',
|
||||||
value: Object.create(null)
|
value: Object.create(null)
|
||||||
|
}, {
|
||||||
|
id: '2',
|
||||||
|
value: Object.create(null)
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@@ -70,13 +70,13 @@ export function transformArguments(
|
|||||||
|
|
||||||
export type SearchRawReply = Array<any>;
|
export type SearchRawReply = Array<any>;
|
||||||
|
|
||||||
export function transformReply(reply: SearchRawReply): SearchReply {
|
export function transformReply(reply: SearchRawReply, withoutDocuments: boolean): SearchReply {
|
||||||
const documents = [];
|
const documents = [];
|
||||||
let i = 1;
|
let i = 1;
|
||||||
while (i < reply.length) {
|
while (i < reply.length) {
|
||||||
documents.push({
|
documents.push({
|
||||||
id: reply[i++],
|
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) {
|
function documentValue(tuples: any) {
|
||||||
const message = Object.create(null);
|
const message = Object.create(null);
|
||||||
if (tuples === undefined) return message;
|
|
||||||
|
|
||||||
let i = 0;
|
let i = 0;
|
||||||
while (i < tuples.length) {
|
while (i < tuples.length) {
|
||||||
|
@@ -506,6 +506,10 @@ export function pushSearchOptions(
|
|||||||
args.push('DIALECT', options.DIALECT.toString());
|
args.push('DIALECT', options.DIALECT.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options?.RETURN?.length === 0) {
|
||||||
|
args.preserve = true;
|
||||||
|
}
|
||||||
|
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user