active-fedora 11.4.1 → 11.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/active_fedora/solr_service.rb +15 -1
- data/lib/active_fedora/version.rb +1 -1
- data/spec/unit/solr_service_spec.rb +34 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 92d0034bbac0025de2d37bbc3c2338dfe7845c26
|
4
|
+
data.tar.gz: adcd29bb2e0243dc8cb72de4196fda37eddfade4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91406a7de60279f1e5c78d4e99d62eb8357e76c31dd62ac56b854198a7fb980b08ddaa52e003cd7fe225b75936e98cbc16c57b2a911cb8b69934f67ccb44a18a
|
7
|
+
data.tar.gz: fad213756426a2855107a96a1a8f95abea32220b1eb283ba67a53deb9842c2284ffd195e499bc731068aac122e55c69f6621b433c0d58cfa01a159b9d0738107
|
@@ -44,9 +44,23 @@ module ActiveFedora
|
|
44
44
|
SolrService.instance.conn.get(select_path, params: args)
|
45
45
|
end
|
46
46
|
|
47
|
+
def post(query, args = {})
|
48
|
+
args = args.merge(q: query, qt: 'standard')
|
49
|
+
SolrService.instance.conn.post(select_path, data: args)
|
50
|
+
end
|
51
|
+
|
47
52
|
def query(query, args = {})
|
48
53
|
Base.logger.warn "Calling ActiveFedora::SolrService.get without passing an explicit value for ':rows' is not recommended. You will end up with Solr's default (usually set to 10)\nCalled by #{caller[0]}" unless args.key?(:rows)
|
49
|
-
|
54
|
+
method = args.delete(:method) || :get
|
55
|
+
|
56
|
+
result = case method
|
57
|
+
when :get
|
58
|
+
get(query, args)
|
59
|
+
when :post
|
60
|
+
post(query, args)
|
61
|
+
else
|
62
|
+
raise "Unsupported HTTP method for querying SolrService (#{method.inspect})"
|
63
|
+
end
|
50
64
|
result['response']['docs'].map do |doc|
|
51
65
|
ActiveFedora::SolrHit.new(doc)
|
52
66
|
end
|
@@ -65,14 +65,48 @@ describe ActiveFedora::SolrService do
|
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
|
+
describe "#post" do
|
69
|
+
it "calls solr" do
|
70
|
+
stub_result = double("Result")
|
71
|
+
expect(mock_conn).to receive(:post).with('select', data: { q: 'querytext', qt: 'standard' }).and_return(stub_result)
|
72
|
+
allow(described_class).to receive(:instance).and_return(double("instance", conn: mock_conn))
|
73
|
+
expect(described_class.post('querytext')).to eq stub_result
|
74
|
+
end
|
75
|
+
it "uses select_path" do
|
76
|
+
stub_result = double("Result")
|
77
|
+
expect(mock_conn).to receive(:post).with('select_test', data: { q: 'querytext', qt: 'standard' }).and_return(stub_result)
|
78
|
+
expect(described_class).to receive(:select_path).and_return('select_test')
|
79
|
+
allow(described_class).to receive(:instance).and_return(double("instance", conn: mock_conn))
|
80
|
+
expect(described_class.post('querytext')).to eq stub_result
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
68
84
|
describe "#query" do
|
69
85
|
let(:doc) { { 'id' => 'x' } }
|
70
86
|
let(:docs) { [doc] }
|
71
87
|
let(:stub_result) { { 'response' => { 'docs' => docs } } }
|
88
|
+
|
72
89
|
before do
|
73
90
|
allow(described_class).to receive(:instance).and_return(double("instance", conn: mock_conn))
|
74
91
|
end
|
75
92
|
|
93
|
+
it "defaults to HTTP GET method" do
|
94
|
+
expect(mock_conn).to receive(:get).with('select', params: { rows: 2, q: 'querytext', qt: 'standard' }).and_return(stub_result)
|
95
|
+
described_class.query('querytext', rows: 2)
|
96
|
+
end
|
97
|
+
|
98
|
+
it "allows callers to specify HTTP POST method" do
|
99
|
+
expect(mock_conn).to receive(:post).with('select', data: { rows: 2, q: 'querytext', qt: 'standard' }).and_return(stub_result)
|
100
|
+
described_class.query('querytext', rows: 2, method: :post)
|
101
|
+
end
|
102
|
+
|
103
|
+
it "raises if method not GET or POST" do
|
104
|
+
expect(mock_conn).not_to receive(:head).with('select', data: { rows: 2, q: 'querytext', qt: 'standard' })
|
105
|
+
expect {
|
106
|
+
described_class.query('querytext', rows: 2, method: :head)
|
107
|
+
}.to raise_error(RuntimeError, "Unsupported HTTP method for querying SolrService (:head)")
|
108
|
+
end
|
109
|
+
|
76
110
|
it "wraps the solr response documents in Solr hits" do
|
77
111
|
expect(mock_conn).to receive(:get).with('select', params: { rows: 2, q: 'querytext', qt: 'standard' }).and_return(stub_result)
|
78
112
|
result = described_class.query('querytext', rows: 2)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active-fedora
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 11.
|
4
|
+
version: 11.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Zumwalt
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2017-10-
|
13
|
+
date: 2017-10-12 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rsolr
|