Skip to content

Conversation

@mackinleysmith
Copy link

@mackinleysmith mackinleysmith commented Nov 5, 2025

This PR adds filtering support to the queryNearest method, allowing users to filter results using the same filter builder API available in query. This addresses the feature request in #17 and the discussion in the Discord thread.

Changes

  • Extended queryNearest signature: The method now accepts an options object that can include both maxDistance and filter parameters, while maintaining backwards compatibility with the existing numeric maxDistance parameter.
  • Filter builder support: Users can now apply the same filter conditions available in query:
    • eq() - equality filters
    • in() - value in a set filters
    • gte() / lt() - sort key range filters
  • Backend implementation: Updated nearestPoints query to accept filtering conditions and sorting intervals, passing them through to ClosestPointQuery.
  • Documentation: Updated README with examples showing the new filtering capabilities.

Example Usage

const result = await geospatial.queryNearest(
  ctx,
  { latitude: 40.7813, longitude: -73.9737 },
  maxResults,
  {
    maxDistance: 10000,
    filter: (q) => q.eq("category", "coffee"),
  },
);

Benefits

  • Filtering helps constrain the search space and can speed up lookups
  • Consistent API with the existing query method
  • Backwards compatible - existing code using numeric maxDistance continues to work
  • Enables use cases like finding nearest points matching specific criteria (e.g., "nearest coffee shops" or "nearest available books")

Testing

  • Added tests for must and should filter conditions in pointQuery.test.ts
  • Verified sort key interval filtering works correctly
  • Existing tests continue to pass

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

…rting options. Update README to reflect new options for maxDistance and filtering logic. Modify API definitions and implementations to support must/should filter conditions and sorting intervals. Add tests for new filtering functionality in closest point queries.
package.json Outdated
"build:go": "cd src/s2-bindings && python build.py",
"build:esm": "tsc --project ./esm.json && echo '{\\n \"type\": \"module\"\\n}' > dist/esm/package.json",
"build:cjs": "tsc --project ./commonjs.json && echo '{\\n \"type\": \"commonjs\"\\n}' > dist/commonjs/package.json",
"build:esm": "tsc --project ./esm.json && echo -e '{\n \"type\": \"module\"\n}' > dist/esm/package.json",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is something weird I had to do to get Vercel to build my fork without erroring out.

The error message I was getting was:

✘ [ERROR] Syntax error "n"
    ../../node_modules/.pnpm/@convex-dev+geospatial@https+++codeload.github.com+mackinleysmith+geospatial+tar.gz+071ac5f5d_veafjjmfdyevjqqmh7gvbjmbv4/node_modules/@convex-dev/geospatial/dist/esm/package.json:1:2:
      1 │ {\n  "type": "module"\n}
        ╵   ^
✖ esbuild failed: Error: Build failed with 1 error:
../../node_modules/.pnpm/@convex-dev+geospatial@https+++codeload.github.com+mackinleysmith+geospatial+tar.gz+071ac5f5d_veafjjmfdyevjqqmh7gvbjmbv4/node_modules/@convex-dev/geospatial/dist/esm/package.json:1:2: ERROR: Syntax error "n"
Error: Command "cd ../../packages/backend && pnpm dlx convex deploy --cmd 'cd ../.. && turbo run build' --cmd-url-env-var-name NEXT_PUBLIC_CONVEX_URL --check-build-environment disable" exited with 1

I'm definitely open to reverting this before merging if it presents some unforeseen consequence -- I am by no means attached to it.

@ianmacartney what do you think?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oof... turns out that echo -e is not supported on macOS, so I'm updating this to use a node script for full cross platform support. Another option is to use printf, but that might lose compatibility with Windows.

I sure am shaving yaks today.

@mackinleysmith mackinleysmith changed the title Enhance geospatial query capabilities by introducing filtering and sorting options. Add support for filtering to queryNearest Nov 8, 2025
@ianmacartney
Copy link
Contributor

ianmacartney commented Nov 10, 2025 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants