Module: AgnosticBackend::Indexable::InstanceMethods

Defined in:
lib/agnostic_backend/indexable/indexable.rb

Instance Method Summary collapse

Instance Method Details

#generate_document(for_index: nil, observer: nil) ⇒ Object



96
97
98
99
100
101
102
103
# File 'lib/agnostic_backend/indexable/indexable.rb', line 96

def generate_document(for_index: nil, observer: nil)
  index_name = for_index.nil? ? self.index_name : for_index.to_s
  return unless respond_to? :_index_content_managers
  manager = _index_content_managers[index_name.to_s]
  raise "Index #{index_name} does not exist" if manager.nil?
  observer ||= AgnosticBackend::Indexable::ObjectObserver.new
  manager.extract_contents_from self, index_name, observer: observer
end

#index_name(source = nil) ⇒ Object



92
93
94
# File 'lib/agnostic_backend/indexable/indexable.rb', line 92

def index_name(source=nil)
  self.class.index_name(source)
end

#index_object(index_name) ⇒ Object



116
117
118
# File 'lib/agnostic_backend/indexable/indexable.rb', line 116

def index_object(index_name)
  put_to_index(index_name)
end

#put_to_index(index_name = nil) ⇒ Object



105
106
107
108
109
110
111
112
113
114
# File 'lib/agnostic_backend/indexable/indexable.rb', line 105

def put_to_index(index_name=nil)
  indexable_class = index_name.nil? ?
                      self.class :
                      AgnosticBackend::Indexable.indexable_class(index_name)

  indexable_class.create_indices.map do |index|
    indexer = index.indexer
    indexer.put(self)
  end
end