我在 solr 中搜索特殊字符时遇到问题。
我的文档有一个“标题”字段,有时它可能像“泰坦尼克号 - 1999”(它有字符“-”)。
当我尝试使用“-”在 solr 中搜索时,我收到 400 错误。我试图转义这个字符,所以我尝试了“-”和“\-”之类的东西。经过这些更改,solr 不会以错误响应我,但它返回 0 个结果。
我如何在 solr 管理中使用该特殊字符进行搜索(例如“-”或“'”???
Regards
UPDATE在这里你可以看到我当前的solr方案https://gist.github.com/cpalomaresbazuca/6269375 https://gist.github.com/cpalomaresbazuca/6269375
我的搜索是“标题”字段。
schema.xml 摘录:
...
<!-- A general text field that has reasonable, generic
cross-language defaults: it tokenizes with StandardTokenizer,
removes stop words from case-insensitive "stopwords.txt"
(empty by default), and down cases. At query time only, it
also applies synonyms. -->
<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>
...
<field name="Title" type="text_general" indexed="true" stored="true"/>
您正在使用标准text_general
标题属性的字段。这可能不是一个好的选择。text_general
旨在用于大量文本(或至少句子),而不是用于名称或标题的精确匹配。
这里的问题是text_general
使用标准分词器工厂 https://wiki.apache.org/solr/AnalyzersTokenizersTokenFilters#solr.StandardTokenizerFactory.
<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
执行以下操作:
一个很好的通用分词器,可以去除许多无关的东西
字符并将标记类型设置为有意义的值。令牌类型有
仅对后续类型感知的标记过滤器有用
相同的令牌类型。
这意味着“-”字符将被完全忽略并用于标记字符串。
“kong-fu”将被表示为“kong”和“fu”。 “-”消失。
这也解释了为什么select?q=title:\-
不会在这里工作。
选择更合适的字段类型:
而不是StandardTokenizerFactory
你可以使用solr.WhitespaceTokenizerFactory
,仅在空格上分割以实现单词的精确匹配。因此,为标题属性创建自己的字段类型将是一个解决方案。
Solr 还有一个名为的字段类型text_ws
。根据您的要求,这可能就足够了。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)