diff --git a/packages/search/lib/commands/CREATE.spec.ts b/packages/search/lib/commands/CREATE.spec.ts index 31eaf02dbb..094ba4529f 100644 --- a/packages/search/lib/commands/CREATE.spec.ts +++ b/packages/search/lib/commands/CREATE.spec.ts @@ -441,6 +441,36 @@ describe('CREATE', () => { ); }); }); + + describe('Missing Values', () => { + it('with INDEXEMPTY', () => { + assert.deepEqual( + transformArguments('index', { + field: { + type: SchemaFieldTypes.TEXT, + MISSING_VALUES: { + INDEXEMPTY: true + } + } + }), + ['FT.CREATE', 'index', 'SCHEMA', 'field', 'TEXT', 'INDEXEMPTY'] + ); + }); + + it('with INDEXMISSING', () => { + assert.deepEqual( + transformArguments('index', { + field: { + type: SchemaFieldTypes.TEXT, + MISSING_VALUES: { + INDEXMISSING: true + } + } + }), + ['FT.CREATE', 'index', 'SCHEMA', 'field', 'TEXT', 'INDEXMISSING'] + ); + }); + }); }); testUtils.testWithClient('client.ft.create', async client => { diff --git a/packages/search/lib/commands/index.ts b/packages/search/lib/commands/index.ts index 053e2fab38..29dbd2480c 100644 --- a/packages/search/lib/commands/index.ts +++ b/packages/search/lib/commands/index.ts @@ -189,12 +189,32 @@ export enum SchemaFieldTypes { GEOSHAPE = 'GEOSHAPE' } +export interface MissingValues { + INDEXEMPTY?: boolean; + INDEXMISSING?: boolean; +} + +function pushMissingValues(args: RedisCommandArguments, missingValues?: MissingValues) { + if (!missingValues) { + return; + } + + if (missingValues.INDEXEMPTY) { + args.push("INDEXEMPTY"); + } + + if (missingValues.INDEXMISSING) { + args.push("INDEXMISSING"); + } +} + type CreateSchemaField< T extends SchemaFieldTypes, E = Record > = T | ({ type: T; AS?: string; + MISSING_VALUES?: MissingValues; } & E); type CreateSchemaCommonField< @@ -313,11 +333,14 @@ export function pushSchema(args: RedisCommandArguments, schema: RediSearchSchema args.push('WITHSUFFIXTRIE'); } + pushMissingValues(args, fieldOptions.MISSING_VALUES); + break; - // case SchemaFieldTypes.NUMERIC: - // case SchemaFieldTypes.GEO: - // break; + case SchemaFieldTypes.NUMERIC: + case SchemaFieldTypes.GEO: + pushMissingValues(args, fieldOptions.MISSING_VALUES); + break; case SchemaFieldTypes.TAG: if (fieldOptions.SEPARATOR) { @@ -332,6 +355,8 @@ export function pushSchema(args: RedisCommandArguments, schema: RediSearchSchema args.push('WITHSUFFIXTRIE'); } + pushMissingValues(args, fieldOptions.MISSING_VALUES); + break; case SchemaFieldTypes.VECTOR: @@ -373,6 +398,8 @@ export function pushSchema(args: RedisCommandArguments, schema: RediSearchSchema } }); + pushMissingValues(args, fieldOptions.MISSING_VALUES); + continue; // vector fields do not contain SORTABLE and NOINDEX options case SchemaFieldTypes.GEOSHAPE: @@ -380,6 +407,8 @@ export function pushSchema(args: RedisCommandArguments, schema: RediSearchSchema args.push('COORD_SYSTEM', fieldOptions.COORD_SYSTEM); } + pushMissingValues(args, fieldOptions.MISSING_VALUES); + continue; // geo shape fields do not contain SORTABLE and NOINDEX options }