Skip to content

Sort nodes by point distance from another point #3900

Open

Description

@Sapulidi

Bascially, I would like to be able to get the 100 (limit) people who are closest to a certain location. And if possible sort them afterwards but that can be done in post processing if needed.

I am building an application that shows me nodes who are close to my location. Let's say I have 5 nodes: A, B, C, D and E. Node A is closest to me and node E is the farthest away. I expect the following query to return A, B and C but instead it returns A, B and E.

{
  "where": {
    "location_LT": {
      "point": {
        "longitude": xxx,
        "latitude": xxx
      },
      "distance": 10000
    },
  },
  "options": {
    "limit": 3,
    "sort": [
      {
        "location": "ASC"
      }
    ]
  }
}

I just found out through the Discord server that the sort is not related to the location (which I thought it was). I currently get a fairly good results if I make 2 separate queries LT and GT but if I add more filtering, some nodes nearby that should be in the results get dropped.

An example of what I'd like might look like this (if you implement this I trust you will use better naming than me).

{
  "where": {
    "location_NEIGHBOUR": {
      "point": {
        "longitude": xxx,
        "latitude": xxx
      },
    },
  },
  "options": {
    "limit": 3,
    "sort": "NEAR" | "FAR"
  }
}

For more context (Neo4J Discord thread): https://discord.com/channels/787399249741479977/1148644450097168524

Thanks!

Activity

  1. deleted a comment from helenesanche on Dec 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions