【发布时间】:2015-09-02 23:06:16
【问题描述】:
我有这个模型(django-oscar 产品):
class Product(AbstractProduct):
# ...
price_display = models.DecimalField(decimal_places=2, max_digits=12, blank=True, null=True)
# ...
由 haystack 索引:
class ProductIndex(indexes.SearchIndex, indexes.Indexable):
# ...
price = indexes.DecimalField(null=True)
# ...
def prepare_price(self, obj):
return obj.price_display or Decimal('0.0')
Haystack 由 elasticsearch 支持
pip freeze | grep elastic
elasticsearch==1.6.0
pyelasticsearch==1.4
pip freeze | grep hays
django-haystack==2.1.0
现在这个查询集:
# ...
qs = qs.filter(text__contains=q)
qs = qs.order_by('price')
返回以这种方式排序的(正确找到的)对象:
120 130 24 300 ... 9
不知道哪里错了……
【问题讨论】:
标签: elasticsearch django-haystack