本文介绍了对 SOLR 搜索执行完全匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在实施 SOLR 搜索.当我输入例如 Richard Chase 我得到索引中的所有 Richards 和所有 Chases,例如 Johnny Chase 等.实际上我只想返回与 Richard 和 Chase 匹配的所有名称.

I am implementing a SOLR search. When I type in e.g Richard Chase I getall the Richards in the index and all the Chases, like Johnny Chase etc.. when actually I only want to return all the names that match BOTH Richard AND Chase.

我的配置设置是

<fieldType name="text_general" class="solr.TextField" positionIncrementGap="100">
  <analyzer type="index">
    <tokenizer class="solr.StandardTokenizerFactory"/>
    <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" enablePositionIncrements="true" />
    <!-- in this example, we will only use synonyms at query time
    <filter class="solr.SynonymFilterFactory" synonyms="index_synonyms.txt" ignoreCase="true" expand="false"/>
    -->
    <filter class="solr.LowerCaseFilterFactory"/>
  </analyzer>
  <analyzer type="query">
    <tokenizer class="solr.StandardTokenizerFactory"/>
    <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" enablePositionIncrements="true" />
    <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
    <filter class="solr.LowerCaseFilterFactory"/>
  </analyzer>
</fieldType>

我的查询搜索文本字段

正文:理查德·蔡斯

知道我做错了什么吗?

推荐答案

您正在使用 StandardTokenizerFactory,遵守词边界规则.

这意味着你的单词会被空格分开.

This would mean that your words get split on spaces.

如果你想要一个真正的完全匹配,即

if you want a real exact match, i.e

Richard Chase 返回只包含 Richard Chase 的文档,那么你应该KeywordTokenizerFactory.

Richard Chase to return documents containing only Richard Chase exactly, then you should you KeywordTokenizerFactory.

但正如您提到的,您想要 Richard John Chase 而不是 Johnny Chase,它告诉我您想要 Richard Chase 的匹配.

But as you mention, you want Richard John Chase but not Johnny Chase, it tells me that you want matches for Richard and Chase.

您可以搜索 Richard AND Chase 或将 schema.xml 中的默认运算符更改为 AND 而不是 OR.请注意,此设置是全局设置.

You could either search for Richard AND Chase or change your default operator in schema.xml to be AND instead of OR. Beware that this setting is global.

这篇关于对 SOLR 搜索执行完全匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-05 03:03