4
我試圖將搜索與django-haystack結合,
雖然它與「sample」後端很好地協作,但在替換後端時與whoosh它總是返回0結果。Django-haystack以「簡單」後端返回結果,但不是「whoosh」
settings.py:
HAYSTACK_DEFAULT_OPERATOR = 'AND'
HAYSTACK_SITECONF = 'search_sites'
HAYSTACK_SEARCH_ENGINE = 'whoosh'
HAYSTACK_SEARCH_RESULTS_PER_PAGE = 20
HAYSTACK_WHOOSH_PATH = os.path.join(PROJECT_ROOT, 'search_index')
search_sites.py
import haystack
haystack.autodiscover()
型材/ search_indexes.py:
from haystack import indexes
from haystack import site
from profiles.models import Profile
class ProfileIndex(indexes.SearchIndex):
text = indexes.CharField(document=True, use_template=True)
def index_queryset(self):
"""Used when the entire index for model is updated."""
return Profile.objects.all()
site.register(Profile, ProfileIndex)
模板/搜索/索引/型材/ profile_text.txt:
{{ profile.name }}
{{ profile.description }}
運行python manage.py rebuild_index
回報:
All documents removed.
Indexing 60 profiles.
運行在shell下面的當:
>>> from haystack.query import SearchQuerySet
>>> sqs = SearchQuerySet().all()
>>> sqs.count()
0
當切換嗖與 「簡單」 的後臺,一切工作正常,60個返回結果。
根據Getting Started with Haystack和Debugging Haystack,一切似乎都正確設置。
我嘗試安裝以前的版本的飛快,沒有任何成功。
感覺很愚蠢在這一點上,任何幫助將非常感激。
包版本:
python==2.7
Django==1.3.1
Whoosh==2.3.2
django-haystack==1.2.6
更新:
- 嗖降級到1.8.4並沒有幫助。
- 使用Haystack Tutorial所述的基本搜索模板時,所有結果均返回1個字母查詢,其他搜索返回0個結果。