diff options
-rw-r--r-- | app/controllers/application.rb | 16 | ||||
-rw-r--r-- | app/models/info_request.rb | 18 | ||||
-rw-r--r-- | app/models/track_mailer.rb | 15 | ||||
-rw-r--r-- | db/schema.rb | 8 |
4 files changed, 22 insertions, 35 deletions
diff --git a/app/controllers/application.rb b/app/controllers/application.rb index e8c8ec199..736656dec 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.37 2008-04-11 15:53:57 francis Exp $ +# $Id: application.rb,v 1.38 2008-04-14 14:46:47 francis Exp $ class ApplicationController < ActionController::Base @@ -155,19 +155,7 @@ class ApplicationController < ActionController::Base else @page = this_page end - - # XXX remove duplication with models/track_mailer.rb - solr_object = InfoRequestEvent.multi_solr_search(@query, :models => [ PublicBody, User ], - :limit => @per_page, :offset => (@page - 1) * @per_page, - :highlight => { - :prefix => html_highlight ? '<span class="highlight">' : "*", - :suffix => html_highlight ? '</span>' : "*", - :fragsize => 250, - :fields => ["solr_text_main", "title", # InfoRequestEvent - "name", "short_name", # PublicBody - "name" # User - ]}, :order => order - ) + solr_object = InfoRequest.full_search(@query, order, @per_page, @page, true) @search_results = solr_object.results @search_hits = solr_object.total_hits diff --git a/app/models/info_request.rb b/app/models/info_request.rb index cf4d6c206..775138b84 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.84 2008-04-14 10:05:21 francis Exp $ +# $Id: info_request.rb,v 1.85 2008-04-14 14:46:48 francis Exp $ require 'digest/sha1' @@ -111,6 +111,22 @@ class InfoRequest < ActiveRecord::Base true end + # Central function to do all searches + def InfoRequest.full_search(query, order, per_page, page, html_highlight) + offset = (page - 1) * per_page + return InfoRequestEvent.multi_solr_search(query, :models => [ PublicBody, User ], + :limit => per_page, :offset => offset, + :highlight => { + :prefix => html_highlight ? '<span class="highlight">' : "*", + :suffix => html_highlight ? '</span>' : "*", + :fragsize => 250, + :fields => ["solr_text_main", "title", # InfoRequestEvent + "name", "short_name", # PublicBody + "name" # User + ]}, :order => order + ) + end + public # When name is changed, also change the url name def title=(title) diff --git a/app/models/track_mailer.rb b/app/models/track_mailer.rb index 119654009..c5d2ef35f 100644 --- a/app/models/track_mailer.rb +++ b/app/models/track_mailer.rb @@ -4,7 +4,7 @@ # Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: track_mailer.rb,v 1.5 2008-04-09 01:32:53 francis Exp $ +# $Id: track_mailer.rb,v 1.6 2008-04-14 14:46:48 francis Exp $ class TrackMailer < ApplicationMailer def event_digest(user, email_about_things) @@ -41,18 +41,7 @@ class TrackMailer < ApplicationMailer end # Query for things in this track - # XXX remove duplication with controllers/application.rb - #perform_search(track_thing.track_query, 'newest', 100, 1, false) - solr_object = InfoRequestEvent.multi_solr_search(track_thing.track_query, :models => [ PublicBody, User ], - :limit => 100, :offset => 0, - :highlight => { - :prefix => "*", :suffix => "*", - :fragsize => 250, - :fields => ["solr_text_main", "title", # InfoRequestEvent - "name", "short_name", # PublicBody - "name" # User - ]}, :order => 'created_at desc' - ) + solr_object = InfoRequest.full_search(track_thing.track_query, 'created_at desc', 100, 1, false) # Go through looking for unalerted things alert_results = [] diff --git a/db/schema.rb b/db/schema.rb index f0f2b4eb8..5e1982b16 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -9,7 +9,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 52) do +ActiveRecord::Schema.define(:version => 51) do create_table "incoming_messages", :force => true do |t| t.integer "info_request_id", :null => false @@ -87,12 +87,6 @@ ActiveRecord::Schema.define(:version => 52) do add_index "public_bodies", ["url_name"], :name => "index_public_bodies_on_url_name", :unique => true - create_table "public_body_tag_categories", :force => true do |t| - t.text "name", :null => false - t.text "title", :null => false - t.text "singular", :null => false - end - create_table "public_body_tags", :force => true do |t| t.integer "public_body_id", :null => false t.text "name", :null => false |