diff --git a/lib/blacklight/bookmarks.rb b/lib/blacklight/bookmarks.rb index 7499deb5cc..fb77fd0cf6 100644 --- a/lib/blacklight/bookmarks.rb +++ b/lib/blacklight/bookmarks.rb @@ -22,7 +22,7 @@ module Blacklight::Bookmarks def action_documents bookmarks = token_or_current_or_guest_user.bookmarks bookmark_ids = bookmarks.collect { |b| b.document_id.to_s } - fetch_many(bookmark_ids) + fetch(bookmark_ids) end def action_success_redirect_path @@ -39,7 +39,7 @@ def index @bookmarks = token_or_current_or_guest_user.bookmarks bookmark_ids = @bookmarks.collect { |b| b.document_id.to_s } - @response, @document_list = fetch_many(bookmark_ids) + @response, @document_list = fetch(bookmark_ids) respond_to do |format| format.html { } diff --git a/lib/blacklight/catalog.rb b/lib/blacklight/catalog.rb index 0df291f959..f97167be16 100644 --- a/lib/blacklight/catalog.rb +++ b/lib/blacklight/catalog.rb @@ -106,7 +106,7 @@ def opensearch end def action_documents - fetch_many(params[:id]) + fetch(Array(params[:id])) end def action_success_redirect_path diff --git a/lib/blacklight/search_helper.rb b/lib/blacklight/search_helper.rb index ff0af7acb0..9e6a9ba135 100644 --- a/lib/blacklight/search_helper.rb +++ b/lib/blacklight/search_helper.rb @@ -124,51 +124,20 @@ def query_solr(user_params = params || {}, extra_controller_params = {}) # retrieve a document, given the doc id # @return [Blacklight::SolrResponse, Blacklight::SolrDocument] the solr response object and the first document def fetch(id=nil, extra_controller_params={}) - if id.nil? - Deprecation.warn Blacklight::SearchHelper, "Calling #fetch without an explicit id argument is deprecated and will be removed in Blacklight 6.0" - id ||= params[:id] - end - - old_solr_doc_params = Deprecation.silence(Blacklight::SearchHelper) do - solr_doc_params(id) - end - - if default_solr_doc_params(id) != old_solr_doc_params - Deprecation.warn Blacklight::SearchHelper, "The #fetch method is deprecated. Instead, you should provide a custom SolrRepository implementation for the additional behavior you're offering. The current behavior will be removed in Blacklight 6.0" - extra_controller_params = extra_controller_params.merge(old_solr_doc_params) + if id.is_a? Array + fetch_many(id, params, extra_controller_params) + else + if id.nil? + Deprecation.warn Blacklight::SearchHelper, "Calling #fetch without an explicit id argument is deprecated and will be removed in Blacklight 6.0" + id ||= params[:id] + end + fetch_one(id, extra_controller_params) end - - solr_response = repository.find id, extra_controller_params - [solr_response, solr_response.documents.first] end alias_method :get_solr_response_for_doc_id, :fetch deprecation_deprecate get_solr_response_for_doc_id: "use fetch(id) instead" - ## - # Retrieve a set of documents by id - # @overload fetch_many(ids, extra_controller_params) - # @overload fetch_many(ids, user_params, extra_controller_params) - def fetch_many(ids=[], *args) - if args.length == 1 - user_params = params - extra_controller_params = args.first || {} - else - user_params, extra_controller_params = args - user_params ||= params - extra_controller_params ||= {} - end - - query = search_builder.with(user_params).query(extra_controller_params.merge(solr_document_ids_params(ids))) - solr_response = repository.search(query) - - [solr_response, solr_response.documents] - end - - alias_method :get_solr_response_for_document_ids, :fetch_many - deprecation_deprecate get_solr_response_for_document_ids: "use fetch_many(ids) instead" - - # given a field name and array of values, get the matching SOLR documents # @return [Blacklight::SolrResponse, Array] the solr response object and a list of solr documents def get_solr_response_for_field_values(field, values, extra_controller_params = {}) @@ -286,22 +255,59 @@ def blacklight_solr private - ## - # @deprecated - def default_solr_doc_params(id=nil) - id ||= params[:id] + ## + # Retrieve a set of documents by id + # @overload fetch_many(ids, extra_controller_params) + # @overload fetch_many(ids, user_params, extra_controller_params) + def fetch_many(ids=[], *args) + if args.length == 1 + Deprecation.warn(SearchHelper, "fetch_many with 2 arguments is deprecated") + user_params = params + extra_controller_params = args.first || {} + else + user_params, extra_controller_params = args + user_params ||= params + extra_controller_params ||= {} + end + + query = search_builder.with(user_params).query(extra_controller_params.merge(solr_document_ids_params(ids))) + solr_response = repository.search(query) + + [solr_response, solr_response.documents] + end - # add our document id to the document_unique_id_param query parameter - p = blacklight_config.default_document_solr_params.merge({ - # this assumes the request handler will map the unique id param - # to the unique key field using either solr local params, the - # real-time get handler, etc. - blacklight_config.document_unique_id_param => id - }) + alias_method :get_solr_response_for_document_ids, :fetch_many + deprecation_deprecate get_solr_response_for_document_ids: "use fetch(ids) instead" - p[:qt] ||= blacklight_config.document_solr_request_handler + def fetch_one(id, extra_controller_params) + old_solr_doc_params = Deprecation.silence(Blacklight::SearchHelper) do + solr_doc_params(id) + end - p - end + if default_solr_doc_params(id) != old_solr_doc_params + Deprecation.warn Blacklight::SearchHelper, "The #solr_doc_params method is deprecated. Instead, you should provide a custom SolrRepository implementation for the additional behavior you're offering. The current behavior will be removed in Blacklight 6.0" + extra_controller_params = extra_controller_params.merge(old_solr_doc_params) + end + solr_response = repository.find id, extra_controller_params + [solr_response, solr_response.documents.first] + end + + ## + # @deprecated + def default_solr_doc_params(id=nil) + id ||= params[:id] + + # add our document id to the document_unique_id_param query parameter + p = blacklight_config.default_document_solr_params.merge({ + # this assumes the request handler will map the unique id param + # to the unique key field using either solr local params, the + # real-time get handler, etc. + blacklight_config.document_unique_id_param => id + }) + + p[:qt] ||= blacklight_config.document_solr_request_handler + + p + end end