gsa 0.6.1 → 0.7.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.
data/lib/gsa.rb CHANGED
@@ -8,10 +8,14 @@ require_relative 'gsa/modules/xmlizer'
8
8
  require_relative 'gsa/records_converter'
9
9
  require_relative 'gsa/feeder'
10
10
  require_relative 'gsa/searcher'
11
- require_relative 'gsa/faceter'
12
11
  require_relative 'gsa/search_converter'
13
12
  require_relative 'gsa/uid_extractor'
14
13
  require_relative 'gsa/exceptions'
14
+ require_relative 'gsa/readable_results'
15
+ require_relative 'gsa/readable_results/readable_buckets'
16
+ require_relative 'gsa/readable_results/readable_facets'
17
+ require_relative 'gsa/readable_results/readable_metatags'
18
+ require_relative 'gsa/readable_results/readable_result_sets'
15
19
 
16
20
  require_relative 'defaults'
17
21
  require_relative 'facade'
@@ -0,0 +1,14 @@
1
+ module GSA
2
+ class ReadableResults
3
+ extend Injector
4
+
5
+ def self.extract(search_results)
6
+ search_results[GSA::GOOGLE_SEARCH_PROTOCOL][GSA::RESULTS]
7
+ end
8
+
9
+ def self.parse_core(parsables)
10
+ parsables = [parsables] if parsables.is_a? Hash
11
+ inject_a(parsables) {|parsable| yield(parsable) }
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,19 @@
1
+ module GSA
2
+ class ReadableBuckets < ReadableResults
3
+
4
+ def self.parse(buckets)
5
+ buckets = (buckets.select {|key, value| key == GSA::BUCKET})[GSA::BUCKET]
6
+ parse_core(buckets) {|bucket| convert(bucket) }
7
+ end
8
+
9
+ def self.convert(bucket)
10
+ bucket = Hash[*bucket] if bucket.is_a? Array
11
+ {
12
+ :bucket_value => bucket[GSA::BUCKET_VALUE],
13
+ :bucket_low_range => bucket[GSA::BUCKET_LOW_RANGE],
14
+ :bucket_high_range => bucket[GSA::BUCKET_HIGH_RANGE],
15
+ :bucket_count => bucket[GSA::BUCKET_COUNT]
16
+ }
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,22 @@
1
+ module GSA
2
+ class ReadableFacets < ReadableResults
3
+
4
+ def self.extract(search_results)
5
+ (search_results[GSA::FACETS].select {|key, value| key == GSA::FACET })[GSA::FACET]
6
+ end
7
+
8
+ def self.parse(facets)
9
+ parse_core(facets) {|facet| convert(facet) }
10
+ end
11
+
12
+ def self.convert(facet)
13
+ {
14
+ :facet_raw_name => facet[GSA::FACET_RAW_NAME],
15
+ :facet_display_name => facet[GSA::FACET_DISPLAY_NAME],
16
+ :facet_is_range => facet[GSA::FACET_IS_RANGE],
17
+ :facet_type => facet[GSA::FACET_TYPE],
18
+ :buckets => ReadableBuckets::parse(facet)
19
+ }
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,15 @@
1
+ module GSA
2
+ class ReadableMetatags < ReadableResults
3
+
4
+ def self.parse(metatags)
5
+ parse_core(metatags) {|meta_pair| convert(meta_pair) }
6
+ end
7
+
8
+ def self.convert(meta_pair)
9
+ {
10
+ :meta_name => meta_pair[GSA::META_NAME],
11
+ :meta_value => meta_pair[GSA::META_VALUE]
12
+ }
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,22 @@
1
+ module GSA
2
+ class ReadableResultSets < ReadableResults
3
+
4
+ def self.extract(search_results)
5
+ (search_results.select {|key, value| key == GSA::RESULT })[GSA::RESULT]
6
+ end
7
+
8
+ def self.parse(results_sets)
9
+ parse_core(results_sets) {|set| convert(set) }
10
+ end
11
+
12
+ def self.convert(set)
13
+ {
14
+ :result_number => set[GSA::RESULT_NUMBER],
15
+ :url => set[GSA::URL],
16
+ :title => set[GSA::TITLE],
17
+ :metatags => GSA::ReadableMetatags.parse(set[GSA::METATAGS]),
18
+ :search_result_snippet => set[GSA::SEARCH_RESULT_SNIPPET]
19
+ }
20
+ end
21
+ end
22
+ end
@@ -1,41 +1,18 @@
1
1
  module GSA
2
2
  class SearchConverter
3
- extend Injector
4
3
 
5
4
  def self.convert(convertable)
6
- parse result_sets_from results_param_in convertable
7
- end
8
-
9
- def self.results_param_in(convertable)
10
- convertable[GSA::GOOGLE_SEARCH_PROTOCOL][GSA::RESULTS]
11
- end
12
-
13
- def self.result_sets_from(results)
14
- (results.keep_if {|key, value| key == GSA::RESULT })[GSA::RESULT]
15
- end
5
+ results = GSA::ReadableResults.extract(convertable)
16
6
 
17
- def self.parse(result_sets)
18
-
19
- # if there is only one result, convert to the expected array.
20
- result_sets = [result_sets] if result_sets.is_a? Hash
21
-
22
- inject_a(result_sets) {|set|
23
- {
24
- :result_number => set[GSA::RESULT_NUMBER],
25
- :url => set[GSA::URL],
26
- :title => set[GSA::TITLE],
27
- :metatags => parse_metatags(set[GSA::METATAGS]),
28
- :search_result_snippet => set[GSA::SEARCH_RESULT_SNIPPET]
29
- }
30
- }
31
- end
32
-
33
- def self.parse_metatags(metatags)
34
- inject_a(metatags) {|meta_pair| convert_meta_pair(meta_pair) }
35
- end
7
+ result_sets = GSA::ReadableResultSets.extract(results)
8
+ result_sets = GSA::ReadableResultSets.parse(result_sets)
9
+
10
+ if results.include?(GSA::FACETS)
11
+ facets = GSA::ReadableFacets.extract(results)
12
+ facets = GSA::ReadableFacets.parse(facets)
13
+ end
36
14
 
37
- def self.convert_meta_pair(meta_pair)
38
- {:meta_name => meta_pair[GSA::META_NAME], :meta_value => meta_pair[GSA::META_VALUE]}
15
+ { :result_sets => result_sets, :facets => (facets || GSA::NO_RESULTS) }
39
16
  end
40
17
  end
41
18
  end
@@ -8,9 +8,10 @@ module GSA
8
8
  num = args[:num] || GSA::DEFAULT_NUM
9
9
  output = args[:output] || GSA::DEFAULT_OUTPUT
10
10
  start = args[:start] || GSA::DEFAULT_START
11
+ client = args[:client] || GSA::DEFAULT_CLIENT
11
12
  requiredfields = args[:filters] || nil
12
13
 
13
- search = "#{GSA.base_uri}/search?q=#{query}&filter=#{filter}&getfields=#{getfields}&sort=#{sort}&num=#{num}&start=#{start}&output=#{output}"
14
+ search = "#{GSA.base_uri}/search?q=#{query}&filter=#{filter}&getfields=#{getfields}&sort=#{sort}&num=#{num}&start=#{start}&output=#{output}&client=#{client}"
14
15
  search = "#{search}&requiredfields=#{clean_query(requiredfields)}" if requiredfields
15
16
 
16
17
  search_results = parsed_json( RestClient.get(search) )
@@ -1,3 +1,3 @@
1
1
  module GSA
2
- VERSION = "0.6.1"
2
+ VERSION = "0.7.0"
3
3
  end
@@ -14,6 +14,7 @@ describe GSA do
14
14
  context "many records" do
15
15
 
16
16
  it "successfully adds the records to the gsa index" do
17
+
17
18
  VCR.use_cassette("many_records") do
18
19
  results = GSA.feed(
19
20
  :records => many_records,
@@ -30,6 +31,7 @@ describe GSA do
30
31
  context "a single record" do
31
32
 
32
33
  it "successfully adds the records to the gsa index" do
34
+
33
35
  VCR.use_cassette("single_record") do
34
36
  results = GSA.feed(
35
37
  :records => many_records,
@@ -49,6 +51,7 @@ describe GSA do
49
51
  context "many records" do
50
52
 
51
53
  it "successfully deletes the records from the gsa index" do
54
+
52
55
  VCR.use_cassette("delete_many_records") do
53
56
  results = GSA.feed(
54
57
  :records => many_records,
@@ -66,6 +69,7 @@ describe GSA do
66
69
  context "a single record" do
67
70
 
68
71
  it "successfully deletes the record from the gsa index" do
72
+
69
73
  VCR.use_cassette("delete_single_record") do
70
74
  results = GSA.feed(
71
75
  :records => one_records,
@@ -114,6 +118,7 @@ describe GSA do
114
118
  let(:results_set) { many_results }
115
119
 
116
120
  it "returns many records" do
121
+
117
122
  VCR.use_cassette("many_results_no_filters") do
118
123
  results = GSA.search(query)
119
124
  results.count.should eq results_set.count
@@ -121,6 +126,7 @@ describe GSA do
121
126
  end
122
127
 
123
128
  it "returns results in the expected 'pretty' format" do
129
+
124
130
  VCR.use_cassette("many_results_no_filters") do
125
131
  results = GSA.search(query)
126
132
  results.should eq results_set
@@ -134,16 +140,18 @@ describe GSA do
134
140
  let(:result_set) { one_results }
135
141
 
136
142
  it "returns a single record" do
143
+
137
144
  VCR.use_cassette("single_result_no_filters") do
138
145
  results = GSA.search(query)
139
- results.count.should eq 1
146
+ results[:result_sets].count.should eq 1
140
147
  end
141
148
  end
142
149
 
143
150
  it "returns the single result in the expected 'pretty' format" do
151
+
144
152
  VCR.use_cassette("single_result_no_filters") do
145
153
  results = GSA.search(query)
146
- results.should eq result_set
154
+ results[:result_sets].should eq result_set[:result_sets]
147
155
  end
148
156
  end
149
157
  end
@@ -153,6 +161,7 @@ describe GSA do
153
161
  let(:query) { none_query }
154
162
 
155
163
  it "returns the no record flag" do
164
+
156
165
  VCR.use_cassette("no_result_no_filters") do
157
166
  results = GSA.search(query)
158
167
  results.should eq GSA::NO_RESULTS
@@ -167,23 +176,25 @@ describe GSA do
167
176
 
168
177
  let(:query) { many_query }
169
178
  let(:results_set) { many_results }
170
- let(:filter_name) { "brand" }
171
- let(:filter_value) { "Philips" }
179
+ let(:filter_name) { "attribute_brand" }
180
+ let(:filter_value) { "HLS" }
172
181
  let(:filters) { "#{filter_name}:#{filter_value}" }
173
182
 
174
183
  it "returns less than the unfiltered results" do
184
+
175
185
  VCR.use_cassette("many_results_with_filters") do
176
186
  results = GSA.search(query, :filters => filters)
177
- results.count.should be < results_set.count
187
+ results[:result_sets].count.should be < results_set[:result_sets].count
178
188
  end
179
189
  end
180
190
 
181
191
  it "should only contain results matched in the unfiltered results" do
192
+
182
193
  VCR.use_cassette("many_results_with_filters") do
183
194
  results = GSA.search(query, :filters => filters)
184
195
 
185
196
  filtered_results = []
186
- results_set.each {|result|
197
+ results_set[:result_sets].each {|result|
187
198
  result[:metatags].each {|tag|
188
199
  if tag[:meta_name] == filter_name && tag[:meta_value] == filter_value
189
200
  filtered_results << result
@@ -191,7 +202,7 @@ describe GSA do
191
202
  }
192
203
  }
193
204
 
194
- result_uids = GSA.uids(results, uid)
205
+ result_uids = GSA.uids(results[:result_sets], uid)
195
206
  filtered_uids = GSA.uids(filtered_results, uid)
196
207
  result_uids.should eq filtered_uids
197
208
  end
@@ -202,24 +213,26 @@ describe GSA do
202
213
 
203
214
  let(:query) { many_query }
204
215
  let(:results_set) { many_results }
205
- let(:filter_1_name) { "brand" }
206
- let(:filter_1_value) { "Philips" }
207
- let(:filter_2_name) { "material" }
208
- let(:filter_2_value) { "Brass" }
216
+ let(:filter_1_name) { "attribute_color" }
217
+ let(:filter_1_value) { "Red" }
218
+ let(:filter_2_name) { "attribute_brand" }
219
+ let(:filter_2_value) { "Vickerman" }
209
220
  let(:filters) { "#{filter_1_name}:#{filter_1_value}.#{filter_2_name}:#{filter_2_value}" }
210
221
 
211
222
  it "returns a single filtered result" do
223
+
212
224
  VCR.use_cassette("single_result_with_filters") do
213
225
  results = GSA.search(query, :filters => filters)
214
- results.count.should eq 1
226
+ results[:result_sets].count.should eq 1
215
227
  end
216
228
  end
217
229
 
218
230
  it "returns a result with the expected matching filters" do
231
+
219
232
  VCR.use_cassette("single_result_with_filters") do
220
233
  results = GSA.search(query, :filters => filters)
221
234
 
222
- results.each.inject([]) {|flags, result| result[:metatags].each {|tag|
235
+ results[:result_sets].each.inject([]) {|flags, result| result[:metatags].each {|tag|
223
236
  flags << 1 if tag[:meta_name] == filter_1_name && tag[:meta_value] == filter_1_value
224
237
  flags << 1 if tag[:meta_name] == filter_2_name && tag[:meta_value] == filter_2_value
225
238
  }
@@ -235,6 +248,7 @@ describe GSA do
235
248
  let(:filters) { "brand:FooBar" }
236
249
 
237
250
  it "returns the no record flag" do
251
+
238
252
  VCR.use_cassette("no_result_with_filters") do
239
253
  results = GSA.search(query, :filters => filters)
240
254
  results.should eq GSA::NO_RESULTS
@@ -252,6 +266,7 @@ describe GSA do
252
266
  end
253
267
 
254
268
  it "raises an error" do
269
+
255
270
  expect {
256
271
 
257
272
  GSA.search(query, :filters => filters)
@@ -262,33 +277,6 @@ describe GSA do
262
277
  end
263
278
  end
264
279
 
265
- describe "#facet" do
266
-
267
- let(:results_set) { many_results }
268
-
269
- context "with multiple facets" do
270
-
271
- let(:facetables) { many_facets }
272
- let(:facet_results) { many_facet_results }
273
-
274
- it "returns multiple facets in the expected form" do
275
- results = GSA.facet(results_set, facetables)
276
- results.should eq facet_results
277
- end
278
- end
279
-
280
- context "with a single facet" do
281
-
282
- let(:facetables) { one_facets }
283
- let(:facet_results) { one_facet_results }
284
-
285
- it "returns a single facet in the expected form" do
286
- results = GSA.facet(results_set, facetables)
287
- results.should eq facet_results
288
- end
289
- end
290
- end
291
-
292
280
  describe "#uids" do
293
281
 
294
282
  context "with multiple records passed in" do
@@ -297,7 +285,8 @@ describe GSA do
297
285
  let(:uids) { many_uids }
298
286
 
299
287
  it "returns multiple uids" do
300
- results = GSA.uids(results_set, uid)
288
+
289
+ results = GSA.uids(results_set[:result_sets], uid)
301
290
  results.should eq uids
302
291
  end
303
292
  end
@@ -308,7 +297,8 @@ describe GSA do
308
297
  let(:uids) { one_uids }
309
298
 
310
299
  it "returns a single uid" do
311
- results = GSA.uids(results_set, uid)
300
+
301
+ results = GSA.uids(results_set[:result_sets], uid)
312
302
  results.should eq uids
313
303
  end
314
304
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gsa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel J. Long
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-03 00:00:00.000000000 Z
12
+ date: 2013-10-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -162,17 +162,13 @@ files:
162
162
  - fixtures/cassette_library/single_record.yml
163
163
  - fixtures/cassette_library/single_result_no_filters.yml
164
164
  - fixtures/cassette_library/single_result_with_filters.yml
165
- - fixtures/facets/many.txt
166
- - fixtures/facets/single.txt
167
165
  - fixtures/feeds/15_records.txt
168
166
  - fixtures/feeds/1_records.txt
169
167
  - fixtures/queries/many.txt
170
168
  - fixtures/queries/none.txt
171
169
  - fixtures/queries/single.txt
172
170
  - fixtures/result_sets/many.txt
173
- - fixtures/result_sets/many_facets.txt
174
171
  - fixtures/result_sets/single.txt
175
- - fixtures/result_sets/single_facets.txt
176
172
  - fixtures/uids/many.txt
177
173
  - fixtures/uids/single.txt
178
174
  - gsa.gemspec
@@ -180,10 +176,14 @@ files:
180
176
  - lib/facade.rb
181
177
  - lib/gsa.rb
182
178
  - lib/gsa/exceptions.rb
183
- - lib/gsa/faceter.rb
184
179
  - lib/gsa/feeder.rb
185
180
  - lib/gsa/modules/injector.rb
186
181
  - lib/gsa/modules/xmlizer.rb
182
+ - lib/gsa/readable_results.rb
183
+ - lib/gsa/readable_results/readable_buckets.rb
184
+ - lib/gsa/readable_results/readable_facets.rb
185
+ - lib/gsa/readable_results/readable_metatags.rb
186
+ - lib/gsa/readable_results/readable_result_sets.rb
187
187
  - lib/gsa/records_converter.rb
188
188
  - lib/gsa/search_converter.rb
189
189
  - lib/gsa/searcher.rb