From 88e6d7464b0872de0bda0f410eae508126eb8650 Mon Sep 17 00:00:00 2001 From: Justin Coyne Date: Tue, 17 Oct 2017 08:35:04 +0200 Subject: [PATCH] Move some methods to private visibility --- app/services/blacklight/search_service.rb | 85 +++++++++++------------ 1 file changed, 41 insertions(+), 44 deletions(-) diff --git a/app/services/blacklight/search_service.rb b/app/services/blacklight/search_service.rb index b967960b03..bff97091b6 100644 --- a/app/services/blacklight/search_service.rb +++ b/app/services/blacklight/search_service.rb @@ -7,47 +7,6 @@ def initialize(blacklight_config, user_params = {}) @user_params = user_params end - # TODO: Can this be private? - attr_reader :blacklight_config - - # Override this method to use a search builder other than the one in the config - delegate :search_builder_class, to: :blacklight_config - - def search_builder - search_builder_class.new(self) - end - - ## - # Opensearch autocomplete parameters for plucking a field's value from the results - def solr_opensearch_params(field) - solr_params = {} - solr_params[:rows] ||= 10 - solr_params[:fl] = field || blacklight_config.view_config(:opensearch).title_field - solr_params - end - - ## - # Pagination parameters for selecting the previous and next documents - # out of a result set. - def previous_and_next_document_params(index, window = 1) - solr_params = blacklight_config.document_pagination_params.dup - - if solr_params.empty? - solr_params[:fl] = blacklight_config.document_model.unique_key - end - - if index > 0 - solr_params[:start] = index - window # get one before - solr_params[:rows] = 2 * window + 1 # and one after - else - solr_params[:start] = 0 # there is no previous doc - solr_params[:rows] = 2 * window # but there should be one after - end - - solr_params[:facet] = false - solr_params - end - # a solr query method # @param [Hash] user_params ({}) the user provided parameters (e.g. query, facets, sort, etc) # @yield [search_builder] optional block yields configured SearchBuilder, caller can modify or create new SearchBuilder to be used. Block should return SearchBuilder to be used. @@ -117,17 +76,55 @@ def opensearch_response(field = nil, extra_controller_params = {}) [user_params[:q], response.documents.flat_map { |doc| doc[field] }.uniq] end + delegate :repository, to: :blacklight_config + + private + + attr_reader :user_params, :blacklight_config + + # Override this method to use a search builder other than the one in the config + delegate :search_builder_class, to: :blacklight_config + + def search_builder + search_builder_class.new(self) + end + ## # The key to use to retrieve the grouped field to display def grouped_key_for_results blacklight_config.index.group end - delegate :repository, to: :blacklight_config + ## + # Opensearch autocomplete parameters for plucking a field's value from the results + def solr_opensearch_params(field) + solr_params = {} + solr_params[:rows] ||= 10 + solr_params[:fl] = field || blacklight_config.view_config(:opensearch).title_field + solr_params + end - private + ## + # Pagination parameters for selecting the previous and next documents + # out of a result set. + def previous_and_next_document_params(index, window = 1) + solr_params = blacklight_config.document_pagination_params.dup + + if solr_params.empty? + solr_params[:fl] = blacklight_config.document_model.unique_key + end + + if index > 0 + solr_params[:start] = index - window # get one before + solr_params[:rows] = 2 * window + 1 # and one after + else + solr_params[:start] = 0 # there is no previous doc + solr_params[:rows] = 2 * window # but there should be one after + end - attr_reader :user_params + solr_params[:facet] = false + solr_params + end ## # Retrieve a set of documents by id