django-haystack(xapianバックエンドを使用)を取得して、ここでモデルにインデックスを付けて、フィールドname
とdescription
フィールドで検索しようとしています。
フィールドを追加する、Item
のサブクラスがあります。Device
manufacturer
モデルは次のItem
ように定義されます。
class Item(models.Model):
name = models.CharField(max_length=255, unique=True)
description = models.TextField(null=True, blank=True)
compatible_with = models.ManyToManyField('self', null=True, blank=True)
often_with = models.ManyToManyField('self', null=True, blank=True)
created_by = models.ForeignKey(User, null=True, blank=True, related_name='created_by')
verified = models.BooleanField(default=False)
verified_by = models.ForeignKey(User, null=True, blank=True, related_name='verified_by')
date_created = models.DateField(auto_now_add=True)
slug = models.SlugField(max_length=300, null=True, blank=True)
django-haystackの私のサブクラスは次のSearchIndex
ようになります。
class ItemIndex(SearchIndex):
text = CharField(document=True, use_template=True)
name = CharField(model_attr='name')
description = CharField(model_attr='description')
site.register(Item, ItemIndex)
私はこのテンプレートを次のように設定しましたtemplates/search/indexes/catalog/item_text.txt
:
{{ object.name }}
{{ object.description }}
モデルオブジェクトがのインスタンスである場合にのみ、フィールドにインデックスが付けられるitem_text.txt
ように何を追加しますか?manufacturer
Device