Module: ElasticSearchable

Includes:
HTTParty
Defined in:
lib/elastic_searchable.rb,
lib/elastic_searchable/index.rb,
lib/elastic_searchable/queries.rb,
lib/elastic_searchable/version.rb,
lib/elastic_searchable/callbacks.rb,
lib/elastic_searchable/paginator.rb,
lib/elastic_searchable/pagination/kaminari.rb,
lib/elastic_searchable/active_record_extensions.rb,
lib/elastic_searchable/pagination/will_paginate.rb

Defined Under Namespace

Modules: ActiveRecordExtensions, Callbacks, Indexing, Pagination, Queries Classes: ElasticError, Paginator

Constant Summary collapse

DEFAULT_INDEX =
'elastic_searchable'
VERSION =
'1.4.0'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.default_indexObject

Returns the value of attribute default_index.



14
15
16
# File 'lib/elastic_searchable.rb', line 14

def default_index
  @default_index
end

.loggerObject

Returns the value of attribute logger.



14
15
16
# File 'lib/elastic_searchable.rb', line 14

def logger
  @logger
end

.offline(&block) ⇒ Object

execute a block of work without reindexing objects



17
18
19
# File 'lib/elastic_searchable.rb', line 17

def offline
  @offline
end

Class Method Details

.encode_json(options = {}) ⇒ Object

encapsulate encoding hash into json string support Yajl encoder if installed



28
29
30
# File 'lib/elastic_searchable.rb', line 28

def encode_json(options = {})
  MultiJson.encode options
end

.escape_query(string) ⇒ Object

escape lucene special characters



46
47
48
# File 'lib/elastic_searchable.rb', line 46

def escape_query(string)
  string.to_s.gsub(/([\(\)\[\]\{\}\?\\\"!\^\+\-\*:~])/,'\\\\\1')
end

.offline?Boolean

Returns:

  • (Boolean)


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

def offline?
  !!@offline
end

.request(method, url, options = {}) ⇒ Object

perform a request to the elasticsearch server configuration: ElasticSearchable.base_uri ‘host:port’ controls where to send request to ElasticSearchable.debug_output outputs all http traffic to console



35
36
37
38
39
40
41
42
43
# File 'lib/elastic_searchable.rb', line 35

def request(method, url, options = {})
  options.merge! :headers => {'Content-Type' => 'application/json'}
  options.merge! :body => ElasticSearchable.encode_json(options.delete(:json_body)) if options[:json_body]

  response = self.send(method, url, options)
  logger.debug "elasticsearch request: #{method} #{url} #{"took #{response['took']}ms" if response['took']}"
  validate_response response
  response
end