1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-07 13:22:56 +03:00

add geoshape support (#2788)

copied from what leibele did for v5
This commit is contained in:
Shaya Potter
2024-07-10 19:45:17 +03:00
committed by GitHub
parent 7d43a97bc7
commit a1bee1caaf
2 changed files with 59 additions and 3 deletions

View File

@@ -185,7 +185,8 @@ export enum SchemaFieldTypes {
NUMERIC = 'NUMERIC',
GEO = 'GEO',
TAG = 'TAG',
VECTOR = 'VECTOR'
VECTOR = 'VECTOR',
GEOSHAPE = 'GEOSHAPE'
}
type CreateSchemaField<
@@ -257,6 +258,17 @@ type CreateSchemaHNSWVectorField = CreateSchemaVectorField<VectorAlgorithms.HNSW
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 CreateSchemaGeoShapeField = CreateSchemaCommonField<SchemaFieldTypes.GEOSHAPE, {
COORD_SYSTEM?: SchemaGeoShapeFieldCoordSystem;
}>;
export interface RediSearchSchema {
[field: string]:
CreateSchemaTextField |
@@ -264,7 +276,8 @@ export interface RediSearchSchema {
CreateSchemaGeoField |
CreateSchemaTagField |
CreateSchemaFlatVectorField |
CreateSchemaHNSWVectorField;
CreateSchemaHNSWVectorField |
CreateSchemaGeoShapeField
}
export function pushSchema(args: RedisCommandArguments, schema: RediSearchSchema) {
@@ -361,6 +374,13 @@ export function pushSchema(args: RedisCommandArguments, schema: RediSearchSchema
});
continue; // vector fields do not contain SORTABLE and NOINDEX options
case SchemaFieldTypes.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) {