From mboxrd@z Thu Jan 1 00:00:00 1970 From: rlane@club.cc.cmu.edu (Rich Lane) Date: Sun, 16 Aug 2009 12:35:31 -0700 Subject: [sup-talk] [PATCH 2/2] xapian index format versioning In-Reply-To: <1250451331-16070-1-git-send-email-rlane@club.cc.cmu.edu> References: <1250451331-16070-1-git-send-email-rlane@club.cc.cmu.edu> Message-ID: <1250451331-16070-2-git-send-email-rlane@club.cc.cmu.edu> --- lib/sup/xapian_index.rb | 13 ++++++++++++- 1 files changed, 12 insertions(+), 1 deletions(-) diff --git a/lib/sup/xapian_index.rb b/lib/sup/xapian_index.rb index 825e7a3..c4989e4 100644 --- a/lib/sup/xapian_index.rb +++ b/lib/sup/xapian_index.rb @@ -8,6 +8,7 @@ module Redwood # for searching due to precomputing thread membership. class XapianIndex < BaseIndex STEM_LANGUAGE = "english" + INDEX_VERSION = '1' ## dates are converted to integers for xapian, and are used for document ids, ## so we must ensure they're reasonably valid. this typically only affect @@ -22,7 +23,17 @@ class XapianIndex < BaseIndex end def load_index - @xapian = Xapian::WritableDatabase.new(File.join(@dir, "xapian"), Xapian::DB_CREATE_OR_OPEN) + path = File.join(@dir, 'xapian') + if File.exists? path + @xapian = Xapian::WritableDatabase.new(path, Xapian::DB_OPEN) + db_version = @xapian.get_metadata 'version' + if db_version != INDEX_VERSION + fail "Index version #{db_version.inspect} is different than Sup version #{INDEX_VERSION.inspect}" + end + else + @xapian = Xapian::WritableDatabase.new(path, Xapian::DB_CREATE) + @xapian.set_metadata 'version', INDEX_VERSION + end @term_generator = Xapian::TermGenerator.new() @term_generator.stemmer = Xapian::Stem.new(STEM_LANGUAGE) @enquire = Xapian::Enquire.new @xapian -- 1.6.4