cloud_search 0.0.4 → 0.0.5
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.
data/lib/cloud_search/config.rb
CHANGED
@@ -1,6 +1,21 @@
|
|
1
1
|
require "singleton"
|
2
2
|
|
3
3
|
module CloudSearch
|
4
|
+
class MissingConfigurationError < StandardError
|
5
|
+
def initialize(parameter_name)
|
6
|
+
super "Missing '#{parameter_name}' configuration parameter"
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
module ConfigurationChecking
|
11
|
+
private
|
12
|
+
|
13
|
+
def check_configuration_parameters
|
14
|
+
raise MissingConfigurationError.new("domain_id") if CloudSearch.config.domain_id.nil?
|
15
|
+
raise MissingConfigurationError.new("domain_name") if CloudSearch.config.domain_name.nil?
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
4
19
|
class Config
|
5
20
|
include Singleton
|
6
21
|
|
data/lib/cloud_search/indexer.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
module CloudSearch
|
2
2
|
class Indexer
|
3
|
+
include ConfigurationChecking
|
4
|
+
|
3
5
|
def initialize
|
4
6
|
@documents = []
|
5
7
|
end
|
@@ -48,6 +50,8 @@ module CloudSearch
|
|
48
50
|
end
|
49
51
|
|
50
52
|
def url
|
53
|
+
check_configuration_parameters
|
54
|
+
|
51
55
|
"#{CloudSearch.config.document_url}/documents/batch"
|
52
56
|
end
|
53
57
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
module CloudSearch
|
2
2
|
class Searcher
|
3
|
+
include ConfigurationChecking
|
3
4
|
|
4
5
|
def search
|
5
6
|
response = SearchResponse.new
|
@@ -74,6 +75,8 @@ module CloudSearch
|
|
74
75
|
end
|
75
76
|
|
76
77
|
def url
|
78
|
+
check_configuration_parameters
|
79
|
+
|
77
80
|
"#{CloudSearch.config.search_url}/search".tap do |u|
|
78
81
|
u.concat("?#{query_parameter}=#{CGI.escape(query)}&size=#{items_per_page}&start=#{start}")
|
79
82
|
u.concat("&return-fields=#{CGI.escape(@fields.join(","))}") unless @fields.nil? or @fields.empty?
|
data/lib/cloud_search/version.rb
CHANGED
@@ -65,6 +65,36 @@ describe CloudSearch::Indexer do
|
|
65
65
|
expect(resp["deletes"]).to eq(0)
|
66
66
|
expect(message).to match(/^200/)
|
67
67
|
end
|
68
|
+
|
69
|
+
context "when the domain id was not configured" do
|
70
|
+
around do |example|
|
71
|
+
domain_id = CloudSearch.config.domain_id
|
72
|
+
CloudSearch.config.domain_id = nil
|
73
|
+
example.call
|
74
|
+
CloudSearch.config.domain_id = domain_id
|
75
|
+
end
|
76
|
+
|
77
|
+
it "raises an error" do
|
78
|
+
expect {
|
79
|
+
indexer.index
|
80
|
+
}.to raise_error(CloudSearch::MissingConfigurationError, "Missing 'domain_id' configuration parameter")
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
context "when the domain name was not configured" do
|
85
|
+
around do |example|
|
86
|
+
domain_name = CloudSearch.config.domain_name
|
87
|
+
CloudSearch.config.domain_name = nil
|
88
|
+
example.call
|
89
|
+
CloudSearch.config.domain_name = domain_name
|
90
|
+
end
|
91
|
+
|
92
|
+
it "raises an error" do
|
93
|
+
expect {
|
94
|
+
indexer.index
|
95
|
+
}.to raise_error(CloudSearch::MissingConfigurationError, "Missing 'domain_name' configuration parameter")
|
96
|
+
end
|
97
|
+
end
|
68
98
|
end
|
69
99
|
|
70
100
|
context "adding a batch of documents" do
|
@@ -140,34 +140,62 @@ describe CloudSearch::Searcher do
|
|
140
140
|
describe "#search" do
|
141
141
|
before do
|
142
142
|
subject
|
143
|
-
|
144
|
-
|
143
|
+
.with_fields(:actor, :director, :title, :year, :text_relevance)
|
144
|
+
.with_query("star wars")
|
145
145
|
end
|
146
146
|
|
147
147
|
around { |example| VCR.use_cassette "search/request/full", &example }
|
148
148
|
|
149
|
-
context "
|
150
|
-
|
151
|
-
|
152
|
-
|
149
|
+
context "when the domain id was not configured" do
|
150
|
+
around do |example|
|
151
|
+
domain_id = CloudSearch.config.domain_id
|
152
|
+
CloudSearch.config.domain_id = nil
|
153
|
+
example.call
|
154
|
+
CloudSearch.config.domain_id = domain_id
|
153
155
|
end
|
154
156
|
|
155
|
-
it "
|
156
|
-
|
157
|
-
|
157
|
+
it "raises an error" do
|
158
|
+
expect {
|
159
|
+
subject.search
|
160
|
+
}.to raise_error(CloudSearch::MissingConfigurationError, "Missing 'domain_id' configuration parameter")
|
158
161
|
end
|
162
|
+
end
|
159
163
|
|
160
|
-
|
161
|
-
|
162
|
-
|
164
|
+
context "when the domain name was not configured" do
|
165
|
+
around do |example|
|
166
|
+
domain_name = CloudSearch.config.domain_name
|
167
|
+
CloudSearch.config.domain_name = nil
|
168
|
+
example.call
|
169
|
+
CloudSearch.config.domain_name = domain_name
|
163
170
|
end
|
164
171
|
|
165
|
-
it "
|
166
|
-
|
167
|
-
|
168
|
-
.
|
172
|
+
it "raises an error" do
|
173
|
+
expect {
|
174
|
+
subject.search
|
175
|
+
}.to raise_error(CloudSearch::MissingConfigurationError, "Missing 'domain_name' configuration parameter")
|
169
176
|
end
|
170
177
|
end
|
178
|
+
|
179
|
+
it "returns http 200 code" do
|
180
|
+
resp = subject.search
|
181
|
+
resp.http_code.should == 200
|
182
|
+
end
|
183
|
+
|
184
|
+
it "has found results" do
|
185
|
+
resp = subject.search
|
186
|
+
resp.should be_found
|
187
|
+
end
|
188
|
+
|
189
|
+
it "returns number of hits" do
|
190
|
+
resp = subject.search
|
191
|
+
expect(resp.hits).to be == 7
|
192
|
+
end
|
193
|
+
|
194
|
+
it "returns Episode II" do
|
195
|
+
resp = subject.search
|
196
|
+
resp.results.inject([]){|acc, i| acc << i['data']['title']}.flatten
|
197
|
+
.should include "Star Wars: Episode II - Attack of the Clones"
|
198
|
+
end
|
171
199
|
end
|
172
200
|
end
|
173
201
|
|