Skip to content

Commit

Permalink
Reindex in Xapian when censor rules change.
Browse files Browse the repository at this point in the history
  • Loading branch information
francis committed Aug 21, 2009
1 parent dd7f06b commit ec3c2d2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
4 changes: 3 additions & 1 deletion app/controllers/admin_controller.rb
Expand Up @@ -4,7 +4,7 @@
# Copyright (c) 2009 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
# $Id: admin_controller.rb,v 1.26 2009-06-30 14:28:25 francis Exp $
# $Id: admin_controller.rb,v 1.27 2009-08-21 17:43:33 francis Exp $


class AdminController < ApplicationController
Expand Down Expand Up @@ -32,6 +32,8 @@ def expire_for_request(info_request)
# the URL, the regular expression makes sure the cache is
# cleared even if someone did that.
expire_fragment /views\/request\/#{info_request.id}.*/
# also force a search reindexing (so changed text reflected in search)
info_request.reindex_request_events
end
end

15 changes: 9 additions & 6 deletions app/models/info_request.rb
Expand Up @@ -24,7 +24,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.200 2009-08-19 00:22:49 francis Exp $
# $Id: info_request.rb,v 1.201 2009-08-21 17:43:33 francis Exp $

require 'digest/sha1'
require File.join(File.dirname(__FILE__),'../../vendor/plugins/acts_as_xapian/lib/acts_as_xapian')
Expand Down Expand Up @@ -123,12 +123,15 @@ def InfoRequest.full_search(models, query, order, ascending, collapse, per_page,

# If the URL name has changed, then all request: queries will break unless
# we update index for every event. Also reindex if prominence changes.
after_update :reindex_request_events
def reindex_request_events
after_update :reindex_some_request_events
def reindex_some_request_events
if self.changes.include?('url_title') || self.changes.include?('prominence')
for info_request_event in self.info_request_events
info_request_event.xapian_mark_needs_index
end
self.reindex_request_events
end
end
def reindex_request_events
for info_request_event in self.info_request_events
info_request_event.xapian_mark_needs_index
end
end

Expand Down

0 comments on commit ec3c2d2

Please sign in to comment.