I want to be able to use django-haystack to do full text searches on a model. This model uses a PointField to store coordinates. I want to filter the results of a search based on the distance from a point. Is this possible with Haystack? Is there a better way to do this?
from django.contrib.gis.db import models
class Listing(models.Model):
name = models.CharField(max_length=255)
description = models.TextField()
location = models.PointField()
It sounds like you want users to input geographic information, like an address or zipcode into the text search. This is how I did it, though I’m not sure how it scales yet. I just finished this 5 minutes ago.
You should create a custom search form subclassed from SearchForm or one of the other options (for me it was FacetedSearchForm). Overwrite the search method.
First turn the search string into a point. http://code.google.com/p/geopy/wiki/GettingStarted
Then take the search query set, I used RelatedSearchQuerySet since it allows you to use load_all_queryset() which is where I filtered by distance. It’s GeoDjango to the rescue with GeoDjango Distance Queries. With the distance query, you can choose how to filter with distance less than, greater than etc. And the distance itself, in whatever units you want.
That should be a solid start. Hope this points you in the right direction.