Sha256: 44d0b91d7a1a6513cde0e19ea1da174d557269e962fc35d494e60c41b65bd3e8

Contents?: true

Size: 942 Bytes

Versions: 1

Compression:

Stored size: 942 Bytes

Contents

class MultipleModels < Array
  def client
    Elasticsearch::Model.client
  end

  def ancestors
    []
  end

  def default_per_page
    10
  end

  def inspect
    "MultipleModels: #{super}"
  end
end

module Elasticsearch::Model
  # Search multiple models
  #
  def search(query_or_payload, models=[], options={})
    if models.empty?
      models = Object.constants
      .select { |c| Kernel.const_get(c).respond_to?(:__elasticsearch__) }
      .map    { |c| c.is_a?(Class) ? c : Kernel.const_get(c) }
    end

    models = MultipleModels.new(models)

    index_names    = models.map { |c| c.index_name }
    document_types = models.map { |c| c.document_type }

    search = Searching::SearchRequest.new(
                 models,
                 query_or_payload,
                 {index: index_names, type: document_types}.merge(options)
               )

    Response::Response.new(models, search)
  end

  module_function :search
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
georgia-0.8.0 config/initializers/elasticsearch.rb