lib/blacklight/search_builder.rb in blacklight-5.10.3 vs lib/blacklight/search_builder.rb in blacklight-5.11.0
- old
+ new
@@ -1,16 +1,24 @@
module Blacklight
class SearchBuilder
extend Deprecation
self.deprecation_horizon = "blacklight 6.0"
+ class_attribute :default_processor_chain
+ self.default_processor_chain = []
+
attr_reader :processor_chain, :blacklight_params
- # @param [List<Symbol>] processor_chain a list of filter methods to run
+ # @param [List<Symbol>,TrueClass] processor_chain a list of filter methods to run or true, to use the default methods
# @param [Object] scope the scope where the filter methods reside in.
def initialize(processor_chain, scope)
- @processor_chain = processor_chain
+ @processor_chain = if processor_chain === true
+ default_processor_chain.dup
+ else
+ processor_chain
+ end
+
@scope = scope
@blacklight_params = {}
end
##
@@ -54,12 +62,12 @@
# spellcheck.q will be supplied with the [:q] value unless specifically
# specified otherwise.
#
# Incoming parameter :f is mapped to :fq solr parameter.
def processed_parameters
- Blacklight::Solr::Request.new.tap do |request_parameters|
- @processor_chain.each do |method_name|
+ request.tap do |request_parameters|
+ processor_chain.each do |method_name|
if scope.respond_to?(method_name, true)
Deprecation.warn Blacklight::SearchBuilder, "Building search parameters by calling #{method_name} on #{scope.class}. This behavior will be deprecated in Blacklight 6.0. Instead, define #{method_name} on a subclass of #{self.class} and set search_builder_class in the configuration"
scope.send(method_name, request_parameters, blacklight_params)
else
send(method_name, request_parameters)
@@ -71,10 +79,14 @@
def blacklight_config
scope.blacklight_config
end
protected
+ def request
+ Blacklight::Solr::Request.new
+ end
+
def page
if blacklight_params[:page].blank?
1
else
blacklight_params[:page].to_i
@@ -119,12 +131,10 @@
def should_add_field_to_request? field_name, field
field.include_in_request || (field.include_in_request.nil? && blacklight_config.add_field_configuration_to_solr_request)
end
- protected
def scope
@scope
end
-
end
end