aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/application_controller.rb5
-rw-r--r--vendor/plugins/acts_as_xapian/lib/acts_as_xapian.rb17
2 files changed, 14 insertions, 8 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 1849f23f3..b681f455d 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -363,7 +363,10 @@ class ApplicationController < ActionController::Base
else
@page = this_page
end
- return InfoRequest.full_search(models, @query, order, ascending, collapse, @per_page, @page)
+ result = InfoRequest.full_search(models, @query, order, ascending, collapse, @per_page, @page)
+ result.results # Touch the results to load them, otherwise accessing them from the view
+ # might fail later if the database has subsequently been reopened.
+ return result
end
def get_search_page_from_params
return (params[:page] || "1").to_i
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 ebb3b1cbd..157bdcff2 100644
--- a/vendor/plugins/acts_as_xapian/lib/acts_as_xapian.rb
+++ b/vendor/plugins/acts_as_xapian/lib/acts_as_xapian.rb
@@ -116,17 +116,20 @@ module ActsAsXapian
raise NoXapianRubyBindingsError.new("Xapian Ruby bindings not installed") unless ActsAsXapian.bindings_available
raise "acts_as_xapian hasn't been called in any models" if @@init_values.empty?
- # if DB is not nil, then we're already initialised, so don't do it again
- # XXX we need to reopen the database each time, so Xapian gets changes to it.
- # Hopefully in later version of Xapian it will autodetect this, and this can
- # be commented back in again.
- # return unless @@db.nil?
-
prepare_environment
+ # We need to reopen the database each time, so Xapian gets changes to it.
+ # Calling reopen() does not always pick up changes for reasons that I can
+ # only speculate about at the moment. (It is easy to reproduce this by
+ # changing the code below to use reopen() rather than open() followed by
+ # close(), and running rake spec.)
+ if !@@db.nil?
+ @@db.close
+ end
+ @@db = Xapian::Database.new(@@db_path)
+
# basic Xapian objects
begin
- @@db = Xapian::Database.new(@@db_path)
@@enquire = Xapian::Enquire.new(@@db)
rescue IOError => e
raise "Failed to open Xapian database #{@@db_path}: #{e.message}"