python - SearchFieldError Django 和 Haystack

标签 python django django-haystack

我正在尝试设置 haystack,但从一开始就出现了一些错误。 尝试打开搜索 url 时出现以下错误:

All 'SearchIndex' classes must use the same 'text' fieldname for the 'document=True' field. Offending index is '<subtitrari.search_indexes.PictureIndex object at 0x7f3a6819be20>'.

关于如何让它工作的任何线索?

谢谢。

这是我的代码:

模型.py

class Picture(models.Model):
    imdb_id = models.CharField(max_length=9, blank=True)
    title = models.CharField(max_length=50)
    tv_show = models.BooleanField(default=False)
    genre = TaggableManager(verbose_name=u'Genres')
    poster = models.ImageField(upload_to=poster_path, blank=True, null=True)
    rating = models.FloatField(max_length=3, null=True, blank=True)
    votes = models.IntegerField(null=True,blank=True)
    release_date = models.CharField(max_length=4, null=True, blank=True)
    plot = models.CharField(max_length=100, null=True, blank=True)
    url = models.URLField(null=True, blank=True)
    trailer = models.URLField(null=True, blank=True)
    slug = models.SlugField(null=True, blank=True)

    @property
    def domain(self):
        return urlparse(self.url).netloc

    def natural_key(self):
        return self.title

     def __unicode__ (self):
        return self.title

搜索索引.py

import datetime

from haystack import indexes

from subtitrari.models import Picture

class PictureIndex(indexes.SearchIndex, indexes.Indexable):
    title = indexes.CharField(document=True, use_template=True)
    uploader = indexes.CharField(model_attr='uploader')
    created_at = indexes.DateTimeField(model_attr='created_at')

    def get_model(self):
        return Picture

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

最佳答案

按照教程,不要将文档字段名称更改为title,保留为text

关于python - SearchFieldError Django 和 Haystack,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19069446/

相关文章:

django - Django Haystack Solr-Solr的推荐位置和目录结构

具有可变默认参数的 Python 数据类继承返回零值

python - django:初始化对象时出现递归错误

python - 如何在 Django 中为 sorl-thumbnail 设计清理任务?

Django haystack,搜索中某些字段的优先级

python - django-haystack 教程中模型的哪些字段被索引?

python - DeepSpeech 给出不好的结果

python - python 中出现意外的缩进错误,但仅在组合两个其他工作语句时出现

python - 使用 numpy 数组按组 ID 创建序列

django - Rebuild_index 和 update_index 被杀死