【发布时间】:2012-04-25 19:01:18
【问题描述】:
我正在按照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 吗?
您是否在主 haystack.site 上注册了您的模型(通常 在你的 search_indexes.py)?
但在第一篇文章中没有提到 search_sites.py 、 haystack.autodiscover 、 haystack.site 。
我很混乱。他们的文档是否处理不同的 haystack 版本?
我的设置是..
haystack 版本 2.0.0.beta
django 1.3.1
solr 3.6.0
sqlite 3
【问题讨论】:
-
在我的(愚蠢的)情况下,rebuild_index 没有获得任何产品的索引,因为没有任何产品(数据库连接不正确)。
标签: solr indexing django-haystack