-
Notifications
You must be signed in to change notification settings - Fork 253
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract SearchBuilder from SolrHelper
- Loading branch information
Showing
9 changed files
with
610 additions
and
510 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
module Blacklight | ||
class SearchBuilder | ||
# @param [Hash,HashWithIndifferentAccess] user_params the user provided parameters (e.g. query, facets, sort, etc) | ||
# @param [List<Symbol>] processor_chain a list of filter methods to run | ||
# @param [Object] scope the scope where the filter methods reside in. | ||
def initialize(user_params, processor_chain, scope) | ||
@user_params = user_params | ||
@processor_chain = processor_chain | ||
@scope = scope | ||
end | ||
|
||
# a solr query method | ||
# @param [Hash,HashWithIndifferentAccess] extra_controller_params (nil) extra parameters to add to the search | ||
# @return [Blacklight::SolrResponse] the solr response object | ||
def query(extra_params = nil) | ||
extra_params ? processed_parameters.merge(extra_params) : processed_parameters | ||
end | ||
|
||
# @returns a params hash for searching solr. | ||
# The CatalogController #index action uses this. | ||
# Solr parameters can come from a number of places. From lowest | ||
# precedence to highest: | ||
# 1. General defaults in blacklight config (are trumped by) | ||
# 2. defaults for the particular search field identified by params[:search_field] (are trumped by) | ||
# 3. certain parameters directly on input HTTP query params | ||
# * not just any parameter is grabbed willy nilly, only certain ones are allowed by HTTP input) | ||
# * for legacy reasons, qt in http query does not over-ride qt in search field definition default. | ||
# 4. extra parameters passed in as argument. | ||
# | ||
# 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 |solr_parameters| | ||
@processor_chain.each do |method_name| | ||
@scope.send(method_name, solr_parameters, @user_params) | ||
end | ||
end | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.