Debian Codegraph @

packages/search/lib/commands/CREATE.ts

raw
1 import { pushOptionalVerdictArgument } from '@redis/client/dist/lib/commands/generic-transformers';
2 import { RedisSearchLanguages, PropertyName, RediSearchSchema, pushSchema } from '.';
3
4 interface CreateOptions {
5 ON?: 'HASH' | 'JSON';
6 PREFIX?: string | Array<string>;
7 FILTER?: string;
8 LANGUAGE?: RedisSearchLanguages;
9 LANGUAGE_FIELD?: PropertyName;
10 SCORE?: number;
11 SCORE_FIELD?: PropertyName;
12 // PAYLOAD_FIELD?: string;
13 MAXTEXTFIELDS?: true;
14 TEMPORARY?: number;
15 NOOFFSETS?: true;
16 NOHL?: true;
17 NOFIELDS?: true;
18 NOFREQS?: true;
19 SKIPINITIALSCAN?: true;
20 STOPWORDS?: string | Array<string>;
21 }
22
23 export function transformArguments(index: string, schema: RediSearchSchema, options?: CreateOptions): Array<string> {
24 const args = ['FT.CREATE', index];
25
26 if (options?.ON) {
27 args.push('ON', options.ON);
28 }
29
30 pushOptionalVerdictArgument(args, 'PREFIX', options?.PREFIX);
31
32 if (options?.FILTER) {
33 args.push('FILTER', options.FILTER);
34 }
35
36 if (options?.LANGUAGE) {
37 args.push('LANGUAGE', options.LANGUAGE);
38 }
39
40 if (options?.LANGUAGE_FIELD) {
41 args.push('LANGUAGE_FIELD', options.LANGUAGE_FIELD);
42 }
43
44 if (options?.SCORE) {
45 args.push('SCORE', options.SCORE.toString());
46 }
47
48 if (options?.SCORE_FIELD) {
49 args.push('SCORE_FIELD', options.SCORE_FIELD);
50 }
51
52 // if (options?.PAYLOAD_FIELD) {
53 // args.push('PAYLOAD_FIELD', options.PAYLOAD_FIELD);
54 // }
55
56 if (options?.MAXTEXTFIELDS) {
57 args.push('MAXTEXTFIELDS');
58 }
59
60 if (options?.TEMPORARY) {
61 args.push('TEMPORARY', options.TEMPORARY.toString());
62 }
63
64 if (options?.NOOFFSETS) {
65 args.push('NOOFFSETS');
66 }
67
68 if (options?.NOHL) {
69 args.push('NOHL');
70 }
71
72 if (options?.NOFIELDS) {
73 args.push('NOFIELDS');
74 }
75
76 if (options?.NOFREQS) {
77 args.push('NOFREQS');
78 }
79
80 if (options?.SKIPINITIALSCAN) {
81 args.push('SKIPINITIALSCAN');
82 }
83
84 pushOptionalVerdictArgument(args, 'STOPWORDS', options?.STOPWORDS);
85 args.push('SCHEMA');
86 pushSchema(args, schema);
87
88 return args;
89 }
90
91 export declare function transformReply(): 'OK';