【问题标题】:Haystack and Solr searching term containing "-"Haystack 和 Solr 搜索包含“-”的词
【发布时间】:2023-03-10 00:06:01
【问题描述】:

在搜索包含字符“-”的字词时,我没有得到任何结果。例如:

我搜索术语“e-shop”,stored_fields 是: { 'url' : u'http://www.e-shop.com/', 'text': u'E-shop\n技术\n', 'name': u'E-shop'}

search_index.py 是:

class ShopIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.EdgeNgramField(document=True, use_template=True)
    name = indexes.CharField(model_attr='name')
    url = indexes.CharField(model_attr='url')

我正在使用 Solr。

你知道我是否必须以某种方式逃避这个角色,是否需要以不同的方式存储或者我做错了什么?

【问题讨论】:

    标签: python solr django-haystack


    【解决方案1】:

    http://ftp.ps.pl/pub/apache/lucene/solr/ref-guide/apache-solr-ref-guide-6.1.pdf

    您需要检查schema.xml 中的edge_ngram 字段声明,我假设默认情况下,大海捞针EdgeNgramField 在其架构声明中具有过滤器,它按字母大小写和- 分割单词,所以当字段值为例如e-shop,solr 构建像essh 等令牌。 还有一件事:https://github.com/django-haystack/django-haystack/blob/master/haystack/templates/search_configuration/solr.xml#L120

    默认情况下,haystack 有minGramSize="2",因此在这种情况下,无法通过单个字符进行搜索。为了按单个字符搜索,将其值更改为"1"

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-25
      • 1970-01-01
      • 2022-11-25
      • 1970-01-01
      相关资源
      最近更新 更多