Class: AgnosticBackend::Indexer

Inherits:
Object
  • Object
show all
Defined in:
lib/agnostic_backend/indexer.rb

Direct Known Subclasses

Cloudsearch::Indexer

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(index) ⇒ Indexer

Returns a new instance of Indexer.



6
7
8
# File 'lib/agnostic_backend/indexer.rb', line 6

def initialize(index)
  @index = index
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



4
5
6
# File 'lib/agnostic_backend/indexer.rb', line 4

def index
  @index
end

Instance Method Details

#delete(document_id) ⇒ Object

Deletes the specified document from the index, This is an abstract method which concrete index classes must implement in order to provide its functionality.

Parameters:

  • the (document_id)

    document id of the indexed document

Raises:

  • (NotImplementedError)


30
31
32
# File 'lib/agnostic_backend/indexer.rb', line 30

def delete(document_id)
  raise NotImplementedError
end

#put(indexable) ⇒ Object

Sends the specified document to the remote backend. This is a template method. returns nil if no indexing attempt is made (e.g. generated document is empty)

Parameters:



15
16
17
18
19
20
21
22
23
24
# File 'lib/agnostic_backend/indexer.rb', line 15

def put(indexable)
  document = indexable.generate_document
  return if document.blank?
  begin
    publish(transform(prepare(document)))
    true
  rescue => e
    false
  end
end