Skip to content

Commit

Permalink
Merge pull request #3463 from projectblacklight/3462-empty-query-afte…
Browse files Browse the repository at this point in the history
…r-advanced-search-sends-null-params-to-solr

Check for present query when appending boolean params
  • Loading branch information
jcoyne authored Dec 10, 2024
2 parents a753cd9 + 511c1f2 commit 5e8327c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/blacklight/solr/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def append_boolean_query(bool_operator, query)
self[:json][:query] ||= { bool: { bool_operator => [] } }
self[:json][:query][:bool][bool_operator] ||= []

if self['q']
if self['q'].present?
self[:json][:query][:bool][:must] ||= []
self[:json][:query][:bool][:must] << self['q']
delete 'q'
Expand Down
7 changes: 7 additions & 0 deletions spec/models/blacklight/solr/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,12 @@

expect(subject.dig('json', 'query', 'bool', 'must')).to contain_exactly('some query', 'also required')
end

it 'filters out empty query' do
subject['q'] = ""
subject.append_boolean_query :must, 'present query'

expect(subject.dig('json', 'query', 'bool', 'must')).to contain_exactly('present query')
end
end
end

0 comments on commit 5e8327c

Please sign in to comment.