node-redis icon indicating copy to clipboard operation
node-redis copied to clipboard

Add support for GEOSHAPE index fields and WITHIN and CONTAINS query operators

Open uglide opened this issue 2 years ago • 4 comments

Motivation

Since RediSearch 2.8, it's possible to do more advanced GEO querying with GEOSHAPE fields.

On the client side, we should provide support for Index creation and Querying. APIs should allow users to use popular WKT libraries that parse and "serialise" to WKT format (e.g. https://github.com/cschwarz/wkx)

Requirements:

  • Add support for GEOSHAPE fields:
    • Perform validations to allow passing only POLYGON and POINT geometry primitives.
    • Support specifying the coordinate system
  • Ensure that querying API is compatible with GEOSHAPE queries

Basic Code Example

// Geometry primitives will be used from third-party libraries and serialized to WKT
let p = new wkx.Polygon([new wkx.Point(1, 2), new wkx.Point(3, 4), new wkx.Point(5, 6), new wkx.Point(1, 2)]);

await client.hSet('land:123', {
    geometry: p.toWkt(), // Serialisation
    price: 29000
})

await client.ft.create('idx:land', {
    'geometry': {
        type: SchemaFieldTypes.GEOSHAPE // New field type
        COORD_SYSTEM: GeoshapeFieldCoordSystem.FLAT // Coordinate system type 
    },
    'price': {
        type: SchemaFieldTypes.NUMERIC,
    }
}, {
    ON: 'HASH',
    PREFIX: 'land:'
});

let areaOfInterest = new wkx.Polygon([new wkx.Point(1, 2), new wkx.Point(3, 4), new wkx.Point(5, 6), new wkx.Point(1, 2)]);

let result = await client.ft.search(
    'idx:land',
    '@geometry:[WITHIN $area] @price:[20000 30000]',
    {
        PARAMS: {
            area: areaOfInterest.toWkt()
        }
    }
);

uglide avatar Sep 18 '23 13:09 uglide

3fa54fef584852d481eec7f788492b500283ea59

  • [x] Add support for GEOSHAPE fields:
    • [ ] ~Perform validations to allow passing only POLYGON and POINT geometry primitives.~ Why? The server should handle this (he already does?), there is no reason to validate twice..
    • [x] Support specifying the coordinate system
  • [x] Ensure that querying API is compatible with GEOSHAPE queries

leibale avatar Sep 18 '23 16:09 leibale

@leibale what's the norm here? The problem is (honestly) in some clients we half do this (randomly validating) and yet don't take it all the way through. Definitely open to not doing this, if it currently goes against lib norm.

chayim avatar Sep 20 '23 09:09 chayim

@chayim unless I have to, I let the server do its job... same for default values for arguments..

leibale avatar Sep 20 '23 13:09 leibale

Will this make it into a Node-Redis 4 release?

simonprickett avatar Oct 13 '23 10:10 simonprickett