Skip to content

Commit

Permalink
Move some methods to private visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Oct 17, 2017
1 parent 3544eb8 commit 88e6d74
Showing 1 changed file with 41 additions and 44 deletions.
85 changes: 41 additions & 44 deletions app/services/blacklight/search_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 88e6d74

Please sign in to comment.