Sha256: 551d92b648a8cc0e2675adcfc2025241aa3ef7c9d21fc53e6cfc6d3ec544b051

Contents?: true

Size: 1.31 KB

Versions: 2

Compression:

Stored size: 1.31 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

2 entries across 2 versions & 1 rubygems

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