django-haystack不会索引我的数据

时间:2012-04-13 12:00:01

标签: solr indexing django-haystack

我正按照haystack documentation.

的说明操作

我没有得到SearchQuerySet()。all()的结果。

我认为问题出在这里

$ ./manage.py rebuild_index

WARNING: This will irreparably remove EVERYTHING from your search index in connection 'default'.
Your choices after this are to restore from backups or rebuild via the `rebuild_index` command.
Are you sure you wish to continue? [y/N] y

Removing all documents from your index because you said so.
All documents removed.
Indexing 0 notes. // <-- here 0 notes!

mysite / note / search_indexes.py看起来像

import datetime
import haystack
from haystack import indexes
from note.models import Note

class NoteIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    author = indexes.CharField(model_attr='user')
    pub_date = indexes.DateTimeField(model_attr='pub_date')

    def get_model(self):
        return Note

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

我有mysite / note / templates / search / indexes / note / Note_text.txt

{{ object.title }}
{{ object.user.get_full_name }}
{{ object.body }}

Debugging haystack document提及

  

你有一个运行haystack.autodiscover的search_sites.py吗?

     

您是否在主干草堆现场注册了您的模型(通常是   在你的search_indexes.py中?

但是第一篇文章中没有提到search_sites.py,haystack.autodiscover,haystack.site。 我很困惑。他们的文档是否涉及不同的干草堆版本?

我的设置是......

haystack version 2.0.0.beta
django 1.3.1
solr 3.6.0
sqlite 3

3 个答案:

答案 0 :(得分:2)

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

是罪魁祸首。

我不知道为什么,但发表评论解决了这个问题 我猜我系统中的'时间'有些搞砸了。

答案 1 :(得分:1)

应该是......

def index_queryset(self, using=None):

我不知道这是否会解决您的问题,但这是该方法的正确签名。

答案 2 :(得分:0)

删除 def index_queryset(self)是有道理的。它构建了一个常规的Django ORM QuerySet ,它决定将哪些对象放入全文索引中。您的示例 index_queryset 仅将对象限制为过去的时间戳(在现在之前)。

因此,您确实有日期时间处理问题。检查SQL数据库的时区以及它如何存储时间。

UTC语言环境中的时间戳比纽约和美国大部分时间早约+5小时。 SQLite通过选择将来的UTC时间为我造成同样的问题。