Skip to content

Commit

Permalink
Changing solr helper method to do one solr query for records in folde…
Browse files Browse the repository at this point in the history
…r instead of one query per record. This method is now taking in a field parameter so it can be used for other fields in the future.
  • Loading branch information
jkeck committed Oct 12, 2010
1 parent 93b5aa5 commit 33d9fb8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
10 changes: 5 additions & 5 deletions app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,19 @@ def opensearch

# citation action
def citation
@documents = get_solr_response_for_doc_ids(params[:id])
@response, @documents = get_solr_response_for_field_values("id",params[:id])
end
# Email Action (this will only be accessed when the Email link is clicked by a non javascript browser)
def email
@documents = get_solr_response_for_doc_ids(params[:id])
@response, @documents = get_solr_response_for_field_values("id",params[:id])
end
# SMS action (this will only be accessed when the SMS link is clicked by a non javascript browser)
def sms
@documents = get_solr_response_for_doc_ids(params[:id])
@response, @documents = get_solr_response_for_field_values("id",params[:id])
end
# grabs a bunch of documents to export to endnote
def endnote
@documents = get_solr_response_for_doc_ids(params[:id])
@response, @documents = get_solr_response_for_field_values("id",params[:id])
respond_to do |format|
format.endnote
end
Expand All @@ -115,7 +115,7 @@ def librarian_view

# action for sending email. This is meant to post from the form and to do processing
def send_email_record
@documents = get_solr_response_for_doc_ids(params[:id])
@response, @documents = get_solr_response_for_field_values("id",params[:id])
if params[:to]
from = request.host # host w/o port for From address (from address cannot have port#)
host = request.host
Expand Down
19 changes: 12 additions & 7 deletions lib/blacklight/solr_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -227,14 +227,19 @@ def get_solr_response_for_doc_id(id=nil, extra_controller_params={})
[solr_response, document]
end

# gets a list of documents based on the document ids provided
def get_solr_response_for_doc_ids(doc_ids=[], extra_controller_params={})
documents = []
doc_ids.each { |doc_id|
response, document = get_solr_response_for_doc_id(doc_id)
documents << document
# given a field name and array of values, get the matching SOLR documents
def get_solr_response_for_field_values(field, values, extra_controller_params={})
value_str = "(\"" + values.to_a.join("\" OR \"") + "\")"
solr_params = {
:qt => "standard", # need boolean for OR
:q => "#{field}:#{value_str}",
'fl' => "*",
'facet' => 'false',
'spellcheck' => 'false'
}
documents
solr_response = Blacklight.solr.find( self.solr_search_params(solr_params.merge(extra_controller_params)) )
document_list = solr_response.docs.collect{|doc| SolrDocument.new(doc) }
[solr_response,document_list]
end

# returns a params hash for a single facet field solr query.
Expand Down

0 comments on commit 33d9fb8

Please sign in to comment.