diff --git a/app/search_builders/hyrax/collection_search_builder.rb b/app/search_builders/hyrax/collection_search_builder.rb index fcdf1f4e85..66e9f7d9f4 100644 --- a/app/search_builders/hyrax/collection_search_builder.rb +++ b/app/search_builders/hyrax/collection_search_builder.rb @@ -37,6 +37,7 @@ def with_access(access) # This overrides the default 'relevance' sort. def add_sorting_to_solr(solr_parameters) return if solr_parameters[:q] + solr_parameters[:sort] ||= sort solr_parameters[:sort] ||= "#{sort_field} asc" end diff --git a/spec/search_builders/hyrax/collection_search_builder_spec.rb b/spec/search_builders/hyrax/collection_search_builder_spec.rb index ad43678c2e..2310a8e08f 100644 --- a/spec/search_builders/hyrax/collection_search_builder_spec.rb +++ b/spec/search_builders/hyrax/collection_search_builder_spec.rb @@ -70,4 +70,18 @@ end end end + + describe '#add_sorting_to_solr' do + let(:builder_2) { described_class.new(scope).with(blacklight_params) } + let(:blacklight_params) do + { "sort" => "system_create_dtsi desc", "per_page" => "50", "locale" => "en" } + end + let(:solr_parameters) { {} } + + before { builder_2.add_sorting_to_solr(solr_parameters) } + + it 'sets the solr paramters for sorting correctly' do + expect(solr_parameters[:sort]).to eq('system_create_dtsi desc') + end + end end