You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-09 00:22:08 +03:00
88 lines
2.3 KiB
TypeScript
88 lines
2.3 KiB
TypeScript
import { RedisCommandArguments } from '@node-redis/client/dist/lib/commands';
|
|
import { transformReplyTuples } from '@node-redis/client/dist/lib/commands/generic-transformers';
|
|
import { pushSearchOptions, RedisSearchLanguages, PropertyName, SortByProperty, SearchReply } from '.';
|
|
|
|
export const FIRST_KEY_INDEX = 1;
|
|
|
|
export const IS_READ_ONLY = true;
|
|
|
|
export interface SearchOptions {
|
|
// NOCONTENT?: true; TODO
|
|
VERBATIM?: true;
|
|
NOSTOPWORDS?: true;
|
|
// WITHSCORES?: true;
|
|
// WITHPAYLOADS?: true;
|
|
WITHSORTKEYS?: true;
|
|
// FILTER?: {
|
|
// field: string;
|
|
// min: number | string;
|
|
// max: number | string;
|
|
// };
|
|
// GEOFILTER?: {
|
|
// field: string;
|
|
// lon: number;
|
|
// lat: number;
|
|
// radius: number;
|
|
// unit: 'm' | 'km' | 'mi' | 'ft';
|
|
// };
|
|
INKEYS?: string | Array<string>;
|
|
INFIELDS?: string | Array<string>;
|
|
RETURN?: string | Array<string>;
|
|
SUMMARIZE?: true | {
|
|
FIELDS?: PropertyName | Array<PropertyName>;
|
|
FRAGS?: number;
|
|
LEN?: number;
|
|
SEPARATOR?: string;
|
|
};
|
|
HIGHLIGHT?: true | {
|
|
FIELDS?: PropertyName | Array<PropertyName>;
|
|
TAGS?: {
|
|
open: string;
|
|
close: string;
|
|
};
|
|
};
|
|
SLOP?: number;
|
|
INORDER?: true;
|
|
LANGUAGE?: RedisSearchLanguages;
|
|
EXPANDER?: string;
|
|
SCORER?: string;
|
|
// EXPLAINSCORE?: true; // TODO: WITHSCORES
|
|
// PAYLOAD?: ;
|
|
SORTBY?: SortByProperty;
|
|
// MSORTBY?: SortByProperty | Array<SortByProperty>;
|
|
LIMIT?: {
|
|
from: number | string;
|
|
size: number | string;
|
|
};
|
|
}
|
|
|
|
export function transformArguments(
|
|
index: string,
|
|
query: string,
|
|
options?: SearchOptions
|
|
): RedisCommandArguments {
|
|
const args: RedisCommandArguments = ['FT.SEARCH', index, query];
|
|
pushSearchOptions(args, options);
|
|
return args;
|
|
}
|
|
|
|
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];
|
|
documents.push({
|
|
id: reply[i],
|
|
value: tuples.length === 2 && tuples[0] === '$' ?
|
|
JSON.parse(tuples[1]) :
|
|
transformReplyTuples(tuples)
|
|
});
|
|
}
|
|
|
|
return {
|
|
total: reply[0],
|
|
documents
|
|
};
|
|
}
|