<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -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 =&gt;true)
+                STDERR.puts(&quot;ActsAsXapian.update_index #{job.action} #{job.model} #{job.model_id.to_s}&quot;) 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 =&gt; 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 &quot;when rebuilding all, please call as first and only thing done in process / task&quot; 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(&quot;.new&quot;)
 
         # 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(&quot;ActsAsXapian.rebuild_index #{model_class} #{model.id}&quot;) if verbose
                 model.xapian_index
             end
         end</diff>
      <filename>lib/acts_as_xapian.rb</filename>
    </modified>
    <modified>
      <diff>@@ -6,21 +6,23 @@ require File.dirname(__FILE__) + '/../lib/acts_as_xapian.rb'
 
 namespace :xapian do
     # Parameters - specify &quot;flush=true&quot; 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
+    # &quot;verbose=true&quot; 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 =&gt; :environment) do
+        ActsAsXapian.update_index(ENV['flush'] ? true : false, ENV['verbose'] ? true : false)
     end
 
     # Parameters - specify 'models=&quot;PublicBody User&quot;' 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 &quot;verbose=true&quot; to
+    # print model name as it is run.
     desc 'Completely rebuilds Xapian search index (must specify all models)'
     task (:rebuild_index =&gt; :environment) do
         raise &quot;specify ALL your models with models=\&quot;ModelName1 ModelName2\&quot; as parameter&quot; if ENV['models'].nil?
-        ActsAsXapian.rebuild_index(ENV['models'].split(&quot; &quot;).map{|m| m.constantize})
+        ActsAsXapian.rebuild_index(ENV['models'].split(&quot; &quot;).map{|m| m.constantize}, ENV['verbose'] ? true : false)
     end
 
     # Parameters - are models, query, offset, limit, sort_by_prefix,</diff>
      <filename>tasks/xapian.rake</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>390c5552c34965ca85a2e9757c3b5e13eaa8d935</id>
    </parent>
  </parents>
  <author>
    <name>Francis Irving</name>
    <email>francis@flourish.org</email>
  </author>
  <url>http://github.com/frabcus/acts_as_xapian/commit/f0375aca4e3f71945e3db31ffcc9cf8c73ed4ec2</url>
  <id>f0375aca4e3f71945e3db31ffcc9cf8c73ed4ec2</id>
  <committed-date>2008-06-23T13:42:31-07:00</committed-date>
  <authored-date>2008-06-23T13:42:31-07:00</authored-date>
  <message>Verbose option in rake tasks for update and reindex</message>
  <tree>c9da414e6f9478e08672564dccf63182cf4a1d52</tree>
  <committer>
    <name>Francis Irving</name>
    <email>francis@flourish.org</email>
  </committer>
</commit>
