首页 > 解决方案 > 带有正斜杠的 Solr 查询不匹配

问题描述

Solr 4.9.1(无法更新,因为这是一个 Silverstripe 插件)。问题出在前端,但以下问题直接来自 Solr 查询面板。我对 Solr 比较陌生,到目前为止,我一直在研究关于 Tokenizers 和 Filters 的建议(但在这个问题的上下文中无法理解这些建议)和转义(这似乎没有任何作用)

这是我的调试输出示例:

现有文档中的字段值: Across the world - Fly/Sail

查询(前端): Fly/Sail

搜索结果: 0

调试输出:

"rawquerystring": "Fly/Sail",
"querystring": "Fly/Sail",
"parsedquery": "PhraseQuery(_text:\"fly sail fly sail\")",
"parsedquery_toString": "_text:\"fly sail fly sail\"",
"explain": {},
"QParser": "LuceneQParser"

最让我困惑的是为什么在解析查询中加倍?用反斜杠转义正斜杠不会改变任何东西。

如果我搜索"Fly Sail",会出现预期的结果。

编辑:我的配置:

<fields>
<field name='_documentid' type='string' indexed='true' stored='true' required='true' />
<field name='ID' type='tint' indexed='true' stored='true' required='true' />
<field name='_text' type='htmltext' indexed='true' stored='true' multiValued='true' />
<field name='VivaTour_TourName' type='text' indexed='true' stored='true' multiValued=''/>
<field name='VivaTour_TourDescription' type='htmltext' indexed='true' stored='true' multiValued=''/>

编辑 2:此搜索的我的分析页面的屏幕截图

https://imgur.com/a/164XNEK

标签: solrlucene

解决方案


试试下面fieldType的你的领域"VivaTour_TourName"

<fieldType name="text_wd" class="solr.TextField" positionIncrementGap="100">
    <analyzer type="index">
          <!-- Splits words based on whitespace characters --> 
          <tokenizer class="solr.WhitespaceTokenizerFactory"/>
          <!-- splits words at delimiters based on different arguments --> 
          <filter class="solr.WordDelimiterGraphFilterFactory" preserveOriginal="1" catenateWords="1"/>
          <!-- Transforms text to lower case -->   
          <filter class="solr.LowerCaseFilterFactory"/>
        </analyzer>

        <analyzer type="query">
          <tokenizer class="solr.WhitespaceTokenizerFactory"/>
          <filter class="solr.LowerCaseFilterFactory"/>
        </analyzer>
  </fieldType>

修改后schema.xml,请重新启动服务器并重新索引数据。

请参阅屏幕截图以供参考。

solr 分析屏幕 1

solr 分析屏幕 2


推荐阅读