index.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.transformProfile = exports.pushSearchOptions = exports.pushParamsArgs = exports.pushSchema = exports.SCHEMA_GEO_SHAPE_COORD_SYSTEM = exports.VectorAlgorithms = exports.SchemaTextFieldPhonetics = exports.SchemaFieldTypes = exports.pushArgumentsWithLength = exports.pushSortByArguments = exports.pushSortByProperty = exports.RedisSearchLanguages = void 0;
  4. const _LIST = require("./_LIST");
  5. const ALTER = require("./ALTER");
  6. const AGGREGATE_WITHCURSOR = require("./AGGREGATE_WITHCURSOR");
  7. const AGGREGATE = require("./AGGREGATE");
  8. const ALIASADD = require("./ALIASADD");
  9. const ALIASDEL = require("./ALIASDEL");
  10. const ALIASUPDATE = require("./ALIASUPDATE");
  11. const CONFIG_GET = require("./CONFIG_GET");
  12. const CONFIG_SET = require("./CONFIG_SET");
  13. const CREATE = require("./CREATE");
  14. const CURSOR_DEL = require("./CURSOR_DEL");
  15. const CURSOR_READ = require("./CURSOR_READ");
  16. const DICTADD = require("./DICTADD");
  17. const DICTDEL = require("./DICTDEL");
  18. const DICTDUMP = require("./DICTDUMP");
  19. const DROPINDEX = require("./DROPINDEX");
  20. const EXPLAIN = require("./EXPLAIN");
  21. const EXPLAINCLI = require("./EXPLAINCLI");
  22. const INFO = require("./INFO");
  23. const PROFILESEARCH = require("./PROFILE_SEARCH");
  24. const PROFILEAGGREGATE = require("./PROFILE_AGGREGATE");
  25. const SEARCH = require("./SEARCH");
  26. const SEARCH_NOCONTENT = require("./SEARCH_NOCONTENT");
  27. const SPELLCHECK = require("./SPELLCHECK");
  28. const SUGADD = require("./SUGADD");
  29. const SUGDEL = require("./SUGDEL");
  30. const SUGGET_WITHPAYLOADS = require("./SUGGET_WITHPAYLOADS");
  31. const SUGGET_WITHSCORES_WITHPAYLOADS = require("./SUGGET_WITHSCORES_WITHPAYLOADS");
  32. const SUGGET_WITHSCORES = require("./SUGGET_WITHSCORES");
  33. const SUGGET = require("./SUGGET");
  34. const SUGLEN = require("./SUGLEN");
  35. const SYNDUMP = require("./SYNDUMP");
  36. const SYNUPDATE = require("./SYNUPDATE");
  37. const TAGVALS = require("./TAGVALS");
  38. const generic_transformers_1 = require("@redis/client/dist/lib/commands/generic-transformers");
  39. exports.default = {
  40. _LIST,
  41. _list: _LIST,
  42. ALTER,
  43. alter: ALTER,
  44. AGGREGATE_WITHCURSOR,
  45. aggregateWithCursor: AGGREGATE_WITHCURSOR,
  46. AGGREGATE,
  47. aggregate: AGGREGATE,
  48. ALIASADD,
  49. aliasAdd: ALIASADD,
  50. ALIASDEL,
  51. aliasDel: ALIASDEL,
  52. ALIASUPDATE,
  53. aliasUpdate: ALIASUPDATE,
  54. CONFIG_GET,
  55. configGet: CONFIG_GET,
  56. CONFIG_SET,
  57. configSet: CONFIG_SET,
  58. CREATE,
  59. create: CREATE,
  60. CURSOR_DEL,
  61. cursorDel: CURSOR_DEL,
  62. CURSOR_READ,
  63. cursorRead: CURSOR_READ,
  64. DICTADD,
  65. dictAdd: DICTADD,
  66. DICTDEL,
  67. dictDel: DICTDEL,
  68. DICTDUMP,
  69. dictDump: DICTDUMP,
  70. DROPINDEX,
  71. dropIndex: DROPINDEX,
  72. EXPLAIN,
  73. explain: EXPLAIN,
  74. EXPLAINCLI,
  75. explainCli: EXPLAINCLI,
  76. INFO,
  77. info: INFO,
  78. PROFILESEARCH,
  79. profileSearch: PROFILESEARCH,
  80. PROFILEAGGREGATE,
  81. profileAggregate: PROFILEAGGREGATE,
  82. SEARCH,
  83. search: SEARCH,
  84. SEARCH_NOCONTENT,
  85. searchNoContent: SEARCH_NOCONTENT,
  86. SPELLCHECK,
  87. spellCheck: SPELLCHECK,
  88. SUGADD,
  89. sugAdd: SUGADD,
  90. SUGDEL,
  91. sugDel: SUGDEL,
  92. SUGGET_WITHPAYLOADS,
  93. sugGetWithPayloads: SUGGET_WITHPAYLOADS,
  94. SUGGET_WITHSCORES_WITHPAYLOADS,
  95. sugGetWithScoresWithPayloads: SUGGET_WITHSCORES_WITHPAYLOADS,
  96. SUGGET_WITHSCORES,
  97. sugGetWithScores: SUGGET_WITHSCORES,
  98. SUGGET,
  99. sugGet: SUGGET,
  100. SUGLEN,
  101. sugLen: SUGLEN,
  102. SYNDUMP,
  103. synDump: SYNDUMP,
  104. SYNUPDATE,
  105. synUpdate: SYNUPDATE,
  106. TAGVALS,
  107. tagVals: TAGVALS
  108. };
  109. var RedisSearchLanguages;
  110. (function (RedisSearchLanguages) {
  111. RedisSearchLanguages["ARABIC"] = "Arabic";
  112. RedisSearchLanguages["BASQUE"] = "Basque";
  113. RedisSearchLanguages["CATALANA"] = "Catalan";
  114. RedisSearchLanguages["DANISH"] = "Danish";
  115. RedisSearchLanguages["DUTCH"] = "Dutch";
  116. RedisSearchLanguages["ENGLISH"] = "English";
  117. RedisSearchLanguages["FINNISH"] = "Finnish";
  118. RedisSearchLanguages["FRENCH"] = "French";
  119. RedisSearchLanguages["GERMAN"] = "German";
  120. RedisSearchLanguages["GREEK"] = "Greek";
  121. RedisSearchLanguages["HUNGARIAN"] = "Hungarian";
  122. RedisSearchLanguages["INDONESAIN"] = "Indonesian";
  123. RedisSearchLanguages["IRISH"] = "Irish";
  124. RedisSearchLanguages["ITALIAN"] = "Italian";
  125. RedisSearchLanguages["LITHUANIAN"] = "Lithuanian";
  126. RedisSearchLanguages["NEPALI"] = "Nepali";
  127. RedisSearchLanguages["NORWEIGAN"] = "Norwegian";
  128. RedisSearchLanguages["PORTUGUESE"] = "Portuguese";
  129. RedisSearchLanguages["ROMANIAN"] = "Romanian";
  130. RedisSearchLanguages["RUSSIAN"] = "Russian";
  131. RedisSearchLanguages["SPANISH"] = "Spanish";
  132. RedisSearchLanguages["SWEDISH"] = "Swedish";
  133. RedisSearchLanguages["TAMIL"] = "Tamil";
  134. RedisSearchLanguages["TURKISH"] = "Turkish";
  135. RedisSearchLanguages["CHINESE"] = "Chinese";
  136. })(RedisSearchLanguages || (exports.RedisSearchLanguages = RedisSearchLanguages = {}));
  137. function pushSortByProperty(args, sortBy) {
  138. if (typeof sortBy === 'string') {
  139. args.push(sortBy);
  140. }
  141. else {
  142. args.push(sortBy.BY);
  143. if (sortBy.DIRECTION) {
  144. args.push(sortBy.DIRECTION);
  145. }
  146. }
  147. }
  148. exports.pushSortByProperty = pushSortByProperty;
  149. function pushSortByArguments(args, name, sortBy) {
  150. const lengthBefore = args.push(name, '' // will be overwritten
  151. );
  152. if (Array.isArray(sortBy)) {
  153. for (const field of sortBy) {
  154. pushSortByProperty(args, field);
  155. }
  156. }
  157. else {
  158. pushSortByProperty(args, sortBy);
  159. }
  160. args[lengthBefore - 1] = (args.length - lengthBefore).toString();
  161. return args;
  162. }
  163. exports.pushSortByArguments = pushSortByArguments;
  164. function pushArgumentsWithLength(args, fn) {
  165. const lengthIndex = args.push('') - 1;
  166. fn(args);
  167. args[lengthIndex] = (args.length - lengthIndex - 1).toString();
  168. return args;
  169. }
  170. exports.pushArgumentsWithLength = pushArgumentsWithLength;
  171. var SchemaFieldTypes;
  172. (function (SchemaFieldTypes) {
  173. SchemaFieldTypes["TEXT"] = "TEXT";
  174. SchemaFieldTypes["NUMERIC"] = "NUMERIC";
  175. SchemaFieldTypes["GEO"] = "GEO";
  176. SchemaFieldTypes["TAG"] = "TAG";
  177. SchemaFieldTypes["VECTOR"] = "VECTOR";
  178. SchemaFieldTypes["GEOSHAPE"] = "GEOSHAPE";
  179. })(SchemaFieldTypes || (exports.SchemaFieldTypes = SchemaFieldTypes = {}));
  180. function pushCommonFieldArguments(args, fieldOptions) {
  181. if (fieldOptions.SORTABLE) {
  182. args.push('SORTABLE');
  183. if (fieldOptions.SORTABLE === 'UNF') {
  184. args.push('UNF');
  185. }
  186. }
  187. if (fieldOptions.NOINDEX) {
  188. args.push('NOINDEX');
  189. }
  190. }
  191. var SchemaTextFieldPhonetics;
  192. (function (SchemaTextFieldPhonetics) {
  193. SchemaTextFieldPhonetics["DM_EN"] = "dm:en";
  194. SchemaTextFieldPhonetics["DM_FR"] = "dm:fr";
  195. SchemaTextFieldPhonetics["FM_PT"] = "dm:pt";
  196. SchemaTextFieldPhonetics["DM_ES"] = "dm:es";
  197. })(SchemaTextFieldPhonetics || (exports.SchemaTextFieldPhonetics = SchemaTextFieldPhonetics = {}));
  198. var VectorAlgorithms;
  199. (function (VectorAlgorithms) {
  200. VectorAlgorithms["FLAT"] = "FLAT";
  201. VectorAlgorithms["HNSW"] = "HNSW";
  202. })(VectorAlgorithms || (exports.VectorAlgorithms = VectorAlgorithms = {}));
  203. exports.SCHEMA_GEO_SHAPE_COORD_SYSTEM = {
  204. SPHERICAL: 'SPHERICAL',
  205. FLAT: 'FLAT'
  206. };
  207. function pushSchema(args, schema) {
  208. for (const [field, fieldOptions] of Object.entries(schema)) {
  209. args.push(field);
  210. if (typeof fieldOptions === 'string') {
  211. args.push(fieldOptions);
  212. continue;
  213. }
  214. if (fieldOptions.AS) {
  215. args.push('AS', fieldOptions.AS);
  216. }
  217. args.push(fieldOptions.type);
  218. switch (fieldOptions.type) {
  219. case SchemaFieldTypes.TEXT:
  220. if (fieldOptions.NOSTEM) {
  221. args.push('NOSTEM');
  222. }
  223. if (fieldOptions.WEIGHT) {
  224. args.push('WEIGHT', fieldOptions.WEIGHT.toString());
  225. }
  226. if (fieldOptions.PHONETIC) {
  227. args.push('PHONETIC', fieldOptions.PHONETIC);
  228. }
  229. if (fieldOptions.WITHSUFFIXTRIE) {
  230. args.push('WITHSUFFIXTRIE');
  231. }
  232. pushCommonFieldArguments(args, fieldOptions);
  233. if (fieldOptions.INDEXEMPTY) {
  234. args.push('INDEXEMPTY');
  235. }
  236. break;
  237. case SchemaFieldTypes.NUMERIC:
  238. case SchemaFieldTypes.GEO:
  239. pushCommonFieldArguments(args, fieldOptions);
  240. break;
  241. case SchemaFieldTypes.TAG:
  242. if (fieldOptions.SEPARATOR) {
  243. args.push('SEPARATOR', fieldOptions.SEPARATOR);
  244. }
  245. if (fieldOptions.CASESENSITIVE) {
  246. args.push('CASESENSITIVE');
  247. }
  248. if (fieldOptions.WITHSUFFIXTRIE) {
  249. args.push('WITHSUFFIXTRIE');
  250. }
  251. pushCommonFieldArguments(args, fieldOptions);
  252. if (fieldOptions.INDEXEMPTY) {
  253. args.push('INDEXEMPTY');
  254. }
  255. break;
  256. case SchemaFieldTypes.VECTOR:
  257. args.push(fieldOptions.ALGORITHM);
  258. pushArgumentsWithLength(args, () => {
  259. args.push('TYPE', fieldOptions.TYPE, 'DIM', fieldOptions.DIM.toString(), 'DISTANCE_METRIC', fieldOptions.DISTANCE_METRIC);
  260. if (fieldOptions.INITIAL_CAP) {
  261. args.push('INITIAL_CAP', fieldOptions.INITIAL_CAP.toString());
  262. }
  263. switch (fieldOptions.ALGORITHM) {
  264. case VectorAlgorithms.FLAT:
  265. if (fieldOptions.BLOCK_SIZE) {
  266. args.push('BLOCK_SIZE', fieldOptions.BLOCK_SIZE.toString());
  267. }
  268. break;
  269. case VectorAlgorithms.HNSW:
  270. if (fieldOptions.M) {
  271. args.push('M', fieldOptions.M.toString());
  272. }
  273. if (fieldOptions.EF_CONSTRUCTION) {
  274. args.push('EF_CONSTRUCTION', fieldOptions.EF_CONSTRUCTION.toString());
  275. }
  276. if (fieldOptions.EF_RUNTIME) {
  277. args.push('EF_RUNTIME', fieldOptions.EF_RUNTIME.toString());
  278. }
  279. break;
  280. }
  281. });
  282. break;
  283. case SchemaFieldTypes.GEOSHAPE:
  284. if (fieldOptions.COORD_SYSTEM !== undefined) {
  285. args.push('COORD_SYSTEM', fieldOptions.COORD_SYSTEM);
  286. }
  287. pushCommonFieldArguments(args, fieldOptions);
  288. break;
  289. }
  290. if (fieldOptions.INDEXMISSING) {
  291. args.push('INDEXMISSING');
  292. }
  293. }
  294. }
  295. exports.pushSchema = pushSchema;
  296. function pushParamsArgs(args, params) {
  297. if (params) {
  298. const enrties = Object.entries(params);
  299. args.push('PARAMS', (enrties.length * 2).toString());
  300. for (const [key, value] of enrties) {
  301. args.push(key, typeof value === 'number' ? value.toString() : value);
  302. }
  303. }
  304. return args;
  305. }
  306. exports.pushParamsArgs = pushParamsArgs;
  307. function pushSearchOptions(args, options) {
  308. if (options?.VERBATIM) {
  309. args.push('VERBATIM');
  310. }
  311. if (options?.NOSTOPWORDS) {
  312. args.push('NOSTOPWORDS');
  313. }
  314. // if (options?.WITHSCORES) {
  315. // args.push('WITHSCORES');
  316. // }
  317. // if (options?.WITHPAYLOADS) {
  318. // args.push('WITHPAYLOADS');
  319. // }
  320. (0, generic_transformers_1.pushOptionalVerdictArgument)(args, 'INKEYS', options?.INKEYS);
  321. (0, generic_transformers_1.pushOptionalVerdictArgument)(args, 'INFIELDS', options?.INFIELDS);
  322. (0, generic_transformers_1.pushOptionalVerdictArgument)(args, 'RETURN', options?.RETURN);
  323. if (options?.SUMMARIZE) {
  324. args.push('SUMMARIZE');
  325. if (typeof options.SUMMARIZE === 'object') {
  326. if (options.SUMMARIZE.FIELDS) {
  327. args.push('FIELDS');
  328. (0, generic_transformers_1.pushVerdictArgument)(args, options.SUMMARIZE.FIELDS);
  329. }
  330. if (options.SUMMARIZE.FRAGS) {
  331. args.push('FRAGS', options.SUMMARIZE.FRAGS.toString());
  332. }
  333. if (options.SUMMARIZE.LEN) {
  334. args.push('LEN', options.SUMMARIZE.LEN.toString());
  335. }
  336. if (options.SUMMARIZE.SEPARATOR) {
  337. args.push('SEPARATOR', options.SUMMARIZE.SEPARATOR);
  338. }
  339. }
  340. }
  341. if (options?.HIGHLIGHT) {
  342. args.push('HIGHLIGHT');
  343. if (typeof options.HIGHLIGHT === 'object') {
  344. if (options.HIGHLIGHT.FIELDS) {
  345. args.push('FIELDS');
  346. (0, generic_transformers_1.pushVerdictArgument)(args, options.HIGHLIGHT.FIELDS);
  347. }
  348. if (options.HIGHLIGHT.TAGS) {
  349. args.push('TAGS', options.HIGHLIGHT.TAGS.open, options.HIGHLIGHT.TAGS.close);
  350. }
  351. }
  352. }
  353. if (options?.SLOP) {
  354. args.push('SLOP', options.SLOP.toString());
  355. }
  356. if (options?.INORDER) {
  357. args.push('INORDER');
  358. }
  359. if (options?.LANGUAGE) {
  360. args.push('LANGUAGE', options.LANGUAGE);
  361. }
  362. if (options?.EXPANDER) {
  363. args.push('EXPANDER', options.EXPANDER);
  364. }
  365. if (options?.SCORER) {
  366. args.push('SCORER', options.SCORER);
  367. }
  368. // if (options?.EXPLAINSCORE) {
  369. // args.push('EXPLAINSCORE');
  370. // }
  371. // if (options?.PAYLOAD) {
  372. // args.push('PAYLOAD', options.PAYLOAD);
  373. // }
  374. if (options?.SORTBY) {
  375. args.push('SORTBY');
  376. pushSortByProperty(args, options.SORTBY);
  377. }
  378. // if (options?.MSORTBY) {
  379. // pushSortByArguments(args, 'MSORTBY', options.MSORTBY);
  380. // }
  381. if (options?.LIMIT) {
  382. args.push('LIMIT', options.LIMIT.from.toString(), options.LIMIT.size.toString());
  383. }
  384. if (options?.PARAMS) {
  385. pushParamsArgs(args, options.PARAMS);
  386. }
  387. if (options?.DIALECT) {
  388. args.push('DIALECT', options.DIALECT.toString());
  389. }
  390. if (options?.RETURN?.length === 0) {
  391. args.preserve = true;
  392. }
  393. if (options?.TIMEOUT !== undefined) {
  394. args.push('TIMEOUT', options.TIMEOUT.toString());
  395. }
  396. return args;
  397. }
  398. exports.pushSearchOptions = pushSearchOptions;
  399. function transformProfile(reply) {
  400. return {
  401. totalProfileTime: reply[0][1],
  402. parsingTime: reply[1][1],
  403. pipelineCreationTime: reply[2][1],
  404. iteratorsProfile: transformIterators(reply[3][1])
  405. };
  406. }
  407. exports.transformProfile = transformProfile;
  408. function transformIterators(IteratorsProfile) {
  409. var res = {};
  410. for (let i = 0; i < IteratorsProfile.length; i += 2) {
  411. const value = IteratorsProfile[i + 1];
  412. switch (IteratorsProfile[i]) {
  413. case 'Type':
  414. res.type = value;
  415. break;
  416. case 'Counter':
  417. res.counter = value;
  418. break;
  419. case 'Time':
  420. res.time = value;
  421. break;
  422. case 'Query type':
  423. res.queryType = value;
  424. break;
  425. case 'Child iterators':
  426. res.childIterators = value.map(transformChildIterators);
  427. break;
  428. }
  429. }
  430. return res;
  431. }
  432. function transformChildIterators(IteratorsProfile) {
  433. var res = {};
  434. for (let i = 1; i < IteratorsProfile.length; i += 2) {
  435. const value = IteratorsProfile[i + 1];
  436. switch (IteratorsProfile[i]) {
  437. case 'Type':
  438. res.type = value;
  439. break;
  440. case 'Counter':
  441. res.counter = value;
  442. break;
  443. case 'Time':
  444. res.time = value;
  445. break;
  446. case 'Size':
  447. res.size = value;
  448. break;
  449. case 'Term':
  450. res.term = value;
  451. break;
  452. case 'Child iterators':
  453. res.childIterators = value.map(transformChildIterators);
  454. break;
  455. }
  456. }
  457. return res;
  458. }