-
Notifications
You must be signed in to change notification settings - Fork 340
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
Geo Search Option? #12
Comments
Any movement on this? I would be interested in helping! |
I can start looking at getting things setup. Just got pulled away on a client project. |
For Elasticsearch the best way to do this would be to index a geo field and then add a function_score query to the should "clause" of a bool query. This increases the score based on distance from indexed doc's field val to the user's given origin. To set up the query you need at minimum:
Could also allow more options for:
This would also mean that a special "location" field be indexed in advance for the query to run against. That all being said, whats the general idea here? How would this geo search mechanism work in practice? |
This would be great! |
I had an attempt with #77. Going with what Taylor said what does everyone believe would be an elegant way to include additional functionality from Algolia and Elasticsearch and what are they key features that should be included? I believe the following are important:
Maybe something like this: Model::search('querystring')->withinLocation($lat, $lng, $radius)->get(); See #78 |
Before querying, the field mapping should be prepared to handle geopoints. This can only be done with a new/empty index as I understand it. Is this possible using Scout, or do we need an external workaround for this? I'll try to map geopoints directly using ES, before indexing documents with Scout, hopefully next week... |
@sandervanhooft From this article it seems that sticking to convention means that a mapping does not need to be made. I believe that means it is then up to the developer to correctly set up their toSearchableArray() method on their model. However, I am not too familiar with ES. Let me know if my understanding is wrong |
@EdwardNelson Thanks for the article. It unfortunately mentions that since the update you do need to provide a mapping. |
@sandervanhooft my fault for skimming the article and hoping for the best! You're completely right. Having to set the mappings on creation of the index and with updating the mappings once the index has been created having the potential to cause problems means that geosearch probably shouldn't be supported in scout? As not everyone will include lat/long from the outset. What's your opinion |
@EdwardNelson It depends on whether Scout breaks the geofield mapping after If that works than geosearch can IMHO be supported from Scout (and should For me personally, Scout is potentially incredible valuable for getting Nevertheless, geospatial search is such a basic requirement I hope to see
|
@EdwardNelson I am happy to report that manually mapping works! :) It takes 2 steps to get the geopoints into ElasticSearch:
1. Manually prepare the elasticsearch type mapping for storing a geopoint field You only need to provide mapping for fields that are not automatically interpreted correctly by ElasticSearch. So in my case I only provided the location mapping. I think the nicest way to do this manual mapping is actually to use a Laravel migration and the elasticsearch/elasticsearch package and the connection config used for Scout to set this up. Anyone up for writing an example for this? 2. Prepare your Laravel model
The Laravel Scout searchable trait is very easy to use if you have stored the location in a single table field, so it matches the Geo-point lat,lon string format or the geohash format . This way you don't need to do any customization and can stick to the formal Laravel Scout docs. If you have used two fields for lon and lat in your table than you'll need to provide a customized After this you can use Laravel Scout as you would normally use it. Example mapping (source):
With cURL this would be:
|
@sandervanhooft Probably getting a bit out of my depth in terms of Elasticsearch. It looks good from my amateur eyes! Probably one for the docs if it can be condensed down? Any chance you can take a look at #78 to see if we can get it merged. |
From an elasticsearch point of view. Yes, I think this would do a fine job of filtering results outside of radius from origin! |
Excellent, thanks! |
I wrote an example in ErickTamayo/laravel-scout-elastic#24 |
You can use the example from here in order to achieve this: ErickTamayo/laravel-scout-elastic#24 (comment) |
I was wondering if people would be interested in possibly a trait to say setup this entry to be able to be geo-searched on. As Algolia and Elasticsearch are separate in the way they do this, so it would require some setup in terms of how to get things setup for the array. If there is interest I can create a PR for this functionality.
The text was updated successfully, but these errors were encountered: