diff --git a/app/services/hyrax/solr_service.rb b/app/services/hyrax/solr_service.rb index 1ed3ae8bc7..60861be9e8 100644 --- a/app/services/hyrax/solr_service.rb +++ b/app/services/hyrax/solr_service.rb @@ -46,9 +46,8 @@ def select_path def get(query = nil, **args) # Make Hyrax.config.solr_select_path the default SOLR path solr_path = args.delete(:path) || Hyrax.config.solr_select_path - args = args.merge(q: query) if query.present? + args = args.merge(q: query, qt: 'standard') if query.present? - args = args.merge(qt: 'standard') unless query.blank? connection.get(solr_path, params: args) end @@ -66,9 +65,8 @@ def ping def post(query = nil, **args) # Make Hyrax.config.solr_select_path the default SOLR path solr_path = args.delete(:path) || Hyrax.config.solr_select_path - args = args.merge(q: query) if query.present? + args = args.merge(q: query, qt: 'standard') if query.present? - args = args.merge(qt: 'standard') unless query.blank? connection.post(solr_path, data: args) end diff --git a/spec/services/hyrax/solr_service_spec.rb b/spec/services/hyrax/solr_service_spec.rb index 3665bcd928..a240e5a639 100644 --- a/spec/services/hyrax/solr_service_spec.rb +++ b/spec/services/hyrax/solr_service_spec.rb @@ -15,7 +15,7 @@ describe "#get" do it "calls solr" do stub_result = double("Result") - params = use_valkyrie ? { q: 'querytext' } : { q: 'querytext', qt: 'standard' } + params = { q: 'querytext', qt: 'standard' } expect(mock_conn).to receive(:get).with('select', params: params).and_return(stub_result) allow(described_class).to receive(:instance).and_return(double("instance", conn: mock_conn)) expect(described_class.get('querytext')).to eq stub_result @@ -23,21 +23,11 @@ it "uses args as params" do stub_result = double("Result") - params = use_valkyrie ? { fq: ["id:\"1234\""], q: 'querytext' } : { fq: ["id:\"1234\""], q: 'querytext', qt: 'standard' } + params = { fq: ["id:\"1234\""], q: 'querytext', qt: 'standard' } expect(mock_conn).to receive(:get).with('select', params: params).and_return(stub_result) allow(described_class).to receive(:instance).and_return(double("instance", conn: mock_conn)) expect(described_class.get('querytext', fq: ["id:\"1234\""])).to eq stub_result end - - context "when use_valkyrie: true" do - subject(:service) { described_class.new(use_valkyrie: true) } - - it "uses valkyrie solr based on config query_index_from_valkyrie" do - stub_result = double("Valkyrie Result") - expect(mock_conn).to receive(:get).with('select', params: { q: 'querytext' }).and_return(stub_result) - expect(service.get('querytext')).to eq stub_result - end - end end describe '#ping' do @@ -64,7 +54,7 @@ describe "#post" do it "calls solr" do stub_result = double("Result") - data = use_valkyrie ? { q: 'querytext' } : { q: 'querytext', qt: 'standard' } + data = { q: 'querytext', qt: 'standard' } expect(mock_conn).to receive(:post).with('select', data: data).and_return(stub_result) allow(described_class).to receive(:instance).and_return(double("instance", conn: mock_conn)) expect(described_class.post('querytext')).to eq stub_result @@ -72,7 +62,7 @@ it "uses args as data" do stub_result = double("Result") - data = use_valkyrie ? { fq: ["id:\"1234\""], q: 'querytext' } : { fq: ["id:\"1234\""], q: 'querytext', qt: 'standard' } + data = { fq: ["id:\"1234\""], q: 'querytext', qt: 'standard' } expect(mock_conn).to receive(:post).with('select', data: data).and_return(stub_result) allow(described_class).to receive(:instance).and_return(double("instance", conn: mock_conn)) expect(described_class.post('querytext', fq: ["id:\"1234\""])).to eq stub_result @@ -84,7 +74,7 @@ it "uses valkyrie solr based on config query_index_from_valkyrie" do stub_result = double("Valkyrie Result") - expect(mock_conn).to receive(:post).with('select', data: { q: 'querytext' }).and_return(stub_result) + expect(mock_conn).to receive(:post).with('select', data: { q: 'querytext', qt: 'standard' }).and_return(stub_result) expect(service.post('querytext')).to eq stub_result end @@ -101,25 +91,25 @@ end it "defaults to HTTP POST method" do - data = use_valkyrie ? { rows: 2, q: 'querytext' } : { rows: 2, q: 'querytext', qt: 'standard' } + data = { rows: 2, q: 'querytext', qt: 'standard' } expect(mock_conn).to receive(:post).with('select', data: data).and_return(stub_result) described_class.query('querytext', rows: 2) end it "allows callers to specify HTTP GET method" do - params = use_valkyrie ? { rows: 2, q: 'querytext' } : { rows: 2, q: 'querytext', qt: 'standard' } + params = { rows: 2, q: 'querytext', qt: 'standard' } expect(mock_conn).to receive(:get).with('select', params: params).and_return(stub_result) described_class.query('querytext', rows: 2, method: :get) end it "allows callers to specify HTTP POST method" do - data = use_valkyrie ? { rows: 2, q: 'querytext' } : { rows: 2, q: 'querytext', qt: 'standard' } + data = { rows: 2, q: 'querytext', qt: 'standard' } expect(mock_conn).to receive(:post).with('select', data: data).and_return(stub_result) described_class.query('querytext', rows: 2, method: :post) end it "raises if method not GET or POST" do - data = use_valkyrie ? { rows: 2, q: 'querytext' } : { rows: 2, q: 'querytext', qt: 'standard' } + data = { rows: 2, q: 'querytext', qt: 'standard' } expect(mock_conn).not_to receive(:head).with('select', data: data) expect do described_class.query('querytext', rows: 2, method: :head) @@ -127,7 +117,7 @@ end it "wraps the solr response documents in Solr hits" do - data = use_valkyrie ? { rows: 2, q: 'querytext' } : { rows: 2, q: 'querytext', qt: 'standard' } + data = { rows: 2, q: 'querytext', qt: 'standard' } expect(mock_conn).to receive(:post).with('select', data: data).and_return(stub_result) result = described_class.query('querytext', rows: 2) expect(result.size).to eq 1 @@ -146,7 +136,7 @@ let(:doc) { { 'id' => 'valkyrie-x' } } it "uses valkyrie solr based on config query_index_from_valkyrie" do - expect(mock_conn).to receive(:post).with('select', data: { q: 'querytext' }).and_return(stub_result) + expect(mock_conn).to receive(:post).with('select', data: { q: 'querytext', qt: 'standard' }).and_return(stub_result) result = service.query('querytext') expect(result.first.id).to eq 'valkyrie-x' @@ -268,7 +258,7 @@ let(:stub_result) { { 'response' => { 'numFound' => '2' } } } it "calls solr" do - data = use_valkyrie ? { rows: 0, q: 'querytext' } : { rows: 0, q: 'querytext', qt: 'standard' } + data = { rows: 0, q: 'querytext', qt: 'standard' } expect(mock_conn).to receive(:post).with('select', data: data).and_return(stub_result) allow(described_class).to receive(:instance).and_return(double("instance", conn: mock_conn)) expect(described_class.count('querytext')).to eq 2 @@ -278,7 +268,7 @@ subject(:service) { described_class.new(use_valkyrie: true) } it "uses valkyrie solr based on config query_index_from_valkyrie" do - expect(mock_conn).to receive(:post).with('select', data: { rows: 0, q: 'querytext' }).and_return(stub_result) + expect(mock_conn).to receive(:post).with('select', data: { rows: 0, q: 'querytext', qt: 'standard' }).and_return(stub_result) expect(service.count('querytext')).to eq 2 end end