Skip to content

Commit

Permalink
Use lucene query parser for search within user-created browse categories
Browse files Browse the repository at this point in the history
  • Loading branch information
marlo-longley committed Jan 13, 2024
1 parent 4272789 commit 546c9c1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
11 changes: 10 additions & 1 deletion app/models/concerns/spotlight/browse_category_search_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,21 @@ def fix_up_browse_category_queries(solr_params)

solr_params.append_query(query) if query.present?

# for a browse category formed from a saved search, the query syntax reads as two "must" values
# e.g. "json"=>{"query"=>{"bool"=>{"must"=>["savedsearchterm", "browsecategorysearchterm"]}}}}
must_values = solr_params.dig(:json, :query, :bool, :must)

# if this the case the query must be parsed by lucene to function
return unless must_values&.any?

solr_params[:defType] = 'lucene'

# This replicates existing spotlight 2.x search behavior, more or less. It
# doesn't take into account the possibility that the browse category query
# could use a different search field (which.. doesn't have an existing UI
# control.. and may require additional upstream work to properly encapsulate
# the two query parameters)
solr_params.dig(:json, :query, :bool, :must)&.map! do |q|
must_values.map! do |q|
q.is_a?(String) ? { edismax: { query: q } } : q
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class BrowseCategoryMockSearchBuilder < Blacklight::SearchBuilder
it 'uses the user-provided query to further restrict the search' do
params = subject.to_hash.with_indifferent_access
expect(params).not_to include(:q)
expect(params).to include(defType: 'lucene')
expect(params).to include(
json: {
query: {
Expand Down

0 comments on commit 546c9c1

Please sign in to comment.