Django haystack搜索返回被排除的项目

时间:2011-05-11 08:00:19

标签: django django-haystack

我在使用django-haystack时遇到了一些问题,需要一些帮助。

我运行一个索引项目的站点,某些项目处于不应该看到的状态,即status='DE'status='PR'

我当前的设置是。

from haystack.indexes import *
from haystack import site
from models import Project

class ProjectIndex(RealTimeSearchIndex):
    project_name = CharField(document=True, use_template=True)
    description = CharField(use_template=True, model_attr='description')
    location = CharField(use_template=True, model_attr='location')
    owner = CharField(model_attr='owner')

    def search(self):
        return Project.objects.filter(status='AP').exclude(status='PR').exclude(status='DE')

    def index_queryset(self):
        """Used when the entire index for model is updated."""
        return Project.objects.filter(status='AP').exclude(status='PR').exclude(status='DE')

    def get_queryset(self):
        """Used when the entire index for model is updated."""
        return Project.objects.filter(status='AP').exclude(status='PR').exclude(status='DE')

    def read_queryset(self):
        """Used when the entire index for model is updated."""
        return Project.objects.filter(status='AP').exclude(status='PR').exclude(status='DE')

site.register(Project, ProjectIndex)

1 个答案:

答案 0 :(得分:5)

我设法通过从1.1更新到1.2来解决这个问题

然后我突然开始收到这些Caught VariableDoesNotExist while rendering: Failed lookup for key [object] in u'None'

用Google搜索并发现某些项目可能已从系统中消失,并且有一个方便的命令。

现在我有一个cronjob每隔几个小时执行以下/usr/bin/python2.6 /www/mysite/manage.py update_index --remove