如何在Solr中查找包含数字和美元符号的文档?
问题描述:
在Solr中,我收到了包含30美元和30美元的文本。如何在Solr中查找包含数字和美元符号的文档?
我想要搜索$ 30,并且只能找到包含$ 30的文档。
但如果有人搜索30日,他们应该找到含$ 30文档和那些含有30
这是我目前使用索引我的文本字段的字段类型:
<!-- 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>
我已经定义字DELIM-types.txt包含:
$ => DIGIT
% => DIGIT
. => DIGIT
所以,当我搜索$ 30,它正确地定位包含文件“$ 30”而不是那些只包含“30 ”。那很好。但是,当我搜索“30”时,它找不到包含“$ 30”的文档,只有那些包含“30”的文档。
有没有办法做到这一点?
答
我找到了解决我的问题。而不是定义$%和。作为DIGIT,我现在将它们定义为ALPHA,在我的“types”文件中作为属性传递给WordDelimiterFilterFactory。
$ => ALPHA
% => ALPHA
. => ALPHA
由于我WordDelimiterFilterFactory其他设置,事情被分解,并在其中实现所需效果的方式链中:
搜索$ 30所产生含$ 30份文件。 搜索30将生成包含$ 30和30的文档。
您从哪里找到该选项?在过滤器文档中没有指定(但不管怎样,它的工作原理!)? – 2014-07-28 09:55:29