Skip to content

Commit

Permalink
Explicitly set q.op for adv search queries
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Aug 29, 2024
1 parent df3498d commit 9a43c88
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app/models/search_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ class SearchBuilder < Blacklight::SearchBuilder
def add_edismax_advanced_parse_q_to_solr(solr_params)
add_advanced_parse_q_to_solr(solr_params)

solr_params[:q] = solr_params[:q].gsub('{!dismax', '{!edismax') if solr_params[:q].respond_to?(:to_str) && solr_params[:q].include?('{!dismax')
return unless solr_params[:q].respond_to?(:to_str) && solr_params[:q].include?('{!dismax')

solr_params[:q] = solr_params[:q].gsub('{!dismax', '{!edismax')

# q.op AND is the default, but we need to set it to 'OR' for advanced search queries.
solr_params[:'q.op'] = 'OR'
end

# Override range limit to only add parameters on search pages, not the home page
Expand Down
1 change: 1 addition & 0 deletions spec/models/search_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
search_builder.add_edismax_advanced_parse_q_to_solr(solr_params)

expect(solr_params[:q]).to eq '_query_:"{!edismax }paintings" AND _query_:"{!edismax mm=1}Dutch Netherlands"'
expect(solr_params[:'q.op']).to eq 'OR'
end
end

Expand Down

0 comments on commit 9a43c88

Please sign in to comment.