Skip to content
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

Sort nodes by point distance from another point #3900

Open
Sapulidi opened this issue Sep 6, 2023 · 1 comment
Open

Sort nodes by point distance from another point #3900

Sapulidi opened this issue Sep 6, 2023 · 1 comment
Labels
feature request New feature or request

Comments

@Sapulidi
Copy link

Sapulidi commented Sep 6, 2023

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!

@Sapulidi Sapulidi added the feature request New feature or request label Sep 6, 2023
@helenesanche
Copy link

Hi @Sapulidi thank you very much for raising this interesting feature.
We will take into consideration prioritising this feature as we're collecting more geospatial use cases.

In the meantime, what I could suggest is to create an index on the point property and this should enable cypher statements to return back the data in a sorted ordered. The issue with this workaround is that it's quite CPU expensive and depending on the amount of data you have it can get quite slow.

I suggest you take a look at our cypher documentation which may help you finding a workaround until we can properly embed this capability in the library.

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

No branches or pull requests

2 participants