Solr:结合 EdgeNGramFilterFactory 和 NGramFilterFactory
我遇到需要同时使用 EdgeNGramFilterFactory 和 NGramFilterFactory 的情况.
I have a situation where I need to use both EdgeNGramFilterFactory and NGramFilterFactory.
我正在使用 NGramFilterFactory 执行包含"样式搜索,最小字符数为 2.我还想搜索第一个字母,例如带有前端 EdgeNGramFilterFactory 的startswith".
I am using NGramFilterFactory to perform a "contains" style search with min number of characters as 2. I also want to search for the first letter, like a "startswith" with a front EdgeNGramFilterFactory.
我不想将 NGramFilterFactory 降低到最少 1 个字符,因为我不想索引所有字符.
I dont want to lower the NGramFilterFactory to min characters of 1 as I dont want to index all characters.
非常感谢您的帮助
干杯
推荐答案
你不一定要在同一个领域做所有这些.我会为每种处理使用不同的自定义类型创建不同的字段,以便您可以单独应用逻辑.
You don't necessarily have to do all this in the same field. I would create a different fields using different custom types for each treatment so that you can apply the logic separately.
如下:
text
包含原始标记,经过最少处理;text_ngram
使用 NGramFilter 处理最少两个字符的标记text_first_letter
使用 EdgeNGram 作为单字符首字母标记
text
contains the original tokens, minimally processed;text_ngram
uses the NGramFilter for your two-character-minimum tokenstext_first_letter
uses EdgeNGram for your one-character initial-letter tokens
如果您以这种方式处理所有 text
字段,那么您也许可以使用 copyField
来填充字段.否则,您可以指示 Solr 客户端为三种不同的字段类型发送相同的字段值.
If you're processing all text
fields in this way, then you might be able to get away with using a copyField
to populate the fields. Otherwise, you can instruct your Solr client to send in the same field values for the three separate field types.
搜索时,使用 qf
参数将所有这些都包含在搜索中.
When searching, include all of them in your searches with the qf
parameter.
<fieldType name="text" class="solr.TextField" positionIncrementGap="100">
<analyzer>
<tokenizer class="solr.StandardTokenizerFactory"/>
<filter class="solr.StandardFilterFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
</fieldType>
<fieldType name="text_ngram" class="solr.TextField" positionIncrementGap="100">
<analyzer>
<tokenizer class="solr.StandardTokenizerFactory"/>
<filter class="solr.StandardFilterFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.NGramFilterFactory" minGramSize="2" maxGramSize="15" side="front"/>
</analyzer>
</fieldType>
<fieldType name="text_first_letter" class="solr.TextField" positionIncrementGap="100">
<analyzer>
<tokenizer class="solr.StandardTokenizerFactory"/>
<filter class="solr.StandardFilterFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.EdgeNGramFilterFactory" minGramSize="1" maxGramSize="1" side="front"/>
</analyzer>
</fieldType>
设置 field
和 dynamicField
定义由您决定.或者,如果您有更多问题,请告诉我,我可以进行编辑并进行澄清.
Setting up field
and dynamicField
definitions are left up to you. Or let me know if you have more questions and I can edit with clarifications.
相关文章