I was wondering:
what's best for indexing places' geolocation ? Geohash or lon/lat ?
I search places based on the distance between the user and the place so what's best for ElasticSearch ? I think Geohash is more powerful but I may be wrong...
Geohash is just a form of lon/lat representation with different accuracy. You should specify geo-point type in your mapping:
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-geo-point-type.html, and you could use both geohash or lon/lot form.
Related
To perform geoqueries in Firebase or Firestore, there are libraries like GeoFire and GeoFirestore. But to sort the results of that geoquery by distance, the entire dataset must be read, correct? If a geoquery produces a large number of results, there is no way to paginate those results (on the backend, not to the user) when sorting by distance, is there?
Yes, in order to sort by distance you must read all results that fall into the Geoquery range.
The reason for this is how such queries work: they return a set of documents that are within a range of geohash values, which is not necessarily the same order as by their distance to the center of the query.
This also means that there is no way to do meaningful pagination in a list of documents that are ordered by their distance, since you need to read all results anyway. The best I can think of is implementing the Geoquery in Cloud Functions, so that you can do the sort/filter there, and only return the page-full of results to the client. While this doesn't save on your cost (as you're still reading all documents in the range), it will save bandwidth in sending documents to the user.
To learn more about how such geoqueries work, which explains why they can't be optimized the way you're looking to do, have a look at the video of my talk here or this article+shorter video on Jeff Delaney's site.
Is it possible to sort returned objects from Backand based on how near the location field of type "point" is to the querying users current location?
From the Backand docs I have only seen support for querying based on a maximum distance from a point but nothing about sorting by geo points.
I was able to create a custom query in Backand which I can hit from the Backand API. Unfortunately in order to sort on the distance of nearby users I need to calculate the distance from the current user to every other user in the database and then sort based on this. Seems very complex - a lot of calculations every time the query is called! Will probably see big performance hits as the database gets larger. Guess it answers this question, but I am hopeful still of finding a better alternative.
I am using Neo4j with PHP.
In my project, I have restaurant nodes. Each node has latitude, longitude and taxonomy properties.
I need to return the restaurant nodes matching user's given taxonomy with results ordered by distance from user's location (that is nearest restaurant at the first).
What is the easiest solution?
I have worked on Mongo DB and Elasticsearch,this is very easy to achieve there using special indexing. But I could not find a straightforward way in Neo4j.
There are a couple of solutions :
Using neo4j spatial plugin : https://github.com/neo4j-contrib/spatial
Computing the distance yourself with haversin in Cypher : http://neo4j.com/docs/stable/query-functions-mathematical.html#functions-spherical-distance-using-the-haversin-function
In 3.0Mx there should be basic Cypher functions for point and distance : https://github.com/neo4j/neo4j/pull/5397/files (I didn't tested it though)
Besides the aforementioned Neo4j-Spatial, in Neo4j 3.0 there is also a built in distance() function.
See this GraphGist:
http://jexp.github.io/graphgist/idx?dropbox-14493611%2Fcypher_spatial.adoc
So if you find and match your restaurants some way you can order them by distance:
MATCH (a:Location), (b:Restaurant)
WHERE ... filtering ...
RETURN b
ORDER BY distance(point(a),point(b))
Neo4j Spatial features distance queries (among lots of other things) and also cares about ordering.
I'm planning to build a Rails application that should store data about a geo routes (potentially millions). The route is recorded from an smartphone or manually "drawn" in an web-interface.
A route consists of multiple (up to about 10.000) coordinates containing timestamp, latitude and longitude - but possible also altitude and accuracy.
When stored, I need to filter out "pgs noice", caluculate the total distance and show in on a map.
How would you suggest I store the route data?
I'm considering using PostgreSQL and would like each Trip to be stored in one row, for fast insertion and retrieval(?). This would require an multidimensional array field, which is only supported i Rails 4.0 (?).
At the same time, I have been looking at PostGIS and the ActiveRecord Adapter, but are not sure if this is overkill or how it would work with an PostgreSQL array.
Any input would be greatly appreciated.
Basically you have two options.
You could use an array of points on PostgreSQL. Arrays in PostgreSQL are relatively complex and it is important to understand arrays and I the primary primitives primarily work on planes, not spheres so you lose spherical trig and the like. For these reasons I don't really recommend this approach unless you are already familiar with both and have specific reasons to choose this one. Of course you could also build your own spherical trig functions if you like.... But why you would when PostGIS is available I don't now.
You can use geography types in PostGIS. These are helpful because you can store very complex multi-lines. PostGIS gives you spherical trig capabilities too. In general the types here are closer to what you are trying to do.
Finally I would recommend look at pgrouting which may give some additional functions you may find helpful.
I'd like to be able to order my search results by score and location. Each user in the DB has lat/lot and I am currently indexing:
location :coordinates do
Sunspot::Util::Coordinates.new latlon[0], latlon[1]
end
The model which I would performing the search against is also indexed in the same manner. Essentially what I am trying to achieve is that the results be ordered by score and then by location. So if I search for Walmart, I would like to see all Walmart's ordered by their geo proximity to my location.
I remember reading something about solr's new geo-sort but not sure if it is out of alpha and/or if sunspot has implemented a wrapper.
What would you recommend?
Because of the way that Sunspot calculates location types you'll need to do some extra leg work to have it sort by distance from your target as well. The way it works is that it creates a geo-hash for each point and then searches using regular fulltext search on that geo-hash. The result is that you probably won't be able to determine if a point 10km away is further than a point that is 5km away, but you'll be able to tell if a point 50km away is further than a point 1-2km away. The exact distances are arbitrary but the result is that you probably won't have as fine-grained of a result as you would like and the search acts more as a way to filter points that are within an acceptable proximity. After you have filtered your points using the built-in location search, there are three ways to accomplish what you want:
Upgrade to Solr 3.1 or later and upgrade your schema.xml to use the new spatial search columns. You'll then need to make custom modifications to Sunspot to create fields and orderings that work with these new data types. As far as I know these aren't available in Sunspot yet, so you'll have to make those connections on your own and you'll have to dig around in Solr to do some manual configurations.
Leverage the Spatial Solr Plugin. You'll have to install a new JAR into your Solr directory and you'll have to make some modifications to Sunspot, but they are relatively painless and the full instructions can be found here.
Leverage your DB, if your DB is also indexed on the location columns then you can use the Sunspot built-in location search to filter your results down to a reasonable sized set. You can then query the DB for those results and order them by proximity to your location using your own distance function.