You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-07 13:22:56 +03:00
* fix #2364 - fix FT.SEARCH RETURN [] * remove console.log
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import { RedisCommandArguments } from '@redis/client/dist/lib/commands';
|
||||
import { transformTuplesReply } from '@redis/client/dist/lib/commands/generic-transformers';
|
||||
import { pushSearchOptions, RedisSearchLanguages, Params, PropertyName, SortByProperty, SearchReply } from '.';
|
||||
|
||||
export const FIRST_KEY_INDEX = 1;
|
||||
@@ -73,13 +72,11 @@ export type SearchRawReply = Array<any>;
|
||||
|
||||
export function transformReply(reply: SearchRawReply): SearchReply {
|
||||
const documents = [];
|
||||
for (let i = 1; i < reply.length; i += 2) {
|
||||
const tuples = reply[i + 1];
|
||||
let i = 1;
|
||||
while (i < reply.length) {
|
||||
documents.push({
|
||||
id: reply[i],
|
||||
value: tuples.length === 2 && tuples[0] === '$' ?
|
||||
JSON.parse(tuples[1]) :
|
||||
transformTuplesReply(tuples)
|
||||
id: reply[i++],
|
||||
value: documentValue(reply[i++])
|
||||
});
|
||||
}
|
||||
|
||||
@@ -88,3 +85,26 @@ export function transformReply(reply: SearchRawReply): SearchReply {
|
||||
documents
|
||||
};
|
||||
}
|
||||
|
||||
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++],
|
||||
value = tuples[i++];
|
||||
if (key === '$') { // might be a JSON reply
|
||||
try {
|
||||
Object.assign(message, JSON.parse(value));
|
||||
continue;
|
||||
} catch {
|
||||
// set as a regular property if not a valid JSON
|
||||
}
|
||||
}
|
||||
|
||||
message[key] = value;
|
||||
}
|
||||
|
||||
return message;
|
||||
}
|
||||
|
Reference in New Issue
Block a user