Skip to content

Commit

Permalink
Merge pull request #4405 from sul-dlss/bool-edismax
Browse files Browse the repository at this point in the history
Force boolean parsed queries to use edismax.
  • Loading branch information
cbeer authored Aug 29, 2024
2 parents cb27846 + b88563d commit df3498d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
11 changes: 10 additions & 1 deletion app/models/search_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,21 @@ class SearchBuilder < Blacklight::SearchBuilder
include BlacklightRangeLimit::RangeLimitBuilder
include CJKQuery

self.default_processor_chain += [:add_advanced_parse_q_to_solr, :add_advanced_search_to_solr]
self.default_processor_chain += [:add_edismax_advanced_parse_q_to_solr, :add_advanced_search_to_solr]
self.default_processor_chain += [:database_prefix_search]
self.default_processor_chain += [:modify_params_for_cjk, :modify_params_for_cjk_advanced]
self.default_processor_chain += [:consolidate_home_page_params]
self.default_processor_chain += [:modify_single_term_qf]

# Tweak advanced search's boolean query output to use edismax instead of dismax.
# By using the same (edismax) query parser for advanced search as we do for regular search,
# the search syntax and relevance ranking are consistent.
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')
end

# Override range limit to only add parameters on search pages, not the home page
def add_range_limit_params(*args)
super unless on_home_page?
Expand Down
12 changes: 11 additions & 1 deletion spec/models/search_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
end
end

describe "advanced search" do
context "with an advanced search" do
let(:action_name) { 'advanced_search' }

it "sets the facet limit to -1 (unlimited)" do
Expand All @@ -73,6 +73,16 @@
end
end

context 'with a boolean query' do
let(:blacklight_params) { { q: '(Dutch OR Netherlands) paintings' } }

it 'converts the subquery to edismax' do
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"'
end
end

describe '#consolidate_home_page_params' do
context 'on the home page' do
it 'overrides solr parameters to just the things the home page needs' do
Expand Down

0 comments on commit df3498d

Please sign in to comment.