Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BL7 Bug Fix - Resolve double facet filter constraint rendering #128

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
inherit_from: .rubocop_todo.yml
require: rubocop-rspec
require: rubocop-rails

AllCops:
DisplayCopNames: true
Expand Down
13 changes: 0 additions & 13 deletions app/views/blacklight_advanced_search/_facet_limit.html.erb
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
<div class="advanced_facet_limit">
<div class="inclusive_or card card-body bg-light mb-3">
<h5>Any of:</h5>
<ul class="list-unstyled facet-values">
<% advanced_query.filters[facet_field.key].each do |value| %>
<li>
<span class="selected"><%= h(value) %></span>
<%= link_to(remove_advanced_facet_param(facet_field.key, value, params), :class => "remove") do %>
<span class="remove-icon"></span>✖<span class="sr-only">[remove]</span>
<% end %>
</li>
<% end %>
</ul>
</div>
<%= render_facet_limit display_facet, :layout => nil, :partial => advanced_search_facet_partial_name(display_facet) %>
</div>
1 change: 1 addition & 0 deletions blacklight_advanced_search.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Gem::Specification.new do |s|
s.add_development_dependency 'solr_wrapper'
s.add_development_dependency 'engine_cart', "~> 2.0"
s.add_development_dependency 'rubocop'
s.add_development_dependency 'rubocop-rails'
s.add_development_dependency 'rubocop-rspec'
s.add_development_dependency 'rsolr'
end
1 change: 1 addition & 0 deletions lib/blacklight_advanced_search/advanced_search_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module AdvancedSearchBuilder
include Blacklight::SearchFields

def is_advanced_search?
return false unless self.blacklight_config.advanced_search[:url_key].present?
(self.blacklight_config.advanced_search && blacklight_params[:search_field] == self.blacklight_config.advanced_search[:url_key]) || blacklight_params[:f_inclusive]
end

Expand Down
34 changes: 8 additions & 26 deletions lib/blacklight_advanced_search/render_constraints_override.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,6 @@ def render_constraints_query(my_params = params)
end
end

# Over-ride of Blacklight method, provide advanced constraints if needed,
# otherwise call super.
def render_constraints_filters(my_params = params)
content = super(my_params)

if advanced_query
advanced_query.filters.each_pair do |field, value_list|
label = facet_field_label(field)
content << render_constraint_element(label,
safe_join(Array(value_list), " <strong class='text-muted constraint-connector'>OR</strong> ".html_safe),
:remove => search_action_path(remove_advanced_filter_group(field, my_params).except(:controller, :action))
)
end
end

content
end

# override of BL method, so our inclusive facet selections
# are still recgonized for eg highlighting facet with selected
# values.
Expand All @@ -72,14 +54,14 @@ def render_search_to_s_filters(my_params)
content = super(my_params)

advanced_query = BlacklightAdvancedSearch::QueryParser.new(my_params, blacklight_config)

unless advanced_query.filters.empty?
advanced_query.filters.each_pair do |field, values|
# old-style, may still be in history
values = values.keys if values.is_a? Hash

label = facet_field_label(field)

content << render_search_to_s_element(
label,
values.join(" OR ")
Expand All @@ -93,24 +75,24 @@ def render_search_to_s_q(my_params)
content = super(my_params)

advanced_query = BlacklightAdvancedSearch::QueryParser.new(my_params, blacklight_config)

if (advanced_query.keyword_queries.length > 1 &&
advanced_query.keyword_op == "OR")
# Need to do something to make the inclusive-or search clear

display_as = advanced_query.keyword_queries.collect do |field, query|
h(blacklight_config.search_fields[field][:label] + ": " + query)
end.join(" ; ")

content << render_search_to_s_element("Any of",
display_as,
:escape_value => false
)
elsif !advanced_query.keyword_queries.empty?
advanced_query.keyword_queries.each_pair do |field, query|
label = blacklight_config.search_fields[field][:label]

content << render_search_to_s_element(label, query)
content << render_search_to_s_element(label, query)
end
end

Expand Down
1 change: 1 addition & 0 deletions solr/conf/solrconfig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

<!-- solr lib dirs -->
<lib dir="${solr.install.dir:../../../..}/contrib/analysis-extras/lib" />
<lib dir="${solr.install.dir:../../../..}/modules/analysis-extras/lib" />
<lib dir="${solr.install.dir:../../../..}/contrib/analysis-extras/lucene-libs" />

<dataDir>${solr.data.dir:}</dataDir>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,4 @@
let(:advanced_query) do
BlacklightAdvancedSearch::QueryParser.new(params, blacklight_config)
end

describe "#render_constraints_filters" do
before do
allow(helper).to receive(:blacklight_config).and_return(blacklight_config)
allow(helper).to receive(:advanced_query).and_return(advanced_query)
allow(helper).to receive(:search_action_path) do |*args|
search_catalog_path(*args)
end
end

subject(:rendered) { helper.render_constraints_filters({}) }

context 'with an array of facet params' do
let(:params) { ActionController::Parameters.new f_inclusive: { 'type' => ['a'] } }

it "renders nothing" do
expect(rendered).to have_text 'Remove constraint Type: a'
end
end

context 'with scalar facet limit params' do
let(:params) { ActionController::Parameters.new f_inclusive: { 'type' => 'a' } }

it "renders the scalar value" do
expect(rendered).to have_text 'Remove constraint Type: a'
end
end
end
end