Class: Blacklight::AbstractSearchBuilder
- Inherits:
-
Object
- Object
- Blacklight::AbstractSearchBuilder
- Defined in:
- lib/blacklight/abstract_search_builder.rb
Overview
Blacklight’s SearchBuilder converts blacklight request parameters into query parameters appropriate for search index. It does so by evaluating a chain of processing methods to populate a result hash (see #to_hash).
Direct Known Subclasses
Instance Attribute Summary collapse
-
#blacklight_params ⇒ Object
readonly
Returns the value of attribute blacklight_params.
-
#processor_chain ⇒ Object
readonly
Returns the value of attribute processor_chain.
-
#search_state ⇒ Object
readonly
Returns the value of attribute search_state.
Instance Method Summary collapse
- #facet(value = nil) ⇒ Object
-
#facet=(value) ⇒ Object
sets the facet that this query pertains to, for the purpose of facet pagination.
-
#initialize(*options) ⇒ AbstractSearchBuilder
constructor
A new instance of AbstractSearchBuilder.
-
#merge(extra_params) ⇒ Object
Merge additional, repository-specific parameters.
-
#reverse_merge(extra_params) ⇒ Object
“Reverse merge” additional, repository-specific parameters.
-
#to_hash ⇒ Blacklight::Solr::Response
(also: #query, #to_h)
a solr query method.
-
#with(blacklight_params_or_search_state = {}) ⇒ Object
Set the parameters to pass through the processor chain.
Constructor Details
#initialize(scope) ⇒ AbstractSearchBuilder #initialize(processor_chain, scope) ⇒ AbstractSearchBuilder
Returns a new instance of AbstractSearchBuilder.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/blacklight/abstract_search_builder.rb', line 19 def initialize(*) case .size when 1 @processor_chain = default_processor_chain.dup @scope = .first when 2 @processor_chain, @scope = else raise ArgumentError, "wrong number of arguments. (#{.size} for 1..2)" end @blacklight_params = {} search_state_class = @scope.try(:search_state_class) || Blacklight::SearchState @search_state = search_state_class.new(@blacklight_params, @scope&.blacklight_config, @scope) @additional_filters = {} @merged_params = {} @reverse_merged_params = {} end |
Instance Attribute Details
#blacklight_params ⇒ Object (readonly)
Returns the value of attribute blacklight_params.
12 13 14 |
# File 'lib/blacklight/abstract_search_builder.rb', line 12 def blacklight_params @blacklight_params end |
#processor_chain ⇒ Object (readonly)
Returns the value of attribute processor_chain.
12 13 14 |
# File 'lib/blacklight/abstract_search_builder.rb', line 12 def processor_chain @processor_chain end |
#search_state ⇒ Object (readonly)
Returns the value of attribute search_state.
12 13 14 |
# File 'lib/blacklight/abstract_search_builder.rb', line 12 def search_state @search_state end |
Instance Method Details
#facet(value = nil) ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/blacklight/abstract_search_builder.rb', line 56 def facet(value = nil) if value self.facet = value return self end @facet end |
#facet=(value) ⇒ Object
sets the facet that this query pertains to, for the purpose of facet pagination
50 51 52 53 |
# File 'lib/blacklight/abstract_search_builder.rb', line 50 def facet=(value) params_will_change! @facet = value end |
#merge(extra_params) ⇒ Object
Merge additional, repository-specific parameters
66 67 68 69 70 71 72 |
# File 'lib/blacklight/abstract_search_builder.rb', line 66 def merge(extra_params, &) if extra_params params_will_change! @merged_params.merge!(extra_params.to_hash, &) end self end |
#reverse_merge(extra_params) ⇒ Object
“Reverse merge” additional, repository-specific parameters
76 77 78 79 80 81 82 |
# File 'lib/blacklight/abstract_search_builder.rb', line 76 def reverse_merge(extra_params, &) if extra_params params_will_change! @reverse_merged_params.reverse_merge!(extra_params.to_hash, &) end self end |
#to_hash ⇒ Blacklight::Solr::Response Also known as: query, to_h
a solr query method
88 89 90 91 92 93 94 95 |
# File 'lib/blacklight/abstract_search_builder.rb', line 88 def to_hash return @params unless params_need_update? @params = processed_parameters .reverse_merge(@reverse_merged_params) .merge(@merged_params) .tap { clear_changes } end |
#with(blacklight_params_or_search_state = {}) ⇒ Object
Set the parameters to pass through the processor chain
42 43 44 45 46 47 |
# File 'lib/blacklight/abstract_search_builder.rb', line 42 def with(blacklight_params_or_search_state = {}) params_will_change! @search_state = blacklight_params_or_search_state.is_a?(Blacklight::SearchState) ? blacklight_params_or_search_state : @search_state.reset(blacklight_params_or_search_state) @blacklight_params = @search_state.params.dup self end |