Class: XapianDb::IndexWriters::TransactionalWriter
- Inherits:
-
Object
- Object
- XapianDb::IndexWriters::TransactionalWriter
- Defined in:
- lib/xapian_db/index_writers/transactional_writer.rb
Instance Attribute Summary collapse
-
#delete_requests ⇒ Object
readonly
Returns the value of attribute delete_requests.
-
#index_requests ⇒ Object
readonly
Returns the value of attribute index_requests.
Instance Method Summary collapse
-
#commit_using(writer) ⇒ Object
Commit all pending changes to the database.
-
#delete_doc_with(xapian_id, commit = false) ⇒ Object
Remove a document from the index.
-
#index(obj, commit = false, changed_attrs: []) ⇒ Object
Update an object in the index.
-
#initialize ⇒ TransactionalWriter
constructor
Constructor.
-
#reindex_class(klass, options = {}) ⇒ Object
Reindex all objects of a given class.
Constructor Details
#initialize ⇒ TransactionalWriter
Constructor
16 17 18 19 |
# File 'lib/xapian_db/index_writers/transactional_writer.rb', line 16 def initialize @index_requests = [] @delete_requests = [] end |
Instance Attribute Details
#delete_requests ⇒ Object (readonly)
Returns the value of attribute delete_requests.
13 14 15 |
# File 'lib/xapian_db/index_writers/transactional_writer.rb', line 13 def delete_requests @delete_requests end |
#index_requests ⇒ Object (readonly)
Returns the value of attribute index_requests.
13 14 15 |
# File 'lib/xapian_db/index_writers/transactional_writer.rb', line 13 def index_requests @index_requests end |
Instance Method Details
#commit_using(writer) ⇒ Object
Commit all pending changes to the database
43 44 45 46 47 |
# File 'lib/xapian_db/index_writers/transactional_writer.rb', line 43 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 |
#delete_doc_with(xapian_id, commit = false) ⇒ Object
Remove a document from the index
29 30 31 |
# File 'lib/xapian_db/index_writers/transactional_writer.rb', line 29 def delete_doc_with(xapian_id, commit=false) @delete_requests << xapian_id end |
#index(obj, commit = false, changed_attrs: []) ⇒ Object
Update an object in the index
23 24 25 |
# File 'lib/xapian_db/index_writers/transactional_writer.rb', line 23 def index(obj, commit=false, changed_attrs: []) @index_requests << obj end |
#reindex_class(klass, options = {}) ⇒ Object
Reindex all objects of a given class
37 38 39 |
# File 'lib/xapian_db/index_writers/transactional_writer.rb', line 37 def reindex_class(klass, ={}) raise "rebuild_xapian_index is not supported in transactions" end |