我尝试了 Haystack 网站上给出的基本教程 http://django-haystack.readthedocs.org/en/latest/tutorial.html并且它可以很好地用于基本搜索。
但它的搜索并不有效,因为假设我的 Note
模块有 3 个 text
字段。
- Twitter Bootstrap 设计师需要设计/编辑网站主题
- 在 Ubuntu 上使用 mod_wsgi、virtualenv 的 Django (python) 应用
- Python 考试将在拉贾斯坦邦举行。
当我搜索
python
结果:2 & 3 文本字段。
python 考试
结果:第三 文本字段
但是当搜索 python flask
时,它没有任何结果。我再次想要第二和第三结果,因为有python
关键字。
当搜索 boot
时没有结果,但它应该显示 1st 结果,它在 bootstrap 词中有 boot
.
当再次搜索 pyton
时没有结果,但它应该显示 2nd 和 3rd 结果,因为 h
中只缺少 1 个字符 python 。
当再次搜索 bootstrap django
时没有结果,但它应该显示第 1 和第 2 结果。
看来我缺少 haystack 的一些高级设置。
我怎样才能让它更有效地搜索,以便它提供更好的结果,而不是简单地直接匹配?
最佳答案
我已经以内联回复的形式回复了您的各种问题。
but when searched python flask it results in nothing. I want 2nd and 3rd result again, as there is python keyword.
您想将 haystack 运算符从 AND
更改为 OR
。参见 http://django-haystack.readthedocs.org/en/v2.1.0/settings.html#haystack-default-operator获取更多信息。
when searched boot no result, but it should show 1st result, it has boot in bootstrap word.
查看 NgramField
和 EdgeNgramField
进行部分匹配。
when searched pyton again no result, but it should show 2nd and 3rd result, since it only 1 char h missing from python.
看haystack的拼写建议:http://django-haystack.readthedocs.org/en/latest/searchqueryset_api.html#spelling-suggestion
when searched bootstrap django again no result, but it should show 1st and 2nd result.
这是由 haystack 运算符(operator)配置的。
Haystack 2.0+ 的示例配置,默认运算符设置为 OR
和 INCLUDE_SPELLING=True
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.backends.solr_backend.SolrEngine',
'URL': 'http://localhost:9001/solr/default',
'INCLUDE_SPELLING': True,
},
}
HAYSTACK_DEFAULT_OPERATOR = 'OR'
关于python - 在 Django 中使用 HayStack + Solr 进行高级搜索?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18168688/