Skip to content

Commit

Permalink
Memoize the search_builder. Fixes #1110
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Feb 24, 2015
1 parent ae5b46c commit 3f552f3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/blacklight/request_builders.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def search_builder_class
end

def search_builder processor_chain = search_params_logic
search_builder_class.new(processor_chain, self)
@search_builder ||= search_builder_class.new(processor_chain, self)
end


Expand Down Expand Up @@ -97,6 +97,7 @@ def solr_document_ids_params(ids = [])
solr_documents_by_field_values_params blacklight_config.document_model.unique_key, ids
end
end
deprecation_deprecate :solr_document_ids_params

##
# Retrieve the results for a list of document ids
Expand Down
7 changes: 7 additions & 0 deletions lib/blacklight/search_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ def with blacklight_params = {}
self
end

##
# Update the :q (query) parameter
def where conditions
@blacklight_params[:q] = conditions
self
end

##
# Append additional processor chain directives
def append *addl_processor_chain
Expand Down
5 changes: 4 additions & 1 deletion lib/blacklight/search_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,10 @@ def fetch_many(ids=[], *args)
extra_controller_params ||= {}
end

query = search_builder.with(user_params).query(extra_controller_params.merge(solr_document_ids_params(ids)))
query = search_builder.
with(user_params).
where(blacklight_config.document_model.unique_key => ids).
query(extra_controller_params.merge(fl: '*'))
solr_response = repository.search(query)

[solr_response, solr_response.documents]
Expand Down

0 comments on commit 3f552f3

Please sign in to comment.