Sha256: b962ae228cce3bdadee329c140f402c920317de3f7abc6d922a215be263301be

Contents?: true

Size: 1.62 KB

Versions: 31

Compression:

Stored size: 1.62 KB

Contents

# encoding: utf-8

# This writer collects index change requests but does not submit them immediately to the database.
# The index changes are applied when the commit method is called.
# This writer is intended for internal use only. Do not use it in a xapian configuration!
# @author Gernot Kogler

module XapianDb
  module IndexWriters

    class TransactionalWriter

      attr_reader :index_requests, :delete_requests

      # Constructor
      def initialize
        @index_requests  = []
        @delete_requests = []
      end

      # Update an object in the index
      # @param [Object] obj An instance of a class with a blueprint configuration
      def index(obj, commit=false)
        @index_requests << obj
      end

      # Remove a document from the index
      # @param [String] xapian_id The document id
      def delete_doc_with(xapian_id, commit=false)
        @delete_requests << xapian_id
      end

      # Reindex all objects of a given class
      # @param [Class] klass The class to reindex
      # @param [Hash] options Options for reindexing
      # @option options [Boolean] :verbose (false) Should the reindexing give status informations?
      def reindex_class(klass, options={})
        raise "rebuild_xapian_index is not supported in transactions"
      end

      # Commit all pending changes to the database
      # @param [DirectWriter, BeanstalkWriter] writer The writer to use
      def commit_using(writer)
        @index_requests.each { |obj| writer.index obj, false }
        @delete_requests.each { |xapian_id| writer.delete_doc_with xapian_id, false }
        XapianDb.database.commit
      end

    end

  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
xapian_db-1.3.5.4 lib/xapian_db/index_writers/transactional_writer.rb
xapian_db-1.3.5.3 lib/xapian_db/index_writers/transactional_writer.rb
xapian_db-1.3.5.2 lib/xapian_db/index_writers/transactional_writer.rb
xapian_db-1.3.5.1 lib/xapian_db/index_writers/transactional_writer.rb
xapian_db-1.3.5 lib/xapian_db/index_writers/transactional_writer.rb
xapian_db-1.3.4 lib/xapian_db/index_writers/transactional_writer.rb
xapian_db-1.3.3.1 lib/xapian_db/index_writers/transactional_writer.rb
xapian_db-1.3.3 lib/xapian_db/index_writers/transactional_writer.rb
xapian_db-1.3.2 lib/xapian_db/index_writers/transactional_writer.rb
xapian_db-1.3.1 lib/xapian_db/index_writers/transactional_writer.rb
xapian_db-1.3 lib/xapian_db/index_writers/transactional_writer.rb
xapian_db-1.2.5.1 lib/xapian_db/index_writers/transactional_writer.rb
xapian_db-1.2.5 lib/xapian_db/index_writers/transactional_writer.rb
xapian_db-1.2.4.7 lib/xapian_db/index_writers/transactional_writer.rb
xapian_db-1.2.4.6 lib/xapian_db/index_writers/transactional_writer.rb
xapian_db-1.2.4.5 lib/xapian_db/index_writers/transactional_writer.rb
xapian_db-1.2.4.4 lib/xapian_db/index_writers/transactional_writer.rb
xapian_db-1.2.4.3 lib/xapian_db/index_writers/transactional_writer.rb
xapian_db-1.2.4.2 lib/xapian_db/index_writers/transactional_writer.rb
xapian_db-1.2.4.1 lib/xapian_db/index_writers/transactional_writer.rb