diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/incoming_message.rb | 4 | ||||
-rw-r--r-- | app/models/info_request.rb | 28 | ||||
-rw-r--r-- | app/models/outgoing_message.rb | 4 |
3 files changed, 32 insertions, 4 deletions
diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb index b3560e006..02256805e 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.48 2008-02-28 14:25:51 francis Exp $ +# $Id: incoming_message.rb,v 1.49 2008-03-06 01:23:38 francis Exp $ # TODO @@ -50,6 +50,8 @@ class IncomingMessage < ActiveRecord::Base has_many :outgoing_message_followups, :class_name => OutgoingMessage + acts_as_solr :fields => [ :get_main_body_text ], :if => "$do_solr_index" + # Return the structured TMail::Mail object # Documentation at http://i.loveruby.net/en/projects/tmail/doc/ def mail diff --git a/app/models/info_request.rb b/app/models/info_request.rb index df2e32c8a..53f349535 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.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: info_request.rb,v 1.53 2008-02-29 16:01:32 francis Exp $ +# $Id: info_request.rb,v 1.54 2008-03-06 01:23:38 francis Exp $ require 'digest/sha1' @@ -63,6 +63,28 @@ class InfoRequest < ActiveRecord::Base end end + # Full text search indexing + acts_as_solr :fields => [ :title ], :if => "$do_solr_index" + $do_solr_index = false + def self.update_solr_index + $do_solr_index = true + InfoRequest.rebuild_solr_index(0) do |ar, options| + ar.find(:all, :conditions => ["not solr_up_to_date"]) + end + OutgoingMessage.rebuild_solr_index(0) do |ar, options| + ar.find(:all, :conditions => ["not (select solr_up_to_date from info_requests where id = outgoing_messages.info_request_id)"]) + end + IncomingMessage.rebuild_solr_index(0) do |ar, options| + ar.find(:all, :conditions => ["not (select solr_up_to_date from info_requests where id = incoming_messages.info_request_id)"]) + end + InfoRequest.update_all("solr_up_to_date = 't'") + $do_solr_index = false + end + def before_update + self.solr_up_to_date = false + true + end + public # When name is changed, also change the url name def title=(title) @@ -110,7 +132,9 @@ public # Return info request corresponding to an incoming email address, or nil if # none found. Checks the hash to ensure the email came from the public body - - # only they are sent the email address with the has in it. + # only they are sent the email address with the has in it. (We don't check + # the prefix and domain, as sometimes those change, or might be elided by + # copying an email, and that doesn't matter) def self.find_by_incoming_email(incoming_email) incoming_email =~ /request-(\d+)-([a-z0-9]+)/ id = $1.to_i diff --git a/app/models/outgoing_message.rb b/app/models/outgoing_message.rb index 03b3e5fef..bbbf1c7bb 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.32 2008-02-27 14:01:30 francis Exp $ +# $Id: outgoing_message.rb,v 1.33 2008-03-06 01:23:38 francis Exp $ class OutgoingMessage < ActiveRecord::Base belongs_to :info_request @@ -32,6 +32,8 @@ 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" + # How the default letter starts and ends def get_salutation ret = "Dear " |