From 7f3edf56ac636dec4cec66d97a103eca264e1bdb Mon Sep 17 00:00:00 2001 From: Cory Lown Date: Mon, 23 Sep 2024 17:03:43 -0400 Subject: [PATCH] Check that search_state.query_param responds to match? --- app/models/search_builder.rb | 3 ++- spec/models/search_builder_spec.rb | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/models/search_builder.rb b/app/models/search_builder.rb index ed9ed6f2..58d7044b 100644 --- a/app/models/search_builder.rb +++ b/app/models/search_builder.rb @@ -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 diff --git a/spec/models/search_builder_spec.rb b/spec/models/search_builder_spec.rb index a9f25293..b4d74526 100644 --- a/spec/models/search_builder_spec.rb +++ b/spec/models/search_builder_spec.rb @@ -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