ypr*_*rez 4 python django whoosh django-haystack
我正在尝试将搜索与django-haystack集成,
虽然它适用于"示例"后端,但当用whoosh替换后端时,它总是返回0结果.
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')
Run Code Online (Sandbox Code Playgroud)
search_sites.py
import haystack
haystack.autodiscover()
Run Code Online (Sandbox Code Playgroud)
配置文件/ 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)
Run Code Online (Sandbox Code Playgroud)
模板/搜索/索引/型材/ profile_text.txt:
{{ profile.name }}
{{ profile.description }}
Run Code Online (Sandbox Code Playgroud)
运行python manage.py rebuild_index回报:
All documents removed.
Indexing 60 profiles.
Run Code Online (Sandbox Code Playgroud)
在shell中运行以下代码时:
>>> from haystack.query import SearchQuerySet
>>> sqs = SearchQuerySet().all()
>>> sqs.count()
0
Run Code Online (Sandbox Code Playgroud)
当用"简单"后端切换飞快移动时,一切正常,返回60个结果.
根据Haystack入门和调试干草堆,似乎所有东西都设置正确.
我尝试安装以前版本的Whoosh,没有任何成功.
在这一点上感到非常愚蠢,任何帮助都将非常感激.
包版本:
python==2.7
Django==1.3.1
Whoosh==2.3.2
django-haystack==1.2.6
Run Code Online (Sandbox Code Playgroud)
更新:
好吧,发现它,然后它更愚蠢然后我...
templates/search/indexes/profiles/profile_text.txt 应该:
{{ object.name }}
{{ object.description }}
Run Code Online (Sandbox Code Playgroud)
并不是:
{{ profile.name }}
{{ profile.description }}
Run Code Online (Sandbox Code Playgroud)
使我困惑的是与数据库匹配的"简单"后端,显然忽略了数据模板.