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 Jan 27, 2018
1 parent 633403f commit 14b41a5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 41 deletions.
68 changes: 34 additions & 34 deletions app/services/blacklight/search_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,6 @@ 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 +86,48 @@ 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

##
# 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

attr_reader :user_params
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

##
# Retrieve a set of documents by id
Expand Down
7 changes: 0 additions & 7 deletions spec/services/blacklight/search_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -376,13 +376,6 @@
expect { service.repository.search }.to raise_exception(/Unable to connect to Solr instance/)
end

describe "grouped_key_for_results" do
it "pulls the grouped key out of the config" do
blacklight_config.index.group = 'xyz'
expect(service.grouped_key_for_results).to eq('xyz')
end
end

describe "#previous_and_next_documents_for_search" do
let(:user_params) { { q: '', per_page: 100 } }
before do
Expand Down

0 comments on commit 14b41a5

Please sign in to comment.