Skip to content

Commit

Permalink
fix statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
digitaltom committed Mar 28, 2012
1 parent 4138747 commit ccefaaa
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions app/controllers/statistic_controller.rb
Expand Up @@ -14,7 +14,11 @@ def top_searches
Rails.cache.fetch('top_searches', :expires_in => 2.hours) do
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;")
result.map{|entry| { :query => entry[0].strip.downcase, :count => entry[1].to_i} }
top = Array.new
result.each do |entry|
top << { :query => entry[0].strip.downcase, :count => entry[1].to_i}
end
top
end
end

Expand All @@ -23,8 +27,13 @@ def failed_searches
Rails.cache.fetch('failed_searches', :expires_in => 2.hours) do
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; ")
result.map{|entry| { :query => entry[0].strip.downcase, :count => entry[1].to_i} }
failed = Array.new
result.each do |entry|
failed << { :query => entry[0].strip.downcase, :count => entry[1].to_i}
end
failed
end
end


end

0 comments on commit ccefaaa

Please sign in to comment.