Sha256: 72fa2f3d007b3dc0f9a041cf74547f2e0ed89ccd7e18cb9dcbb30340404396b1

Contents?: true

Size: 1.26 KB

Versions: 1

Compression:

Stored size: 1.26 KB

Contents

module Gummi
  module DbLayer
    module Document
      module Search
        module Searching
          extend ActiveSupport::Concern

          included do
            include Virtus.model

            attribute :document_class, Class
            attribute :index,          String, default: lambda { |search, attr| Gummi::DbLayer::DefaultIndex.name }
            attribute :type,           String
            attribute :page,           Gummi::DbLayer::Fields::PositiveInteger, default: 1
            attribute :per_page,       Gummi::DbLayer::Fields::PositiveInteger, default: 300
            attribute :options,        Hash, default: {}
          end

          def to_client_args
            args = {
              index: index,
              from:  from,
              size:  size,
            }
            args[:type]  = type if type
            args.merge options
          end

          def execute
            Gummi::DbLayer::Document::Search::Result.new client.search(to_client_args), document_class, per_page, page
          end

          private

          def size
            per_page
          end

          def from
            per_page * (page - 1)
          end

          def client
            Gummi::API.client
          end

        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gummi-0.2.2 lib/gummi/db_layer/document/search/searching.rb