Skip to content

Commit

Permalink
Merge pull request #1887 from sul-dlss/corylown-patch-1
Browse files Browse the repository at this point in the history
Check that search_state.query_param responds to match?
  • Loading branch information
jcoyne authored Sep 25, 2024
2 parents af2196c + 7f3edf5 commit 1774749
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/models/search_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class SearchBuilder < Blacklight::SearchBuilder
# more advanced search queries. Setting `mm=1` means only 1 clause needs to match, but the lucene query parser (in
# edismax) will precompose the query strings so everything works out.
def min_match_for_boolean(solr_parameters)
return unless search_state.query_param&.match?(/\s(AND|OR|NOT)\s/)
return unless search_state.query_param.respond_to?(:match?) &&
search_state.query_param&.match?(/\s(AND|OR|NOT)\s/)

solr_parameters[:mm] = '1'
end
Expand Down
8 changes: 8 additions & 0 deletions spec/models/search_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,13 @@
expect(solr_parameters[:mm]).to be_nil
end
end

context "when the query isn't a string" do
let(:query) { { q: { a: 1 } } }

it 'does not set min match' do
expect(solr_parameters[:mm]).to be_nil
end
end
end
end

0 comments on commit 1774749

Please sign in to comment.