inquisitio 1.1.0 → 1.1.1
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/CHANGELOG.md +4 -0
- data/bin/facet_query +9 -9
- data/lib/inquisitio/searcher.rb +33 -17
- data/lib/inquisitio/version.rb +1 -1
- data/test/searcher_test.rb +30 -11
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2441b583d2147a1ae532629e234864e41e647559
|
4
|
+
data.tar.gz: 27392ff3783c2a60312f24d4a20e9da16d87bede
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa1af91095a8da0800a5f66c5deef6c328d17c31bdd2c3005b47081dc1a612e9fc3088da6d8d2b8250f6815b2c14484779aa8f5793cfe81e3c060c90c312b2ce
|
7
|
+
data.tar.gz: 369761c5a03509d7ee631207243d29dbdb79eb743b15e90c1101f9b69238db2c1dc895fe437515070f25662e4a4035b98110317a341f4c25bfdd8158d2bfcd60
|
data/CHANGELOG.md
CHANGED
data/bin/facet_query
CHANGED
@@ -14,18 +14,18 @@ require "inquisitio"
|
|
14
14
|
endpoint = ARGV[0]
|
15
15
|
query = ARGV[1]
|
16
16
|
filter_name = ARGV[2]
|
17
|
-
filter_value =
|
18
|
-
return_fields = [
|
17
|
+
filter_value = ARGV[3]
|
18
|
+
return_fields = [ARGV[4]]
|
19
19
|
|
20
20
|
Inquisitio.config do |config|
|
21
21
|
config.search_endpoint = endpoint
|
22
22
|
end
|
23
23
|
|
24
24
|
puts Inquisitio.search(query,
|
25
|
-
{
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
}
|
25
|
+
{filter_name.to_sym => filter_value.to_sym,
|
26
|
+
:arguments => {:facet => 'genre',
|
27
|
+
'facet-genre-constraints' => 'Animation',
|
28
|
+
'facet-genre-top-n' => '5'
|
29
|
+
},
|
30
|
+
:return_fields => return_fields
|
31
|
+
})
|
data/lib/inquisitio/searcher.rb
CHANGED
@@ -9,6 +9,7 @@ module Inquisitio
|
|
9
9
|
end
|
10
10
|
|
11
11
|
attr_reader :params
|
12
|
+
|
12
13
|
def initialize(params = nil)
|
13
14
|
@params = params || {
|
14
15
|
criteria: [],
|
@@ -28,23 +29,38 @@ module Inquisitio
|
|
28
29
|
end
|
29
30
|
|
30
31
|
def ids
|
31
|
-
@ids ||= map{|r|r['data']['id'].first}.flatten.map(&:to_i)
|
32
|
+
@ids ||= map { |r| r['data']['id'].first }.flatten.map(&:to_i)
|
32
33
|
end
|
33
34
|
|
34
35
|
def records
|
35
|
-
@records
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
36
|
+
return @records unless @records.nil?
|
37
|
+
|
38
|
+
@records = []
|
39
|
+
klasses = {}
|
40
|
+
results.each do |result|
|
41
|
+
klass = result['data']['type'].first
|
42
|
+
id = result['data']['id'].first
|
43
|
+
klasses[klass] ||= []
|
44
|
+
klasses[klass] << id
|
45
|
+
end
|
42
46
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
+
objs = klasses.map { |klass_name, ids|
|
48
|
+
klass_name = klass_name.gsub("_", "::")
|
49
|
+
klass = klass_name.constantize
|
50
|
+
klass.where(id: ids)
|
51
|
+
}.flatten
|
52
|
+
|
53
|
+
results.each do |result|
|
54
|
+
klass_name = result['data']['type'].first
|
55
|
+
klass_name = klass_name.gsub("_", "::")
|
56
|
+
id = result['data']['id'].first
|
57
|
+
record = objs.select { |r|
|
58
|
+
r.class.name == klass_name && r.id == id.to_i
|
59
|
+
}.first
|
60
|
+
@records << record
|
47
61
|
end
|
62
|
+
|
63
|
+
return @records
|
48
64
|
end
|
49
65
|
|
50
66
|
def where(value)
|
@@ -52,7 +68,7 @@ module Inquisitio
|
|
52
68
|
if value.is_a?(Array)
|
53
69
|
s.params[:criteria] += value
|
54
70
|
elsif value.is_a?(Hash)
|
55
|
-
value.each do |k,v|
|
71
|
+
value.each do |k, v|
|
56
72
|
s.params[:filters][k] ||= []
|
57
73
|
if v.is_a?(Array)
|
58
74
|
s.params[:filters][k] = v
|
@@ -110,9 +126,9 @@ module Inquisitio
|
|
110
126
|
raise InquisitioError.new("Search failed with status code: #{response.status} Message #{response.body}") unless response.status == 200
|
111
127
|
body = JSON.parse(response.body)
|
112
128
|
@results = Results.new(body["hits"]["hit"],
|
113
|
-
|
114
|
-
|
115
|
-
|
129
|
+
params[:page],
|
130
|
+
params[:per],
|
131
|
+
body["hits"]["found"])
|
116
132
|
rescue => e
|
117
133
|
@failed_attempts += 1
|
118
134
|
Inquisitio.config.logger.error("Exception Performing search: #{search_url} #{e}")
|
@@ -127,7 +143,7 @@ module Inquisitio
|
|
127
143
|
|
128
144
|
def search_url
|
129
145
|
@search_url ||= begin
|
130
|
-
return_fields = params[:returns].empty
|
146
|
+
return_fields = params[:returns].empty? ? [:type, :id] : params[:returns]
|
131
147
|
|
132
148
|
SearchUrlBuilder.build(
|
133
149
|
query: params[:criteria],
|
data/lib/inquisitio/version.rb
CHANGED
data/test/searcher_test.rb
CHANGED
@@ -1,6 +1,21 @@
|
|
1
1
|
require File.expand_path('../test_helper', __FILE__)
|
2
2
|
|
3
3
|
module Inquisitio
|
4
|
+
|
5
|
+
class Elephant
|
6
|
+
attr_accessor :id, :name
|
7
|
+
def initialize(_id, _name)
|
8
|
+
@id, @name = _id, _name
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class Giraffe
|
13
|
+
attr_accessor :id, :name
|
14
|
+
def initialize(_id, _name)
|
15
|
+
@id, @name = _id, _name
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
4
19
|
class SearcherTest < Minitest::Test
|
5
20
|
def setup
|
6
21
|
super
|
@@ -288,20 +303,24 @@ module Inquisitio
|
|
288
303
|
assert_equal [1,2,20], searcher.ids
|
289
304
|
end
|
290
305
|
|
291
|
-
def
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
res1 = "Foobar"
|
296
|
-
res2 = 123
|
297
|
-
res3 = true
|
306
|
+
def test_should_return_records_in_results_order
|
307
|
+
expected_1 = Elephant.new(2, 'Sootica')
|
308
|
+
expected_2 = Giraffe.new(20, 'Wolf')
|
309
|
+
expected_3 = Elephant.new(1, 'Gobbolino')
|
298
310
|
|
299
|
-
|
300
|
-
|
311
|
+
Elephant.expects(:where).with(id: ['2','1']).returns([expected_3, expected_1])
|
312
|
+
Giraffe.expects(:where).with(id: ['20']).returns([expected_2])
|
301
313
|
|
302
314
|
searcher = Searcher.new
|
303
|
-
|
304
|
-
|
315
|
+
result = [
|
316
|
+
{'data' => {'id' => ['2'], 'type' => ['Inquisitio_Elephant']}},
|
317
|
+
{'data' => {'id' => ['20'], 'type' => ['Inquisitio_Giraffe']}},
|
318
|
+
{'data' => {'id' => ['1'], 'type' => ['Inquisitio_Elephant']}}
|
319
|
+
]
|
320
|
+
searcher.instance_variable_set("@results", result)
|
321
|
+
expected_records = [expected_1, expected_2, expected_3]
|
322
|
+
actual_records = searcher.records
|
323
|
+
assert_equal expected_records, actual_records
|
305
324
|
end
|
306
325
|
end
|
307
326
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inquisitio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Walker
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2014-01-
|
13
|
+
date: 2014-01-25 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: excon
|
@@ -175,7 +175,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
175
175
|
version: '0'
|
176
176
|
requirements: []
|
177
177
|
rubyforge_project:
|
178
|
-
rubygems_version: 2.
|
178
|
+
rubygems_version: 2.1.9
|
179
179
|
signing_key:
|
180
180
|
specification_version: 4
|
181
181
|
summary: This wraps AWS CloudSearch in a Ruby Gem
|