Hi Elisabeth,

Sorry for not responding sooner; I forgot.

You’re in need of some spatial nearest-neighbor code I wrote but it isn’t
open-sourced yet.  It works on the RPT grid.

Any way, you should consider doing this in two searches: the first query
tries the bbox provided, and if that returns nothing then issue a second
for the closest within the a 1000km distance.  The first query is
straight-forward as documented.  The second would be close to what you gave
in your example but sort by distance and return rows=1.  It will *not*
compute the distance to every document, just those within the 1000km radius
plus some grid internal grid squares *if* you use spatial RPT
(“location_rpt” in the example schema).  But use LatLonType for optimal
sorting performance, not RPT.

With respect to doing this in one search vs two, that would involve writing
a custom request handler.  I have a patch to make this easier:
https://issues.apache.org/jira/browse/SOLR-5005.  If in your case there are
absolutely no other filters and it’s not a distributed search (no
sharding), then you could approach this with a custom query parser that
generates and executes one query to know if it should return that query or
return the fallback.

Please let me know how this goes.

~ David Smiley
Freelance Apache Lucene/Solr Search Consultant/Developer
http://www.linkedin.com/in/davidwsmiley


On Tue, Jul 22, 2014 at 3:12 AM, elisabeth benoit <elisaelisael...@gmail.com
> wrote:

> Hello,
>
> I am using solr 4.2.1. I have the following use case.
>
> I should find results inside bbox OR if there is none, first result outside
> bbox within a 1000 km distance. I was wondering what is the best way to
> proceed.
>
> I was considering doing a geofilt search from the center of my bounding box
> and post filtering results.
>
> fq={!geofilt sfield=store}&pt=45.15,-93.85&d=1000
>
> From a performance point of view I don't think it's a good solution though,
> since solr will have to calculate every document distance, then sort.
>
> I was wondering if there was another way to do this and avoid sending more
> than one request to solr.
>
> Thanks,
> Elisabeth
>

Reply via email to