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.
- #generate_document(indexable) ⇒ Object
-
#initialize(index) ⇒ Indexer
constructor
A new instance of Indexer.
- #publish(document) ⇒ Object
- #publish_all(documents) ⇒ Object
-
#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
38 39 40 |
# File 'lib/agnostic_backend/indexer.rb', line 38 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.
46 47 48 |
# File 'lib/agnostic_backend/indexer.rb', line 46 def delete_all(document_ids) raise NotImplementedError end |
#generate_document(indexable) ⇒ Object
32 33 34 |
# File 'lib/agnostic_backend/indexer.rb', line 32 def generate_document(indexable) transform(prepare(indexable.generate_document)) end |
#publish(document) ⇒ Object
50 51 52 |
# File 'lib/agnostic_backend/indexer.rb', line 50 def publish(document) publish_all([document]) end |
#publish_all(documents) ⇒ Object
54 55 56 |
# File 'lib/agnostic_backend/indexer.rb', line 54 def publish_all(documents) 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 29 |
# File 'lib/agnostic_backend/indexer.rb', line 22 def put_all(indexables) documents = indexables.map do |indexable| generate_document(indexable) end documents.reject!(&:empty?) publish_all(documents) unless documents.empty? end |