如何在 Solr 中查找包含数字和美元符号的文档? [英] How do I find documents containing digits and dollar signs in Solr?
问题描述
在 Solr 中,我有包含 $30 和 30 的文本.
In Solr, I've got text that contains $30 and 30.
我想搜索 $30 并且只找到包含 $30 的文档.
I would like to search for $30 and only find documents containing $30.
但是如果有人搜索 30,他们应该会找到包含 $30 的文档和包含 30 的文档.
But if someone searches for 30, they should find both documents containing $30 and those containing 30.
这是我目前用于索引文本字段的字段类型:
Here is the field type I'm currently using to index my text field:
<!-- Just like text_en_splitting, but with the addition of reversed tokens for leading wildcard matches -->
<fieldType name="text_en_splitting_reversed" class="solr.TextField" positionIncrementGap="100" autoGeneratePhraseQueries="true">
<analyzer type="index">
<tokenizer class="solr.WhitespaceTokenizerFactory"/>
<!-- in this example, we will only use synonyms at query time
<filter class="solr.SynonymFilterFactory" synonyms="index_synonyms.txt" ignoreCase="true" expand="false"/>
-->
<!-- Case insensitive stop word removal.
add enablePositionIncrements=true in both the index and query
analyzers to leave a 'gap' for more accurate phrase queries.
-->
<filter class="solr.StopFilterFactory"
ignoreCase="true"
words="lang/stopwords_en.txt"
enablePositionIncrements="true"
/>
<filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="1" catenateNumbers="1" catenateAll="0" splitOnCaseChange="1" types="word-delim-types.txt" />
<filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.KeywordMarkerFilterFactory" protected="protwords.txt"/>
<filter class="solr.PorterStemFilterFactory"/>
<filter class="solr.ReversedWildcardFilterFactory" withOriginal="true"
maxPosAsterisk="3" maxPosQuestion="2" maxFractionAsterisk="0.33"/>
</analyzer>
<analyzer type="query">
<tokenizer class="solr.WhitespaceTokenizerFactory"/>
<filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
<filter class="solr.StopFilterFactory"
ignoreCase="true"
words="lang/stopwords_en.txt"
enablePositionIncrements="true"
/>
<filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="0" catenateNumbers="0" catenateAll="0" splitOnCaseChange="1" types="word-delim-types.txt" />
<filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.KeywordMarkerFilterFactory" protected="protwords.txt"/>
<filter class="solr.PorterStemFilterFactory"/>
</analyzer>
</fieldType>
我已经定义了 word-delim-types.txt 来包含:
I have defined word-delim-types.txt to contain:
$ => DIGIT
% => DIGIT
. => DIGIT
因此,当我搜索 $30 时,它会正确定位包含$30"的文档,而不是仅包含30"的文档.那挺好的.但是当我搜索30"时,它没有找到包含$30"的文件,只有那些包含30"的文件.
So when I search for $30, it correctly locates documents containing "$30" but not those containing just "30". That's good. But when I search for "30" it does not find documents containing "$30", only those containing "30".
有没有办法做到这一点?
Is there some way to do this?
推荐答案
我已经找到了我的问题的解决方案.而不是定义 $% 和 .作为 DIGIT,我现在将它们定义为 ALPHA,在作为属性传入 WordDelimiterFilterFactory 的类型"文件中.
I have found the solution to my question. Instead of defining $ % and . as DIGIT, I now define them as ALPHA, in my "types" file that is passed in as an attribute to the WordDelimiterFilterFactory.
$ => ALPHA
% => ALPHA
. => ALPHA
由于我的 WordDelimiterFilterFactory 设置的其余部分,事情以达到预期效果的方式分解和串联:
Due to the rest of my WordDelimiterFilterFactory settings, things are broken up and catenated in a way where the desired effect is achieved:
搜索 30 美元只会产生包含 30 美元的文档.搜索 30 个同时包含 $30 和 30 的文档.
Searching for $30 yields only documents containing $30. Searching for 30 yields documents containing both $30 and 30.
这篇关于如何在 Solr 中查找包含数字和美元符号的文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!