Module: Escargot::ActiveRecordExtensions::InstanceMethods
- Defined in:
- lib/escargot/activerecord_ex.rb
Instance Method Summary collapse
-
#delete_from_index ⇒ Object
deletes the document from the index using the appropiate policy (“simple” or “distributed”).
- #local_index_in_elastic_search(options = {}) ⇒ Object
-
#update_index ⇒ Object
updates the index using the appropiate policy.
Instance Method Details
#delete_from_index ⇒ Object
deletes the document from the index using the appropiate policy (“simple” or “distributed”)
161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/escargot/activerecord_ex.rb', line 161 def delete_from_index if self.class.update_index_policy == :immediate_with_refresh self.class.delete_id_from_index(self.id, :refresh => true) # As of Oct 25 2010, :refresh => true is not working self.class.refresh_index() elsif self.class.update_index_policy == :enqueue Resque.enqueue(DistributedIndexing::ReIndexDocuments, self.class.to_s, [self.id]) else self.class.delete_id_from_index(self.id) end end |
#local_index_in_elastic_search(options = {}) ⇒ Object
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/escargot/activerecord_ex.rb', line 173 def local_index_in_elastic_search( = {}) [:index] ||= self.class.index_name [:type] ||= self.class.name.underscore.singularize.gsub(/\//,'-') [:id] ||= self.id.to_s $elastic_search_client.index( self.respond_to?(:indexed_json_document) ? self.indexed_json_document : self.to_json, ) ## !!!!! passing :refresh => true should make ES auto-refresh only the affected ## shards but as of Oct 25 2010 with ES 0.12 && rubberband 0.0.2 that's not the case if [:refresh] self.class.refresh_index([:index]) end end |
#update_index ⇒ Object
updates the index using the appropiate policy
150 151 152 153 154 155 156 157 158 |
# File 'lib/escargot/activerecord_ex.rb', line 150 def update_index if self.class.update_index_policy == :immediate_with_refresh local_index_in_elastic_search(:refresh => true) elsif self.class.update_index_policy == :enqueue Resque.enqueue(DistributedIndexing::ReIndexDocuments, self.class.to_s, [self.id]) else local_index_in_elastic_search end end |