Ok, so got further and at least it is working. If anyone has any improvements to suggest, would be most welcome!
class OrganizationSearchView(FacetedSearchView, ):
"""
Faceted browsing for organizations.
"""
def __name__(self):
return "OrganizationSearchView"
def __init__(self, *args, **kwargs):
super(OrganizationSearchView, self).__init__(*args, **kwargs)
self.searchqueryset = SearchQuerySet().models(Organization).filter(client=True).facet('industry').facet('address_country')
self.form_class=FacetedBrowserForm
self.template='search/organizationsearch.html'
def get_results(self):
sqs = super(OrganizationSearchView, self).get_results()
try:
pnt = self.request.user.get_profile().location
sqs = sqs.distance('location', pnt)
sqs = sqs.order_by('distance')
except:
sqs.order_by('registration_date')
return sqs
On Tuesday, May 21, 2013 11:27:27 PM UTC+2, zwervertje wrote:
Hey!
First, thanks for a fantastic module!
I was hoping to use haystack for implementing a faceted browser, but one of my main requirements is that I should be able to sort by distance. The use case is fairly straightforward: I have a set of places (which have a Point) and a logged in user (which also has a Point in the userprofile). Depending on which user is currently logged in, I would like to calculate the distance from the Point of the user to each of the places in the set.
Is this feasible? Using Geodjango, this is a no-brainer, but not sure about Haystack (as this is based on indexing?)
In order to play with this, I was trying to place the searchqueryset definition in the view (as there we have self.request.user), but did not manage to get that working yet by the way. Am I missing something obvious for this?
And for ref., using Solr as backend.
Thanks!