Skip to content

Commit

Permalink
Merge 67e3070 into 15954ce
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Nov 7, 2018
2 parents 15954ce + 67e3070 commit d98b561
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
10 changes: 8 additions & 2 deletions app/controllers/concerns/blacklight/search_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
1 change: 1 addition & 0 deletions lib/blacklight/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 26 additions & 7 deletions spec/controllers/blacklight/search_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,26 @@
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
{}
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 = ''
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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|
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d98b561

Please sign in to comment.