gpt4 book ai didi

使用特殊字符在 solr 中搜索

转载 作者:行者123 更新时间:2023-12-04 11:39:28 24 4
gpt4 key购买 nike

我在 solr 中搜索特殊字符时遇到问题。
我的文档有一个字段“标题”,有时它可能像“泰坦尼克号 - 1999”(它有字符“-”)。
当我尝试使用“-”在 solr 中搜索时,我收到 400 错误。我试图逃避这个角色,所以我尝试了像“-”和“\-”这样的东西。有了这些更改,solr 不会以错误响应我,但它返回 0 结果。

我如何在 solr 管理员中搜索具有该特殊字符(例如“-”或“'”之类的东西???

问候

更新
在这里你可以看到我当前的 solr 方案 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 title 属性的字段。这可能不是一个好的选择。 text_general用于大量文本(或至少是句子),而不是用于精确匹配名称或标题。
这里的问题是 text_general使用 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执行以下操作:

A good general purpose tokenizer that strips many extraneouscharacters and sets token types to meaningful values. Token types areonly useful for subsequent token filters that are type-aware of thesame token types.


这意味着“-”字符将被完全忽略并用于标记字符串。

"kong-fu" will be represented as "kong" and "fu". The '-' disappears.


这也解释了为什么 select?q=title:\-不会在这里工作。
选择更合适的字段类型:
而不是 StandardTokenizerFactory您可以使用 solr.WhitespaceTokenizerFactory , 仅在空格上拆分以精确匹配单词。因此,为 title 属性创建自己的字段类型将是一个解决方案。
Solr 还有一个名为 text_ws 的字段类型.根据您的要求,这可能就足够了。

关于使用特殊字符在 solr 中搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18277609/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com