Module: ElasticSearchable
- Includes:
- HTTParty
- Defined in:
- lib/elastic_searchable.rb,
lib/elastic_searchable/version.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, Pagination Classes: ElasticError, Paginator
Constant Summary collapse
- VERSION =
'3.0.2'
- @@offline =
false
Class Attribute Summary collapse
-
.index_name ⇒ Object
Returns the value of attribute index_name.
-
.index_settings ⇒ Object
Returns the value of attribute index_settings.
-
.logger ⇒ Object
Returns the value of attribute logger.
Class Method Summary collapse
-
.backgrounded_options ⇒ Object
options for automatic active record indexing.
- .create_index ⇒ Object
-
.delete_index ⇒ Object
deletes the entire index www.elasticsearch.com/docs/elasticsearch/rest_api/admin/indices/delete_index/.
-
.encode_json(options = {}) ⇒ Object
encapsulate encoding hash into json string support Yajl encoder if installed.
-
.escape_query(string) ⇒ Object
escape lucene special characters.
-
.offline(&block) ⇒ Object
execute a block of work without reindexing objects.
- .offline? ⇒ Boolean
-
.refresh_index ⇒ Object
explicitly refresh the index, making all operations performed since the last refresh available for search.
-
.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.
-
.request_path(action = nil) ⇒ Object
helper method to generate elasticsearch url for this index.
Class Attribute Details
.index_name ⇒ Object
Returns the value of attribute index_name.
13 14 15 |
# File 'lib/elastic_searchable.rb', line 13 def index_name @index_name end |
.index_settings ⇒ Object
Returns the value of attribute index_settings.
13 14 15 |
# File 'lib/elastic_searchable.rb', line 13 def index_settings @index_settings end |
.logger ⇒ Object
Returns the value of attribute logger.
13 14 15 |
# File 'lib/elastic_searchable.rb', line 13 def logger @logger end |
Class Method Details
.backgrounded_options ⇒ Object
options for automatic active record indexing
47 48 49 |
# File 'lib/elastic_searchable.rb', line 47 def {:queue => 'elasticsearch'} end |
.create_index ⇒ Object
58 59 60 61 62 |
# File 'lib/elastic_searchable.rb', line 58 def create_index = {} [:settings] = self.index_settings if self.index_settings self.request :put, self.request_path, :json_body => end |
.delete_index ⇒ Object
deletes the entire index www.elasticsearch.com/docs/elasticsearch/rest_api/admin/indices/delete_index/
74 75 76 |
# File 'lib/elastic_searchable.rb', line 74 def delete_index self.request :delete, self.request_path end |
.encode_json(options = {}) ⇒ Object
encapsulate encoding hash into json string support Yajl encoder if installed
29 30 31 |
# File 'lib/elastic_searchable.rb', line 29 def encode_json( = {}) MultiJson.encode end |
.escape_query(string) ⇒ Object
escape lucene special characters
52 53 54 |
# File 'lib/elastic_searchable.rb', line 52 def escape_query(string) string.to_s.gsub(/([\(\)\[\]\{\}\?\\\"!\^\+\-\*:~])/,'\\\\\1') end |
.offline(&block) ⇒ Object
execute a block of work without reindexing objects
17 18 19 20 21 22 23 |
# File 'lib/elastic_searchable.rb', line 17 def offline(&block) original_value = offline? @@offline = true yield ensure @@offline = original_value end |
.offline? ⇒ Boolean
24 25 26 |
# File 'lib/elastic_searchable.rb', line 24 def offline? !!@@offline end |
.refresh_index ⇒ Object
explicitly refresh the index, making all operations performed since the last refresh available for search
www.elasticsearch.com/docs/elasticsearch/rest_api/admin/indices/refresh/
68 69 70 |
# File 'lib/elastic_searchable.rb', line 68 def refresh_index self.request :post, self.request_path('_refresh') 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
36 37 38 39 40 41 42 43 44 |
# File 'lib/elastic_searchable.rb', line 36 def request(method, url, = {}) .merge! :headers => {'Content-Type' => 'application/json'} .merge! :body => self.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 |
.request_path(action = nil) ⇒ Object
helper method to generate elasticsearch url for this index
79 80 81 |
# File 'lib/elastic_searchable.rb', line 79 def request_path(action = nil) ['', index_name, action].compact.join('/') end |