module Gummi module Document module Search module Searching extend ActiveSupport::Concern included do include Virtus.model attribute :type, String attribute :index, String, default: lambda {|search, attr| Gummi::DefaultIndex.name} attribute :page, Gummi::Fields::PositiveInteger, default: 1 attribute :per_page, Gummi::Fields::PositiveInteger, default: 300 attribute :options, Hash, default: {} end def size per_page end def from per_page * (page - 1) end def execute Gummi::Document::Search::Result.new client.search(to_client_args) end def to_client_args args = {} args[:index] = index args[:type] = type if type args[:from] = from args[:size] = size args.merge options end private def client Gummi::API.client end end end end end