I'm working on allowing geojson callbacks to a solr view and need a bbox views argument. I've added it here for search_api_location.
The math is a little interesting. I'm looking for the center point of the box and the radius and then sending it to the solr facet as point and radius.
Patch coming...
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | 2061639-10--bbox_argument--interdiff.txt | 6.21 KB | drunken monkey |
| #10 | 2061639-10--bbox_argument.patch | 5.44 KB | drunken monkey |
Comments
Comment #1
randallknutson commentedHere is the patch. There is probably room for improvement in the math.
You will also need #2061629: Allow other views arguments to provide BBOX
Comment #2
randallknutson commentedAlso see: #1641870: Bounding Box support with Search API views
Comment #3
drunken monkeyThanks for your suggestion, and for providing a patch!
I don't really know, though, whether this would be generally useful enough to warrant being added to this module. I mean, this functionality could very easily be added by another (maybe custom) module, too, and it seems rather specific. Also, since there is then a double conversion from/to a bounding box, an implementation which works closer with Solr (so, e.g., non-square rectangles are possible, and there is no complex math needed in the module) might also be a better solution here (if you opt for a custom module, that is).
If it's just that you want to use the "bbox" method of filtering for performance reasons, a simple select box for the normal contectual filter should also do it.
Furthermore, there are several problems with the patch itself:
query()you can just use{@inheritdoc}) and also add some inline comments where things aren't obvious. Some of them are really not so trivial (though I guess explaining the math of_calc_distance()would be out of scope – but maybe a link would help, if you have one).You don't need to fix them at the moment, though, as I'd first need some further feedback of people who would find this useful.
Comment #4
user654 commented.
Comment #5
das-peter commentedI'd like to see bbox support in this module too.
I've just added "proper" bbox support to Search API Solr: #2368399: Support for "proper" bbox location searches
But since #3 is a bit discouraging I decided to build the usage of the feature directly into Views GeoJSON #1641870: Bounding Box support with Search API views as this is the place I need it.
However, I also overhauled the class provided here.
@drunken monkey Up to you if this is a desirable functionality or not. I'd think there's no better place than this module.
Comment #6
drunken monkeyNo. Such things are better done with a taxonomy term, I'd say. This patch just lets you filter for a square (or rectangle, with Peter's improvements) instead of a circle – but still just a geometric shape, no political borders of any kind.
@ das-peter: Thanks, that new option does make a lot of sense! If we could then rewrite the argument handler to use that instead, I think I wouldn't be opposed to using it anymore.
However, the option description has several typos, and also fails to specify how this option interacts with "radius". (I'd be for letting both work separately – but then your Solr code in #2368399: Support for "proper" bbox location searches would need to be slightly tweaked.) Also, it should be stated explicitly that all four sub-keys have to be present.
Comment #7
das-peter commented@drunken monkey Thanks. Awesome to hear that.
So here we go. Fixed the typos and made crystal clear the four coordinates are required and have to be keyed.
Slimmed down the argument handler to just provide bbox values.
Sorry, patch contains changes of #2366857: More defensive code in search_api_location_views_views_data_alter() too - if it's a struggle to review, lazy ass me will split it up.
Comment #8
das-peter commentedRe-roll since #2366857: More defensive code in search_api_location_views_views_data_alter() is in.
Comment #9
boabjohn commentedHi guys,
This looks spectacularly exciting!
Can I ask a newbie question please?
With this patch we get the capacity to filter on a bbox value (eg, a user draws a bbox of interest using a geofiled input widget?) and then solr returns records where that bbox filter (fully encloses) or (overlaps) their own bbox.
Ok so far?
So my usecase starts one step back...my nodes have a geofield with geojson data. Geofield helpfully stores top/bottom/left/right values. I have no idea what solr does with it.
Is this extension going to pick the appropriate values out of the solr index automagically...or?
Thanks in advance for your guidance.
And thanks for the contrib work in the Drupal-geo space...it's fully appreciated!
Comment #10
drunken monkeyThanks for the re-roll!
In general, the patch already looks really good. I just cleaned it up a bit more and elaborated a bit on the description of the
bboxoption key.It's contained in the attached patch, which is RTBC in my opinion. Please see if it still OK for you. (It's nearly exclusively string and comment changes – mostly to change "bbox" to "bounding box", since I don't think the former is really commonly used.)
@ boabjohn: No, you are mistaken, sorry. It is currently (as far as I know) not possible to index any location data other than points, and this patch doesn't change that. It just lets you filter the results not only for a circle around a given point (as previously), but also in a given rectangle.
Comment #11
das-peter commentedThanks for the feedback. I think this is good to go :)
Comment #12
drunken monkeyOK, great. Committed.
Thanks again!
Comment #15
Exploratus commentedHow is this actually implemented?