我正在尝试将搜索与 django-haystack 集成,
虽然它与“样本”后端配合良好,但当用 whoosh 替换后端时,它总是返回 0 个结果。
设置.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 ,一切似乎都设置正确。
我尝试安装以前版本的 Whoosh,但没有成功。
在这一点上感觉很愚蠢,任何帮助将不胜感激。
包版本:
python==2.7
Django==1.3.1
Whoosh==2.3.2
django-haystack==1.2.6
更新:
- 将 Whoosh 降级到 1.8.4 并没有帮助。
- 使用Haystack 教程中描述的基本搜索模板时,1 个字母查询返回所有结果,其他搜索返回 0 个结果。