From 67e3070434ede01e98648cc247899c8036b02d6e Mon Sep 17 00:00:00 2001 From: Chris Beer Date: Wed, 7 Nov 2018 07:31:55 -0800 Subject: [PATCH] Backport cb4b259 to deprecate behavior removed in 7.x --- .../concerns/blacklight/search_helper.rb | 10 ++++-- lib/blacklight/configuration.rb | 1 + .../blacklight/search_helper_spec.rb | 33 +++++++++++++++---- 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/app/controllers/concerns/blacklight/search_helper.rb b/app/controllers/concerns/blacklight/search_helper.rb index 90657b28b8..bd1245f095 100644 --- a/app/controllers/concerns/blacklight/search_helper.rb +++ b/app/controllers/concerns/blacklight/search_helper.rb @@ -141,8 +141,9 @@ def fetch_many(ids, user_params, extra_controller_params) query = search_builder. with(user_params). where(blacklight_config.document_model.unique_key => ids). - merge(extra_controller_params). - merge(fl: '*') + merge(blacklight_config.fetch_many_document_params || deprecated_fetch_many_document_params). + merge(extra_controller_params) + solr_response = repository.search(query) [solr_response, solr_response.documents] @@ -152,4 +153,9 @@ def fetch_one(id, extra_controller_params) solr_response = repository.find id, extra_controller_params [solr_response, solr_response.documents.first] end + + def deprecated_fetch_many_document_params + Deprecation.warn(self, 'You should configure blacklight_config.fetch_many_document_params; defaulting to { fl: "*" }, but this will be removed in Blacklight 7') + { fl: '*' } + end end diff --git a/lib/blacklight/configuration.rb b/lib/blacklight/configuration.rb index a54d43175a..f3d0cb8d98 100644 --- a/lib/blacklight/configuration.rb +++ b/lib/blacklight/configuration.rb @@ -57,6 +57,7 @@ def default_values #rows: 1 }, document_pagination_params: {}, + fetch_many_document_params: nil, ## # == Response models ## Class for sending and receiving requests from a search index diff --git a/spec/controllers/blacklight/search_helper_spec.rb b/spec/controllers/blacklight/search_helper_spec.rb index 469e6fcd73..ed747a4844 100644 --- a/spec/controllers/blacklight/search_helper_spec.rb +++ b/spec/controllers/blacklight/search_helper_spec.rb @@ -16,13 +16,13 @@ class SearchHelperTestClass include Blacklight::SearchHelper - attr_accessor :blacklight_config - attr_accessor :repository + attr_accessor :blacklight_config, :repository, :search_state - def initialize blacklight_config, conn + def initialize blacklight_config, conn, state self.blacklight_config = blacklight_config self.repository = Blacklight::Solr::Repository.new(blacklight_config) self.repository.connection = conn + self.search_state = search_state end def params @@ -30,11 +30,12 @@ def params end end - subject { SearchHelperTestClass.new blacklight_config, blacklight_solr } + subject { SearchHelperTestClass.new blacklight_config, blacklight_solr, state } let(:blacklight_config) { Blacklight::Configuration.new } let(:copy_of_catalog_config) { ::CatalogController.blacklight_config.deep_copy } let(:blacklight_solr) { RSolr.connect(Blacklight.connection_config.except(:adapter)) } + let(:state) { {} } before(:each) do @all_docs_query = '' @@ -307,6 +308,24 @@ def params end end + describe 'Get multiple documents By Id', integration: true do + let(:doc_id) { '2007020969' } + let(:bad_id) { 'redrum' } + let(:response) { subject.fetch([doc_id]).first } + + before do + blacklight_config.fetch_many_document_params = { fl: 'id,format' } + end + + it 'has the expected value in the id field' do + expect(response.documents.first.id).to eq doc_id + end + + it 'returns all the requested fields' do + expect(response.documents.first['format']).to eq ['Book'] + end + end + # SPECS FOR SPELLING SUGGESTIONS VIA SEARCH describe "Searches should return spelling suggestions", :integration => true do it 'search results for just-poor-enough-query term should have (multiple) spelling suggestions' do @@ -377,7 +396,7 @@ def params it "returns nil if no @response available" do expect(subject.facet_limit_for("some_unknown_field")).to be_nil end - it "gets from @response facet.limit if available" do + it "gets from @response facet.limit if available" do @response = instance_double(Blacklight::Solr::Response, aggregations: { "language_facet" => double(limit: nil) }) subject.instance_variable_set(:@response, @response) blacklight_config.facet_fields['language_facet'].limit = 10 @@ -392,7 +411,7 @@ def params expect(subject.facet_limit_for("language_facet")).to eq 10 end end - + context 'for facet fields with a key that is different from the field name' do let(:blacklight_config) do Blacklight::Configuration.new do |config| @@ -424,7 +443,7 @@ def params it "pulls the grouped key out of the config" do blacklight_config.index.group = 'xyz' expect(subject.grouped_key_for_results).to eq('xyz') - end + end end describe "#get_previous_and_next_documents_for_search" do