【问题标题】:advanced search using HayStack + Solr in Django?在 Django 中使用 HayStack + Solr 进行高级搜索?
【发布时间】:2013-08-12 16:25:17
【问题描述】:

我尝试了 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 exam 结果:3rd 文本字段

但是当搜索python flask 时,它什么也没有。我想要 2nd 和 3rd 结果再次,因为有 python 关键字。

当搜索boot没有结果,但它应该显示第一个结果,它在bootstrap字中有boot

当再次搜索 pyton 时没有结果,但它应该显示 2nd 和 3rd 结果,因为 python 中只缺少 1 个字符 h

当再次搜索bootstrap django 时没有结果,但它应该显示第一个和第二个结果。

所以,看起来我缺少 haystack 的一些高级设置。

我怎样才能使它更有效的搜索,以便它提供更好的结果,而不是简单地直接匹配?

【问题讨论】:

    标签: python django search solr django-haystack


    【解决方案1】:

    我已将您的各种问题作为内联回复回复。

    但是当搜索 python 烧瓶时,它什么也没有。我想要第二和 又是第三个结果,因为有 python 关键字。

    您想将 haystack 运算符从 AND 更改为 OR。请参阅http://django-haystack.readthedocs.org/en/v2.1.0/settings.html#haystack-default-operator 了解更多信息。

    当搜索启动没有结果,但它应该显示第一个结果,它有 在引导词中引导。

    查看NgramFieldEdgeNgramField 进行部分匹配。

    当再次搜索 pyton 时没有结果,但它应该显示 2nd 和 3rd 结果,因为它只从 python 中丢失了 1 个字符 h。

    看haystack的拼写建议:http://django-haystack.readthedocs.org/en/latest/searchqueryset_api.html#spelling-suggestion

    当再次搜索 bootstrap django 时没有结果,但它应该显示 1st 和第二个结果。

    这是由 haystack 操作员配置的。


    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'
    

    【讨论】:

    • 我在哪里放 'INCLUDE_SPELLING': True,或 HAYSTACK_DEFAULT_OPERATOR = 'OR'。我尝试将它们放在 HAYSTACK_CONNECTIONS 字段上方的 settings.py 中,也在 HAYSTACK_CONNECTIONS 块内。但没有效果。
    • 我已经用一个例子更新了答案。该文档还有一些值得一看的示例:django-haystack.readthedocs.org/en/latest/settings.html
    • 我已经尝试了与您相同的代码,但“或”运算符没有生效。应用程序的任何其他部分是否需要任何其他设置更改或修改?
    • 我不熟悉使用 Solr 后端,但您是否尝试过致电 rebuild_index 看看是否有帮助?
    • 是的,已经尝试过rebuild_index 和update_index,但仍然没有成功。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多