inquisitio 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +13 -5
- data/CHANGELOG.md +4 -0
- data/lib/inquisitio/results.rb +27 -0
- data/lib/inquisitio/searcher.rb +5 -1
- data/lib/inquisitio/version.rb +1 -1
- data/lib/inquisitio.rb +1 -0
- data/test/results_test.rb +102 -0
- data/test/searcher_test.rb +10 -2
- metadata +15 -12
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZjQ3YThiYjYzNzQ5YTc0OGRjZjcxMTc5NjcwMDJmYjlmYzgwMjQ0Yw==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NTE2NmJiOTgxODVlMWZiN2U2MjYwOWFjNGJiMmNkMWQwNTJiMjNlZA==
|
5
7
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NDI3MWRhNzhkMTk2ZGUxNWE4MWRkYTQxNWE4YjIzNmE5OGU3MjYyMjJhZmQw
|
10
|
+
ZjI2NzBhYzU2NDNmMDY1NjhjN2FmZWViYTVjNWMxZGE3ZGVhNmQ1NWJhMWI5
|
11
|
+
OGFiN2E5NDBlMGIzNTkyMGVmOTc1N2U2ZDBmODQ2ZWUyMzFiZjc=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NjhhZmJmOTVkY2ZjY2JjY2M3MDFlODVhN2ZiZDU0ZGNkMzdlMmNhMjYxYTQz
|
14
|
+
ZWEyMzU5NmY1MDMzMDNhMWM2OWU1N2M0ZmI0ZTI0NGU0NjY4YmY5Y2I2MmRh
|
15
|
+
Njk1NzBiZGU2ODZiNjIwYWJjNmU1MWJkMzIwMzQ2NTUyYmU5NTY=
|
data/CHANGELOG.md
CHANGED
@@ -0,0 +1,27 @@
|
|
1
|
+
module Inquisitio
|
2
|
+
class Results < Array
|
3
|
+
def initialize(items, current_page, results_per_page, total_count)
|
4
|
+
super(items)
|
5
|
+
@current_page = current_page
|
6
|
+
@results_per_page = results_per_page
|
7
|
+
@total_count = total_count
|
8
|
+
end
|
9
|
+
|
10
|
+
attr_reader :total_count, :results_per_page, :current_page
|
11
|
+
alias_method :total_entries, :total_count
|
12
|
+
alias_method :limit_value, :results_per_page
|
13
|
+
|
14
|
+
def total_pages
|
15
|
+
(total_count / results_per_page.to_f).ceil
|
16
|
+
end
|
17
|
+
alias_method :num_pages, :total_pages
|
18
|
+
|
19
|
+
def last_page?
|
20
|
+
current_page == total_pages
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_a
|
24
|
+
self
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/inquisitio/searcher.rb
CHANGED
@@ -104,7 +104,11 @@ module Inquisitio
|
|
104
104
|
if @results.nil?
|
105
105
|
response = Excon.get(search_url)
|
106
106
|
raise InquisitioError.new("Search failed with status code: #{response.status} Message #{response.body}") unless response.status == 200
|
107
|
-
|
107
|
+
body = JSON.parse(response.body)
|
108
|
+
@results = Results.new(body["hits"]["hit"],
|
109
|
+
params[:page],
|
110
|
+
params[:per],
|
111
|
+
body["hits"]["found"])
|
108
112
|
end
|
109
113
|
@results
|
110
114
|
end
|
data/lib/inquisitio/version.rb
CHANGED
data/lib/inquisitio.rb
CHANGED
@@ -0,0 +1,102 @@
|
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
|
3
|
+
module Inquisitio
|
4
|
+
class ResultsTest < Minitest::Test
|
5
|
+
def setup
|
6
|
+
super
|
7
|
+
@search_endpoint = 'http://my.search-endpoint.com'
|
8
|
+
Inquisitio.config.search_endpoint = @search_endpoint
|
9
|
+
@result_1 = {'data' => {'med_id' => ['1'], 'title' => ["Foobar"], 'med_type' => ["Cat"]}}
|
10
|
+
@result_2 = {'data' => {'med_id' => ['2'], 'title' => ["Foobar"], 'med_type' => ["Cat"]}}
|
11
|
+
@result_3 = {'data' => {'med_id' => ['20'], 'title' => ["Foobar2"], 'med_type' => ["Module_Dog"]}}
|
12
|
+
@expected_results = [@result_1, @result_2, @result_3]
|
13
|
+
@start = 5
|
14
|
+
@found = 8
|
15
|
+
|
16
|
+
@body = <<-EOS
|
17
|
+
{"rank":"-text_relevance","match-expr":"(label 'star wars')","hits":{"found":#{@found},"start":#{@start},"hit":#{@expected_results.to_json}},"info":{"rid":"9d3b24b0e3399866dd8d376a7b1e0f6e930d55830b33a474bfac11146e9ca1b3b8adf0141a93ecee","time-ms":3,"cpu-time-ms":0}}
|
18
|
+
EOS
|
19
|
+
|
20
|
+
Excon.defaults[:mock] = true
|
21
|
+
Excon.stub({}, {body: @body, status: 200})
|
22
|
+
end
|
23
|
+
|
24
|
+
def teardown
|
25
|
+
super
|
26
|
+
Excon.stubs.clear
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_should_return_total_count
|
30
|
+
searcher = Searcher.where("star_wars")
|
31
|
+
searcher.search
|
32
|
+
assert_equal @found, searcher.total_entries
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_total_entries_should_proxy
|
36
|
+
searcher = Searcher.where("star_wars")
|
37
|
+
searcher.search
|
38
|
+
assert_equal @found, searcher.total_count
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_should_return_results_per_page
|
42
|
+
per = 9
|
43
|
+
searcher = Searcher.per(per)
|
44
|
+
searcher.search
|
45
|
+
assert_equal per, searcher.results_per_page
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_should_return_limit_value
|
49
|
+
per = 9
|
50
|
+
searcher = Searcher.per(per)
|
51
|
+
searcher.search
|
52
|
+
assert_equal per, searcher.limit_value
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_should_return_current_page
|
56
|
+
page = 7
|
57
|
+
searcher = Searcher.page(7)
|
58
|
+
searcher.search
|
59
|
+
assert_equal page, searcher.current_page
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_should_return_total_pages_with_less
|
63
|
+
per = 10
|
64
|
+
searcher = Searcher.per(per)
|
65
|
+
searcher.search
|
66
|
+
assert_equal 1, searcher.total_pages
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_should_return_total_pages_with_equal
|
70
|
+
per = 8
|
71
|
+
searcher = Searcher.per(per)
|
72
|
+
searcher.search
|
73
|
+
assert_equal 1, searcher.total_pages
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_should_return_total_pages_with_more
|
77
|
+
per = 3
|
78
|
+
searcher = Searcher.per(per)
|
79
|
+
searcher.search
|
80
|
+
assert_equal 3, searcher.total_pages
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_nums_pages_should_proxy
|
84
|
+
per = 3
|
85
|
+
searcher = Searcher.per(per)
|
86
|
+
searcher.search
|
87
|
+
assert_equal 3, searcher.num_pages
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_last_page_before
|
91
|
+
results = Inquisitio::Results.new([], 1, nil, nil)
|
92
|
+
results.expects(total_pages: 2)
|
93
|
+
refute results.last_page?
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_last_page_equal
|
97
|
+
results = Inquisitio::Results.new([], 2, nil, nil)
|
98
|
+
results.expects(total_pages: 2)
|
99
|
+
assert results.last_page?
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
data/test/searcher_test.rb
CHANGED
@@ -10,9 +10,11 @@ module Inquisitio
|
|
10
10
|
@result_2 = {'data' => {'med_id' => ['2'], 'title' => ["Foobar"], 'med_type' => ["Cat"]}}
|
11
11
|
@result_3 = {'data' => {'med_id' => ['20'], 'title' => ["Foobar2"], 'med_type' => ["Module_Dog"]}}
|
12
12
|
@expected_results = [@result_1, @result_2, @result_3]
|
13
|
+
@start = 5
|
14
|
+
@found = 8
|
13
15
|
|
14
16
|
@body = <<-EOS
|
15
|
-
{"rank":"-text_relevance","match-expr":"(label 'star wars')","hits":{"found"
|
17
|
+
{"rank":"-text_relevance","match-expr":"(label 'star wars')","hits":{"found":#{@found},"start":#{@start},"hit":#{@expected_results.to_json}},"info":{"rid":"9d3b24b0e3399866dd8d376a7b1e0f6e930d55830b33a474bfac11146e9ca1b3b8adf0141a93ecee","time-ms":3,"cpu-time-ms":0}}
|
16
18
|
EOS
|
17
19
|
|
18
20
|
Excon.defaults[:mock] = true
|
@@ -235,12 +237,18 @@ module Inquisitio
|
|
235
237
|
searcher.select { }
|
236
238
|
end
|
237
239
|
|
238
|
-
def
|
240
|
+
def test_search_should_set_results
|
239
241
|
searcher = Searcher.where("star_wars")
|
240
242
|
searcher.search
|
241
243
|
assert_equal @expected_results, searcher.instance_variable_get("@results")
|
242
244
|
end
|
243
245
|
|
246
|
+
def test_search_should_create_a_results_object
|
247
|
+
searcher = Searcher.where("star_wars")
|
248
|
+
searcher.search
|
249
|
+
assert Results, searcher.instance_variable_get("@results").class
|
250
|
+
end
|
251
|
+
|
244
252
|
def test_search_only_runs_once
|
245
253
|
searcher = Searcher.where("star_wars")
|
246
254
|
Excon.expects(:get).returns(mock(status: 200, body: @body)).once
|
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: 0.1.
|
4
|
+
version: 0.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: 2013-10-
|
13
|
+
date: 2013-10-29 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: excon
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
name: ruby_deep_clone
|
31
31
|
requirement: !ruby/object:Gem::Requirement
|
32
32
|
requirements:
|
33
|
-
- - '>='
|
33
|
+
- - ! '>='
|
34
34
|
- !ruby/object:Gem::Version
|
35
35
|
version: '0'
|
36
36
|
type: :runtime
|
37
37
|
prerelease: false
|
38
38
|
version_requirements: !ruby/object:Gem::Requirement
|
39
39
|
requirements:
|
40
|
-
- - '>='
|
40
|
+
- - ! '>='
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
version: '0'
|
43
43
|
- !ruby/object:Gem::Dependency
|
@@ -58,42 +58,42 @@ dependencies:
|
|
58
58
|
name: rake
|
59
59
|
requirement: !ruby/object:Gem::Requirement
|
60
60
|
requirements:
|
61
|
-
- - '>='
|
61
|
+
- - ! '>='
|
62
62
|
- !ruby/object:Gem::Version
|
63
63
|
version: '0'
|
64
64
|
type: :development
|
65
65
|
prerelease: false
|
66
66
|
version_requirements: !ruby/object:Gem::Requirement
|
67
67
|
requirements:
|
68
|
-
- - '>='
|
68
|
+
- - ! '>='
|
69
69
|
- !ruby/object:Gem::Version
|
70
70
|
version: '0'
|
71
71
|
- !ruby/object:Gem::Dependency
|
72
72
|
name: mocha
|
73
73
|
requirement: !ruby/object:Gem::Requirement
|
74
74
|
requirements:
|
75
|
-
- - '>='
|
75
|
+
- - ! '>='
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '0'
|
78
78
|
type: :development
|
79
79
|
prerelease: false
|
80
80
|
version_requirements: !ruby/object:Gem::Requirement
|
81
81
|
requirements:
|
82
|
-
- - '>='
|
82
|
+
- - ! '>='
|
83
83
|
- !ruby/object:Gem::Version
|
84
84
|
version: '0'
|
85
85
|
- !ruby/object:Gem::Dependency
|
86
86
|
name: yard
|
87
87
|
requirement: !ruby/object:Gem::Requirement
|
88
88
|
requirements:
|
89
|
-
- - '>='
|
89
|
+
- - ! '>='
|
90
90
|
- !ruby/object:Gem::Version
|
91
91
|
version: '0'
|
92
92
|
type: :development
|
93
93
|
prerelease: false
|
94
94
|
version_requirements: !ruby/object:Gem::Requirement
|
95
95
|
requirements:
|
96
|
-
- - '>='
|
96
|
+
- - ! '>='
|
97
97
|
- !ruby/object:Gem::Version
|
98
98
|
version: '0'
|
99
99
|
- !ruby/object:Gem::Dependency
|
@@ -143,6 +143,7 @@ files:
|
|
143
143
|
- lib/inquisitio/indexer.rb
|
144
144
|
- lib/inquisitio/inquisitio_error.rb
|
145
145
|
- lib/inquisitio/logger.rb
|
146
|
+
- lib/inquisitio/results.rb
|
146
147
|
- lib/inquisitio/search_url_builder.rb
|
147
148
|
- lib/inquisitio/searcher.rb
|
148
149
|
- lib/inquisitio/version.rb
|
@@ -150,6 +151,7 @@ files:
|
|
150
151
|
- test/document_test.rb
|
151
152
|
- test/indexer_test.rb
|
152
153
|
- test/logger_test.rb
|
154
|
+
- test/results_test.rb
|
153
155
|
- test/search_url_builder_test.rb
|
154
156
|
- test/searcher_test.rb
|
155
157
|
- test/test_helper.rb
|
@@ -163,12 +165,12 @@ require_paths:
|
|
163
165
|
- lib
|
164
166
|
required_ruby_version: !ruby/object:Gem::Requirement
|
165
167
|
requirements:
|
166
|
-
- - '>='
|
168
|
+
- - ! '>='
|
167
169
|
- !ruby/object:Gem::Version
|
168
170
|
version: '0'
|
169
171
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
170
172
|
requirements:
|
171
|
-
- - '>='
|
173
|
+
- - ! '>='
|
172
174
|
- !ruby/object:Gem::Version
|
173
175
|
version: '0'
|
174
176
|
requirements: []
|
@@ -182,6 +184,7 @@ test_files:
|
|
182
184
|
- test/document_test.rb
|
183
185
|
- test/indexer_test.rb
|
184
186
|
- test/logger_test.rb
|
187
|
+
- test/results_test.rb
|
185
188
|
- test/search_url_builder_test.rb
|
186
189
|
- test/searcher_test.rb
|
187
190
|
- test/test_helper.rb
|