Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
uglide opened this issue Sep 18, 2023 · 0 comments · Fixed by #191
Closed

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

uglide opened this issue Sep 18, 2023 · 0 comments · Fixed by #191
Labels

Comments

@uglide
Copy link
Contributor

uglide commented Sep 18, 2023

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)

Consider the following type-script pseudo-code:

// 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()
        }
    }
);

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

Reference documentation:
https://redis.io/commands/ft.create/
https://redis.io/commands/ft.search/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant