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.
精彩评论