You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
feat(search): Set default dialect to 2 for Redis Search commands (#2895)
- The default dialect `DEFAULT_DIALECT` is now set to '2' - Automatically append DIALECT parameter to search commands when not explicitly specified
This commit is contained in:
@@ -2,13 +2,14 @@ import { strict as assert } from 'node:assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import AGGREGATE from './AGGREGATE';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
import { DEFAULT_DIALECT } from '../dialect/default';
|
||||
|
||||
describe('AGGREGATE', () => {
|
||||
describe('AGGREGATE', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('without options', () => {
|
||||
assert.deepEqual(
|
||||
parseArgs(AGGREGATE, 'index', '*'),
|
||||
['FT.AGGREGATE', 'index', '*']
|
||||
['FT.AGGREGATE', 'index', '*', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
|
||||
@@ -17,14 +18,14 @@ describe('AGGREGATE', () => {
|
||||
parseArgs(AGGREGATE, 'index', '*', {
|
||||
VERBATIM: true
|
||||
}),
|
||||
['FT.AGGREGATE', 'index', '*', 'VERBATIM']
|
||||
['FT.AGGREGATE', 'index', '*', 'VERBATIM', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
|
||||
it('with ADDSCORES', () => {
|
||||
assert.deepEqual(
|
||||
parseArgs(AGGREGATE, 'index', '*', { ADDSCORES: true }),
|
||||
['FT.AGGREGATE', 'index', '*', 'ADDSCORES']
|
||||
['FT.AGGREGATE', 'index', '*', 'ADDSCORES', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
|
||||
@@ -36,7 +37,7 @@ describe('AGGREGATE', () => {
|
||||
parseArgs(AGGREGATE, 'index', '*', {
|
||||
LOAD: '@property'
|
||||
}),
|
||||
['FT.AGGREGATE', 'index', '*', 'LOAD', '1', '@property']
|
||||
['FT.AGGREGATE', 'index', '*', 'LOAD', '1', '@property', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
|
||||
@@ -47,7 +48,7 @@ describe('AGGREGATE', () => {
|
||||
identifier: '@property'
|
||||
}
|
||||
}),
|
||||
['FT.AGGREGATE', 'index', '*', 'LOAD', '1', '@property']
|
||||
['FT.AGGREGATE', 'index', '*', 'LOAD', '1', '@property', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -60,7 +61,7 @@ describe('AGGREGATE', () => {
|
||||
AS: 'alias'
|
||||
}
|
||||
}),
|
||||
['FT.AGGREGATE', 'index', '*', 'LOAD', '3', '@property', 'AS', 'alias']
|
||||
['FT.AGGREGATE', 'index', '*', 'LOAD', '3', '@property', 'AS', 'alias', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -70,7 +71,7 @@ describe('AGGREGATE', () => {
|
||||
parseArgs(AGGREGATE, 'index', '*', {
|
||||
LOAD: ['@1', '@2']
|
||||
}),
|
||||
['FT.AGGREGATE', 'index', '*', 'LOAD', '2', '@1', '@2']
|
||||
['FT.AGGREGATE', 'index', '*', 'LOAD', '2', '@1', '@2', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -89,7 +90,7 @@ describe('AGGREGATE', () => {
|
||||
}
|
||||
}]
|
||||
}),
|
||||
['FT.AGGREGATE', 'index', '*', 'GROUPBY', '0', 'REDUCE', 'COUNT', '0']
|
||||
['FT.AGGREGATE', 'index', '*', 'GROUPBY', '0', 'REDUCE', 'COUNT', '0', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
|
||||
@@ -104,7 +105,7 @@ describe('AGGREGATE', () => {
|
||||
}
|
||||
}]
|
||||
}),
|
||||
['FT.AGGREGATE', 'index', '*', 'GROUPBY', '0', 'REDUCE', 'COUNT', '0', 'AS', 'count']
|
||||
['FT.AGGREGATE', 'index', '*', 'GROUPBY', '0', 'REDUCE', 'COUNT', '0', 'AS', 'count', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -121,7 +122,7 @@ describe('AGGREGATE', () => {
|
||||
}
|
||||
}]
|
||||
}),
|
||||
['FT.AGGREGATE', 'index', '*', 'GROUPBY', '1', '@property', 'REDUCE', 'COUNT', '0']
|
||||
['FT.AGGREGATE', 'index', '*', 'GROUPBY', '1', '@property', 'REDUCE', 'COUNT', '0', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
|
||||
@@ -136,7 +137,7 @@ describe('AGGREGATE', () => {
|
||||
}
|
||||
}]
|
||||
}),
|
||||
['FT.AGGREGATE', 'index', '*', 'GROUPBY', '2', '@1', '@2', 'REDUCE', 'COUNT', '0']
|
||||
['FT.AGGREGATE', 'index', '*', 'GROUPBY', '2', '@1', '@2', 'REDUCE', 'COUNT', '0', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -153,7 +154,7 @@ describe('AGGREGATE', () => {
|
||||
}
|
||||
}]
|
||||
}),
|
||||
['FT.AGGREGATE', 'index', '*', 'GROUPBY', '0', 'REDUCE', 'COUNT_DISTINCT', '1', '@property']
|
||||
['FT.AGGREGATE', 'index', '*', 'GROUPBY', '0', 'REDUCE', 'COUNT_DISTINCT', '1', '@property', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
|
||||
@@ -168,7 +169,7 @@ describe('AGGREGATE', () => {
|
||||
}
|
||||
}]
|
||||
}),
|
||||
['FT.AGGREGATE', 'index', '*', 'GROUPBY', '0', 'REDUCE', 'COUNT_DISTINCTISH', '1', '@property']
|
||||
['FT.AGGREGATE', 'index', '*', 'GROUPBY', '0', 'REDUCE', 'COUNT_DISTINCTISH', '1', '@property', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
|
||||
@@ -183,7 +184,7 @@ describe('AGGREGATE', () => {
|
||||
}
|
||||
}]
|
||||
}),
|
||||
['FT.AGGREGATE', 'index', '*', 'GROUPBY', '0', 'REDUCE', 'SUM', '1', '@property']
|
||||
['FT.AGGREGATE', 'index', '*', 'GROUPBY', '0', 'REDUCE', 'SUM', '1', '@property', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
|
||||
@@ -198,7 +199,7 @@ describe('AGGREGATE', () => {
|
||||
}
|
||||
}]
|
||||
}),
|
||||
['FT.AGGREGATE', 'index', '*', 'GROUPBY', '0', 'REDUCE', 'MIN', '1', '@property']
|
||||
['FT.AGGREGATE', 'index', '*', 'GROUPBY', '0', 'REDUCE', 'MIN', '1', '@property', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
|
||||
@@ -213,7 +214,7 @@ describe('AGGREGATE', () => {
|
||||
}
|
||||
}]
|
||||
}),
|
||||
['FT.AGGREGATE', 'index', '*', 'GROUPBY', '0', 'REDUCE', 'MAX', '1', '@property']
|
||||
['FT.AGGREGATE', 'index', '*', 'GROUPBY', '0', 'REDUCE', 'MAX', '1', '@property', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
|
||||
@@ -228,7 +229,7 @@ describe('AGGREGATE', () => {
|
||||
}
|
||||
}]
|
||||
}),
|
||||
['FT.AGGREGATE', 'index', '*', 'GROUPBY', '0', 'REDUCE', 'AVG', '1', '@property']
|
||||
['FT.AGGREGATE', 'index', '*', 'GROUPBY', '0', 'REDUCE', 'AVG', '1', '@property', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
it('STDDEV', () => {
|
||||
@@ -242,7 +243,7 @@ describe('AGGREGATE', () => {
|
||||
}
|
||||
}]
|
||||
}),
|
||||
['FT.AGGREGATE', 'index', '*', 'GROUPBY', '0', 'REDUCE', 'STDDEV', '1', '@property']
|
||||
['FT.AGGREGATE', 'index', '*', 'GROUPBY', '0', 'REDUCE', 'STDDEV', '1', '@property', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
|
||||
@@ -258,7 +259,7 @@ describe('AGGREGATE', () => {
|
||||
}
|
||||
}]
|
||||
}),
|
||||
['FT.AGGREGATE', 'index', '*', 'GROUPBY', '0', 'REDUCE', 'QUANTILE', '2', '@property', '0.5']
|
||||
['FT.AGGREGATE', 'index', '*', 'GROUPBY', '0', 'REDUCE', 'QUANTILE', '2', '@property', '0.5', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
|
||||
@@ -273,7 +274,7 @@ describe('AGGREGATE', () => {
|
||||
}
|
||||
}]
|
||||
}),
|
||||
['FT.AGGREGATE', 'index', '*', 'GROUPBY', '0', 'REDUCE', 'TOLIST', '1', '@property']
|
||||
['FT.AGGREGATE', 'index', '*', 'GROUPBY', '0', 'REDUCE', 'TOLIST', '1', '@property', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
|
||||
@@ -289,7 +290,7 @@ describe('AGGREGATE', () => {
|
||||
}
|
||||
}]
|
||||
}),
|
||||
['FT.AGGREGATE', 'index', '*', 'GROUPBY', '0', 'REDUCE', 'FIRST_VALUE', '1', '@property']
|
||||
['FT.AGGREGATE', 'index', '*', 'GROUPBY', '0', 'REDUCE', 'FIRST_VALUE', '1', '@property', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
|
||||
@@ -307,7 +308,7 @@ describe('AGGREGATE', () => {
|
||||
}
|
||||
}]
|
||||
}),
|
||||
['FT.AGGREGATE', 'index', '*', 'GROUPBY', '0', 'REDUCE', 'FIRST_VALUE', '3', '@property', 'BY', '@by']
|
||||
['FT.AGGREGATE', 'index', '*', 'GROUPBY', '0', 'REDUCE', 'FIRST_VALUE', '3', '@property', 'BY', '@by', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
|
||||
@@ -326,7 +327,7 @@ describe('AGGREGATE', () => {
|
||||
}
|
||||
}]
|
||||
}),
|
||||
['FT.AGGREGATE', 'index', '*', 'GROUPBY', '0', 'REDUCE', 'FIRST_VALUE', '3', '@property', 'BY', '@by']
|
||||
['FT.AGGREGATE', 'index', '*', 'GROUPBY', '0', 'REDUCE', 'FIRST_VALUE', '3', '@property', 'BY', '@by', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -346,7 +347,7 @@ describe('AGGREGATE', () => {
|
||||
}
|
||||
}]
|
||||
}),
|
||||
['FT.AGGREGATE', 'index', '*', 'GROUPBY', '0', 'REDUCE', 'FIRST_VALUE', '4', '@property', 'BY', '@by', 'ASC']
|
||||
['FT.AGGREGATE', 'index', '*', 'GROUPBY', '0', 'REDUCE', 'FIRST_VALUE', '4', '@property', 'BY', '@by', 'ASC', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -364,7 +365,7 @@ describe('AGGREGATE', () => {
|
||||
}
|
||||
}]
|
||||
}),
|
||||
['FT.AGGREGATE', 'index', '*', 'GROUPBY', '0', 'REDUCE', 'RANDOM_SAMPLE', '2', '@property', '1']
|
||||
['FT.AGGREGATE', 'index', '*', 'GROUPBY', '0', 'REDUCE', 'RANDOM_SAMPLE', '2', '@property', '1', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -378,7 +379,7 @@ describe('AGGREGATE', () => {
|
||||
BY: '@by'
|
||||
}]
|
||||
}),
|
||||
['FT.AGGREGATE', 'index', '*', 'SORTBY', '1', '@by']
|
||||
['FT.AGGREGATE', 'index', '*', 'SORTBY', '1', '@by', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
|
||||
@@ -390,7 +391,7 @@ describe('AGGREGATE', () => {
|
||||
BY: ['@1', '@2']
|
||||
}]
|
||||
}),
|
||||
['FT.AGGREGATE', 'index', '*', 'SORTBY', '2', '@1', '@2']
|
||||
['FT.AGGREGATE', 'index', '*', 'SORTBY', '2', '@1', '@2', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
|
||||
@@ -403,7 +404,7 @@ describe('AGGREGATE', () => {
|
||||
MAX: 1
|
||||
}]
|
||||
}),
|
||||
['FT.AGGREGATE', 'index', '*', 'SORTBY', '3', '@by', 'MAX', '1']
|
||||
['FT.AGGREGATE', 'index', '*', 'SORTBY', '3', '@by', 'MAX', '1', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -417,7 +418,7 @@ describe('AGGREGATE', () => {
|
||||
AS: 'as'
|
||||
}]
|
||||
}),
|
||||
['FT.AGGREGATE', 'index', '*', 'APPLY', '@field + 1', 'AS', 'as']
|
||||
['FT.AGGREGATE', 'index', '*', 'APPLY', '@field + 1', 'AS', 'as', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
|
||||
@@ -430,7 +431,7 @@ describe('AGGREGATE', () => {
|
||||
size: 1
|
||||
}]
|
||||
}),
|
||||
['FT.AGGREGATE', 'index', '*', 'LIMIT', '0', '1']
|
||||
['FT.AGGREGATE', 'index', '*', 'LIMIT', '0', '1', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
|
||||
@@ -442,7 +443,7 @@ describe('AGGREGATE', () => {
|
||||
expression: '@field != ""'
|
||||
}]
|
||||
}),
|
||||
['FT.AGGREGATE', 'index', '*', 'FILTER', '@field != ""']
|
||||
['FT.AGGREGATE', 'index', '*', 'FILTER', '@field != ""', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -454,7 +455,7 @@ describe('AGGREGATE', () => {
|
||||
param: 'value'
|
||||
}
|
||||
}),
|
||||
['FT.AGGREGATE', 'index', '*', 'PARAMS', '2', 'param', 'value']
|
||||
['FT.AGGREGATE', 'index', '*', 'PARAMS', '2', 'param', 'value', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
|
||||
@@ -470,7 +471,7 @@ describe('AGGREGATE', () => {
|
||||
it('with TIMEOUT', () => {
|
||||
assert.deepEqual(
|
||||
parseArgs(AGGREGATE, 'index', '*', { TIMEOUT: 10 }),
|
||||
['FT.AGGREGATE', 'index', '*', 'TIMEOUT', '10']
|
||||
['FT.AGGREGATE', 'index', '*', 'TIMEOUT', '10', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
});
|
||||
|
@@ -3,6 +3,7 @@ import { ArrayReply, BlobStringReply, Command, MapReply, NumberReply, RedisArgum
|
||||
import { RediSearchProperty } from './CREATE';
|
||||
import { FtSearchParams, parseParamsArgument } from './SEARCH';
|
||||
import { transformTuplesReply } from '@redis/client/dist/lib/commands/generic-transformers';
|
||||
import { DEFAULT_DIALECT } from '../dialect/default';
|
||||
|
||||
type LoadField = RediSearchProperty | {
|
||||
identifier: RediSearchProperty;
|
||||
@@ -12,12 +13,12 @@ type LoadField = RediSearchProperty | {
|
||||
export const FT_AGGREGATE_STEPS = {
|
||||
GROUPBY: 'GROUPBY',
|
||||
SORTBY: 'SORTBY',
|
||||
APPLY: 'APPLY',
|
||||
APPLY: 'APPLY',
|
||||
LIMIT: 'LIMIT',
|
||||
FILTER: 'FILTER'
|
||||
} as const;
|
||||
|
||||
type FT_AGGREGATE_STEPS = typeof FT_AGGREGATE_STEPS;
|
||||
type FT_AGGREGATE_STEPS = typeof FT_AGGREGATE_STEPS;
|
||||
|
||||
export type FtAggregateStep = FT_AGGREGATE_STEPS[keyof FT_AGGREGATE_STEPS];
|
||||
|
||||
@@ -249,8 +250,10 @@ export function parseAggregateOptions(parser: CommandParser , options?: FtAggreg
|
||||
|
||||
parseParamsArgument(parser, options?.PARAMS);
|
||||
|
||||
if (options?.DIALECT !== undefined) {
|
||||
if (options?.DIALECT) {
|
||||
parser.push('DIALECT', options.DIALECT.toString());
|
||||
} else {
|
||||
parser.push('DIALECT', DEFAULT_DIALECT);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -2,13 +2,14 @@ import { strict as assert } from 'node:assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import AGGREGATE_WITHCURSOR from './AGGREGATE_WITHCURSOR';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
import { DEFAULT_DIALECT } from '../dialect/default';
|
||||
|
||||
describe('AGGREGATE WITHCURSOR', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('without options', () => {
|
||||
assert.deepEqual(
|
||||
parseArgs(AGGREGATE_WITHCURSOR, 'index', '*'),
|
||||
['FT.AGGREGATE', 'index', '*', 'WITHCURSOR']
|
||||
['FT.AGGREGATE', 'index', '*', 'DIALECT', DEFAULT_DIALECT, 'WITHCURSOR']
|
||||
);
|
||||
});
|
||||
|
||||
@@ -17,7 +18,7 @@ describe('AGGREGATE WITHCURSOR', () => {
|
||||
parseArgs(AGGREGATE_WITHCURSOR, 'index', '*', {
|
||||
COUNT: 1
|
||||
}),
|
||||
['FT.AGGREGATE', 'index', '*', 'WITHCURSOR', 'COUNT', '1']
|
||||
['FT.AGGREGATE', 'index', '*', 'DIALECT', DEFAULT_DIALECT, 'WITHCURSOR', 'COUNT', '1']
|
||||
);
|
||||
});
|
||||
|
||||
@@ -26,7 +27,7 @@ describe('AGGREGATE WITHCURSOR', () => {
|
||||
parseArgs(AGGREGATE_WITHCURSOR, 'index', '*', {
|
||||
MAXIDLE: 1
|
||||
}),
|
||||
['FT.AGGREGATE', 'index', '*', 'WITHCURSOR', 'MAXIDLE', '1']
|
||||
['FT.AGGREGATE', 'index', '*', 'DIALECT', DEFAULT_DIALECT, 'WITHCURSOR', 'MAXIDLE', '1']
|
||||
);
|
||||
});
|
||||
});
|
||||
|
@@ -3,13 +3,14 @@ import EXPLAIN from './EXPLAIN';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import { SCHEMA_FIELD_TYPE } from './CREATE';
|
||||
import { DEFAULT_DIALECT } from '../dialect/default';
|
||||
|
||||
describe('EXPLAIN', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('simple', () => {
|
||||
assert.deepEqual(
|
||||
parseArgs(EXPLAIN, 'index', '*'),
|
||||
['FT.EXPLAIN', 'index', '*']
|
||||
['FT.EXPLAIN', 'index', '*', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
|
||||
@@ -20,7 +21,7 @@ describe('EXPLAIN', () => {
|
||||
param: 'value'
|
||||
}
|
||||
}),
|
||||
['FT.EXPLAIN', 'index', '*', 'PARAMS', '2', 'param', 'value']
|
||||
['FT.EXPLAIN', 'index', '*', 'PARAMS', '2', 'param', 'value', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
|
||||
|
@@ -1,6 +1,7 @@
|
||||
import { CommandParser } from '@redis/client/dist/lib/client/parser';
|
||||
import { RedisArgument, SimpleStringReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||
import { FtSearchParams, parseParamsArgument } from './SEARCH';
|
||||
import { DEFAULT_DIALECT } from '../dialect/default';
|
||||
|
||||
export interface FtExplainOptions {
|
||||
PARAMS?: FtSearchParams;
|
||||
@@ -22,6 +23,8 @@ export default {
|
||||
|
||||
if (options?.DIALECT) {
|
||||
parser.push('DIALECT', options.DIALECT.toString());
|
||||
} else {
|
||||
parser.push('DIALECT', DEFAULT_DIALECT);
|
||||
}
|
||||
},
|
||||
transformReply: undefined as unknown as () => SimpleStringReply
|
||||
|
@@ -1,12 +1,20 @@
|
||||
import { strict as assert } from 'node:assert';
|
||||
import EXPLAINCLI from './EXPLAINCLI';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
import { DEFAULT_DIALECT } from '../dialect/default';
|
||||
|
||||
describe('EXPLAINCLI', () => {
|
||||
it('transformArguments', () => {
|
||||
assert.deepEqual(
|
||||
parseArgs(EXPLAINCLI, 'index', '*'),
|
||||
['FT.EXPLAINCLI', 'index', '*']
|
||||
['FT.EXPLAINCLI', 'index', '*', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
|
||||
it('with dialect', () => {
|
||||
assert.deepEqual(
|
||||
parseArgs(EXPLAINCLI, 'index', '*', {DIALECT: 1}),
|
||||
['FT.EXPLAINCLI', 'index', '*', 'DIALECT', '1']
|
||||
);
|
||||
});
|
||||
});
|
||||
|
@@ -1,11 +1,27 @@
|
||||
import { CommandParser } from '@redis/client/dist/lib/client/parser';
|
||||
import { RedisArgument, ArrayReply, BlobStringReply, Command } from '@redis/client/dist/lib/RESP/types';
|
||||
import { DEFAULT_DIALECT } from '../dialect/default';
|
||||
|
||||
export interface FtExplainCLIOptions {
|
||||
DIALECT?: number;
|
||||
}
|
||||
|
||||
export default {
|
||||
NOT_KEYED_COMMAND: true,
|
||||
IS_READ_ONLY: true,
|
||||
parseCommand(parser: CommandParser, index: RedisArgument, query: RedisArgument) {
|
||||
parseCommand(
|
||||
parser: CommandParser,
|
||||
index: RedisArgument,
|
||||
query: RedisArgument,
|
||||
options?: FtExplainCLIOptions
|
||||
) {
|
||||
parser.push('FT.EXPLAINCLI', index, query);
|
||||
|
||||
if (options?.DIALECT) {
|
||||
parser.push('DIALECT', options.DIALECT.toString());
|
||||
} else {
|
||||
parser.push('DIALECT', DEFAULT_DIALECT);
|
||||
}
|
||||
},
|
||||
transformReply: undefined as unknown as () => ArrayReply<BlobStringReply>
|
||||
} as const satisfies Command;
|
||||
|
@@ -4,13 +4,14 @@ import { FT_AGGREGATE_STEPS } from './AGGREGATE';
|
||||
import PROFILE_AGGREGATE from './PROFILE_AGGREGATE';
|
||||
import { SCHEMA_FIELD_TYPE } from './CREATE';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
import { DEFAULT_DIALECT } from '../dialect/default';
|
||||
|
||||
describe('PROFILE AGGREGATE', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('without options', () => {
|
||||
assert.deepEqual(
|
||||
parseArgs(PROFILE_AGGREGATE, 'index', 'query'),
|
||||
['FT.PROFILE', 'index', 'AGGREGATE', 'QUERY', 'query']
|
||||
['FT.PROFILE', 'index', 'AGGREGATE', 'QUERY', 'query', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
|
||||
@@ -25,7 +26,7 @@ describe('PROFILE AGGREGATE', () => {
|
||||
}]
|
||||
}),
|
||||
['FT.PROFILE', 'index', 'AGGREGATE', 'LIMITED', 'QUERY', 'query',
|
||||
'VERBATIM', 'SORTBY', '1', '@by']
|
||||
'VERBATIM', 'SORTBY', '1', '@by', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
});
|
||||
|
@@ -3,14 +3,14 @@ import testUtils, { GLOBAL } from '../test-utils';
|
||||
import PROFILE_SEARCH from './PROFILE_SEARCH';
|
||||
import { SCHEMA_FIELD_TYPE } from './CREATE';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
|
||||
import { DEFAULT_DIALECT } from '../dialect/default';
|
||||
|
||||
describe('PROFILE SEARCH', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('without options', () => {
|
||||
assert.deepEqual(
|
||||
parseArgs(PROFILE_SEARCH, 'index', 'query'),
|
||||
['FT.PROFILE', 'index', 'SEARCH', 'QUERY', 'query']
|
||||
['FT.PROFILE', 'index', 'SEARCH', 'QUERY', 'query', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
|
||||
@@ -22,7 +22,7 @@ describe('PROFILE SEARCH', () => {
|
||||
INKEYS: 'key'
|
||||
}),
|
||||
['FT.PROFILE', 'index', 'SEARCH', 'LIMITED', 'QUERY', 'query',
|
||||
'VERBATIM', 'INKEYS', '1', 'key']
|
||||
'VERBATIM', 'INKEYS', '1', 'key', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
});
|
||||
|
@@ -2,13 +2,15 @@ import { strict as assert } from 'node:assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import SEARCH from './SEARCH';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
import { DEFAULT_DIALECT } from '../dialect/default';
|
||||
|
||||
|
||||
describe('FT.SEARCH', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('without options', () => {
|
||||
assert.deepEqual(
|
||||
parseArgs(SEARCH, 'index', 'query'),
|
||||
['FT.SEARCH', 'index', 'query']
|
||||
['FT.SEARCH', 'index', 'query', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
|
||||
@@ -17,7 +19,7 @@ describe('FT.SEARCH', () => {
|
||||
parseArgs(SEARCH, 'index', 'query', {
|
||||
VERBATIM: true
|
||||
}),
|
||||
['FT.SEARCH', 'index', 'query', 'VERBATIM']
|
||||
['FT.SEARCH', 'index', 'query', 'VERBATIM', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
|
||||
@@ -26,7 +28,7 @@ describe('FT.SEARCH', () => {
|
||||
parseArgs(SEARCH, 'index', 'query', {
|
||||
NOSTOPWORDS: true
|
||||
}),
|
||||
['FT.SEARCH', 'index', 'query', 'NOSTOPWORDS']
|
||||
['FT.SEARCH', 'index', 'query', 'NOSTOPWORDS', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
|
||||
@@ -35,7 +37,7 @@ describe('FT.SEARCH', () => {
|
||||
parseArgs(SEARCH, 'index', 'query', {
|
||||
INKEYS: 'key'
|
||||
}),
|
||||
['FT.SEARCH', 'index', 'query', 'INKEYS', '1', 'key']
|
||||
['FT.SEARCH', 'index', 'query', 'INKEYS', '1', 'key', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
|
||||
@@ -44,7 +46,7 @@ describe('FT.SEARCH', () => {
|
||||
parseArgs(SEARCH, 'index', 'query', {
|
||||
INFIELDS: 'field'
|
||||
}),
|
||||
['FT.SEARCH', 'index', 'query', 'INFIELDS', '1', 'field']
|
||||
['FT.SEARCH', 'index', 'query', 'INFIELDS', '1', 'field', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
|
||||
@@ -53,7 +55,7 @@ describe('FT.SEARCH', () => {
|
||||
parseArgs(SEARCH, 'index', 'query', {
|
||||
RETURN: 'return'
|
||||
}),
|
||||
['FT.SEARCH', 'index', 'query', 'RETURN', '1', 'return']
|
||||
['FT.SEARCH', 'index', 'query', 'RETURN', '1', 'return', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
|
||||
@@ -63,7 +65,7 @@ describe('FT.SEARCH', () => {
|
||||
parseArgs(SEARCH, 'index', 'query', {
|
||||
SUMMARIZE: true
|
||||
}),
|
||||
['FT.SEARCH', 'index', 'query', 'SUMMARIZE']
|
||||
['FT.SEARCH', 'index', 'query', 'SUMMARIZE', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
|
||||
@@ -75,7 +77,7 @@ describe('FT.SEARCH', () => {
|
||||
FIELDS: '@field'
|
||||
}
|
||||
}),
|
||||
['FT.SEARCH', 'index', 'query', 'SUMMARIZE', 'FIELDS', '1', '@field']
|
||||
['FT.SEARCH', 'index', 'query', 'SUMMARIZE', 'FIELDS', '1', '@field', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
|
||||
@@ -86,7 +88,7 @@ describe('FT.SEARCH', () => {
|
||||
FIELDS: ['@1', '@2']
|
||||
}
|
||||
}),
|
||||
['FT.SEARCH', 'index', 'query', 'SUMMARIZE', 'FIELDS', '2', '@1', '@2']
|
||||
['FT.SEARCH', 'index', 'query', 'SUMMARIZE', 'FIELDS', '2', '@1', '@2', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -98,7 +100,7 @@ describe('FT.SEARCH', () => {
|
||||
FRAGS: 1
|
||||
}
|
||||
}),
|
||||
['FT.SEARCH', 'index', 'query', 'SUMMARIZE', 'FRAGS', '1']
|
||||
['FT.SEARCH', 'index', 'query', 'SUMMARIZE', 'FRAGS', '1', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
|
||||
@@ -109,7 +111,7 @@ describe('FT.SEARCH', () => {
|
||||
LEN: 1
|
||||
}
|
||||
}),
|
||||
['FT.SEARCH', 'index', 'query', 'SUMMARIZE', 'LEN', '1']
|
||||
['FT.SEARCH', 'index', 'query', 'SUMMARIZE', 'LEN', '1', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
|
||||
@@ -120,7 +122,7 @@ describe('FT.SEARCH', () => {
|
||||
SEPARATOR: 'separator'
|
||||
}
|
||||
}),
|
||||
['FT.SEARCH', 'index', 'query', 'SUMMARIZE', 'SEPARATOR', 'separator']
|
||||
['FT.SEARCH', 'index', 'query', 'SUMMARIZE', 'SEPARATOR', 'separator', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -131,7 +133,7 @@ describe('FT.SEARCH', () => {
|
||||
parseArgs(SEARCH, 'index', 'query', {
|
||||
HIGHLIGHT: true
|
||||
}),
|
||||
['FT.SEARCH', 'index', 'query', 'HIGHLIGHT']
|
||||
['FT.SEARCH', 'index', 'query', 'HIGHLIGHT', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
|
||||
@@ -143,7 +145,7 @@ describe('FT.SEARCH', () => {
|
||||
FIELDS: ['@field']
|
||||
}
|
||||
}),
|
||||
['FT.SEARCH', 'index', 'query', 'HIGHLIGHT', 'FIELDS', '1', '@field']
|
||||
['FT.SEARCH', 'index', 'query', 'HIGHLIGHT', 'FIELDS', '1', '@field', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
|
||||
@@ -154,7 +156,7 @@ describe('FT.SEARCH', () => {
|
||||
FIELDS: ['@1', '@2']
|
||||
}
|
||||
}),
|
||||
['FT.SEARCH', 'index', 'query', 'HIGHLIGHT', 'FIELDS', '2', '@1', '@2']
|
||||
['FT.SEARCH', 'index', 'query', 'HIGHLIGHT', 'FIELDS', '2', '@1', '@2', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -169,7 +171,7 @@ describe('FT.SEARCH', () => {
|
||||
}
|
||||
}
|
||||
}),
|
||||
['FT.SEARCH', 'index', 'query', 'HIGHLIGHT', 'TAGS', 'open', 'close']
|
||||
['FT.SEARCH', 'index', 'query', 'HIGHLIGHT', 'TAGS', 'open', 'close', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -179,7 +181,7 @@ describe('FT.SEARCH', () => {
|
||||
parseArgs(SEARCH, 'index', 'query', {
|
||||
SLOP: 1
|
||||
}),
|
||||
['FT.SEARCH', 'index', 'query', 'SLOP', '1']
|
||||
['FT.SEARCH', 'index', 'query', 'SLOP', '1', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
|
||||
@@ -188,7 +190,7 @@ describe('FT.SEARCH', () => {
|
||||
parseArgs(SEARCH, 'index', 'query', {
|
||||
TIMEOUT: 1
|
||||
}),
|
||||
['FT.SEARCH', 'index', 'query', 'TIMEOUT', '1']
|
||||
['FT.SEARCH', 'index', 'query', 'TIMEOUT', '1', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
|
||||
@@ -197,7 +199,7 @@ describe('FT.SEARCH', () => {
|
||||
parseArgs(SEARCH, 'index', 'query', {
|
||||
INORDER: true
|
||||
}),
|
||||
['FT.SEARCH', 'index', 'query', 'INORDER']
|
||||
['FT.SEARCH', 'index', 'query', 'INORDER', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
|
||||
@@ -206,7 +208,7 @@ describe('FT.SEARCH', () => {
|
||||
parseArgs(SEARCH, 'index', 'query', {
|
||||
LANGUAGE: 'Arabic'
|
||||
}),
|
||||
['FT.SEARCH', 'index', 'query', 'LANGUAGE', 'Arabic']
|
||||
['FT.SEARCH', 'index', 'query', 'LANGUAGE', 'Arabic', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
|
||||
@@ -215,7 +217,7 @@ describe('FT.SEARCH', () => {
|
||||
parseArgs(SEARCH, 'index', 'query', {
|
||||
EXPANDER: 'expender'
|
||||
}),
|
||||
['FT.SEARCH', 'index', 'query', 'EXPANDER', 'expender']
|
||||
['FT.SEARCH', 'index', 'query', 'EXPANDER', 'expender', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
|
||||
@@ -224,7 +226,7 @@ describe('FT.SEARCH', () => {
|
||||
parseArgs(SEARCH, 'index', 'query', {
|
||||
SCORER: 'scorer'
|
||||
}),
|
||||
['FT.SEARCH', 'index', 'query', 'SCORER', 'scorer']
|
||||
['FT.SEARCH', 'index', 'query', 'SCORER', 'scorer', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
|
||||
@@ -233,7 +235,7 @@ describe('FT.SEARCH', () => {
|
||||
parseArgs(SEARCH, 'index', 'query', {
|
||||
SORTBY: '@by'
|
||||
}),
|
||||
['FT.SEARCH', 'index', 'query', 'SORTBY', '@by']
|
||||
['FT.SEARCH', 'index', 'query', 'SORTBY', '@by', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
|
||||
@@ -245,7 +247,7 @@ describe('FT.SEARCH', () => {
|
||||
size: 1
|
||||
}
|
||||
}),
|
||||
['FT.SEARCH', 'index', 'query', 'LIMIT', '0', '1']
|
||||
['FT.SEARCH', 'index', 'query', 'LIMIT', '0', '1', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
|
||||
@@ -258,7 +260,7 @@ describe('FT.SEARCH', () => {
|
||||
number: 1
|
||||
}
|
||||
}),
|
||||
['FT.SEARCH', 'index', 'query', 'PARAMS', '6', 'string', 'string', 'buffer', Buffer.from('buffer'), 'number', '1']
|
||||
['FT.SEARCH', 'index', 'query', 'PARAMS', '6', 'string', 'string', 'buffer', Buffer.from('buffer'), 'number', '1', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
|
||||
|
@@ -2,6 +2,7 @@ import { CommandParser } from '@redis/client/dist/lib/client/parser';
|
||||
import { RedisArgument, Command, ReplyUnion } from '@redis/client/dist/lib/RESP/types';
|
||||
import { RedisVariadicArgument, parseOptionalVariadicArgument } from '@redis/client/dist/lib/commands/generic-transformers';
|
||||
import { RediSearchProperty, RediSearchLanguage } from './CREATE';
|
||||
import { DEFAULT_DIALECT } from '../dialect/default';
|
||||
|
||||
export type FtSearchParams = Record<string, RedisArgument | number>;
|
||||
|
||||
@@ -150,8 +151,10 @@ export function parseSearchOptions(parser: CommandParser, options?: FtSearchOpti
|
||||
|
||||
parseParamsArgument(parser, options?.PARAMS);
|
||||
|
||||
if (options?.DIALECT !== undefined) {
|
||||
if (options?.DIALECT) {
|
||||
parser.push('DIALECT', options.DIALECT.toString());
|
||||
} else {
|
||||
parser.push('DIALECT', DEFAULT_DIALECT);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -2,13 +2,14 @@ import { strict as assert } from 'assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import SEARCH_NOCONTENT from './SEARCH_NOCONTENT';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
import { DEFAULT_DIALECT } from '../dialect/default';
|
||||
|
||||
describe('FT.SEARCH NOCONTENT', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('without options', () => {
|
||||
assert.deepEqual(
|
||||
parseArgs(SEARCH_NOCONTENT, 'index', 'query'),
|
||||
['FT.SEARCH', 'index', 'query', 'NOCONTENT']
|
||||
['FT.SEARCH', 'index', 'query', 'DIALECT', DEFAULT_DIALECT, 'NOCONTENT']
|
||||
);
|
||||
});
|
||||
});
|
||||
|
@@ -5,7 +5,7 @@ export default {
|
||||
NOT_KEYED_COMMAND: SEARCH.NOT_KEYED_COMMAND,
|
||||
IS_READ_ONLY: SEARCH.IS_READ_ONLY,
|
||||
parseCommand(...args: Parameters<typeof SEARCH.parseCommand>) {
|
||||
SEARCH.parseCommand(...args);
|
||||
SEARCH.parseCommand(...args);
|
||||
args[0].push('NOCONTENT');
|
||||
},
|
||||
transformReply: {
|
||||
|
@@ -2,13 +2,14 @@ import { strict as assert } from 'node:assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import SPELLCHECK from './SPELLCHECK';
|
||||
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
|
||||
import { DEFAULT_DIALECT } from '../dialect/default';
|
||||
|
||||
describe('FT.SPELLCHECK', () => {
|
||||
describe('transformArguments', () => {
|
||||
it('without options', () => {
|
||||
assert.deepEqual(
|
||||
parseArgs(SPELLCHECK, 'index', 'query'),
|
||||
['FT.SPELLCHECK', 'index', 'query']
|
||||
['FT.SPELLCHECK', 'index', 'query', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
|
||||
@@ -17,7 +18,7 @@ describe('FT.SPELLCHECK', () => {
|
||||
parseArgs(SPELLCHECK, 'index', 'query', {
|
||||
DISTANCE: 2
|
||||
}),
|
||||
['FT.SPELLCHECK', 'index', 'query', 'DISTANCE', '2']
|
||||
['FT.SPELLCHECK', 'index', 'query', 'DISTANCE', '2', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
|
||||
@@ -30,7 +31,7 @@ describe('FT.SPELLCHECK', () => {
|
||||
dictionary: 'dictionary'
|
||||
}
|
||||
}),
|
||||
['FT.SPELLCHECK', 'index', 'query', 'TERMS', 'INCLUDE', 'dictionary']
|
||||
['FT.SPELLCHECK', 'index', 'query', 'TERMS', 'INCLUDE', 'dictionary', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
|
||||
@@ -45,7 +46,7 @@ describe('FT.SPELLCHECK', () => {
|
||||
dictionary: 'exclude'
|
||||
}]
|
||||
}),
|
||||
['FT.SPELLCHECK', 'index', 'query', 'TERMS', 'INCLUDE', 'include', 'TERMS', 'EXCLUDE', 'exclude']
|
||||
['FT.SPELLCHECK', 'index', 'query', 'TERMS', 'INCLUDE', 'include', 'TERMS', 'EXCLUDE', 'exclude', 'DIALECT', DEFAULT_DIALECT]
|
||||
);
|
||||
});
|
||||
});
|
||||
|
@@ -1,5 +1,6 @@
|
||||
import { CommandParser } from '@redis/client/dist/lib/client/parser';
|
||||
import { RedisArgument, Command, ReplyUnion } from '@redis/client/dist/lib/RESP/types';
|
||||
import { DEFAULT_DIALECT } from '../dialect/default';
|
||||
|
||||
export interface Terms {
|
||||
mode: 'INCLUDE' | 'EXCLUDE';
|
||||
@@ -34,6 +35,8 @@ export default {
|
||||
|
||||
if (options?.DIALECT) {
|
||||
parser.push('DIALECT', options.DIALECT.toString());
|
||||
} else {
|
||||
parser.push('DIALECT', DEFAULT_DIALECT);
|
||||
}
|
||||
},
|
||||
transformReply: {
|
||||
|
Reference in New Issue
Block a user