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...

Comments

randallknutson’s picture

Status: Active » Needs review
StatusFileSize
new3.45 KB

Here is the patch. There is probably room for improvement in the math.

You will also need #2061629: Allow other views arguments to provide BBOX

randallknutson’s picture

drunken monkey’s picture

Status: Needs review » Needs work

Thanks 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:

  • Please use a new file for the class instead of an old one.
  • Trailing whitespace in several locations in the file.
  • Please document all methods (for 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).
  • Also, please use camelCase for method names, and don't use leading underscores.

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.

user654’s picture

.

das-peter’s picture

Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new8.5 KB

I'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.

drunken monkey’s picture

Status: Needs review » Needs work

i am insterested in search for nodes inside an area e.g. inside London.Is this possible to do with this patch?

No. 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.

das-peter’s picture

Status: Needs work » Needs review
StatusFileSize
new6.08 KB

@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.

das-peter’s picture

boabjohn’s picture

Hi 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!

drunken monkey’s picture

StatusFileSize
new5.44 KB
new6.21 KB

Thanks 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 bbox option 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.

das-peter’s picture

Status: Needs review » Reviewed & tested by the community

Thanks for the feedback. I think this is good to go :)

drunken monkey’s picture

Status: Reviewed & tested by the community » Fixed

OK, great. Committed.
Thanks again!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

Exploratus’s picture

How is this actually implemented?