module Elastics::ActiveRecord::HelperMethods::ClassMethods

Public Instance Methods

find_all_ordered(ids, conditions_present = false) click to toggle source

Finds items by ids and returns array in the order in which ids were given. Every missing record is replaced with `nil` in the result. If `conditions_present` is `true` it doesn't add where clause.

# File lib/elastics/active_record/helper_methods.rb, line 25
def find_all_ordered(ids, conditions_present = false)
  relation = conditions_present ? where(id: ids) : self
  items_by_id = relation.index_by(&:id)
  ids.map { |i| items_by_id[i] }
end
index_all_elastics(*args) click to toggle source

Indexes all records in current scope.

# File lib/elastics/active_record/helper_methods.rb, line 32
def index_all_elastics(*args)
  find_in_batches(*args) do |batch|
    index_batch_elastics(batch)
  end
end
reindex_elastics(options = {}) click to toggle source

Reindexes records with `#index_all_elastics`. If model has scope named `reindex_scope`, this method will apply it.

Also supports `:updated_after` option to reindex only updated records. Nothing is performed when `:updated_after` is set but model has not `updated_at` column.

# File lib/elastics/active_record/helper_methods.rb, line 44
def reindex_elastics(options = {})
  scope = respond_to?(:reindex_scope) ? reindex_scope : all
  if after = options.delete(:updated_after)
    if updated_at = arel_table[:updated_at]
      scope = scope.where(updated_at.gt(after))
    else
      return
    end
  end
  scope.index_all_elastics(options)
end
search_elastics(data = {}, options = {}) click to toggle source

Performs `_search` request on type and instantiates result object. SearchResult is a default result class. It can be overriden with :result_class option.

Calls superclass method
# File lib/elastics/active_record/helper_methods.rb, line 16
def search_elastics(data = {}, options = {})
  options[:result_class] ||= SearchResult
  options[:model] = self
  super
end