Skip to content

Commit

Permalink
SearchHelper#fetch method can handle a single id or an array of ids
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Feb 24, 2015
1 parent 419f92d commit a1dc319
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 56 deletions.
4 changes: 2 additions & 2 deletions lib/blacklight/bookmarks.rb
Expand Up @@ -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
Expand All @@ -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 { }
Expand Down
2 changes: 1 addition & 1 deletion lib/blacklight/catalog.rb
Expand Up @@ -106,7 +106,7 @@ def opensearch
end

def action_documents
fetch_many(params[:id])
fetch(Array(params[:id]))
end

def action_success_redirect_path
Expand Down
112 changes: 59 additions & 53 deletions lib/blacklight/search_helper.rb
Expand Up @@ -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<Blacklight::SolrDocument>] the solr response object and a list of solr documents
def get_solr_response_for_field_values(field, values, extra_controller_params = {})
Expand Down Expand Up @@ -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

0 comments on commit a1dc319

Please sign in to comment.