在 Sunspot 中使用 edgeNGram 过滤器
我正在尝试使用 EdgeNGramFilterFactory 来索引名称字段。我尝试模仿 schema.xml
<fieldType name="text_prefix" class="solr.TextField" omitNorms="false">
<analyzer type="index">
<tokenizer class="solr.StandardTokenizerFactory"/>
<filter class="solr.StandardFilterFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.ISOLatin1AccentFilterFactory"/>
<filter class="solr.TrimFilterFactory" />
<filter class="solr.EdgeNGramFilterFactory" minGramSize="1" maxGramSize="20" side="front"/>
</analyzer>
<analyzer type="query">
<tokenizer class="solr.StandardTokenizerFactory"/>
<filter class="solr.StandardFilterFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.ISOLatin1AccentFilterFactory"/>
<filter class="solr.TrimFilterFactory" />
</analyzer>
</fieldType>
...
<field name="text_prefix" stored="false" type="string" multiValued="true" indexed="true"/>
,在我的模型中我有:
searchable do
text :name, :as => :text_prefix
但是它似乎没有效果。我缺少什么吗?
I am trying to use EdgeNGramFilterFactory to index a name field. I tried mimicking the schema.xml
<fieldType name="text_prefix" class="solr.TextField" omitNorms="false">
<analyzer type="index">
<tokenizer class="solr.StandardTokenizerFactory"/>
<filter class="solr.StandardFilterFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.ISOLatin1AccentFilterFactory"/>
<filter class="solr.TrimFilterFactory" />
<filter class="solr.EdgeNGramFilterFactory" minGramSize="1" maxGramSize="20" side="front"/>
</analyzer>
<analyzer type="query">
<tokenizer class="solr.StandardTokenizerFactory"/>
<filter class="solr.StandardFilterFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.ISOLatin1AccentFilterFactory"/>
<filter class="solr.TrimFilterFactory" />
</analyzer>
</fieldType>
...
<field name="text_prefix" stored="false" type="string" multiValued="true" indexed="true"/>
and in my model I have:
searchable do
text :name, :as => :text_prefix
However it seems to have no effect. I am missing something?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的架构看起来不错,除了一件事:您的
text_prefix
字段的类型为string
而不是text_prefix
,因此它不使用EdgeNGramFilterFactory
。改变这一行
你应该像这样
Your schema looks good except for one thing: your
text_prefix
field is of typestring
and nottext_prefix
, thus it doesn't useEdgeNGramFilterFactory
.You should change this line
like this