Skip to content

Commit 5e8327c

Browse files
authored
Merge pull request #3463 from projectblacklight/3462-empty-query-after-advanced-search-sends-null-params-to-solr
Check for present query when appending boolean params
2 parents a753cd9 + 511c1f2 commit 5e8327c

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/blacklight/solr/request.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def append_boolean_query(bool_operator, query)
3636
self[:json][:query] ||= { bool: { bool_operator => [] } }
3737
self[:json][:query][:bool][bool_operator] ||= []
3838

39-
if self['q']
39+
if self['q'].present?
4040
self[:json][:query][:bool][:must] ||= []
4141
self[:json][:query][:bool][:must] << self['q']
4242
delete 'q'

spec/models/blacklight/solr/request_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,12 @@
6464

6565
expect(subject.dig('json', 'query', 'bool', 'must')).to contain_exactly('some query', 'also required')
6666
end
67+
68+
it 'filters out empty query' do
69+
subject['q'] = ""
70+
subject.append_boolean_query :must, 'present query'
71+
72+
expect(subject.dig('json', 'query', 'bool', 'must')).to contain_exactly('present query')
73+
end
6774
end
6875
end

0 commit comments

Comments
 (0)