diff options
author | Seb Bacon <seb.bacon@gmail.com> | 2011-06-14 11:51:41 +0100 |
---|---|---|
committer | Seb Bacon <seb.bacon@gmail.com> | 2011-06-14 11:51:41 +0100 |
commit | 2ee3d07d49a28d7560329ba2c71e411b1f3afe74 (patch) | |
tree | a1a1c3d7df6b178b9eb904a0a8031f312f270eed /app/controllers/general_controller.rb | |
parent | c78e3b2aba67ad9844175e1e27016692759f498a (diff) |
allow search and publicbody examples to be provided in config file, falling back to a vaguely sensible default based on existing data if not present. Note that the fallback is a slow query on a large database!
Diffstat (limited to 'app/controllers/general_controller.rb')
-rw-r--r-- | app/controllers/general_controller.rb | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb index cf28208a0..47962d60a 100644 --- a/app/controllers/general_controller.rb +++ b/app/controllers/general_controller.rb @@ -21,8 +21,22 @@ class GeneralController < ApplicationController # New, improved front page! def frontpage behavior_cache do + + # get some example searches and public bodies to display + # either from config, or based on a (slow!) query if not set + body_short_names = MySociety::Config.get('FRONTPAGE_PUBLICBODY_EXAMPLES', '').split(/\s*;\s*/).map{|s| "'%s'" % s.gsub(/'/, "''") }.join(", ") + if body_short_names.empty? # This is too slow - @popular_bodies = PublicBody.find(:all, :select => "*, (select count(*) from info_requests where info_requests.public_body_id = public_bodies.id) as c", :order => "c desc", :limit => 32) + @popular_bodies = PublicBody.find(:all, :select => "*, (select count(*) from info_requests where info_requests.public_body_id = public_bodies.id) as c", :order => "c desc", :limit => 32) + else + @popular_bodies = PublicBody.find(:all, :conditions => ["url_name in (" + body_short_names + ")"]) + end + @search_examples = MySociety::Config.get('FRONTPAGE_SEARCH_EXAMPLES', '').split(/\s*;\s*/) + if @search_examples.empty? + @search_examples = @popular_bodies.map { |body| body.name } + end + + # Get some successful requests # begin query = 'variety:response (status:successful OR status:partially_successful)' |