Sha256: 19abd91892ce3a83b1a4be31c8cec3e5f830c757f808e32ab5ab1aa7fc350d10
Contents?: true
Size: 1.6 KB
Versions: 2
Compression:
Stored size: 1.6 KB
Contents
module AgnosticBackend class IndexingError < StandardError; end class Indexer attr_reader :index def initialize(index) @index = index end # Sends the specified document to the remote backend. # @param [Indexable] an Indexable object def put(indexable) put_all([indexable]) end # Sends the specified documents to the remote backend # using bulk upload (if supported by the backend) # @param [Indexable] an Indexable object def put_all(indexables) documents = indexables.map do |indexable| generate_document(indexable) end documents.reject!(&:empty?) publish_all(documents) unless documents.empty? end # @param [Indexable] an Indexable object def generate_document(indexable) transform(prepare(indexable.generate_document)) end # Deletes the specified document from the index # @param [document_id] the document id of the indexed document def delete(document_id) delete_all([document_id]) end # Deletes the specified documents from the index. # This is an abstract method which concrete index classes # must implement in order to provide its functionality. # @param [document_ids] an array of document ids def delete_all(document_ids) raise NotImplementedError end def publish(document) publish_all([document]) end def publish_all(documents) raise NotImplementedError end private def transform(document) raise NotImplementedError end def prepare(document) raise NotImplementedError end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
agnostic_backend-1.0.4 | lib/agnostic_backend/indexer.rb |
agnostic_backend-1.0.3 | lib/agnostic_backend/indexer.rb |