Sha256: 89f7d4ced71cd703434ed244aed4b6a8216293e540f21583f6d17c52a0521c5b
Contents?: true
Size: 1.64 KB
Versions: 13
Compression:
Stored size: 1.64 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, changed_attrs: []) @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
13 entries across 13 versions & 1 rubygems