diff options
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/application.rb | 45 | ||||
-rw-r--r-- | app/controllers/general_controller.rb | 44 | ||||
-rw-r--r-- | app/controllers/request_controller.rb | 17 |
3 files changed, 64 insertions, 42 deletions
diff --git a/app/controllers/application.rb b/app/controllers/application.rb index daa8a955b..c92e084a7 100644 --- a/app/controllers/application.rb +++ b/app/controllers/application.rb @@ -6,7 +6,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: application.rb,v 1.32 2008-03-21 14:45:38 francis Exp $ +# $Id: application.rb,v 1.33 2008-04-01 00:36:56 francis Exp $ class ApplicationController < ActionController::Base @@ -124,6 +124,49 @@ class ApplicationController < ActionController::Base end end + # Function for search + def perform_search(query, sortby) + @query = query + @sortby = sortby + + # Work out sorting method + if @sortby.nil? + order = nil + elsif @sortby == 'newest' + order = 'created_at desc' + elsif @sortby == 'described' + order = 'last_described_at desc' # use this for RSS + else + raise "Unknown sort order " + @sortby + end + + # Peform the search + @per_page = 20 + @page = (params[:page] || "1").to_i + + solr_object = InfoRequestEvent.multi_solr_search(@query, :models => [ PublicBody, User ], + :limit => @per_page, :offset => (@page - 1) * @per_page, + :highlight => { + :prefix => '<span class="highlight">', + :suffix => '</span>', + :fragsize => 250, + :fields => ["solr_text_main", "title", # InfoRequestEvent + "name", "short_name", # PublicBody + "name" # User + ]}, :order => order + ) + @search_results = solr_object.results + @search_hits = solr_object.total_hits + + # Calculate simple word highlighting view code for users and public bodies + query_nopunc = @query.gsub(/[^a-z0-9]/i, " ") + query_nopunc = query_nopunc.gsub(/\s+/, " ") + @highlight_words = query_nopunc.split(" ") + + # Extract better Solr highlighting for info request related results + @highlighting = solr_object.highlights + end + # URL generating functions are needed by all controllers (for redirects) # and views (for links), so include them into all of both. include LinkToHelper diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb index 16f34f1b8..6930b1ddd 100644 --- a/app/controllers/general_controller.rb +++ b/app/controllers/general_controller.rb @@ -5,7 +5,7 @@ # Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: general_controller.rb,v 1.14 2008-03-31 23:19:16 francis Exp $ +# $Id: general_controller.rb,v 1.15 2008-04-01 00:36:56 francis Exp $ class GeneralController < ApplicationController @@ -51,46 +51,12 @@ class GeneralController < ApplicationController # Actual search def search - @per_page = 20 - @query = params[:query] - @sortby = params[:sortby] - @page = (params[:page] || "1").to_i - - # Work out sorting method - if @sortby.nil? - order = nil - elsif @sortby == 'newest' - order = 'created_at desc' - elsif @sortby == 'described' - order = 'last_described_at desc' # use this for RSS - else - raise "Unknown sort order " + @sortby - end - - # Peform the search - solr_object = InfoRequestEvent.multi_solr_search(@query, :models => [ PublicBody, User ], - :limit => @per_page, :offset => (@page - 1) * @per_page, - :highlight => { - :prefix => '<span class="highlight">', - :suffix => '</span>', - :fragsize => 250, - :fields => ["solr_text_main", "title", # InfoRequestEvent - "name", "short_name", # PublicBody - "name" # User - ]}, :order => order - ) - @search_results = solr_object.results - @search_hits = solr_object.total_hits - - # Calculate simple word highlighting view code for users and public bodies - query_nopunc = @query.gsub(/[^a-z0-9]/i, " ") - query_nopunc = query_nopunc.gsub(/\s+/, " ") - @highlight_words = query_nopunc.split(" ") - - # Extract better Solr highlighting for info request related results - @highlighting = solr_object.highlights + query = params[:query] + sortby = params[:sortby] + perform_search(query, sortby) end + # For debugging def fai_test sleep 10 render :text => "awake\n" diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index 7fe9feda5..4275c944d 100644 --- a/app/controllers/request_controller.rb +++ b/app/controllers/request_controller.rb @@ -4,7 +4,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: request_controller.rb,v 1.68 2008-03-17 10:36:41 francis Exp $ +# $Id: request_controller.rb,v 1.69 2008-04-01 00:36:56 francis Exp $ class RequestController < ApplicationController @@ -37,7 +37,20 @@ class RequestController < ApplicationController end def list - @info_requests = InfoRequest.paginate :order => "created_at desc", :page => params[:page], :per_page => 25, :conditions => "prominence = 'normal'" + view = params[:view] + + if view.nil? + @title = "Recent Freedom of Information requests" + query = "variety:sent"; + sortby = "newest" + elsif view == 'successful' + @title = "Recent successful responses" + query = 'variety:response (status:successful OR status:partially_successful)' + sortby = "newest" + else + raise "unknown request list view " + view.to_s + end + perform_search(query, sortby) end # Page new form posts to |