Skip to content

Commit

Permalink
close #2210 - add support for FT.CREATE WITHSUFFIXTRIE (#2212)
Browse files Browse the repository at this point in the history
  • Loading branch information
leibale authored Jul 28, 2022
1 parent c1fd867 commit 60ad6aa
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
24 changes: 24 additions & 0 deletions packages/search/lib/commands/CREATE.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ describe('CREATE', () => {
['FT.CREATE', 'index', 'SCHEMA', 'field', 'TEXT', 'PHONETIC', SchemaTextFieldPhonetics.DM_EN]
);
});

it('with WITHSUFFIXTRIE', () => {
assert.deepEqual(
transformArguments('index', {
field: {
type: SchemaFieldTypes.TEXT,
WITHSUFFIXTRIE: true
}
}),
['FT.CREATE', 'index', 'SCHEMA', 'field', 'TEXT', 'WITHSUFFIXTRIE']
);
});
});

it('NUMERIC', () => {
Expand Down Expand Up @@ -124,6 +136,18 @@ describe('CREATE', () => {
['FT.CREATE', 'index', 'SCHEMA', 'field', 'TAG', 'CASESENSITIVE']
);
});

it('with WITHSUFFIXTRIE', () => {
assert.deepEqual(
transformArguments('index', {
field: {
type: SchemaFieldTypes.TAG,
WITHSUFFIXTRIE: true
}
}),
['FT.CREATE', 'index', 'SCHEMA', 'field', 'TAG', 'WITHSUFFIXTRIE']
);
});
});

describe('VECTOR', () => {
Expand Down
10 changes: 10 additions & 0 deletions packages/search/lib/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ type CreateSchemaTextField = CreateSchemaCommonField<SchemaFieldTypes.TEXT, {
NOSTEM?: true;
WEIGHT?: number;
PHONETIC?: SchemaTextFieldPhonetics;
WITHSUFFIXTRIE?: boolean;
}>;

type CreateSchemaNumericField = CreateSchemaCommonField<SchemaFieldTypes.NUMERIC>;
Expand All @@ -215,6 +216,7 @@ type CreateSchemaGeoField = CreateSchemaCommonField<SchemaFieldTypes.GEO>;
type CreateSchemaTagField = CreateSchemaCommonField<SchemaFieldTypes.TAG, {
SEPARATOR?: string;
CASESENSITIVE?: true;
WITHSUFFIXTRIE?: boolean;
}>;

export enum VectorAlgorithms {
Expand Down Expand Up @@ -282,6 +284,10 @@ export function pushSchema(args: RedisCommandArguments, schema: RediSearchSchema
args.push('PHONETIC', fieldOptions.PHONETIC);
}

if (fieldOptions.WITHSUFFIXTRIE) {
args.push('WITHSUFFIXTRIE');
}

break;

// case SchemaFieldTypes.NUMERIC:
Expand All @@ -297,6 +303,10 @@ export function pushSchema(args: RedisCommandArguments, schema: RediSearchSchema
args.push('CASESENSITIVE');
}

if (fieldOptions.WITHSUFFIXTRIE) {
args.push('WITHSUFFIXTRIE');
}

break;

case SchemaFieldTypes.VECTOR:
Expand Down

0 comments on commit 60ad6aa

Please sign in to comment.