我已经浏览了github中的文档:http://github.com/outoftime/sunspot来找到突出显示的解决方案,但它似乎对我不起作用.
我的工作模型有这样的块(有意省略了一些字段):
searchable do
text :name
string :name, :stored => true
time :updated_at
time :created_at
time :expires_on
我有这个,它返回结果:
search = Sunspot.search(Job) do keywords 'Senior', :fields => "name", :highlight => true end => 0, :fl=>"* score", :"hl.simple.pre"=>"@@@hl@@@", :qf=>"name_text", :rows=>30, :"hl.simple.post"=>"@@@endhl@@@", :hl=>"on", :q=>"senior", :fq=>["type:Job"], :defType=>"dismax"}>
并获得如此命中:
>> search.hits => [#, #, #, #, #, #, #, #, #, #, #, #, #, #, #, #, #]
这是查询的结果,显示名称:
>> search.results.collect{|x| x.name}
= …