开发者

How to get query time from a Sunspot Search

开发者 https://www.devze.com 2023-01-12 13:59 出处:网络
I\'ve implemented Sunspot to do searching on a Rails App. Is there any way to get the time the query took to execute?

I've implemented Sunspot to do searching on a Rails App. Is there any way to get the time the query took to execute?

Eg. 10 records returned in 0.5 second开发者_运维技巧s

I've been searching around the sunspot docs, but i can't seem to find out if they support this or not.


The query time is not exposed in the Sunspot public API but it is available in the returned search object. Place the following monkey match into an initializer (such as config/initializers/sunspot_query_time.rb):

class Sunspot::Search::AbstractSearch
  def query_time
    @solr_result['responseHeader']['QTime']
  end
end

You can then call query_time on any search object to get query time in milliseconds.

0

精彩评论

暂无评论...
验证码 换一张
取 消