python – Django-haystack返回带有“简单”后端的结果,但没有“whoosh”
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了python – Django-haystack返回带有“简单”后端的结果,但没有“whoosh”,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1705字,纯文字阅读大概需要3分钟。
内容图文
![python – Django-haystack返回带有“简单”后端的结果,但没有“whoosh”](/upload/InfoBanner/zyjiaocheng/802/26dc3ba7b5774ef3b87c230a46afb545.jpg)
我正在尝试将搜索与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')
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
更新:
>将飞快降级至1.8.4并没有帮助.
>当使用Haystack Tutorial中描述的基本搜索模板时,所有结果将返回1个字母查询,0个结果返回其他搜索.
解决方法:
好吧,发现它,然后它更愚蠢然后我…
templates / search / indexes / profiles / profile_text.txt应为:
{{ object.name }}
{{ object.description }}
并不是:
{{ profile.name }}
{{ profile.description }}
使我困惑的是与数据库匹配的“简单”后端,显然忽略了数据模板.
内容总结
以上是互联网集市为您收集整理的python – Django-haystack返回带有“简单”后端的结果,但没有“whoosh”全部内容,希望文章能够帮你解决python – Django-haystack返回带有“简单”后端的结果,但没有“whoosh”所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。