开发者

How to perform Geo Spatial search with django-haystack + solr

开发者 https://www.devze.com 2023-01-26 05:47 出处:网络
I\'m currently using django haystack with xapian. I couldn\'t find any documentation on how to perform geospatial queries on xapian. But there seems to be some momentum on Solr. So i\'m currently expe

I'm currently using django haystack with xapian. I couldn't find any documentation on how to perform geospatial queries on xapian. But there seems to be some momentum on Solr. So i'm currently experimenting with that.

I couldn't get spatialSolr to work properly on local, but for now working with spatial-solr-light, which seems to work fine. It accepts queries like

http://127.0.0.1:8080/solr/select/?q=blahblah&spatial={!radius=1.0%20sort=true}lat:10.0,lng:-10.0

Can anyony point me to a patch for haystack that allows me to pass custom queries like that. I could use raw_search(), but i can't chain the resuts. In any case i would like to find a cleaner way to do something like sqs.spatial(....)

There are some patches from other people mentioned on the google group(links below), but most of them are unreachable.

References:

  • https://github.com/fizx/solr-spatial-light

  • http://groups.googl开发者_Python百科e.com/group/django-haystack/browse_thread/thread/d0e23d45c0baa300/2298b6cf43389e18?lnk=gst&q=Spatial#2298b6cf43389e18

  • http://groups.google.com/group/django-haystack/browse_thread/thread/f88d625679941d77/420892adac151a64

  • http://groups.google.com/group/django-haystack/browse_thread/thread/e3a70112ce944b00/33bd673fbaaed0a7?lnk=gst&q=jteam#33bd673fbaaed0a7


If you're not tied to Xapian, look at Django, Sphinx and search by distance. I had a similar problem when I ran across this question and this seems to solve it. Thanks to django-sphinx, it's about as easy to set up as Haystack. Sphinx also seems to offer more flexibility.


Here's a fork of django haystack that adds in support for :

https://github.com/sidmitra/django-haystack-spatialsolrplugin

And corresponding notes are here: https://github.com/sidmitra/django-haystack-spatialsolrplugin/wiki/_pages


Sidmitra, I made port of your solution using haystack 1.2.X and solr 3.4. With some limitations to be frank - no support for schema generation at the moment, only LatLong geo type supported, sorting by distance is not perfect (but works)

https://github.com/frutik/django-haystack/tree/1.2.X


I agree with https://github.com/sidmitra/django-haystack-spatialsolrplugin .

It seems to be out-of-date, but I could beat it into shape with some work. Issues I had:

  • Hard to find the java SSP and when I found it it was the wrong version. http://www.dutchworks.nl/en/home/download.html was the link that worked for me.

  • The classpaths in the example xml files I found on the net were all wrong; I had to remove .solrext. from all of them.

  • The plugin was very picky about which directory it lived in; it couldn't talk to anything else until it was happily in solr/lib

  • solr_backend.py required the following patch (around line 505):

    if self.spatial_query:
        final_query = '{{!spatial circles={lat},{long},{radius} }}{0}'.format(final_query,**self.spatial_query)
    
  • I had further issues with making the solrconfig.xml so that GeoDistanceComponent never loaded before the query had a valid rsp.

In other words, you can certainly make it work, but you have to be able to deal with a number of error messages in both python and java before you get there.

0

精彩评论

暂无评论...
验证码 换一张
取 消