diff options
-rw-r--r-- | app/models/public_body.rb | 16 | ||||
-rw-r--r-- | spec/models/xapian_spec.rb | 44 | ||||
-rw-r--r-- | todo.txt | 15 |
3 files changed, 69 insertions, 6 deletions
diff --git a/app/models/public_body.rb b/app/models/public_body.rb index 97f48db44..dfefbc7ab 100644 --- a/app/models/public_body.rb +++ b/app/models/public_body.rb @@ -26,7 +26,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.140 2009-04-13 09:18:48 tony Exp $ +# $Id: public_body.rb,v 1.141 2009-04-21 17:10:21 francis Exp $ require 'csv' require 'set' @@ -209,6 +209,20 @@ class PublicBody < ActiveRecord::Base "authority" end + # if the URL name has changed, then all requested_from: queries + # will break unless we update index for every event for every + # request linked to it + after_save :reindex_requested_from + def reindex_requested_from + if self.changes.include?('url_name') + for info_request in self.info_requests + for info_request_event in info_request.info_request_events + info_request_event.xapian_mark_needs_index + end + end + end + end + # When name or short name is changed, also change the url name def short_name=(short_name) write_attribute(:short_name, short_name) diff --git a/spec/models/xapian_spec.rb b/spec/models/xapian_spec.rb index d3e88eedf..0228713b2 100644 --- a/spec/models/xapian_spec.rb +++ b/spec/models/xapian_spec.rb @@ -1,6 +1,6 @@ require File.dirname(__FILE__) + '/../spec_helper' -describe User, " when indexing with Xapian" do +describe User, " when indexing users with Xapian" do fixtures :users before(:all) do @@ -16,7 +16,7 @@ describe User, " when indexing with Xapian" do end -describe PublicBody, " when indexing with Xapian" do +describe PublicBody, " when indexing public bodies with Xapian" do fixtures :public_bodies before(:all) do @@ -37,4 +37,44 @@ describe PublicBody, " when indexing with Xapian" do end +describe " when indexing requests by body they are to" do + fixtures :public_bodies, :info_request_events + + before(:all) do + rebuild_xapian_index + end + + it "should find requests to the body" do + xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_from:tgq", 'created_at', true, nil, 100, 1) + xapian_object.results.size.should == 4 + end + + it "should update index correctly when URL name of body changes" do + verbose = false + + # initial search + xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_from:tgq", 'created_at', true, nil, 100, 1) + xapian_object.results.size.should == 4 + models_found_before = xapian_object.results.map { |x| x[:model] } + + # change the URL name of the body + body = public_bodies(:geraldine_public_body) + body.short_name = 'GQ' + body.save! + body.url_name.should == 'gq' + ActsAsXapian.update_index(true, verbose) # true = flush to disk + + # check we get results expected + xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_from:tgq", 'created_at', true, nil, 100, 1) + xapian_object.results.size.should == 0 + xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_from:gq", 'created_at', true, nil, 100, 1) + xapian_object.results.size.should == 4 + models_found_after = xapian_object.results.map { |x| x[:model] } + + models_found_before.should == models_found_after + end +end + + + @@ -1,11 +1,20 @@ +When a InfoRequest's url_title changes: + [ :request, 'R', "request" ] - all events for that request + +When User's url_name changes: + [ :requested_by, 'B', "requested_by" ] - all events for all requests by that user + [ :commented_by, 'C', "commented_by" ] - all comments made by that user + +Rebuild all index - turn off cron meanwhile? + Next (things that will reduce admin time mainly) ==== -Just stop worrying about old requests which are unclassified in status, or -make it a public wiki? At least improve usability a bit more for the alert -emails reminding you to fill in status. +Check up on how the public old request status editing is being used in +practice. Think about UI a bit more to try and up rate, and UI of +alerts to requester. Enable SPF, to reduce number of requests lost to spam filters http://www.openspf.org/SPF_Record_Syntax#include |