Skip to content

Commit

Permalink
fix #2614 - add support for RediSearch GEOSHAPE fields
Browse files Browse the repository at this point in the history
  • Loading branch information
leibale committed Sep 18, 2023
1 parent 292dc58 commit 3fa54fe
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
36 changes: 36 additions & 0 deletions packages/search/lib/commands/CREATE.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,42 @@ describe('FT.CREATE', () => {
);
});
});

describe('GEOSHAPE', () => {
describe('without options', () => {
it('SCHEMA_FIELD_TYPE.GEOSHAPE', () => {
assert.deepEqual(
CREATE.transformArguments('index', {
field: SCHEMA_FIELD_TYPE.GEOSHAPE
}),
['FT.CREATE', 'index', 'SCHEMA', 'field', 'GEOSHAPE']
);
});

it('{ type: SCHEMA_FIELD_TYPE.GEOSHAPE }', () => {
assert.deepEqual(
CREATE.transformArguments('index', {
field: {
type: SCHEMA_FIELD_TYPE.GEOSHAPE
}
}),
['FT.CREATE', 'index', 'SCHEMA', 'field', 'GEOSHAPE']
);
});
});

it('with COORD_SYSTEM', () => {
assert.deepEqual(
CREATE.transformArguments('index', {
field: {
type: SCHEMA_FIELD_TYPE.GEOSHAPE,
COORD_SYSTEM: 'SPHERICAL'
}
}),
['FT.CREATE', 'index', 'SCHEMA', 'field', 'GEOSHAPE', 'COORD_SYSTEM', 'SPHERICAL']
);
});
});

it('with AS', () => {
assert.deepEqual(
Expand Down
24 changes: 22 additions & 2 deletions packages/search/lib/commands/CREATE.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ export const SCHEMA_FIELD_TYPE = {
NUMERIC: 'NUMERIC',
GEO: 'GEO',
TAG: 'TAG',
VECTOR: 'VECTOR'
VECTOR: 'VECTOR',
GEOSHAPE: 'GEOSHAPE'
} as const;

export type SchemaFieldType = typeof SCHEMA_FIELD_TYPE[keyof typeof SCHEMA_FIELD_TYPE];
Expand Down Expand Up @@ -85,14 +86,26 @@ type SchemaHNSWVectorField = SchemaVectorField<typeof SCHEMA_VECTOR_FIELD_ALGORI
EF_RUNTIME?: number;
}>;

export const SCHEMA_GEO_SHAPE_COORD_SYSTEM = {
SPHERICAL: 'SPHERICAL',
FLAT: 'FLAT'
} as const;

export type SchemaGeoShapeFieldCoordSystem = typeof SCHEMA_GEO_SHAPE_COORD_SYSTEM[keyof typeof SCHEMA_GEO_SHAPE_COORD_SYSTEM];

type SchemaGeoShapeField = SchemaField<typeof SCHEMA_FIELD_TYPE['GEOSHAPE'], {
COORD_SYSTEM?: SchemaGeoShapeFieldCoordSystem;
}>;

export interface RediSearchSchema {
[field: string]:(
SchemaTextField |
SchemaNumericField |
SchemaGeoField |
SchemaTagField |
SchemaFlatVectorField |
SchemaHNSWVectorField
SchemaHNSWVectorField |
SchemaGeoShapeField
);
}

Expand Down Expand Up @@ -191,6 +204,13 @@ export function pushSchema(args: CommandArguments, schema: RediSearchSchema) {
args[lengthIndex] = (args.length - lengthIndex - 1).toString();

continue; // vector fields do not contain SORTABLE and NOINDEX options

case SCHEMA_FIELD_TYPE.GEOSHAPE:
if (fieldOptions.COORD_SYSTEM !== undefined) {
args.push('COORD_SYSTEM', fieldOptions.COORD_SYSTEM);
}

continue; // geo shape fields do not contain SORTABLE and NOINDEX options
}

if (fieldOptions.SORTABLE) {
Expand Down

0 comments on commit 3fa54fe

Please sign in to comment.