mar*_*-sn 9 search ruby-on-rails sunspot hit-highlighting
我已经浏览了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}
=> ["Senior Associate, Executive Membership", "Senior International Costing Analyst", "Senior Process Engineer", "Deputy Senior Process Manager", "Senior Engineer (Rotating Equipment)", "Senior Technical Expert, Indonesia", "Senior Combustion Engineer", "Senior Project Engineer/ Engineering Manager", "Senior Substructure Design Specialist, Bangladesh", "Senior Supervision Engineer (Superstructure), Bangladesh", "Senior Program and Strategy Development Advisor- Consultant", "Senior Associate (Natural Resource Management Specialist)", "Senior Manager (Agriculture Market Development, Afghanistan)", "Senior Material Engineer (Main Bridge), Bangladesh", "Senior Resident Engineer (Main Bridge), Bangladesh", "Senior Resident Engineer (Main Bridge), Bangladesh", "Senior Material Engineer (Main Bridge), Bangladesh"]
这是我的问题..当我得到亮点时,没有人返回:
>> search.hits.collect{|x| x.highlight(:name)}
=> [nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil]
甚至这个,不会返回高亮点击:
>> search.hits.collect{|x| x.highlights}
=> [[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], []]
我错过了其他标志或参数吗?
我认为这与文本字段是否存储有关.这有什么不同:
searchable do
text :name, :stored => true
...
Run Code Online (Sandbox Code Playgroud)
这就是:在这个例子中配置:body字段:
http://github.com/outoftime/sunspot-rails-example/blob/master/app/models/post.rb
:body字段是在控制器中查询高亮显示的字段:
http://github.com/outoftime/sunspot-rails-example/blob/master/app/controllers/searches_controller.rb
希望能做到!
| 归档时间: |
|
| 查看次数: |
2369 次 |
| 最近记录: |