1 class StatisticController < ApplicationController
3 TIME_LIMIT = DateTime.parse 3.months.ago.to_s
6 @top_searches = top_searches
7 @failed_searches = failed_searches
14 Rails.cache.fetch('top_searches', :expires_in => 2.hours) do
15 result = ActiveRecord::Base.connection.execute("select query, count(*) as c from search_histories where query is NOT NULL AND count > 0 AND created_at > '#{TIME_LIMIT}' group by query order by c desc limit 15;")
17 result.each do |entry|
18 top << { :query => entry[0].strip.downcase, :count => entry[1].to_i}
26 Rails.cache.fetch('failed_searches', :expires_in => 2.hours) do
27 result = ActiveRecord::Base.connection.execute("select query, count(*) as c from search_histories where query is NOT NULL AND count = 0 AND created_at > '#{TIME_LIMIT}' group by query order by c desc limit 15; ")
29 result.each do |entry|
30 top << { :query => entry[0].strip.downcase, :count => entry[1].to_i}