Django 文件场中的Haystack搜索
我在Django项目中为以下模型使用haystack+elasticsearch:Django 文件场中的Haystack搜索,django,
elasticsearch,django-haystack,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/')
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
我应该如何更改haystack搜索索引,以便它可以在附件文件字段中搜索
您想搜索附件的内容还是文件名?@EWit,在PDF/Word/ExcelNo idea等内容文件中,在这种情况下,可以查看:?
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())