FileFIeld中的干草堆搜索

时间:2014-01-08 20:19:21

标签: django elasticsearch django-haystack

我在我的Django项目中使用haystack + elasticsearch用于以下模型:

class Note(models.Model):
    title = models.CharField(max_length=1000)
    body = models.TextField()
    timestamp = models.DateTimeField(auto_now=True)
    attachment = models.FileField(upload_to='notes/')

    def __unicode__(self):
        return self.title

如何更改大海捞针搜索索引,以便可以在attachment FileField中进行搜索?

class NoteIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    title = indexes.CharField(model_attr='title')
    body = indexes.CharField(model_attr='body')
    attachment = indexes.CharField(model_attr='attachment')

    def get_model(self):
        return Note

    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())

0 个答案:

没有答案