diff options
author | francis <francis> | 2008-06-23 20:43:30 +0000 |
---|---|---|
committer | francis <francis> | 2008-06-23 20:43:30 +0000 |
commit | eea463798341b0084f4e0622bd36611b24c837e9 (patch) | |
tree | 39c7b07d2aa8cb6979f3b9f42cb95a46ff021586 | |
parent | 2c26fc9c18d5750acaa48bbbaba2bcdacb53f340 (diff) |
Verbose option.
-rw-r--r-- | vendor/plugins/acts_as_xapian/lib/acts_as_xapian.rb | 14 | ||||
-rw-r--r-- | vendor/plugins/acts_as_xapian/tasks/xapian.rake | 12 |
2 files changed, 17 insertions, 9 deletions
diff --git a/vendor/plugins/acts_as_xapian/lib/acts_as_xapian.rb b/vendor/plugins/acts_as_xapian/lib/acts_as_xapian.rb index 0e80d4900..6fd5abc1b 100644 --- a/vendor/plugins/acts_as_xapian/lib/acts_as_xapian.rb +++ b/vendor/plugins/acts_as_xapian/lib/acts_as_xapian.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: acts_as_xapian.rb,v 1.27 2008-05-18 22:26:21 francis Exp $ +# $Id: acts_as_xapian.rb,v 1.28 2008-06-23 20:43:30 francis Exp $ # Documentation # ============= @@ -381,13 +381,14 @@ module ActsAsXapian # flush your changes. Specifying flush will reduce performance, but # make sure that each index update is definitely saved to disk before # logging in the database that it has been. - def ActsAsXapian.update_index(flush = false) + def ActsAsXapian.update_index(flush = false, verbose = false) ActsAsXapian.writable_init ids_to_refresh = ActsAsXapianJob.find(:all).map() { |i| i.id } for id in ids_to_refresh ActiveRecord::Base.transaction do job = ActsAsXapianJob.find(id, :lock =>true) + STDERR.puts("ActsAsXapian.update_index #{job.action} #{job.model} #{job.model_id.to_s}") if verbose if job.action == 'update' # XXX Index functions may reference other models, so we could eager load here too? model = job.model.constantize.find(job.model_id) # :include => cls.constantize.xapian_options[:include] @@ -411,7 +412,7 @@ module ActsAsXapian # You must specify *all* the models here, this totally rebuilds the Xapian database. # You'll want any readers to reopen the database after this. - def ActsAsXapian.rebuild_index(model_classes) + def ActsAsXapian.rebuild_index(model_classes, verbose = false) raise "when rebuilding all, please call as first and only thing done in process / task" if not ActsAsXapian.writable_db.nil? # Delete any existing .new database, and open a new one @@ -423,10 +424,15 @@ module ActsAsXapian ActsAsXapian.writable_init(".new") # Index everything - ActsAsXapianJob.destroy_all + # XXX not a good place to do this destroy, as unindexed list is lost if + # process is aborted and old database carries on being used. Perhaps do in + # transaction and commit after rename below? Not sure if thenlocking is then bad + # for live website running at same time. + ActsAsXapianJob.destroy_all for model_class in model_classes models = model_class.find(:all) for model in models + STDERR.puts("ActsAsXapian.rebuild_index #{model_class} #{model.id}") if verbose model.xapian_index end end diff --git a/vendor/plugins/acts_as_xapian/tasks/xapian.rake b/vendor/plugins/acts_as_xapian/tasks/xapian.rake index 3b8d0aecd..70772dbea 100644 --- a/vendor/plugins/acts_as_xapian/tasks/xapian.rake +++ b/vendor/plugins/acts_as_xapian/tasks/xapian.rake @@ -6,21 +6,23 @@ require File.dirname(__FILE__) + '/../lib/acts_as_xapian.rb' namespace :xapian do # Parameters - specify "flush=true" to save changes to the Xapian database - # after each model that is updated. This is safer, but slower. + # after each model that is updated. This is safer, but slower. Specify + # "verbose=true" to print model name as it is run. desc 'Updates Xapian search index with changes to models since last call' - task :update_index do - ActsAsXapian.update_index(ENV['flush'] ? true : false) + task (:update_index => :environment) do + ActsAsXapian.update_index(ENV['flush'] ? true : false, ENV['verbose'] ? true : false) end # Parameters - specify 'models="PublicBody User"' to say which models # you index with Xapian. # This totally rebuilds the database, so you will want to restart any # web server afterwards to make sure it gets the changes, rather than - # still pointing to the old deleted database. + # still pointing to the old deleted database. Specify "verbose=true" to + # print model name as it is run. desc 'Completely rebuilds Xapian search index (must specify all models)' task (:rebuild_index => :environment) do raise "specify ALL your models with models=\"ModelName1 ModelName2\" as parameter" if ENV['models'].nil? - ActsAsXapian.rebuild_index(ENV['models'].split(" ").map{|m| m.constantize}) + ActsAsXapian.rebuild_index(ENV['models'].split(" ").map{|m| m.constantize}, ENV['verbose'] ? true : false) end # Parameters - are models, query, offset, limit, sort_by_prefix, |