Django-haystack在外国领域的分面

时间:2017-09-21 14:57:59

标签: python django python-3.x elasticsearch django-haystack

是否可以通过搜索索引在外部字段属性上进行构面。

search_indexes.py

class ProductIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.EdgeNgramField(
        document=True, use_template=True,
        template_name='/home/wilkinj33/bargainforest/bargainforestenv/motorclass/templates/search/indexes/product_text.txt'
        )

    title = indexes.EdgeNgramField(model_attr='title')
    retailer = indexes.CharField(model_attr='retailer', faceted=True)
    price = indexes.IntegerField(model_attr='price', faceted=True)
    barcode = indexes.CharField(model_attr='barcode')

    def get_model(self):
        return Product

    def index_queryset(self, using=None):
        """Used when the entire index for model is updated."""
        return self.get_model().objects.filter(timestamp__lte=timezone.now())

我想面对以下模型,name属性。

class top_category(models.Model):
    class Meta:
        verbose_name_plural = 'Top Categories'

    name = models.CharField(max_length=500)

    def __str__(self):
        return self.name

0 个答案:

没有答案