在ThiningSphinx v3上,如何结合BatchedSearch检索搜索结果权重?
我使用了here所描述的BatchedSearch:
batch = ThinkingSphinx::BatchedSearch.new
batch.searches << Article.search('foo', :select => '*, weight()')
batch.searches << Article.search(:conditions => {:name => 'bar'}, :select => '*, weight()')
batch.searches << Article.search_for_ids('baz', :select => '*, weight()')
batch.populate
res = batch.searches #=> [[foo results], [bar results], [baz results]]
在这3个搜索结果集中的每一个中,我想访问Result Weights,但似乎只能通过单个搜索对象访问权重?在上面的代码块之后,我试过了:
res.each do |w|
w.context[:panes] << ThinkingSphinx::Panes::WeightPane
end
res.first.first #is a valid search result
res.first.first.weight
#returns error:
#<NoMethodError: undefined method `weight' for #<Work:0xb2a9a648>>
答案 0 :(得分:1)
您需要在填充结果之前将窗格添加到每个搜索对象。所以,请尝试以下方法:
batch = ThinkingSphinx::BatchedSearch.new
batch.searches << Article.search('foo', :select => '*, weight()')
batch.searches << Article.search(:conditions => {:name => 'bar'}, :select => '*, weight()')
batch.searches << Article.search_for_ids('baz', :select => '*, weight()')
batch.searches.each do |search|
search.context[:panes] << ThinkingSphinx::Panes::WeightPane
end
batch.populate
res = batch.searches
res.first.first.weight