aboutsummaryrefslogtreecommitdiffstats
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/info_request.rb79
-rw-r--r--app/models/info_request_event.rb36
-rw-r--r--app/models/public_body.rb12
-rw-r--r--app/models/track_mailer.rb16
-rw-r--r--app/models/user.rb10
5 files changed, 49 insertions, 104 deletions
diff --git a/app/models/info_request.rb b/app/models/info_request.rb
index 49245ab1b..22ef40883 100644
--- a/app/models/info_request.rb
+++ b/app/models/info_request.rb
@@ -13,7 +13,6 @@
# awaiting_description :boolean default(false), not null
# prominence :string(255) default("normal"), not null
# url_title :text not null
-# solr_up_to_date :boolean default(false), not null
#
# models/info_request.rb:
@@ -22,9 +21,10 @@
# 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.95 2008-04-21 16:44:06 francis Exp $
+# $Id: info_request.rb,v 1.96 2008-04-24 23:52:59 francis Exp $
require 'digest/sha1'
+require 'vendor/plugins/acts_as_xapian/lib/acts_as_xapian'
class InfoRequest < ActiveRecord::Base
validates_presence_of :title, :message => "^Please enter a summary of your request"
@@ -64,67 +64,19 @@ class InfoRequest < ActiveRecord::Base
end
end
- # Full text search indexing
- $do_solr_index = false
- $do_solr_index_marking = false
- def InfoRequest.update_solr_index
- #STDERR.puts "self.update_solr_index"
- $do_solr_index = true
-
- # Index each item separately in a transaction, so solr_up_to_date is right
- ids_to_refresh = InfoRequest.find(:all, :conditions => ["not solr_up_to_date"]).map() { |i| i.id }
- for id in ids_to_refresh
- #STDERR.puts "updating id " + id.to_s
- ActiveRecord::Base.transaction do
- info_request = InfoRequest.find(id, :lock =>true)
- do_index = (info_request.prominence != 'backpage')
-
- info_request.calculate_event_states
-
- # index all the events
- for event in info_request.info_request_events
- if do_index and event.indexed_by_solr
- event.solr_save
- else
- event.solr_destroy
- end
- end
-
- $do_solr_index = false # disable indexing again while we save it, or else destroyed things get put back
- $do_solr_index_marking = true # but record that we want to set solr_up_to_date to be true, so before_update doesn't clobber it
- info_request.solr_up_to_date = true
- #STDERR.puts "saving " + info_request.solr_up_to_date.to_s
- info_request.save!
- $do_solr_index_marking = false
- $do_solr_index = true
- end
- end
- InfoRequestEvent.solr_optimize
- $do_solr_index = false
- end
- def before_update
- # If we're not mid index, then mark we need to index later
- if not $do_solr_index_marking
- self.solr_up_to_date = false
- end
- true
- end
-
# Central function to do all searches
- def InfoRequest.full_search(query, order, per_page, page, html_highlight)
+ # (Not really the right place to put it, but everything can get it here, and it
+ # does *mainly* find info requests, via their events, so hey)
+ def InfoRequest.full_search(query, order, ascending, per_page, page, html_highlight)
+ # XXX handle order better
+ # XXX 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,
- :include => { :InfoRequestEvent => [ { :incoming_message => { :info_request => :public_body }}, :outgoing_message, { :info_request => [ :user, :public_body ] } ] }
+ return ::ActsAsXapian::Search.new(
+ [InfoRequestEvent, PublicBody, User], query,
+ :offset => offset, :limit => per_page,
+ :sort_by_prefix => order,
+ :sort_by_ascending => ascending,
+ :collapse_by_prefix => "request_collapse"
)
end
@@ -135,7 +87,7 @@ class InfoRequest < ActiveRecord::Base
t = Time.now.usec - t
secs = t / 1000000.0
STDOUT.write secs.to_s + " query " + i.to_s + "\n"
- results = InfoRequest.full_search(query, "created_at desc", 25, 1, false).results
+ results = InfoRequest.full_search(query, "created_at", false, 25, 1, false).results
end
end
@@ -499,9 +451,6 @@ public
self.incoming_messages.each { |a| a.destroy }
self.outgoing_messages.each { |a| a.destroy }
self.user_info_request_sent_alerts.each { |a| a.destroy }
- for event in self.info_request_events
- event.solr_destroy
- end
self.info_request_events.each { |a| a.destroy }
self.destroy
end
diff --git a/app/models/info_request_event.rb b/app/models/info_request_event.rb
index e8e1ecaa5..a89e98cad 100644
--- a/app/models/info_request_event.rb
+++ b/app/models/info_request_event.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: info_request_event.rb,v 1.39 2008-04-24 22:50:03 angie Exp $
+# $Id: info_request_event.rb,v 1.40 2008-04-24 23:52:59 francis Exp $
class InfoRequestEvent < ActiveRecord::Base
belongs_to :info_request
@@ -53,20 +53,19 @@ class InfoRequestEvent < ActiveRecord::Base
]
# Full text search indexing
- acts_as_solr :fields => [
- { :solr_text_main => :text },
- { :title => :text },
- { :status => :string },
- { :requested_by => :string },
- { :requested_from => :string },
- { :request => :string },
- { :created_at => :date },
- { :rss_at => :date },
- { :variety => :string }
- ], :if => "$do_solr_index"
- def status # for name in Solr queries
- self.calculated_state
- end
+ acts_as_xapian :texts => [ :search_text_main, :title ],
+ :values => [ [ :created_at, 0, "created_at", :date ],
+ [ :rss_at, 1, "rss_at", :date ],
+ [ :request, 2, "request_collapse", :string ]
+ ],
+ :terms => [ [ :calculated_state, 'S', "status" ],
+ [ :requested_by, 'B', "requested_by" ],
+ [ :requested_from, 'F', "requested_from" ],
+ [ :request, 'R', "request" ],
+ [ :variety, 'V', "variety" ]
+ ],
+ :if => :indexed_by_search,
+ :eager_load => [ { :incoming_message => { :info_request => :public_body }}, :outgoing_message, { :info_request => [ :user, :public_body ] } ]
def requested_by
self.info_request.user.url_name
end
@@ -83,7 +82,7 @@ class InfoRequestEvent < ActiveRecord::Base
# types, just use the create at date.
self.last_described_at || self.created_at
end
- def solr_text_main
+ def search_text_main
text = ''
if self.event_type == 'sent'
text = text + self.outgoing_message.body_without_salutation + "\n\n"
@@ -102,8 +101,11 @@ class InfoRequestEvent < ActiveRecord::Base
end
return ''
end
- def indexed_by_solr
+ def indexed_by_search
if ['sent', 'followup_sent', 'response'].include?(self.event_type)
+ if info_request.prominence == 'backpage'
+ return false
+ end
return true
else
return false
diff --git a/app/models/public_body.rb b/app/models/public_body.rb
index ab06209e3..4d073b4a2 100644
--- a/app/models/public_body.rb
+++ b/app/models/public_body.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: public_body.rb,v 1.66 2008-04-22 00:54:07 francis Exp $
+# $Id: public_body.rb,v 1.67 2008-04-24 23:52:59 francis Exp $
require 'csv'
require 'set'
@@ -79,13 +79,9 @@ class PublicBody < ActiveRecord::Base
attr_accessor :created_at
end
-
- acts_as_solr :fields => [
- {:name => { :boost => 10.0 }},
- {:short_name => { :boost => 10.0 }},
- { :created_at => :date },
- { :variety => :string }
- ]
+ acts_as_xapian :texts => [ :name, :short_name ],
+ :values => [ [ :created_at, 0, "created_at", :date ] ],
+ :terms => [ [ :variety, 'V', "variety" ] ]
def variety
"authority"
end
diff --git a/app/models/track_mailer.rb b/app/models/track_mailer.rb
index c5d2ef35f..5bd41a715 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.6 2008-04-14 14:46:48 francis Exp $
+# $Id: track_mailer.rb,v 1.7 2008-04-24 23:52:59 francis Exp $
class TrackMailer < ApplicationMailer
def event_digest(user, email_about_things)
@@ -41,13 +41,13 @@ class TrackMailer < ApplicationMailer
end
# Query for things in this track
- solr_object = InfoRequest.full_search(track_thing.track_query, 'created_at desc', 100, 1, false)
+ xapian_object = InfoRequest.full_search(track_thing.track_query, 'created_at', false, 100, 1, false)
# Go through looking for unalerted things
alert_results = []
- for result in solr_object.results
- if result.class.to_s == "InfoRequestEvent"
- if not done_info_request_events.include?(result.id) and track_thing.created_at < result.created_at
+ for result in xapian_object.results
+ if result[:model].class.to_s == "InfoRequestEvent"
+ if not done_info_request_events.include?(result[:model].id) and track_thing.created_at < result[:model].created_at
# OK alert this one
alert_results.push(result)
end
@@ -68,7 +68,7 @@ class TrackMailer < ApplicationMailer
for track_thing, alert_results in email_about_things
STDERR.puts " tracking " + track_thing.track_query
for result in alert_results.reverse
- STDERR.puts " result " + result.class.to_s + " id " + result.id.to_s
+ STDERR.puts " result " + result[:model].class.to_s + " id " + result[:model].id.to_s
end
end
@@ -81,8 +81,8 @@ class TrackMailer < ApplicationMailer
for result in alert_results
track_things_sent_email = TrackThingsSentEmail.new
track_things_sent_email.track_thing_id = track_thing.id
- if result.class.to_s == "InfoRequestEvent"
- track_things_sent_email.info_request_event_id = result.id
+ if result[:model].class.to_s == "InfoRequestEvent"
+ track_things_sent_email.info_request_event_id = result[:model].id
else
raise "need to add other types to TrackMailer.alert_tracks (mark alerted)"
end
diff --git a/app/models/user.rb b/app/models/user.rb
index 76b63c310..9042fda26 100644
--- a/app/models/user.rb
+++ b/app/models/user.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: user.rb,v 1.51 2008-04-21 16:44:06 francis Exp $
+# $Id: user.rb,v 1.52 2008-04-24 23:52:59 francis Exp $
require 'digest/sha1'
@@ -41,11 +41,9 @@ 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 }},
- { :created_at => :date },
- { :variety => :string }
- ]
+ acts_as_xapian :texts => [ :name ],
+ :values => [ [ :created_at, 0, "created_at", :date ] ],
+ :terms => [ [ :variety, 'V', "variety" ] ]
def variety
"user"
end