Module: ElasticSearchable::ActiveRecordExtensions::LocalMethods
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/elastic_searchable/active_record_extensions.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#as_json_for_index ⇒ Object
document to index in elasticsearch can be overridden by implementing class to customize the content.
-
#percolate(percolator_query = nil) ⇒ Object
percolate this object to see what registered searches match can be done on transient/non-persisted objects! can be done automatically when indexing using :percolate => true config option www.elasticsearch.org/blog/2011/02/08/percolator.html.
-
#percolations ⇒ Object
retuns list of percolation matches found during indexing usable when the model is configured with an :after_index callback.
-
#reindex(lifecycle = nil) ⇒ Object
reindex the object in elasticsearch fires after_index callbacks after operation is complete see www.elasticsearch.org/guide/reference/api/index_.html.
-
#should_index? ⇒ Boolean
flag to tell if this instance should be indexed.
Instance Method Details
#as_json_for_index ⇒ Object
document to index in elasticsearch can be overridden by implementing class to customize the content
216 217 218 219 220 221 222 |
# File 'lib/elastic_searchable/active_record_extensions.rb', line 216 def as_json_for_index original_include_root_in_json = self.class.include_root_in_json self.class.include_root_in_json = false return self.as_json self.class.[:json] ensure self.class.include_root_in_json = original_include_root_in_json end |
#percolate(percolator_query = nil) ⇒ Object
percolate this object to see what registered searches match can be done on transient/non-persisted objects! can be done automatically when indexing using :percolate => true config option www.elasticsearch.org/blog/2011/02/08/percolator.html
234 235 236 237 238 239 |
# File 'lib/elastic_searchable/active_record_extensions.rb', line 234 def percolate(percolator_query = nil) body = {:doc => self.as_json_for_index} body[:query] = percolator_query if percolator_query response = ElasticSearchable.request :get, self.class.index_mapping_path('_percolate'), :json_body => body @percolations = response['matches'] || [] end |
#percolations ⇒ Object
retuns list of percolation matches found during indexing usable when the model is configured with an :after_index callback
195 196 197 |
# File 'lib/elastic_searchable/active_record_extensions.rb', line 195 def percolations @percolations || [] end |
#reindex(lifecycle = nil) ⇒ Object
reindex the object in elasticsearch fires after_index callbacks after operation is complete see www.elasticsearch.org/guide/reference/api/index_.html
202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/elastic_searchable/active_record_extensions.rb', line 202 def reindex(lifecycle = nil) query = {} query[:percolate] = "*" if _percolate_callbacks.any? response = ElasticSearchable.request :put, self.class.index_mapping_path(self.id), :query => query, :json_body => self.as_json_for_index self.index_lifecycle = lifecycle ? lifecycle.to_sym : nil run_callbacks :index @percolations = response['matches'] || [] run_callbacks :percolate if @percolations.any? end |
#should_index? ⇒ Boolean
flag to tell if this instance should be indexed
225 226 227 228 |
# File 'lib/elastic_searchable/active_record_extensions.rb', line 225 def should_index? [self.class.[:if]].flatten.compact.all? { |m| evaluate_elastic_condition(m) } && ![self.class.[:unless]].flatten.compact.any? { |m| evaluate_elastic_condition(m) } end |