Class: AgnosticBackend::Indexer
- Inherits:
-
Object
- Object
- AgnosticBackend::Indexer
- Defined in:
- lib/agnostic_backend/indexer.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#index ⇒ Object
readonly
Returns the value of attribute index.
Instance Method Summary collapse
-
#delete(document_id) ⇒ Object
Deletes the specified document from the index.
-
#delete_all(document_ids) ⇒ Object
Deletes the specified documents from the index.
-
#initialize(index) ⇒ Indexer
constructor
A new instance of Indexer.
-
#put(indexable) ⇒ Object
Sends the specified document to the remote backend.
-
#put_all(indexables) ⇒ Object
Sends the specified documents to the remote backend using bulk upload (if supported by the backend).
Constructor Details
#initialize(index) ⇒ Indexer
Returns a new instance of Indexer.
9 10 11 |
# File 'lib/agnostic_backend/indexer.rb', line 9 def initialize(index) @index = index end |
Instance Attribute Details
#index ⇒ Object (readonly)
Returns the value of attribute index.
7 8 9 |
# File 'lib/agnostic_backend/indexer.rb', line 7 def index @index end |
Instance Method Details
#delete(document_id) ⇒ Object
Deletes the specified document from the index
32 33 34 |
# File 'lib/agnostic_backend/indexer.rb', line 32 def delete(document_id) delete_all([document_id]) end |
#delete_all(document_ids) ⇒ Object
Deletes the specified documents from the index. This is an abstract method which concrete index classes must implement in order to provide its functionality.
40 41 42 |
# File 'lib/agnostic_backend/indexer.rb', line 40 def delete_all(document_ids) raise NotImplementedError end |
#put(indexable) ⇒ Object
Sends the specified document to the remote backend.
15 16 17 |
# File 'lib/agnostic_backend/indexer.rb', line 15 def put(indexable) put_all([indexable]) end |
#put_all(indexables) ⇒ Object
Sends the specified documents to the remote backend using bulk upload (if supported by the backend)
22 23 24 25 26 27 28 |
# File 'lib/agnostic_backend/indexer.rb', line 22 def put_all(indexables) documents = indexables.map do |indexable| transform(prepare(indexable.generate_document)) end documents.reject!(&:empty?) publish_all(documents) unless documents.empty? end |