aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/models/info_request.rb14
-rw-r--r--spec/models/xapian_spec.rb32
-rw-r--r--todo.txt3
3 files changed, 45 insertions, 4 deletions
diff --git a/app/models/info_request.rb b/app/models/info_request.rb
index 025a9247e..a37baf8d8 100644
--- a/app/models/info_request.rb
+++ b/app/models/info_request.rb
@@ -23,7 +23,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.186 2009-04-13 09:18:48 tony Exp $
+# $Id: info_request.rb,v 1.187 2009-04-22 01:10:33 francis Exp $
require 'digest/sha1'
require File.join(File.dirname(__FILE__),'../../vendor/plugins/acts_as_xapian/lib/acts_as_xapian')
@@ -105,6 +105,18 @@ class InfoRequest < ActiveRecord::Base
)
end
+ # if the URL name has changed, then all request: queries
+ # will break unless we update index for every event
+ after_save :reindex_request_events
+ def reindex_request_events
+ if self.changes.include?('url_title')
+ for info_request_event in self.info_request_events
+ info_request_event.xapian_mark_needs_index
+ end
+ end
+ end
+
+
# For debugging
def InfoRequest.profile_search(query)
t = Time.now.usec
diff --git a/spec/models/xapian_spec.rb b/spec/models/xapian_spec.rb
index 9df56d1ca..d4da1fd77 100644
--- a/spec/models/xapian_spec.rb
+++ b/spec/models/xapian_spec.rb
@@ -151,6 +151,38 @@ describe " when indexing comments by user they are by" do
end
end
+describe " when indexing requests by their title" do
+ fixtures :info_request_events, :info_requests
+
+ before(:all) do
+ rebuild_xapian_index
+ end
+
+ it "should find events for the request" do
+ xapian_object = InfoRequest.full_search([InfoRequestEvent], "request:how_much_public_money_is_wasted_o", 'created_at', true, nil, 100, 1)
+ xapian_object.results.size.should == 1
+ xapian_object.results[0][:model] == info_request_events(:silly_outgoing_message_event)
+ end
+
+ it "should update index correctly when URL title of request changes" do
+ verbose = false
+
+ # change the URL name of the body
+ ir = info_requests(:naughty_chicken_request)
+ ir.title = 'Really naughty'
+ ir.save!
+ ir.url_title.should == 'really_naughty'
+ ActsAsXapian.update_index(true, verbose) # true = flush to disk
+
+ # check we get results expected
+ xapian_object = InfoRequest.full_search([InfoRequestEvent], "request:how_much_public_money_is_wasted_o", 'created_at', true, nil, 100, 1)
+ xapian_object.results.size.should == 0
+ xapian_object = InfoRequest.full_search([InfoRequestEvent], "request:really_naughty", 'created_at', true, nil, 100, 1)
+ xapian_object.results.size.should == 1
+ xapian_object.results[0][:model] == info_request_events(:silly_outgoing_message_event)
+ end
+end
+
diff --git a/todo.txt b/todo.txt
index bba1a2a8b..b0c1489be 100644
--- a/todo.txt
+++ b/todo.txt
@@ -2,9 +2,6 @@
When a InfoRequest's url_title changes:
[ :request, 'R', "request" ] - all events for that request
-When User's url_name changes:
- [ :commented_by, 'C', "commented_by" ] - all comments made by that user
-
Rebuild all index - turn off cron meanwhile?