Sha256: 5892d14e9b9454043d57b7fc2438dc20f81438e7a8917247239a571da91430f7

Contents?: true

Size: 1015 Bytes

Versions: 31

Compression:

Stored size: 1015 Bytes

Contents

# frozen_string_literal: true
class Blacklight::Solr::InvalidParameter < ArgumentError; end

class Blacklight::Solr::Request < ActiveSupport::HashWithIndifferentAccess
  SINGULAR_KEYS = %w(facet fl q qt rows start spellcheck spellcheck.q sort per_page wt hl group defType)
  ARRAY_KEYS = %w(facet.field facet.query facet.pivot fq hl.fl)

  def initialize(constructor = {})
    if constructor.is_a?(Hash)
      super()
      update(constructor)
    else
      super(constructor)
    end
    ARRAY_KEYS.each do |key|
      self[key] ||= []
    end
  end

  def append_filter_query(query)
    self['fq'] << query
  end

  def append_facet_fields(values)
    self['facet.field'] += Array(values)
  end

  def append_facet_query(values)
    self['facet.query'] += Array(values)
  end

  def append_facet_pivot(query)
    self['facet.pivot'] << query
  end

  def append_highlight_field(query)
    self['hl.fl'] << query
  end

  def to_hash
    reject { |key, value| ARRAY_KEYS.include?(key) && value.blank? }
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
blacklight-7.16.0 lib/blacklight/solr/request.rb
blacklight-7.15.2 lib/blacklight/solr/request.rb
blacklight-7.15.1 lib/blacklight/solr/request.rb
blacklight-7.15.0 lib/blacklight/solr/request.rb
blacklight-7.14.1 lib/blacklight/solr/request.rb
blacklight-7.14.0 lib/blacklight/solr/request.rb
blacklight-7.13.2 lib/blacklight/solr/request.rb
blacklight-7.13.1 lib/blacklight/solr/request.rb
blacklight-7.13.0 lib/blacklight/solr/request.rb
blacklight-7.12.1 lib/blacklight/solr/request.rb
blacklight-7.12.0 lib/blacklight/solr/request.rb
blacklight-7.11.1 lib/blacklight/solr/request.rb
blacklight-7.10.0 lib/blacklight/solr/request.rb
blacklight-7.9.0 lib/blacklight/solr/request.rb
blacklight-7.8.1 lib/blacklight/solr/request.rb
blacklight-7.8.0 lib/blacklight/solr/request.rb
blacklight-7.7.0 lib/blacklight/solr/request.rb
blacklight-7.6.0 lib/blacklight/solr/request.rb
blacklight-7.5.1 lib/blacklight/solr/request.rb
blacklight-7.5.0 lib/blacklight/solr/request.rb