Skip to content

Commit

Permalink
Update Blacklight::SearchState methods to not accept source_params; i…
Browse files Browse the repository at this point in the history
…nstead, a new Blacklight::SearchState object should be used
  • Loading branch information
cbeer committed Nov 7, 2015
1 parent 6212647 commit 3c79414
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
2 changes: 1 addition & 1 deletion app/helpers/blacklight/url_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def link_to_previous_search(params)
# @param [Blacklight::SolrResponse::Group]
# @return [Hash]
def add_group_facet_params_and_redirect group
search_state.add_facet_params_and_redirect(group.field, group.key, params)
search_state.add_facet_params_and_redirect(group.field, group.key)
end

# A URL to refworks export, with an embedded callback URL to this app.
Expand Down
2 changes: 1 addition & 1 deletion app/presenters/blacklight/document_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def get_field_values field, field_config, options = {}
end

Array(value).map do |v|
@controller.link_to render_field_value(v, field_config), @controller.search_action_path(@controller.add_facet_params(link_field, v, {}))
@controller.link_to render_field_value(v, field_config), @controller.search_action_path(@controller.search_state.reset.add_facet_params(link_field, v))
end if field
else
value
Expand Down
32 changes: 20 additions & 12 deletions lib/blacklight/search_state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ def initialize(params, blacklight_config)
@blacklight_config = blacklight_config
end

def reset
Blacklight::SearchState.new({}, blacklight_config)
end

def url_for_document(doc, options = {})
if respond_to?(:blacklight_config) and
blacklight_config.show.route and
Expand All @@ -27,8 +31,21 @@ def url_for_document(doc, options = {})
# Does NOT remove request keys and otherwise ensure that the hash
# is suitable for a redirect. See
# add_facet_params_and_redirect
def add_facet_params(field, item, source_params=params)
def add_facet_params(field, item)
p = reset_search_params

if item and item.respond_to?(:fq) and item.fq
Array(item.fq).each do |f, v|
add_facet_param(p, f, v)
end
else
add_facet_param(p, field, item)
end

p
end

def add_facet_param(p, field, item)
if item.respond_to? :field
field = item.field
end
Expand All @@ -39,7 +56,6 @@ def add_facet_params(field, item, source_params=params)

value = facet_value_for_facet_item(item)

p = reset_search_params(source_params)
p[:f] = (p[:f] || {}).dup # the command above is not deep in rails3, !@#$!@#$
p[:f][url_field] = (p[:f][url_field] || []).dup

Expand All @@ -48,14 +64,6 @@ def add_facet_params(field, item, source_params=params)
end

p[:f][url_field].push(value)

if item and item.respond_to?(:fq) and item.fq
Array(item.fq).each do |f,v|
p = add_facet_params(f, v, p)
end
end

p
end

# Used in catalog/facet action, facets.rb view, for a click
Expand Down Expand Up @@ -127,8 +135,8 @@ def params_for_search(params_to_merge={}, &block)
##
# Reset any search parameters that store search context
# and need to be reset when e.g. constraints change
def reset_search_params source_params
Parameters.sanitize(source_params).except(:page, :counter).with_indifferent_access
def reset_search_params
Parameters.sanitize(params).except(:page, :counter).with_indifferent_access
end

# TODO: this code is duplicated in Blacklight::FacetsHelperBehavior
Expand Down

0 comments on commit 3c79414

Please sign in to comment.