diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/general_controller.rb | 20 | ||||
-rw-r--r-- | app/models/incoming_message.rb | 7 | ||||
-rw-r--r-- | app/models/info_request.rb | 6 | ||||
-rw-r--r-- | app/models/outgoing_message.rb | 7 | ||||
-rw-r--r-- | app/models/public_body.rb | 8 | ||||
-rw-r--r-- | app/models/user.rb | 7 | ||||
-rw-r--r-- | app/views/general/search.rhtml | 15 |
7 files changed, 50 insertions, 20 deletions
diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb index 95e228957..0920b2eb6 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.8 2008-03-10 13:06:53 francis Exp $ +# $Id: general_controller.rb,v 1.9 2008-03-13 11:29:46 francis Exp $ class GeneralController < ApplicationController @@ -50,7 +50,18 @@ class GeneralController < ApplicationController # Actual search def search @per_page = 20 - @query = params[:query].join("/") + @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' + else + raise "Unknown sort order " + @sortby + end # Used for simpler word highlighting view code for users and public bodies query_nopunc = @query.gsub(/[^a-z0-9]/i, " ") @@ -58,7 +69,7 @@ class GeneralController < ApplicationController @highlight_words = query_nopunc.split(" ") @solr_object = InfoRequest.multi_solr_search(@query, :models => [ OutgoingMessage, IncomingMessage, PublicBody, User ], - :limit => @per_page, :offset => ((params[:page]||"1").to_i-1) * @per_page, + :limit => @per_page, :offset => (@page - 1) * @per_page, :highlight => { :prefix => '<span class="highlight">', :suffix => '</span>', @@ -68,9 +79,10 @@ class GeneralController < ApplicationController "get_text_for_indexing", # IncomingMessage "name", "short_name", # PublicBody "name" # User - ]} + ]}, :order => order ) @search_results = @solr_object.results + @search_hits = @solr_object.total_hits # Extract better Solr highlighting for info request related results @highlighting = @solr_object.highlights diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb index a44cddcfe..f098660bb 100644 --- a/app/models/incoming_message.rb +++ b/app/models/incoming_message.rb @@ -18,7 +18,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: incoming_message.rb,v 1.57 2008-03-12 16:07:13 francis Exp $ +# $Id: incoming_message.rb,v 1.58 2008-03-13 11:29:47 francis Exp $ # TODO @@ -50,7 +50,10 @@ class IncomingMessage < ActiveRecord::Base has_many :outgoing_message_followups, :class_name => OutgoingMessage - acts_as_solr :fields => [ :get_text_for_indexing ], :if => "$do_solr_index" + acts_as_solr :fields => [ + :get_text_for_indexing, + { :created_at => :date } + ], :if => "$do_solr_index" # Return the structured TMail::Mail object # Documentation at http://i.loveruby.net/en/projects/tmail/doc/ diff --git a/app/models/info_request.rb b/app/models/info_request.rb index 793506dfe..3f8a56b1a 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -22,7 +22,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: info_request.rb,v 1.61 2008-03-12 16:07:13 francis Exp $ +# $Id: info_request.rb,v 1.62 2008-03-13 11:29:47 francis Exp $ require 'digest/sha1' @@ -66,8 +66,8 @@ class InfoRequest < ActiveRecord::Base acts_as_solr :fields => [ :title, :initial_request_text, - { :status => :string } -# { :created_at => :date } + { :status => :string }, + { :created_at => :date } ], :if => "$do_solr_index" def status # for name in Solr queries calculate_status diff --git a/app/models/outgoing_message.rb b/app/models/outgoing_message.rb index 3e21a8af7..e12d91e65 100644 --- a/app/models/outgoing_message.rb +++ b/app/models/outgoing_message.rb @@ -21,7 +21,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: outgoing_message.rb,v 1.34 2008-03-12 16:07:13 francis Exp $ +# $Id: outgoing_message.rb,v 1.35 2008-03-13 11:29:47 francis Exp $ class OutgoingMessage < ActiveRecord::Base belongs_to :info_request @@ -32,7 +32,10 @@ class OutgoingMessage < ActiveRecord::Base belongs_to :incoming_message_followup, :foreign_key => 'incoming_message_followup_id', :class_name => 'IncomingMessage' - acts_as_solr :fields => [ :body ], :if => "$do_solr_index" + acts_as_solr :fields => [ + :body, + { :created_at => :date } + ], :if => "$do_solr_index" # How the default letter starts and ends def get_salutation diff --git a/app/models/public_body.rb b/app/models/public_body.rb index 031c1e476..9c5fe6927 100644 --- a/app/models/public_body.rb +++ b/app/models/public_body.rb @@ -22,7 +22,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: public_body.rb,v 1.35 2008-03-12 16:07:13 francis Exp $ +# $Id: public_body.rb,v 1.36 2008-03-13 11:29:47 francis Exp $ require 'csv' require 'set' @@ -59,7 +59,11 @@ class PublicBody < ActiveRecord::Base acts_as_versioned self.non_versioned_columns << 'created_at' << 'updated_at' - acts_as_solr :fields => [{:name => { :boost => 10.0 }}, {:short_name => { :boost => 10.0 }} ] + acts_as_solr :fields => [ + {:name => { :boost => 10.0 }}, + {:short_name => { :boost => 10.0 }}, + { :created_at => :date } + ] # When name or short name is changed, also change the url name def short_name=(short_name) diff --git a/app/models/user.rb b/app/models/user.rb index 14a1d63e3..6c426c810 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -20,7 +20,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: user.rb,v 1.35 2008-03-12 16:07:13 francis Exp $ +# $Id: user.rb,v 1.36 2008-03-13 11:29:47 francis Exp $ require 'digest/sha1' @@ -39,7 +39,10 @@ class User < ActiveRecord::Base attr_accessor :password_confirmation validates_confirmation_of :password, :message =>"^Please enter the same password twice" - acts_as_solr :fields => [ {:name => { :boost => 5.0 }} ] + acts_as_solr :fields => [ + {:name => { :boost => 5.0 }}, + { :created_at => :date } + ] def validate errors.add(:email, "doesn't look like a valid address") unless MySociety::Validate.is_valid_email(self.email) diff --git a/app/views/general/search.rhtml b/app/views/general/search.rhtml index 761e7e22c..e91aef2e5 100644 --- a/app/views/general/search.rhtml +++ b/app/views/general/search.rhtml @@ -1,8 +1,11 @@ <% if @query.nil? %> - <% @title = "Search requests, public bodies and users" %> + <% @title = "Search Freedom of Information requests, public bodies and users" %> <h1><%=@title%></h1> +<% elsif @search_hits == 0 %> + <% @title = "Nothing found for '" + h(@query) + "'" %> + <% else %> - <% @title = "Search for '" + h(@query) + "'" %> + <% @title = "Results " + ((@page-1)*@per_page+1).to_s + "-" + [@page*@per_page, @search_hits].min.to_s + " of " + @search_hits.to_s + " for '" + h(@query) + "'" %> <% end%> <% form_tag({:action => "search_redirect"}, {:id => "search_form"}) do %> @@ -16,11 +19,13 @@ <% end %> <% if not @search_results.nil? %> + <%=link_to_unless @sortby.nil?, "Show most relevant results first", { :sortby => nil } %> + | + <%=link_to_unless @sortby == 'newest', "Newest results first", { :sortby => "newest" } %> <h1><%=@title%></h1> <% if @search_results.empty? %> - None found. <% else %> <% for search_result in @search_results %> <% if search_result.class.to_s == 'InfoRequest' %> @@ -39,13 +44,13 @@ <% end %> <% end %> - <%= will_paginate WillPaginate::Collection.new(params[:page]||1, @per_page, @solr_object.total_hits) %> + <%= will_paginate WillPaginate::Collection.new(@page, @per_page, @search_hits) %> <% end %> <% if @search_results.nil? or @search_results.empty? %> <h2>Search tips</h2> <ul> - <li>Enter words that you want to find, e.g. climbing lane</li> + <li>Enter words that you want to find separated by spaces, e.g. climbing lane</li> <li>Use OR (in capital letters) where you don't mind which word, e.g. commons OR lords <li>Use quotes when you want to find an exact phrase, e.g. "Liverpool City Council" <li>Type status: to select based on the status of the request. |