You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
@@ -1,7 +1,7 @@
|
|||||||
import { strict as assert } from 'assert';
|
import { strict as assert } from 'assert';
|
||||||
import testUtils, { GLOBAL } from '../test-utils';
|
import testUtils, { GLOBAL } from '../test-utils';
|
||||||
import { AggregateGroupByReducers, AggregateSteps, transformArguments } from './AGGREGATE';
|
import { AggregateGroupByReducers, AggregateSteps, transformArguments } from './AGGREGATE';
|
||||||
import { SchemaFieldTypes } from './CREATE';
|
import { SchemaFieldTypes } from '.';
|
||||||
|
|
||||||
describe('AGGREGATE', () => {
|
describe('AGGREGATE', () => {
|
||||||
describe('transformArguments', () => {
|
describe('transformArguments', () => {
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
import { RedisCommandArguments } from '@node-redis/client/dist/lib/commands';
|
import { RedisCommandArguments } from '@node-redis/client/dist/lib/commands';
|
||||||
import { pushVerdictArgument, transformReplyTuples, TuplesObject } from '@node-redis/client/dist/lib/commands/generic-transformers';
|
import { pushVerdictArgument, transformReplyTuples, TuplesObject } from '@node-redis/client/dist/lib/commands/generic-transformers';
|
||||||
import { PropertyName, pushArgumentsWithLength, pushSortByArguments, SortByProperty } from '.';
|
import { AggregateReply, PropertyName, pushArgumentsWithLength, pushSortByArguments, SortByProperty } from '.';
|
||||||
|
|
||||||
export enum AggregateSteps {
|
export enum AggregateSteps {
|
||||||
GROUPBY = 'GROUPBY',
|
GROUPBY = 'GROUPBY',
|
||||||
@@ -118,14 +118,27 @@ type LoadField = PropertyName | {
|
|||||||
AS?: string;
|
AS?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface AggregateOptions {
|
export interface AggregateOptions {
|
||||||
VERBATIM?: true;
|
VERBATIM?: true;
|
||||||
LOAD?: LoadField | Array<LoadField>;
|
LOAD?: LoadField | Array<LoadField>;
|
||||||
STEPS?: Array<GroupByStep | SortStep | ApplyStep | LimitStep | FilterStep>;
|
STEPS?: Array<GroupByStep | SortStep | ApplyStep | LimitStep | FilterStep>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function transformArguments(index: string, query: string, options?: AggregateOptions): RedisCommandArguments {
|
export function transformArguments(
|
||||||
|
index: string,
|
||||||
|
query: string,
|
||||||
|
options?: AggregateOptions
|
||||||
|
): RedisCommandArguments {
|
||||||
|
|
||||||
const args = ['FT.AGGREGATE', index, query];
|
const args = ['FT.AGGREGATE', index, query];
|
||||||
|
pushAggregatehOptions(args, options);
|
||||||
|
return args;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function pushAggregatehOptions(
|
||||||
|
args: RedisCommandArguments,
|
||||||
|
options?: AggregateOptions
|
||||||
|
): RedisCommandArguments {
|
||||||
|
|
||||||
if (options?.VERBATIM) {
|
if (options?.VERBATIM) {
|
||||||
args.push('VERBATIM');
|
args.push('VERBATIM');
|
||||||
@@ -258,16 +271,11 @@ function pushGroupByReducer(args: RedisCommandArguments, reducer: GroupByReducer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type AggregateRawReply = [
|
export type AggregateRawReply = [
|
||||||
total: number,
|
total: number,
|
||||||
...results: Array<Array<string>>
|
...results: Array<Array<string>>
|
||||||
];
|
];
|
||||||
|
|
||||||
interface AggregateReply {
|
|
||||||
total: number;
|
|
||||||
results: Array<TuplesObject>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function transformReply(rawReply: AggregateRawReply): AggregateReply {
|
export function transformReply(rawReply: AggregateRawReply): AggregateReply {
|
||||||
const results: Array<TuplesObject> = [];
|
const results: Array<TuplesObject> = [];
|
||||||
for (let i = 1; i < rawReply.length; i++) {
|
for (let i = 1; i < rawReply.length; i++) {
|
||||||
|
37
packages/search/lib/commands/ALTER.spec.ts
Normal file
37
packages/search/lib/commands/ALTER.spec.ts
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
import { strict as assert } from 'assert';
|
||||||
|
import testUtils, { GLOBAL } from '../test-utils';
|
||||||
|
import { transformArguments } from './ALTER';
|
||||||
|
import { SchemaFieldTypes } from '.';
|
||||||
|
|
||||||
|
describe('ALTER', () => {
|
||||||
|
describe('transformArguments', () => {
|
||||||
|
it('with NOINDEX', () => {
|
||||||
|
assert.deepEqual(
|
||||||
|
transformArguments('index', {
|
||||||
|
field: {
|
||||||
|
type: SchemaFieldTypes.TEXT,
|
||||||
|
NOINDEX: true,
|
||||||
|
SORTABLE: 'UNF',
|
||||||
|
AS: 'text'
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
['FT.ALTER', 'index', 'SCHEMA', 'ADD', 'field', 'AS', 'text', 'TEXT', 'SORTABLE', 'UNF', 'NOINDEX']
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
testUtils.testWithClient('client.ft.create', async client => {
|
||||||
|
await Promise.all([
|
||||||
|
client.ft.create('index', {
|
||||||
|
title: SchemaFieldTypes.TEXT
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
|
||||||
|
assert.equal(
|
||||||
|
await client.ft.alter('index', {
|
||||||
|
body: SchemaFieldTypes.TEXT
|
||||||
|
}),
|
||||||
|
'OK'
|
||||||
|
);
|
||||||
|
}, GLOBAL.SERVERS.OPEN);
|
||||||
|
});
|
10
packages/search/lib/commands/ALTER.ts
Normal file
10
packages/search/lib/commands/ALTER.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import { CreateSchema, pushSchema } from '.';
|
||||||
|
|
||||||
|
export function transformArguments(index: string, schema: CreateSchema): Array<string> {
|
||||||
|
const args = ['FT.ALTER', index, 'SCHEMA', 'ADD'];
|
||||||
|
pushSchema(args, schema);
|
||||||
|
|
||||||
|
return args;
|
||||||
|
}
|
||||||
|
|
||||||
|
export declare function transformReply(): 'OK';
|
@@ -1,7 +1,7 @@
|
|||||||
import { strict as assert } from 'assert';
|
import { strict as assert } from 'assert';
|
||||||
import testUtils, { GLOBAL } from '../test-utils';
|
import testUtils, { GLOBAL } from '../test-utils';
|
||||||
import { SchemaFieldTypes, SchemaTextFieldPhonetics, transformArguments } from './CREATE';
|
import { transformArguments } from './CREATE';
|
||||||
import { RedisSearchLanguages } from '.';
|
import { SchemaFieldTypes, SchemaTextFieldPhonetics, RedisSearchLanguages } from '.';
|
||||||
|
|
||||||
describe('CREATE', () => {
|
describe('CREATE', () => {
|
||||||
describe('transformArguments', () => {
|
describe('transformArguments', () => {
|
||||||
|
@@ -1,49 +1,5 @@
|
|||||||
import { pushOptionalVerdictArgument } from '@node-redis/client/dist/lib/commands/generic-transformers';
|
import { pushOptionalVerdictArgument } from '@node-redis/client/dist/lib/commands/generic-transformers';
|
||||||
import { RedisSearchLanguages, PropertyName } from '.';
|
import { RedisSearchLanguages, PropertyName, CreateSchema, pushSchema } from '.';
|
||||||
|
|
||||||
export enum SchemaFieldTypes {
|
|
||||||
TEXT = 'TEXT',
|
|
||||||
NUMERIC = 'NUMERIC',
|
|
||||||
GEO = 'GEO',
|
|
||||||
TAG = 'TAG'
|
|
||||||
}
|
|
||||||
|
|
||||||
type CreateSchemaField<T extends SchemaFieldTypes, E = Record<string, never>> = T | ({
|
|
||||||
type: T;
|
|
||||||
AS?: string;
|
|
||||||
SORTABLE?: true | 'UNF';
|
|
||||||
NOINDEX?: true;
|
|
||||||
} & E);
|
|
||||||
|
|
||||||
export enum SchemaTextFieldPhonetics {
|
|
||||||
DM_EN = 'dm:en',
|
|
||||||
DM_FR = 'dm:fr',
|
|
||||||
FM_PT = 'dm:pt',
|
|
||||||
DM_ES = 'dm:es'
|
|
||||||
}
|
|
||||||
|
|
||||||
type CreateSchemaTextField = CreateSchemaField<SchemaFieldTypes.TEXT, {
|
|
||||||
NOSTEM?: true;
|
|
||||||
WEIGHT?: number;
|
|
||||||
PHONETIC?: SchemaTextFieldPhonetics;
|
|
||||||
}>;
|
|
||||||
|
|
||||||
type CreateSchemaNumericField = CreateSchemaField<SchemaFieldTypes.NUMERIC>;
|
|
||||||
|
|
||||||
type CreateSchemaGeoField = CreateSchemaField<SchemaFieldTypes.GEO>;
|
|
||||||
|
|
||||||
type CreateSchemaTagField = CreateSchemaField<SchemaFieldTypes.TAG, {
|
|
||||||
SEPERATOR?: string;
|
|
||||||
CASESENSITIVE?: true;
|
|
||||||
}>;
|
|
||||||
|
|
||||||
interface CreateSchema {
|
|
||||||
[field: string]:
|
|
||||||
CreateSchemaTextField |
|
|
||||||
CreateSchemaNumericField |
|
|
||||||
CreateSchemaGeoField |
|
|
||||||
CreateSchemaTagField
|
|
||||||
}
|
|
||||||
|
|
||||||
interface CreateOptions {
|
interface CreateOptions {
|
||||||
ON?: 'HASH' | 'JSON';
|
ON?: 'HASH' | 'JSON';
|
||||||
@@ -126,67 +82,8 @@ export function transformArguments(index: string, schema: CreateSchema, options?
|
|||||||
}
|
}
|
||||||
|
|
||||||
pushOptionalVerdictArgument(args, 'STOPWORDS', options?.STOPWORDS);
|
pushOptionalVerdictArgument(args, 'STOPWORDS', options?.STOPWORDS);
|
||||||
|
|
||||||
args.push('SCHEMA');
|
args.push('SCHEMA');
|
||||||
|
pushSchema(args, schema);
|
||||||
for (const [field, fieldOptions] of Object.entries(schema)) {
|
|
||||||
args.push(field);
|
|
||||||
|
|
||||||
if (typeof fieldOptions === 'string') {
|
|
||||||
args.push(fieldOptions);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fieldOptions.AS) {
|
|
||||||
args.push('AS', fieldOptions.AS);
|
|
||||||
}
|
|
||||||
|
|
||||||
args.push(fieldOptions.type);
|
|
||||||
|
|
||||||
switch (fieldOptions.type) {
|
|
||||||
case 'TEXT':
|
|
||||||
if (fieldOptions.NOSTEM) {
|
|
||||||
args.push('NOSTEM');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fieldOptions.WEIGHT) {
|
|
||||||
args.push('WEIGHT', fieldOptions.WEIGHT.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fieldOptions.PHONETIC) {
|
|
||||||
args.push('PHONETIC', fieldOptions.PHONETIC);
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
// case 'NUMERIC':
|
|
||||||
// case 'GEO':
|
|
||||||
// break;
|
|
||||||
|
|
||||||
case 'TAG':
|
|
||||||
if (fieldOptions.SEPERATOR) {
|
|
||||||
args.push('SEPERATOR', fieldOptions.SEPERATOR);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fieldOptions.CASESENSITIVE) {
|
|
||||||
args.push('CASESENSITIVE');
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fieldOptions.SORTABLE) {
|
|
||||||
args.push('SORTABLE');
|
|
||||||
|
|
||||||
if (fieldOptions.SORTABLE === 'UNF') {
|
|
||||||
args.push('UNF');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fieldOptions.NOINDEX) {
|
|
||||||
args.push('NOINDEX');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
import { strict as assert } from 'assert';
|
import { strict as assert } from 'assert';
|
||||||
import testUtils, { GLOBAL } from '../test-utils';
|
import testUtils, { GLOBAL } from '../test-utils';
|
||||||
import { SchemaFieldTypes } from './CREATE';
|
import { SchemaFieldTypes } from '.';
|
||||||
import { transformArguments } from './DROPINDEX';
|
import { transformArguments } from './DROPINDEX';
|
||||||
|
|
||||||
describe('DROPINDEX', () => {
|
describe('DROPINDEX', () => {
|
||||||
|
@@ -1,6 +1,5 @@
|
|||||||
import { strict as assert } from 'assert';
|
import { strict as assert } from 'assert';
|
||||||
import testUtils, { GLOBAL } from '../test-utils';
|
import testUtils, { GLOBAL } from '../test-utils';
|
||||||
import { SchemaFieldTypes } from './CREATE';
|
|
||||||
import { transformArguments } from './INFO';
|
import { transformArguments } from './INFO';
|
||||||
|
|
||||||
describe('INFO', () => {
|
describe('INFO', () => {
|
||||||
|
@@ -1,26 +0,0 @@
|
|||||||
export const IS_READ_ONLY = true;
|
|
||||||
|
|
||||||
interface ProfileOptions {
|
|
||||||
LIMITED?: true;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function transformArguments(
|
|
||||||
index: string,
|
|
||||||
type: 'SEARCH' | 'AGGREGATE',
|
|
||||||
query: string,
|
|
||||||
options?: ProfileOptions
|
|
||||||
): Array<string> {
|
|
||||||
const args = ['FT.PROFILE', index, type];
|
|
||||||
|
|
||||||
if (options?.LIMITED) {
|
|
||||||
args.push('LIMITED');
|
|
||||||
}
|
|
||||||
|
|
||||||
args.push('QUERY', query);
|
|
||||||
|
|
||||||
return args;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function transformReply() {
|
|
||||||
|
|
||||||
}
|
|
46
packages/search/lib/commands/PROFILE_AGGREGATE.spec.ts
Normal file
46
packages/search/lib/commands/PROFILE_AGGREGATE.spec.ts
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
import { strict as assert } from 'assert';
|
||||||
|
import testUtils, { GLOBAL } from '../test-utils';
|
||||||
|
import { SchemaFieldTypes } from '.';
|
||||||
|
import { transformArguments } from './PROFILE_AGGREGATE';
|
||||||
|
import { AggregateSteps } from './AGGREGATE';
|
||||||
|
|
||||||
|
describe('PROFILE AGGREGATE', () => {
|
||||||
|
describe('transformArguments', () => {
|
||||||
|
it('without options', () => {
|
||||||
|
assert.deepEqual(
|
||||||
|
transformArguments('index', 'query'),
|
||||||
|
['FT.PROFILE', 'index', 'AGGREGATE', 'QUERY', 'query']
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('with options', () => {
|
||||||
|
assert.deepEqual(
|
||||||
|
transformArguments('index', 'query', {
|
||||||
|
LIMITED: true,
|
||||||
|
VERBATIM: true,
|
||||||
|
STEPS: [{
|
||||||
|
type: AggregateSteps.SORTBY,
|
||||||
|
BY: '@by'
|
||||||
|
}]
|
||||||
|
}),
|
||||||
|
['FT.PROFILE', 'index', 'AGGREGATE', 'LIMITED', 'QUERY', 'query',
|
||||||
|
'VERBATIM', 'SORTBY', '1', '@by']
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
testUtils.testWithClient('client.ft.search', async client => {
|
||||||
|
await Promise.all([
|
||||||
|
client.ft.create('index', {
|
||||||
|
field: SchemaFieldTypes.NUMERIC
|
||||||
|
}),
|
||||||
|
client.hSet('1', 'field', '1'),
|
||||||
|
client.hSet('2', 'field', '2')
|
||||||
|
]);
|
||||||
|
|
||||||
|
const res = await client.ft.profileAggregate('index', '*');
|
||||||
|
assert.ok(typeof res.profile.iteratorsProfile.counter === 'number');
|
||||||
|
assert.ok(typeof res.profile.parsingTime === 'string');
|
||||||
|
assert.ok(res.results.total == 1);
|
||||||
|
}, GLOBAL.SERVERS.OPEN);
|
||||||
|
});
|
29
packages/search/lib/commands/PROFILE_AGGREGATE.ts
Normal file
29
packages/search/lib/commands/PROFILE_AGGREGATE.ts
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import { pushAggregatehOptions, AggregateOptions, transformReply as transformAggregateReply, AggregateRawReply } from './AGGREGATE';
|
||||||
|
import { ProfileOptions, ProfileRawReply, ProfileReply, transformProfile } from '.';
|
||||||
|
|
||||||
|
export const IS_READ_ONLY = true;
|
||||||
|
|
||||||
|
export function transformArguments(
|
||||||
|
index: string,
|
||||||
|
query: string,
|
||||||
|
options?: ProfileOptions & AggregateOptions
|
||||||
|
): Array<string> {
|
||||||
|
const args = ['FT.PROFILE', index, 'AGGREGATE'];
|
||||||
|
|
||||||
|
if (options?.LIMITED) {
|
||||||
|
args.push('LIMITED');
|
||||||
|
}
|
||||||
|
|
||||||
|
args.push('QUERY', query);
|
||||||
|
pushAggregatehOptions(args, options)
|
||||||
|
return args;
|
||||||
|
}
|
||||||
|
|
||||||
|
type ProfileAggeregateRawReply = ProfileRawReply<AggregateRawReply>;
|
||||||
|
|
||||||
|
export function transformReply(reply: ProfileAggeregateRawReply): ProfileReply {
|
||||||
|
return {
|
||||||
|
results: transformAggregateReply(reply[0]),
|
||||||
|
profile: transformProfile(reply[1])
|
||||||
|
};
|
||||||
|
}
|
41
packages/search/lib/commands/PROFILE_SEARCH.spec.ts
Normal file
41
packages/search/lib/commands/PROFILE_SEARCH.spec.ts
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
import { strict as assert } from 'assert';
|
||||||
|
import testUtils, { GLOBAL } from '../test-utils';
|
||||||
|
import { SchemaFieldTypes } from '.';
|
||||||
|
import { transformArguments } from './PROFILE_SEARCH';
|
||||||
|
|
||||||
|
describe('PROFILE SEARCH', () => {
|
||||||
|
describe('transformArguments', () => {
|
||||||
|
it('without options', () => {
|
||||||
|
assert.deepEqual(
|
||||||
|
transformArguments('index', 'query'),
|
||||||
|
['FT.PROFILE', 'index', 'SEARCH', 'QUERY', 'query']
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('with options', () => {
|
||||||
|
assert.deepEqual(
|
||||||
|
transformArguments('index', 'query', {
|
||||||
|
LIMITED: true,
|
||||||
|
VERBATIM: true,
|
||||||
|
INKEYS: 'key'
|
||||||
|
}),
|
||||||
|
['FT.PROFILE', 'index', 'SEARCH', 'LIMITED', 'QUERY', 'query',
|
||||||
|
'VERBATIM', 'INKEYS', '1', 'key']
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
testUtils.testWithClient('client.ft.search', async client => {
|
||||||
|
await Promise.all([
|
||||||
|
client.ft.create('index', {
|
||||||
|
field: SchemaFieldTypes.NUMERIC
|
||||||
|
}),
|
||||||
|
client.hSet('1', 'field', '1')
|
||||||
|
]);
|
||||||
|
|
||||||
|
const res = await client.ft.profileSearch('index', '*');
|
||||||
|
assert.ok(typeof res.profile.iteratorsProfile.counter === 'number');
|
||||||
|
assert.ok(typeof res.profile.parsingTime === 'string');
|
||||||
|
assert.ok(res.results.total == 1);
|
||||||
|
}, GLOBAL.SERVERS.OPEN);
|
||||||
|
});
|
29
packages/search/lib/commands/PROFILE_SEARCH.ts
Normal file
29
packages/search/lib/commands/PROFILE_SEARCH.ts
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import { SearchOptions, SearchRawReply, transformReply as transformSearchReply } from './SEARCH';
|
||||||
|
import { pushSearchOptions, ProfileOptions, ProfileRawReply, ProfileReply, transformProfile } from '.';
|
||||||
|
|
||||||
|
export const IS_READ_ONLY = true;
|
||||||
|
|
||||||
|
export function transformArguments(
|
||||||
|
index: string,
|
||||||
|
query: string,
|
||||||
|
options?: ProfileOptions & SearchOptions
|
||||||
|
): Array<string> {
|
||||||
|
const args = ['FT.PROFILE', index, 'SEARCH'];
|
||||||
|
|
||||||
|
if (options?.LIMITED) {
|
||||||
|
args.push('LIMITED');
|
||||||
|
}
|
||||||
|
|
||||||
|
args.push('QUERY', query);
|
||||||
|
pushSearchOptions(args, options)
|
||||||
|
return args;
|
||||||
|
}
|
||||||
|
|
||||||
|
type ProfileSearchRawReply = ProfileRawReply<SearchRawReply>;
|
||||||
|
|
||||||
|
export function transformReply(reply: ProfileSearchRawReply): ProfileReply {
|
||||||
|
return {
|
||||||
|
results: transformSearchReply(reply[0]),
|
||||||
|
profile: transformProfile(reply[1])
|
||||||
|
};
|
||||||
|
}
|
@@ -1,7 +1,6 @@
|
|||||||
import { strict as assert } from 'assert';
|
import { strict as assert } from 'assert';
|
||||||
import { RedisSearchLanguages } from '.';
|
import { RedisSearchLanguages, SchemaFieldTypes } from '.';
|
||||||
import testUtils, { GLOBAL } from '../test-utils';
|
import testUtils, { GLOBAL } from '../test-utils';
|
||||||
import { SchemaFieldTypes } from './CREATE';
|
|
||||||
import { transformArguments } from './SEARCH';
|
import { transformArguments } from './SEARCH';
|
||||||
|
|
||||||
describe('SEARCH', () => {
|
describe('SEARCH', () => {
|
||||||
|
@@ -1,12 +1,12 @@
|
|||||||
import { RedisCommandArguments } from '@node-redis/client/dist/lib/commands';
|
import { RedisCommandArguments } from '@node-redis/client/dist/lib/commands';
|
||||||
import { pushOptionalVerdictArgument, pushVerdictArgument, transformReplyTuples } from '@node-redis/client/dist/lib/commands/generic-transformers';
|
import { transformReplyTuples } from '@node-redis/client/dist/lib/commands/generic-transformers';
|
||||||
import { RedisSearchLanguages, PropertyName, pushSortByProperty, SortByProperty } from '.';
|
import { pushSearchOptions, RedisSearchLanguages, PropertyName, SortByProperty, SearchReply } from '.';
|
||||||
|
|
||||||
export const FIRST_KEY_INDEX = 1;
|
export const FIRST_KEY_INDEX = 1;
|
||||||
|
|
||||||
export const IS_READ_ONLY = true;
|
export const IS_READ_ONLY = true;
|
||||||
|
|
||||||
interface SearchOptions {
|
export interface SearchOptions {
|
||||||
// NOCONTENT?: true; TODO
|
// NOCONTENT?: true; TODO
|
||||||
VERBATIM?: true;
|
VERBATIM?: true;
|
||||||
NOSTOPWORDS?: true;
|
NOSTOPWORDS?: true;
|
||||||
@@ -62,126 +62,13 @@ export function transformArguments(
|
|||||||
options?: SearchOptions
|
options?: SearchOptions
|
||||||
): RedisCommandArguments {
|
): RedisCommandArguments {
|
||||||
const args: RedisCommandArguments = ['FT.SEARCH', index, query];
|
const args: RedisCommandArguments = ['FT.SEARCH', index, query];
|
||||||
|
pushSearchOptions(args, options);
|
||||||
if (options?.VERBATIM) {
|
|
||||||
args.push('VERBATIM');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options?.NOSTOPWORDS) {
|
|
||||||
args.push('NOSTOPWORDS');
|
|
||||||
}
|
|
||||||
|
|
||||||
// if (options?.WITHSCORES) {
|
|
||||||
// args.push('WITHSCORES');
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (options?.WITHPAYLOADS) {
|
|
||||||
// args.push('WITHPAYLOADS');
|
|
||||||
// }
|
|
||||||
|
|
||||||
pushOptionalVerdictArgument(args, 'INKEYS', options?.INKEYS);
|
|
||||||
pushOptionalVerdictArgument(args, 'INFIELDS', options?.INFIELDS);
|
|
||||||
pushOptionalVerdictArgument(args, 'RETURN', options?.RETURN);
|
|
||||||
|
|
||||||
if (options?.SUMMARIZE) {
|
|
||||||
args.push('SUMMARIZE');
|
|
||||||
|
|
||||||
if (typeof options.SUMMARIZE === 'object') {
|
|
||||||
if (options.SUMMARIZE.FIELDS) {
|
|
||||||
args.push('FIELDS');
|
|
||||||
pushVerdictArgument(args, options.SUMMARIZE.FIELDS);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options.SUMMARIZE.FRAGS) {
|
|
||||||
args.push('FRAGS', options.SUMMARIZE.FRAGS.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options.SUMMARIZE.LEN) {
|
|
||||||
args.push('LEN', options.SUMMARIZE.LEN.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options.SUMMARIZE.SEPARATOR) {
|
|
||||||
args.push('SEPARATOR', options.SUMMARIZE.SEPARATOR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options?.HIGHLIGHT) {
|
|
||||||
args.push('HIGHLIGHT');
|
|
||||||
|
|
||||||
if (typeof options.HIGHLIGHT === 'object') {
|
|
||||||
if (options.HIGHLIGHT.FIELDS) {
|
|
||||||
args.push('FIELDS');
|
|
||||||
pushVerdictArgument(args, options.HIGHLIGHT.FIELDS);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options.HIGHLIGHT.TAGS) {
|
|
||||||
args.push('TAGS', options.HIGHLIGHT.TAGS.open, options.HIGHLIGHT.TAGS.close);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options?.SLOP) {
|
|
||||||
args.push('SLOP', options.SLOP.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options?.INORDER) {
|
|
||||||
args.push('INORDER');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options?.LANGUAGE) {
|
|
||||||
args.push('LANGUAGE', options.LANGUAGE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options?.EXPANDER) {
|
|
||||||
args.push('EXPANDER', options.EXPANDER);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options?.SCORER) {
|
|
||||||
args.push('SCORER', options.SCORER);
|
|
||||||
}
|
|
||||||
|
|
||||||
// if (options?.EXPLAINSCORE) {
|
|
||||||
// args.push('EXPLAINSCORE');
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (options?.PAYLOAD) {
|
|
||||||
// args.push('PAYLOAD', options.PAYLOAD);
|
|
||||||
// }
|
|
||||||
|
|
||||||
if (options?.SORTBY) {
|
|
||||||
args.push('SORTBY');
|
|
||||||
pushSortByProperty(args, options.SORTBY);
|
|
||||||
}
|
|
||||||
|
|
||||||
// if (options?.MSORTBY) {
|
|
||||||
// pushSortByArguments(args, 'MSORTBY', options.MSORTBY);
|
|
||||||
// }
|
|
||||||
|
|
||||||
if (options?.LIMIT) {
|
|
||||||
args.push(
|
|
||||||
'LIMIT',
|
|
||||||
options.LIMIT.from.toString(),
|
|
||||||
options.LIMIT.size.toString()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface SearchDocumentValue {
|
export type SearchRawReply = Array<any>;
|
||||||
[key: string]: string | number | null | Array<SearchDocumentValue> | SearchDocumentValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface SearchReply {
|
export function transformReply(reply: SearchRawReply): SearchReply {
|
||||||
total: number;
|
|
||||||
documents: Array<{
|
|
||||||
id: string;
|
|
||||||
value: SearchDocumentValue;
|
|
||||||
}>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function transformReply(reply: Array<any>): SearchReply {
|
|
||||||
const documents = [];
|
const documents = [];
|
||||||
for (let i = 1; i < reply.length; i += 2) {
|
for (let i = 1; i < reply.length; i += 2) {
|
||||||
const tuples = reply[i + 1];
|
const tuples = reply[i + 1];
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
import { strict as assert } from 'assert';
|
import { strict as assert } from 'assert';
|
||||||
import testUtils, { GLOBAL } from '../test-utils';
|
import testUtils, { GLOBAL } from '../test-utils';
|
||||||
import { SchemaFieldTypes } from './CREATE';
|
import { SchemaFieldTypes } from '.';
|
||||||
import { transformArguments } from './SPELLCHECK';
|
import { transformArguments } from './SPELLCHECK';
|
||||||
|
|
||||||
describe('SPELLCHECK', () => {
|
describe('SPELLCHECK', () => {
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
import { strict as assert } from 'assert';
|
import { strict as assert } from 'assert';
|
||||||
import testUtils, { GLOBAL } from '../test-utils';
|
import testUtils, { GLOBAL } from '../test-utils';
|
||||||
import { SchemaFieldTypes } from './CREATE';
|
import { SchemaFieldTypes } from '.';
|
||||||
import { transformArguments } from './TAGVALS';
|
import { transformArguments } from './TAGVALS';
|
||||||
|
|
||||||
describe('TAGVALS', () => {
|
describe('TAGVALS', () => {
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
import * as _LIST from './_LIST';
|
import * as _LIST from './_LIST';
|
||||||
|
import * as ALTER from './ALTER';
|
||||||
import * as AGGREGATE from './AGGREGATE';
|
import * as AGGREGATE from './AGGREGATE';
|
||||||
import * as ALIASADD from './ALIASADD';
|
import * as ALIASADD from './ALIASADD';
|
||||||
import * as ALIASDEL from './ALIASDEL';
|
import * as ALIASDEL from './ALIASDEL';
|
||||||
@@ -13,7 +14,8 @@ import * as DROPINDEX from './DROPINDEX';
|
|||||||
import * as EXPLAIN from './EXPLAIN';
|
import * as EXPLAIN from './EXPLAIN';
|
||||||
import * as EXPLAINCLI from './EXPLAINCLI';
|
import * as EXPLAINCLI from './EXPLAINCLI';
|
||||||
import * as INFO from './INFO';
|
import * as INFO from './INFO';
|
||||||
// import * as PROFILE from './PROFILE';
|
import * as PROFILESEARCH from './PROFILE_SEARCH';
|
||||||
|
import * as PROFILEAGGREGATE from './PROFILE_AGGREGATE';
|
||||||
import * as SEARCH from './SEARCH';
|
import * as SEARCH from './SEARCH';
|
||||||
import * as SPELLCHECK from './SPELLCHECK';
|
import * as SPELLCHECK from './SPELLCHECK';
|
||||||
import * as SUGADD from './SUGADD';
|
import * as SUGADD from './SUGADD';
|
||||||
@@ -27,10 +29,15 @@ import * as SYNDUMP from './SYNDUMP';
|
|||||||
import * as SYNUPDATE from './SYNUPDATE';
|
import * as SYNUPDATE from './SYNUPDATE';
|
||||||
import * as TAGVALS from './TAGVALS';
|
import * as TAGVALS from './TAGVALS';
|
||||||
import { RedisCommandArguments } from '@node-redis/client/dist/lib/commands';
|
import { RedisCommandArguments } from '@node-redis/client/dist/lib/commands';
|
||||||
|
import { pushOptionalVerdictArgument, pushVerdictArgument, TuplesObject } from '@node-redis/client/dist/lib/commands/generic-transformers';
|
||||||
|
import internal = require('stream');
|
||||||
|
import { SearchOptions } from './SEARCH';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
_LIST,
|
_LIST,
|
||||||
_list: _LIST,
|
_list: _LIST,
|
||||||
|
ALTER,
|
||||||
|
alter: ALTER,
|
||||||
AGGREGATE,
|
AGGREGATE,
|
||||||
aggregate: AGGREGATE,
|
aggregate: AGGREGATE,
|
||||||
ALIASADD,
|
ALIASADD,
|
||||||
@@ -59,8 +66,10 @@ export default {
|
|||||||
explainCli: EXPLAINCLI,
|
explainCli: EXPLAINCLI,
|
||||||
INFO,
|
INFO,
|
||||||
info: INFO,
|
info: INFO,
|
||||||
// PROFILE,
|
PROFILESEARCH,
|
||||||
// profile: PROFILE,
|
profileSearch: PROFILESEARCH,
|
||||||
|
PROFILEAGGREGATE,
|
||||||
|
profileAggregate: PROFILEAGGREGATE,
|
||||||
SEARCH,
|
SEARCH,
|
||||||
search: SEARCH,
|
search: SEARCH,
|
||||||
SPELLCHECK,
|
SPELLCHECK,
|
||||||
@@ -159,3 +168,347 @@ export function pushArgumentsWithLength(args: RedisCommandArguments, fn: (args:
|
|||||||
args[lengthIndex] = (args.length - lengthIndex - 1).toString();
|
args[lengthIndex] = (args.length - lengthIndex - 1).toString();
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum SchemaFieldTypes {
|
||||||
|
TEXT = 'TEXT',
|
||||||
|
NUMERIC = 'NUMERIC',
|
||||||
|
GEO = 'GEO',
|
||||||
|
TAG = 'TAG'
|
||||||
|
}
|
||||||
|
|
||||||
|
type CreateSchemaField<T extends SchemaFieldTypes, E = Record<string, never>> = T | ({
|
||||||
|
type: T;
|
||||||
|
AS?: string;
|
||||||
|
SORTABLE?: true | 'UNF';
|
||||||
|
NOINDEX?: true;
|
||||||
|
} & E);
|
||||||
|
|
||||||
|
export enum SchemaTextFieldPhonetics {
|
||||||
|
DM_EN = 'dm:en',
|
||||||
|
DM_FR = 'dm:fr',
|
||||||
|
FM_PT = 'dm:pt',
|
||||||
|
DM_ES = 'dm:es'
|
||||||
|
}
|
||||||
|
|
||||||
|
type CreateSchemaTextField = CreateSchemaField<SchemaFieldTypes.TEXT, {
|
||||||
|
NOSTEM?: true;
|
||||||
|
WEIGHT?: number;
|
||||||
|
PHONETIC?: SchemaTextFieldPhonetics;
|
||||||
|
}>;
|
||||||
|
|
||||||
|
type CreateSchemaNumericField = CreateSchemaField<SchemaFieldTypes.NUMERIC>;
|
||||||
|
|
||||||
|
type CreateSchemaGeoField = CreateSchemaField<SchemaFieldTypes.GEO>;
|
||||||
|
|
||||||
|
type CreateSchemaTagField = CreateSchemaField<SchemaFieldTypes.TAG, {
|
||||||
|
SEPERATOR?: string;
|
||||||
|
CASESENSITIVE?: true;
|
||||||
|
}>;
|
||||||
|
|
||||||
|
export interface CreateSchema {
|
||||||
|
[field: string]:
|
||||||
|
CreateSchemaTextField |
|
||||||
|
CreateSchemaNumericField |
|
||||||
|
CreateSchemaGeoField |
|
||||||
|
CreateSchemaTagField
|
||||||
|
}
|
||||||
|
|
||||||
|
export function pushSchema(args: RedisCommandArguments, schema: CreateSchema) {
|
||||||
|
for (const [field, fieldOptions] of Object.entries(schema)) {
|
||||||
|
args.push(field);
|
||||||
|
|
||||||
|
if (typeof fieldOptions === 'string') {
|
||||||
|
args.push(fieldOptions);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fieldOptions.AS) {
|
||||||
|
args.push('AS', fieldOptions.AS);
|
||||||
|
}
|
||||||
|
|
||||||
|
args.push(fieldOptions.type);
|
||||||
|
|
||||||
|
switch (fieldOptions.type) {
|
||||||
|
case 'TEXT':
|
||||||
|
if (fieldOptions.NOSTEM) {
|
||||||
|
args.push('NOSTEM');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fieldOptions.WEIGHT) {
|
||||||
|
args.push('WEIGHT', fieldOptions.WEIGHT.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fieldOptions.PHONETIC) {
|
||||||
|
args.push('PHONETIC', fieldOptions.PHONETIC);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
// case 'NUMERIC':
|
||||||
|
// case 'GEO':
|
||||||
|
// break;
|
||||||
|
|
||||||
|
case 'TAG':
|
||||||
|
if (fieldOptions.SEPERATOR) {
|
||||||
|
args.push('SEPERATOR', fieldOptions.SEPERATOR);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fieldOptions.CASESENSITIVE) {
|
||||||
|
args.push('CASESENSITIVE');
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fieldOptions.SORTABLE) {
|
||||||
|
args.push('SORTABLE');
|
||||||
|
|
||||||
|
if (fieldOptions.SORTABLE === 'UNF') {
|
||||||
|
args.push('UNF');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fieldOptions.NOINDEX) {
|
||||||
|
args.push('NOINDEX');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function pushSearchOptions(
|
||||||
|
args: RedisCommandArguments,
|
||||||
|
options?: SearchOptions
|
||||||
|
): RedisCommandArguments {
|
||||||
|
|
||||||
|
if (options?.VERBATIM) {
|
||||||
|
args.push('VERBATIM');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options?.NOSTOPWORDS) {
|
||||||
|
args.push('NOSTOPWORDS');
|
||||||
|
}
|
||||||
|
|
||||||
|
// if (options?.WITHSCORES) {
|
||||||
|
// args.push('WITHSCORES');
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if (options?.WITHPAYLOADS) {
|
||||||
|
// args.push('WITHPAYLOADS');
|
||||||
|
// }
|
||||||
|
|
||||||
|
pushOptionalVerdictArgument(args, 'INKEYS', options?.INKEYS);
|
||||||
|
pushOptionalVerdictArgument(args, 'INFIELDS', options?.INFIELDS);
|
||||||
|
pushOptionalVerdictArgument(args, 'RETURN', options?.RETURN);
|
||||||
|
|
||||||
|
if (options?.SUMMARIZE) {
|
||||||
|
args.push('SUMMARIZE');
|
||||||
|
|
||||||
|
if (typeof options.SUMMARIZE === 'object') {
|
||||||
|
if (options.SUMMARIZE.FIELDS) {
|
||||||
|
args.push('FIELDS');
|
||||||
|
pushVerdictArgument(args, options.SUMMARIZE.FIELDS);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.SUMMARIZE.FRAGS) {
|
||||||
|
args.push('FRAGS', options.SUMMARIZE.FRAGS.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.SUMMARIZE.LEN) {
|
||||||
|
args.push('LEN', options.SUMMARIZE.LEN.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.SUMMARIZE.SEPARATOR) {
|
||||||
|
args.push('SEPARATOR', options.SUMMARIZE.SEPARATOR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options?.HIGHLIGHT) {
|
||||||
|
args.push('HIGHLIGHT');
|
||||||
|
|
||||||
|
if (typeof options.HIGHLIGHT === 'object') {
|
||||||
|
if (options.HIGHLIGHT.FIELDS) {
|
||||||
|
args.push('FIELDS');
|
||||||
|
pushVerdictArgument(args, options.HIGHLIGHT.FIELDS);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.HIGHLIGHT.TAGS) {
|
||||||
|
args.push('TAGS', options.HIGHLIGHT.TAGS.open, options.HIGHLIGHT.TAGS.close);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options?.SLOP) {
|
||||||
|
args.push('SLOP', options.SLOP.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options?.INORDER) {
|
||||||
|
args.push('INORDER');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options?.LANGUAGE) {
|
||||||
|
args.push('LANGUAGE', options.LANGUAGE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options?.EXPANDER) {
|
||||||
|
args.push('EXPANDER', options.EXPANDER);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options?.SCORER) {
|
||||||
|
args.push('SCORER', options.SCORER);
|
||||||
|
}
|
||||||
|
|
||||||
|
// if (options?.EXPLAINSCORE) {
|
||||||
|
// args.push('EXPLAINSCORE');
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if (options?.PAYLOAD) {
|
||||||
|
// args.push('PAYLOAD', options.PAYLOAD);
|
||||||
|
// }
|
||||||
|
|
||||||
|
if (options?.SORTBY) {
|
||||||
|
args.push('SORTBY');
|
||||||
|
pushSortByProperty(args, options.SORTBY);
|
||||||
|
}
|
||||||
|
|
||||||
|
// if (options?.MSORTBY) {
|
||||||
|
// pushSortByArguments(args, 'MSORTBY', options.MSORTBY);
|
||||||
|
// }
|
||||||
|
|
||||||
|
if (options?.LIMIT) {
|
||||||
|
args.push(
|
||||||
|
'LIMIT',
|
||||||
|
options.LIMIT.from.toString(),
|
||||||
|
options.LIMIT.size.toString()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return args;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface SearchDocumentValue {
|
||||||
|
[key: string]: string | number | null | Array<SearchDocumentValue> | SearchDocumentValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SearchReply {
|
||||||
|
total: number;
|
||||||
|
documents: Array<{
|
||||||
|
id: string;
|
||||||
|
value: SearchDocumentValue;
|
||||||
|
}>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface AggregateReply {
|
||||||
|
total: number;
|
||||||
|
results: Array<TuplesObject>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ProfileOptions {
|
||||||
|
LIMITED?: true;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ProfileRawReply<T> = [
|
||||||
|
results: T,
|
||||||
|
profile: [
|
||||||
|
_: string,
|
||||||
|
TotalProfileTime: string,
|
||||||
|
_: string,
|
||||||
|
ParsingTime: string,
|
||||||
|
_: string,
|
||||||
|
PipelineCreationTime: string,
|
||||||
|
_: string,
|
||||||
|
IteratorsProfile: Array<any>
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
export interface ProfileReply {
|
||||||
|
results: SearchReply | AggregateReply,
|
||||||
|
profile: ProfileData
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ChildIterator {
|
||||||
|
type?: string,
|
||||||
|
counter?: number,
|
||||||
|
term?: string,
|
||||||
|
size?: number,
|
||||||
|
time?: string,
|
||||||
|
childIterators?: Array<ChildIterator>
|
||||||
|
}
|
||||||
|
|
||||||
|
interface IteratorsProfile {
|
||||||
|
type?: string,
|
||||||
|
counter?: number,
|
||||||
|
queryType?: string,
|
||||||
|
time?: string,
|
||||||
|
childIterators?: Array<ChildIterator>
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ProfileData {
|
||||||
|
totalProfileTime: string,
|
||||||
|
parsingTime: string,
|
||||||
|
pipelineCreationTime: string,
|
||||||
|
iteratorsProfile: IteratorsProfile
|
||||||
|
}
|
||||||
|
|
||||||
|
export function transformProfile(reply: Array<any>): ProfileData{
|
||||||
|
return {
|
||||||
|
totalProfileTime: reply[0][1],
|
||||||
|
parsingTime: reply[1][1],
|
||||||
|
pipelineCreationTime: reply[2][1],
|
||||||
|
iteratorsProfile: transformIterators(reply[3][1])
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function transformIterators(IteratorsProfile: Array<any>): IteratorsProfile {
|
||||||
|
var res: IteratorsProfile = {};
|
||||||
|
for (let i = 0; i < IteratorsProfile.length; i += 2) {
|
||||||
|
const value = IteratorsProfile[i+1];
|
||||||
|
switch (IteratorsProfile[i]) {
|
||||||
|
case 'Type':
|
||||||
|
res.type = value;
|
||||||
|
break;
|
||||||
|
case 'Counter':
|
||||||
|
res.counter = value;
|
||||||
|
break;
|
||||||
|
case 'Time':
|
||||||
|
res.time = value;
|
||||||
|
break;
|
||||||
|
case 'Query type':
|
||||||
|
res.queryType = value;
|
||||||
|
break;
|
||||||
|
case 'Child iterators':
|
||||||
|
res.childIterators = value.map(transformChildIterators);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
function transformChildIterators(IteratorsProfile: Array<any>): ChildIterator {
|
||||||
|
var res: ChildIterator = {};
|
||||||
|
for (let i = 1; i < IteratorsProfile.length; i += 2) {
|
||||||
|
const value = IteratorsProfile[i+1];
|
||||||
|
switch (IteratorsProfile[i]) {
|
||||||
|
case 'Type':
|
||||||
|
res.type = value;
|
||||||
|
break;
|
||||||
|
case 'Counter':
|
||||||
|
res.counter = value;
|
||||||
|
break;
|
||||||
|
case 'Time':
|
||||||
|
res.time = value;
|
||||||
|
break;
|
||||||
|
case 'Size':
|
||||||
|
res.size = value;
|
||||||
|
break;
|
||||||
|
case 'Term':
|
||||||
|
res.term = value;
|
||||||
|
break;
|
||||||
|
case 'Child iterators':
|
||||||
|
res.childIterators = value.map(transformChildIterators);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
export { default } from './commands';
|
export { default } from './commands';
|
||||||
|
|
||||||
export { SchemaFieldTypes, SchemaTextFieldPhonetics } from './commands/CREATE';
|
export { SchemaFieldTypes, SchemaTextFieldPhonetics } from './commands';
|
||||||
export { AggregateSteps, AggregateGroupByReducers } from './commands/AGGREGATE';
|
export { AggregateSteps, AggregateGroupByReducers } from './commands/AGGREGATE';
|
||||||
|
Reference in New Issue
Block a user