【发布时间】:2015-01-25 12:02:37
【问题描述】:
我将 Django Haystack 与 Elasticsearch 一起使用。 ElasticSearch 可以执行距离查询并返回 5 英里半径范围内的 11 个结果,而 Haystack 的 dwithin 方法仅针对相同条件返回一个结果。以下是我在表单中使用的搜索查询。
def search(self):
if not self.is_valid():
return self.no_query_found()
if not self.cleaned_data['q']:
return self.no_query_found()
sqs = self.searchqueryset.all()
distance = D(mi=5)
obj= Geo.objects.get(zip_code=self.cleaned_data['q'])
latitude = obj.latitude
longitude = obj.longitude
center_point = Point(longitude, latitude)
sqs = sqs.dwithin('location', center_point, distance)
if self.load_all:
sqs.load_all()
return sqs
【问题讨论】:
标签: python elasticsearch django-haystack