Module: EsSearchable::ClassMethods

Defined in:
lib/es_searchable.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &blk) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/es_searchable.rb', line 45

def method_missing(meth, *args, &blk)
  case meth
  when /(.*)_(gt|lt|gte|lte|between|like)/
    es_collection.send(meth, *args, &blk)
  else
    super
  end
end

Instance Method Details

#clientObject



27
28
29
30
31
# File 'lib/es_searchable.rb', line 27

def client
  @client ||= Elasticsearch::Client.new(EsSearchable.options.slice(
    :log, :retry_on_failure, :reload_on_failure, :hosts, :logger
  ))
end

#es_collectionObject



19
20
21
# File 'lib/es_searchable.rb', line 19

def es_collection
  @es_collection = SearchCollection.new(self)
end

#es_index(index) ⇒ Object



37
38
39
# File 'lib/es_searchable.rb', line 37

def es_index(index)
  @index = index
end

#es_search(conditions) ⇒ Object



33
34
35
# File 'lib/es_searchable.rb', line 33

def es_search(conditions)
  client.search(index: index, body: conditions)
end

#handle_es_response(es_coll) ⇒ Object



23
24
25
# File 'lib/es_searchable.rb', line 23

def handle_es_response(es_coll)
  es_coll
end

#indexObject



41
42
43
# File 'lib/es_searchable.rb', line 41

def index
  @index ||= self.name.demodulize.downcase.pluralize
end