阅读 Sunspot 文档,我试图找到如何查询自动完成字段。
我在这里创建它们 https://github.com/haitham/sunspot_autocomplete
这是配置 solr/conf/schema.xml
<types>
.......
<fieldType name="autocomplete" class="solr.TextField" positionIncrementGap="100">
<analyzer type="index">
<tokenizer class="solr.LetterTokenizerFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.EdgeNGramFilterFactory" minGramSize="1" maxGramSize="25" />
</analyzer>
<analyzer type="query">
<tokenizer class="solr.KeywordTokenizerFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
</fieldType>
<fieldType name="autosuggest" class="solr.TextField" positionIncrementGap="100">
<analyzer type="index">
<tokenizer class="solr.KeywordTokenizerFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.EdgeNGramFilterFactory" minGramSize="1" maxGramSize="25" />
</analyzer>
<analyzer type="query">
<tokenizer class="solr.LetterTokenizerFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
</fieldType>
.....
</types>
<fields>
....
<dynamicField name="*_ac" type="autocomplete" indexed="true" stored="true"/>
<dynamicField name="*_as" type="autosuggest" indexed="true" stored="true"/>
....
</fields>
我有可搜索字段的模型:
class Post < ActiveRecord::Base
attr_accessible :text, :user_id
has_one :user
searchable do
text :text
integer :user_id, :references => User
autocomplete :post_text, :using => :text
end
end
当我尝试像这样搜索自动完成字段时:
Sunspot.search(Post) { keywords('ra', :fields => :'autocomplete') }
我得到错误:
Sunspot::UnrecognizedFieldError: No text field configured for Post with name 'autocomplete'
我做错了什么?
我在 github 上分享了应用程序:https ://github.com/pironim/my_sunspot_app.git