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
-
.default_index ⇒ Object
Returns the value of attribute default_index.
-
.logger ⇒ Object
Returns the value of attribute logger.
-
.offline(&block) ⇒ Object
execute a block of work without reindexing objects.
Class Method Summary collapse
-
.encode_json(options = {}) ⇒ Object
encapsulate encoding hash into json string support Yajl encoder if installed.
-
.escape_query(string) ⇒ Object
escape lucene special characters.
- .offline? ⇒ Boolean
-
.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.
Class Attribute Details
.default_index ⇒ Object
Returns the value of attribute default_index.
14 15 16 |
# File 'lib/elastic_searchable.rb', line 14 def default_index @default_index end |
.logger ⇒ Object
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( = {}) MultiJson.encode 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
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, = {}) .merge! :headers => {'Content-Type' => 'application/json'} .merge! :body => ElasticSearchable.encode_json(.delete(:json_body)) if [:json_body] response = self.send(method, url, ) logger.debug "elasticsearch request: #{method} #{url} #{"took #{response['took']}ms" if response['took']}" validate_response response response end |