[Patch] Adding spacial search for Solr backend

149 views
Skip to first unread message

xgdlm

unread,
Jan 8, 2010, 5:52:29 PM1/8/10
to django-haystack
Hello all,

Here is a patch to add spacial search to haystack with Solr backend:
http://1cafe.fr/spacial.diff.txt

Patch is build on django-haystack-1.0.1-final.tar.gz.

This patch works with the jteam spacial plugin for Solr:
http://www.jteam.nl/news/spatialsolr

Here is an exemple of a spacial search, for instance searching all the
result within 3km from a center point:
SearchQuerySet().spacial(lat=49.4338870, long=1.0888390, radius=3,
unit='km').order_by('-geo_distance')

Of course this patch is a quick and dirty fix for people who wants to
run spacial queries with haystack. It works well for me, so may be it
will for others.

Regards,

xav

xgdlm

unread,
Jan 9, 2010, 8:27:02 AM1/9/10
to django-haystack
Actually I misspelled "spacial", should be "spatial"
Patch is updated.

and spatial queries should be done like this:

SearchQuerySet().spatial(lat=49.4338870, long=1.0888390, radius=3,


unit='km').order_by('-geo_distance')

xav

xgdlm

unread,
Nov 18, 2010, 6:36:18 PM11/18/10
to django-...@googlegroups.com
>> Here is a patch to add spacial search to haystack with Solr backend:http://1cafe.fr/spacial.diff.txt

For those complaining about the down link, patch can be found at :

http://friendpaste.com/6y88Nn4tCyRkBmxOOdg8He

Regards,

xav


Sid

unread,
Nov 26, 2010, 7:11:29 PM11/26/10
to django-haystack
Here's a forked version containing those changes.

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

-Sid

Sid

unread,
Sep 28, 2011, 3:52:57 AM9/28/11
to django-...@googlegroups.com
I've moved the above repository to here, for posterity.






Dominique Guardiola Falco

unread,
Sep 28, 2011, 6:51:41 AM9/28/11
to django-...@googlegroups.com
Hi

this is great for everybody,as this solr extension is used by many people already, why don't you submit it to the main repository ?

Sid

unread,
Sep 29, 2011, 3:04:29 PM9/29/11
to django-...@googlegroups.com
- Firstly, i want to implement the changes for Solr 1.3+ . Since solr now has built in support for Geo stuff, i think that should be natively supported by haystack now.
I'll send a pull request, after i've done that. Someone else(Samuel Joos) did send me some changes he did to make it work, which i'll try to commit to github.

As far as the JTeam SSP is concerned
- Also, I don't think support for an extra plugin like belongs in the main repository.

- The current code base is haystack 1.1.1 i think, so need to merge in the latest master and test it out.
-  The plugin jar i used was 1.x, but JTeam seems to have upgraded it to 2.x so will have to see if there are backward compatible changes.

Dominique Guardiola Falco

unread,
Sep 30, 2011, 4:52:43 AM9/30/11
to django-...@googlegroups.com
Thanks for this explanation Siddartha
I did not check Solr for a while and did not know they had their own geo support shipping now, good news


Frutik

unread,
Nov 4, 2011, 9:40:52 AM11/4/11
to django-haystack
Hi Sid!

I have made port of your patch for solr 3.4 and haystack 2.* and looks
like it works :-)

You can find all stuff on github https://github.com/frutik/django-haystack

Usage example:

from haystack.query import SearchQuerySet
s = SearchQuerySet()
s.spatial(lat=9.671519, long=46.686754000000001, sfield='location',
distance=10)

Hopefully it can be usefull for somebody else

Kind regards,
Andrew

Sid

unread,
Nov 5, 2011, 12:05:15 AM11/5/11
to django-...@googlegroups.com
Hi Andrew,

     Can you link to the specific commit with your changes. I only see the Readme change on your repo. I didn't see any branches with spatial related commits. Maybe i'm missing something.

Anyways i'd been experimenting with Solr 3.4 + haystack. I just pushed whatever changes i had last to a separate branch for now "solr34"

It's not working yet, but i was trying to use the solr built in LatLon field type. Will work when i'm free next(tricky!). Feel free to share your code. It'll be a great help seeing your implementation.

I've been thinking of merging my JTeam SSP + this solr34 work into the same branch. Maybe add a flag to settings.py to figure out what query syntax to use. They're pretty similar.
Although SSP 2.x, differs from SSP 1.x, so i'd have to maintain 3 syntaxes slightly different in their own ways. But should be simple enough. Maybe in the future i can look at geohash etc. as well.
Reply all
Reply to author
Forward
0 new messages