Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我已经实现了 Sunspot 在 Rails 应用程序上进行搜索。有什么方法可以获取查询执行的时间吗?
例如。0.5秒返回10条记录
我一直在搜索太阳黑子文档,但我似乎无法确定他们是否支持这一点。
查询时间未在 Sunspot 公共 API 中公开,但在返回的搜索对象中可用。将以下猴子匹配放入初始化程序(例如config/initializers/sunspot_query_time.rb):
config/initializers/sunspot_query_time.rb
class Sunspot::Search::AbstractSearch def query_time @solr_result['responseHeader']['QTime'] end end
然后,您可以调用query_time任何搜索对象以获取以毫秒为单位的查询时间。
query_time