Skip to content

Commit

Permalink
Merge branch 'blacklight-upgrades' of github.com:cul/clio-spectrum in…
Browse files Browse the repository at this point in the history
…to blacklight-upgrades
  • Loading branch information
marquis committed Aug 16, 2016
2 parents a1afa75 + dee070e commit 11d6f9f
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 28 deletions.
6 changes: 4 additions & 2 deletions app/controllers/browse_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,10 @@ def get_items_by_key(fieldname, fieldvalue, count)
# Run the query in slices, merge them.
solr_document_list = []
key_list.each_slice(20) { |slice|
# response, slice_document_list = get_solr_response_for_field_values(fieldname, slice, solr_params)
response, slice_document_list = fetch(slice, solr_params)
browse_field_param = { fieldname => slice }
# raise
# request all fields, so that shelfkey comes back
response, slice_document_list = search_results(solr_params.merge(q: browse_field_param, fl: '*').with_indifferent_access)
solr_document_list += slice_document_list
}

Expand Down
16 changes: 10 additions & 6 deletions app/helpers/advanced_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@ def change_params_and_redirect(changed_params, reg_params = params)
end

def standard_hidden_keys_for_search
# advice from: https://groups.google.com/forum/#!topic/hydra-tech/4PeyyiZ8VNY
# search_as_hidden_fields(omit_keys: [:q, :search_field, :qt, :page, :categories, :advanced_operator, :adv, :advanced]).html_safe
omit = [:q, :search_field, :qt, :page, :categories,
:advanced_operator, :adv, :advanced]
# http://apidock.com/rails/Hash/except#1507-Passing-an-array-of-keys-to-exclude-
render_hash_as_hidden_fields(params_for_search.except(*omit))
# # advice from: https://groups.google.com/forum/#!topic/hydra-tech/4PeyyiZ8VNY
# # search_as_hidden_fields(omit_keys: [:q, :search_field, :qt, :page, :categories, :advanced_operator, :adv, :advanced]).html_safe
# omit = [:q, :search_field, :qt, :page, :categories,
# :advanced_operator, :adv, :advanced]
# # http://apidock.com/rails/Hash/except#1507-Passing-an-array-of-keys-to-exclude-
# render_hash_as_hidden_fields(params_for_search.except(*omit))

# BL 6
render_hash_as_hidden_fields(search_state.params_for_search.except(:q, :search_field, :qt, :page, :utf8, :categories,
:advanced_operator, :adv, :advanced))
end

# Unused?
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/cul_catalog_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@ def catalog_per_page_link(per_page)
current_per_page = @response.rows || 25

# we need these to compute the correct new_page_number, below.
current_page = [params_for_search[:page].to_i, 1].max
current_page = [search_state.params_for_search[:page].to_i, 1].max
first_record_on_page = (current_per_page * (current_page - 1)) + 1

# do the math such that the current 1st item is still in the set
new_page_number = (first_record_on_page / per_page).to_i + 1

href = url_for(params_for_search.merge(rows: per_page, page: new_page_number))
href = url_for(search_state.params_for_search.merge(rows: per_page, page: new_page_number))

per_page_link(href, per_page, current_per_page)
end
Expand Down
35 changes: 20 additions & 15 deletions app/models/search_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,28 @@ class SearchBuilder < Blacklight::SearchBuilder

# NEXT-1043 - Better handling of extremely long queries
def trim_long_queries(solr_parameters)
# raise
if solr_parameters['q']
# Truncate queries longer than N letters
maxLetters = 200
if solr_parameters['q'].size > maxLetters
# flash.now[:error] = "Your query was automatically truncated to the first #{maxLetters} letters. Letters beyond this do not help to further narrow the result set."
solr_parameters['q'] = solr_parameters['q'].first(maxLetters)
end

# Truncate queries longer than N words
maxTerms = 30
terms = solr_parameters['q'].split(' ')
if terms.size > maxTerms
# flash.now[:error] = "Your query was automatically truncated to the first #{maxTerms} words. Terms beyond this do not help to further narrow the result set."
solr_parameters['q'] = terms[0,maxTerms].join(' ')
end
# If there's no 'q', don't do anything
return unless solr_parameters['q']

# For shelf-browse we construct monstrous queries against the shelfkey field
return if solr_parameters['q'].include? "shelfkey:"

# Truncate queries longer than N letters
maxLetters = 200
if solr_parameters['q'].size > maxLetters
# flash.now[:error] = "Your query was automatically truncated to the first #{maxLetters} letters. Letters beyond this do not help to further narrow the result set."
solr_parameters['q'] = solr_parameters['q'].first(maxLetters)
end

# Truncate queries longer than N words
maxTerms = 30
terms = solr_parameters['q'].split(' ')
if terms.size > maxTerms
# flash.now[:error] = "Your query was automatically truncated to the first #{maxTerms} words. Terms beyond this do not help to further narrow the result set."
solr_parameters['q'] = terms[0,maxTerms].join(' ')
end

end

def add_debug_to_solr(solr_parameters)
Expand Down
3 changes: 2 additions & 1 deletion app/views/catalog/_index_toolbar.haml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

= fix_catalog_links(render :partial => "paginate_compact", :object => @response)

= fix_catalog_links(link_to image_tag('rss-feed-icon-14x14.png', :size => "13x13"), catalog_index_path(params.merge(:format => 'atom')), :class => "rss-feed hidden-xs")
-# = fix_catalog_links(link_to image_tag('rss-feed-icon-14x14.png', :size => "13x13"), catalog_index_path(params.merge(:format => 'atom')), :class => "rss-feed hidden-xs")
= fix_catalog_links(link_to image_tag('rss-feed-icon-14x14.png', :size => "13x13"), catalog_index_path(search_state.params_for_search(format: 'atom')), :class => "rss-feed hidden-xs")



Expand Down
2 changes: 1 addition & 1 deletion app/views/catalog/_sort_widget.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<ul class="dropdown-menu">

<%- blacklight_config.sort_fields.each do |sort_key, field| %>
<li><%= link_to(field.label, url_for(params_for_search.merge(:sort => sort_key))) %></li>
<li><%= link_to(field.label, url_for(search_state.params_for_search.merge(:sort => sort_key))) %></li>
<%- end -%>

</ul>
Expand Down
2 changes: 1 addition & 1 deletion app/views/spectrum/_aggregate.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

- else
-# Async == YES, that is, all current traffic comes here
.result_set.async_result_set{:"data-result-set" => spectrum_searchjson_path(sanitize_search_params(params).to_hash.merge(:datasource => search['source'] )), :"data-source" => search['source']}
.result_set.async_result_set{:"data-result-set" => spectrum_searchjson_path(Blacklight::Parameters.sanitize(params).to_hash.merge(:datasource => search['source'] )), :"data-source" => search['source']}
= render partial: "/spectrum/aggregate/result_header_async", locals: {source: search['source'], result: result, title: source['title'], description: source['description']}
= render partial: '/datasource_warning', locals: {warning: warning}
Expand Down

0 comments on commit 11d6f9f

Please sign in to comment.