lib/ddr/index/query.rb in ddr-models-2.4.0.rc2 vs lib/ddr/index/query.rb in ddr-models-2.4.0.rc3

- old
+ new

@@ -1,11 +1,20 @@ +require "virtus" +require "forwardable" + module Ddr::Index class Query + include Virtus.model + extend Forwardable - attr_reader :q, :fields, :filters, :sort, :rows + attribute :q, String + attribute :fields, Array[String], default: [ ] + attribute :filters, Array[Filter], default: [ ] + attribute :sort, Array[String], default: [ ] + attribute :rows, Integer - delegate :count, :docs, :pids, :each_pid, :all, to: :result + def_delegators :result, :count, :docs, :pids, :each_pid, :all def inspect "#<#{self.class.name} q=#{q.inspect}, filters=#{filters.inspect}," \ " sort=#{sort.inspect}, rows=#{rows.inspect}, fields=#{fields.inspect}>" end @@ -13,15 +22,10 @@ def to_s URI.encode_www_form(params) end def params - { q: q, - fq: filters.map(&:clauses).flatten, - fl: fields.join(","), - sort: sort.join(","), - rows: rows, - }.select { |k, v| v.present? } + QueryParams.new(self).params end def result QueryResult.new(self) end