Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

advanced search updates #286

Closed
wants to merge 5 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix add_advanved_parse_q_to_solr to accept other solr_param[:q] values
rococodogs committed Sep 24, 2019
commit 7ec56762f5f8b9133d01dfae058d6a5920f0b750
9 changes: 8 additions & 1 deletion app/search_builders/spot/catalog_search_builder.rb
Original file line number Diff line number Diff line change
@@ -6,7 +6,14 @@ class CatalogSearchBuilder < ::Hyrax::CatalogSearchBuilder

class_attribute :join_fields
self.join_fields = %w[all_fields full_text advanced]
self.default_processor_chain += [:add_advanced_search_to_solr]
self.default_processor_chain += [:add_advanced_parse_q_to_solr, :add_advanced_search_to_solr]

def add_advanced_parse_q_to_solr(solr_parameters)
super(adv_params = {})

solr_parameters[:q] = [solr_parameters[:q], adv_params[:q]].reject(&:blank?).join(' ')
solr_parameters[:defType] = adv_params[:defType]
end

# Rewrites +BlacklightAdvancedSearch::AdvancedSearch#add_advanced_search_to_solr+
# so that a pre-existing +solr_parameters[:q]+ value isn't truncated by the
25 changes: 24 additions & 1 deletion spec/search_builders/spot/catalog_search_builder_spec.rb
Original file line number Diff line number Diff line change
@@ -7,6 +7,29 @@
let(:params) { { search_field: 'advanced' } }
let(:solr_parameters) { {} }

describe '#add_advanced_parse_q_to_solr' do
before { builder.add_advanced_parse_q_to_solr(solr_parameters) }

# note: the spaces after !dismax are expected
let(:parsed_q) { '_query_:"{!dismax }+q +me" AND NOT _query_:"{!dismax }you"' }
let(:blacklight_params) { { q: 'q AND me NOT you', search_field: 'title' } }

context 'when the only query to exist' do
it 'adds the parsed query to solr_parameters[:q]' do
expect(solr_parameters[:q]).to eq parsed_q
end
end

context 'when not the only query' do
let(:solr_parameters) { { q: 'a previous example' } }

it 'appends the value (rather than truncates)' do
expect(solr_parameters[:q]).to include parsed_q
expect(solr_parameters[:q]).to include 'a previous example'
end
end
end

describe '#add_advanced_search_to_solr' do
before { builder.add_advanced_search_to_solr(solr_parameters) }

@@ -27,7 +50,7 @@
end
end

describe 'show_works_or_works_that_contain_files' do
describe '#show_works_or_works_that_contain_files' do
before { builder.show_works_or_works_that_contain_files(solr_parameters) }

let(:blacklight_params) { params.merge(q: 'a good search') }