下面是我用于自动完成的新字段类型:
<fieldType name="autocomplete_edge" class="solr.TextField">
<analyzer type="index">
<charFilter class="solr.MappingCharFilterFactory" mapping="mapping-ISOLatin1Accent.txt"/>
<tokenizer class="solr.StandardTokenizerFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.EdgeNGramFilterFactory" maxGramSize="30" minGramSize="2"/>
</analyzer>
<analyzer type="query">
<charFilter class="solr.MappingCharFilterFactory" mapping="mapping-ISOLatin1Accent.txt"/>
<tokenizer class="solr.StandardTokenizerFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
</fieldType>字段定义如下:
<field name="title" type="autocomplete_edge" indexed="true" stored="true" required="true"/>我的问题是,假设索引的字段文本是:
“指环王”
我的目标是让SOLR能够返回包含以下所有查询的文档:
query-1: title:"th“query-2: title:"the of”query-3: title:“of”query-4: title:"the rin“
等。
在分析标记化和EdgeNGram过滤后得到的索引时,我看到索引项如下:
"th“”的“"lo”“或”"lor“"th”“的”"ri“"ring”“ring”“
因此,查询“matches of”匹配,但查询"the ring“不匹配。
我知道,对于索引(性能和磁盘空间),保留所有可能的边缘ngram组合是昂贵的,但是对于应用程序,我们必须这样做。
欢迎任何可能的解决方案。
提前感谢并致以最良好的问候。
发布于 2013-07-08 16:55:33
查询the rings应匹配。
EdgeNGramFilterFactory将生成边缘图,但是生成的边缘图具有相同的位置。
因此,如果你检查由edge生成的标记,那么gram将具有相同的位置。
th,-> 1
lo,lor,->领主2
th,-> 3
ri、ring、ring、ring -> 4
因此,查询lord of和the rings应该与搜索字段匹配,因为它们是相邻的。
如果查询在同一字段上搜索,请使用debug进行检查。
https://stackoverflow.com/questions/17521699
复制相似问题