python - 在 Django 中使用 HayStack + Solr 进行高级搜索?

标签 python django search solr django-haystack

我尝试了 Haystack 网站上给出的基本教程 http://django-haystack.readthedocs.org/en/latest/tutorial.html并且它可以很好地用于基本搜索。 但它的搜索并不有效,因为假设我的 Note 模块有 3 个 text 字段。

  1. Twitter Bootstrap 设计师需要设计/编辑网站主题
  2. 在 Ubuntu 上使用 mod_wsgi、virtualenv 的 Django (python) 应用
  3. 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.

查看 NgramFieldEdgeNgramField 进行部分匹配。

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+ 的示例配置,默认运算符设置为 ORINCLUDE_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/

相关文章:

python - 在 python 中如何从实例访问类变量? - 一个令人困惑的例子

python - Pandas + Matplotlib,让条形图中的一种颜色脱颖而出

python - 在 Django Rest Framework 中为自定义字段序列化数据

Django选择具有特定列的查询

api - 如何限制搜索到多个站点?

php - 如何使用 Elastica 正确运行_count_查询?

python - 如何在python中将元素添加到已排序的redis集中

python - 更改模型管理表单默认值

php - 如何在 mySQL 中创建搜索查询数据集的相关分析

python - 在 azure ml 中运行笔记本时,如何最好地将 azure blob csv 格式转换为 pandas dataframe