inquisitio 1.3.1 → 1.4.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/CHANGELOG.md +3 -0
- data/lib/inquisitio/search_url_builder.rb +16 -14
- data/lib/inquisitio/searcher.rb +10 -2
- data/lib/inquisitio/version.rb +1 -1
- data/test/search_url_builder_for_2011_test.rb +14 -14
- data/test/search_url_builder_for_2013_test.rb +20 -14
- data/test/searcher_test.rb +31 -6
- 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: 27dadb327fcc1198c7659d113e0c497c8e2ed787
|
4
|
+
data.tar.gz: b074ca69a037d70633334e9b9c6fec1824ba5c5f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26adef66c212f20277c36a9cdf8fb656fc8b844293e3284d6bdc9f2d54e03b78d1ff795e58309a263bc48999da8ed7cb8e5ba83ce0d6a7ae2136206723c47ff3
|
7
|
+
data.tar.gz: a5f8436b07dbfefcb928544e76196d61b2014a23b14162bfc87b32246b08c82e7813130f010390f70a3c92dd3cc5f7e8d45ece65b6a2645a5de68bc272ede2da
|
data/CHANGELOG.md
CHANGED
@@ -6,9 +6,10 @@ module Inquisitio
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def initialize(options = {})
|
9
|
-
@query
|
10
|
-
@filters
|
11
|
-
@
|
9
|
+
@query = options[:query]
|
10
|
+
@filters = options[:filters] || {}
|
11
|
+
@q_options = options[:q_options] || {}
|
12
|
+
@arguments = options[:arguments] || {}
|
12
13
|
@return_fields = options[:return_fields]
|
13
14
|
@size = options[:size] || Inquisitio.config.default_search_size
|
14
15
|
@start = options[:start] || 0
|
@@ -21,15 +22,16 @@ module Inquisitio
|
|
21
22
|
components << (is_simple ? simple_query : boolean_query)
|
22
23
|
components << return_fields_query_string
|
23
24
|
components << arguments
|
25
|
+
components << '&q.options=' + CGI::escape(@q_options.map { |k, v| "{#{k}:#{v}}" }.join('')) unless @q_options.empty?
|
24
26
|
components << "&size=#{@size}" unless @arguments[:size]
|
25
27
|
components << "&start=#{@start}" unless @arguments[:start] || @start == 0 || @start == '0'
|
26
|
-
components << '&sort=' + @sort.map {|k,v| "#{k}%20#{v}"}.join(',') unless @sort.empty?
|
28
|
+
components << '&sort=' + @sort.map { |k, v| "#{k}%20#{v}" }.join(',') unless @sort.empty?
|
27
29
|
components.join('')
|
28
30
|
end
|
29
31
|
|
30
32
|
private
|
31
33
|
def simple_query
|
32
|
-
"q=#{
|
34
|
+
"q=#{CGI::escape(sanitise(@query.first)).gsub('&', '%26')}"
|
33
35
|
end
|
34
36
|
|
35
37
|
def boolean_query
|
@@ -41,42 +43,42 @@ module Inquisitio
|
|
41
43
|
elsif @query.size == 1
|
42
44
|
query_blocks << "'#{sanitise(@query.first)}'"
|
43
45
|
else
|
44
|
-
query_blocks << "(or #{@query.map{|q| "'#{sanitise(q)}'"}.join(' ')})"
|
46
|
+
query_blocks << "(or #{@query.map { |q| "'#{sanitise(q)}'" }.join(' ')})"
|
45
47
|
end
|
46
48
|
|
47
|
-
query_blocks += @filters.map do |key,value|
|
49
|
+
query_blocks += @filters.map do |key, value|
|
48
50
|
if value.is_a?(String)
|
49
51
|
"#{sanitise(key)}:'#{sanitise(value)}'"
|
50
52
|
elsif value.is_a?(Array)
|
51
|
-
"(or #{value.map {|v| "#{sanitise(key)}:'#{sanitise(v)}'" }.join(" ")})"
|
53
|
+
"(or #{value.map { |v| "#{sanitise(key)}:'#{sanitise(v)}'" }.join(" ")})"
|
52
54
|
else
|
53
55
|
raise InquisitioError.new('Filter values must be strings or arrays.')
|
54
56
|
end
|
55
57
|
end
|
56
58
|
|
57
59
|
if Inquisitio.config.api_version == '2011-02-01'
|
58
|
-
"bq=#{
|
60
|
+
"bq=#{CGI::escape("(and #{query_blocks.join(' ')})").gsub('&', '%26')}"
|
59
61
|
elsif Inquisitio.config.api_version == '2013-01-01'
|
60
|
-
"q=#{
|
62
|
+
"q=#{CGI::escape("(and #{query_blocks.join(' ')})").gsub('&', '%26')}&q.parser=structured"
|
61
63
|
end
|
62
64
|
end
|
63
65
|
|
64
66
|
def sanitise(value)
|
65
|
-
value.to_s.gsub('\'','')
|
67
|
+
value.to_s.gsub('\'', '')
|
66
68
|
end
|
67
69
|
|
68
70
|
def return_fields_query_string
|
69
71
|
return '' if @return_fields.nil?
|
70
72
|
if Inquisitio.config.api_version == '2011-02-01'
|
71
|
-
"&return-fields=#{
|
73
|
+
"&return-fields=#{CGI::escape(@return_fields.join(',').gsub('\'', ''))}"
|
72
74
|
elsif Inquisitio.config.api_version == '2013-01-01'
|
73
|
-
"&return=#{
|
75
|
+
"&return=#{CGI::escape(@return_fields.join(',').gsub('\'', ''))}"
|
74
76
|
end
|
75
77
|
end
|
76
78
|
|
77
79
|
def arguments
|
78
80
|
return '' if @arguments.nil?
|
79
|
-
@arguments.map{|key,value| "&#{key.to_s.gsub('\'','')}=#{value.to_s.gsub('\'','')}"}.join("")
|
81
|
+
@arguments.map { |key, value| "&#{key.to_s.gsub('\'', '')}=#{value.to_s.gsub('\'', '')}" }.join("")
|
80
82
|
end
|
81
83
|
|
82
84
|
def url_root
|
data/lib/inquisitio/searcher.rb
CHANGED
@@ -7,7 +7,7 @@ module Inquisitio
|
|
7
7
|
Searcher.new.send(name, *args)
|
8
8
|
end
|
9
9
|
|
10
|
-
attr_reader :params
|
10
|
+
attr_reader :params, :options
|
11
11
|
|
12
12
|
def initialize(params = nil)
|
13
13
|
@params = params || {
|
@@ -17,7 +17,8 @@ module Inquisitio
|
|
17
17
|
page: 1,
|
18
18
|
returns: [],
|
19
19
|
with: {},
|
20
|
-
sort: {}
|
20
|
+
sort: {},
|
21
|
+
q_options: {}
|
21
22
|
}
|
22
23
|
@failed_attempts = 0
|
23
24
|
|
@@ -83,6 +84,12 @@ module Inquisitio
|
|
83
84
|
end
|
84
85
|
end
|
85
86
|
|
87
|
+
def options(value)
|
88
|
+
clone do |s|
|
89
|
+
s.params[:q_options] = value
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
86
93
|
def per(value)
|
87
94
|
clone do |s|
|
88
95
|
s.params[:per] = value.to_i
|
@@ -166,6 +173,7 @@ module Inquisitio
|
|
166
173
|
size: params[:per],
|
167
174
|
start: params[:per] * (params[:page] - 1),
|
168
175
|
sort: params[:sort],
|
176
|
+
q_options: params[:q_options],
|
169
177
|
return_fields: return_fields
|
170
178
|
)
|
171
179
|
end
|
data/lib/inquisitio/version.rb
CHANGED
@@ -11,7 +11,7 @@ module Inquisitio
|
|
11
11
|
|
12
12
|
def test_create_correct_search_url_with_single_criteria_query
|
13
13
|
url = SearchUrlBuilder.build(query: ['Star Wars'])
|
14
|
-
expected_url = 'http://my.search-endpoint.com/2011-02-01/search?q=Star
|
14
|
+
expected_url = 'http://my.search-endpoint.com/2011-02-01/search?q=Star+Wars&size=10'
|
15
15
|
assert_equal expected_url, url
|
16
16
|
end
|
17
17
|
|
@@ -23,80 +23,80 @@ module Inquisitio
|
|
23
23
|
|
24
24
|
def test_create_correct_search_url_with_multiple_criteria_should_create_boolean_query
|
25
25
|
url = SearchUrlBuilder.build(query: ['Star Wars', 'Episode One'])
|
26
|
-
expected_url = 'http://my.search-endpoint.com/2011-02-01/search?bq
|
26
|
+
expected_url = 'http://my.search-endpoint.com/2011-02-01/search?bq=%28and+%28or+%27Star+Wars%27+%27Episode+One%27%29%29&size=10'
|
27
27
|
assert_equal expected_url, url
|
28
28
|
end
|
29
29
|
|
30
30
|
def test_create_correct_search_url_with_multiple_criteria_with_ampersand
|
31
31
|
url = SearchUrlBuilder.build(query: ['Star&Wars', 'Episode One'])
|
32
|
-
expected_url = 'http://my.search-endpoint.com/2011-02-01/search?bq
|
32
|
+
expected_url = 'http://my.search-endpoint.com/2011-02-01/search?bq=%28and+%28or+%27Star%26Wars%27+%27Episode+One%27%29%29&size=10'
|
33
33
|
assert_equal expected_url, url
|
34
34
|
end
|
35
35
|
|
36
36
|
|
37
37
|
def test_create_correct_search_url_including_return_fields
|
38
38
|
url = SearchUrlBuilder.build(query: ['Star Wars'], return_fields: [ 'title', 'year', '%' ] )
|
39
|
-
expected_url = 'http://my.search-endpoint.com/2011-02-01/search?q=Star
|
39
|
+
expected_url = 'http://my.search-endpoint.com/2011-02-01/search?q=Star+Wars&return-fields=title%2Cyear%2C%25&size=10'
|
40
40
|
assert_equal expected_url, url
|
41
41
|
end
|
42
42
|
|
43
43
|
def test_create_boolean_query_search_url_with_only_filters
|
44
44
|
url = SearchUrlBuilder.build(filters: {title: 'Star Wars'})
|
45
|
-
expected_url = 'http://my.search-endpoint.com/2011-02-01/search?bq
|
45
|
+
expected_url = 'http://my.search-endpoint.com/2011-02-01/search?bq=%28and+title%3A%27Star+Wars%27%29&size=10'
|
46
46
|
assert_equal expected_url, url
|
47
47
|
end
|
48
48
|
|
49
49
|
def test_create_boolean_query_search_url_with_query_and_filters
|
50
50
|
url = SearchUrlBuilder.build(query: ['Star Wars'], filters: {genre: 'Animation'})
|
51
|
-
expected_url = 'http://my.search-endpoint.com/2011-02-01/search?bq
|
51
|
+
expected_url = 'http://my.search-endpoint.com/2011-02-01/search?bq=%28and+%27Star+Wars%27+genre%3A%27Animation%27%29&size=10'
|
52
52
|
assert_equal expected_url, url
|
53
53
|
end
|
54
54
|
|
55
55
|
def test_create_boolean_query_search_url_with_query_and_filters_and_return_fields
|
56
56
|
url = SearchUrlBuilder.build(query: ['Star Wars'], filters: {genre: 'Animation'}, return_fields: [ 'title', 'year', '%' ])
|
57
|
-
expected_url = 'http://my.search-endpoint.com/2011-02-01/search?bq
|
57
|
+
expected_url = 'http://my.search-endpoint.com/2011-02-01/search?bq=%28and+%27Star+Wars%27+genre%3A%27Animation%27%29&return-fields=title%2Cyear%2C%25&size=10'
|
58
58
|
assert_equal expected_url, url
|
59
59
|
end
|
60
60
|
|
61
61
|
def test_create_search_url_with_added_arguments
|
62
62
|
url = SearchUrlBuilder.build(query: ['Star Wars'], filters: {genre: 'Animation'}, :arguments => { facet: 'genre', 'facet-genre-constraints' => 'Animation', 'facet-genre-top-n' => '5'})
|
63
|
-
expected_url = 'http://my.search-endpoint.com/2011-02-01/search?bq
|
63
|
+
expected_url = 'http://my.search-endpoint.com/2011-02-01/search?bq=%28and+%27Star+Wars%27+genre%3A%27Animation%27%29&facet=genre&facet-genre-constraints=Animation&facet-genre-top-n=5&size=10'
|
64
64
|
assert_equal expected_url, url
|
65
65
|
end
|
66
66
|
|
67
67
|
def test_create_search_url_with_default_size
|
68
68
|
url = SearchUrlBuilder.build(query: ['Star Wars'])
|
69
|
-
expected_url = 'http://my.search-endpoint.com/2011-02-01/search?q=Star
|
69
|
+
expected_url = 'http://my.search-endpoint.com/2011-02-01/search?q=Star+Wars&size=10'
|
70
70
|
assert_equal expected_url, url
|
71
71
|
end
|
72
72
|
|
73
73
|
def test_create_search_url_overriding_default_size
|
74
74
|
url = SearchUrlBuilder.build(query: ['Star Wars'], :arguments => { size: '200' })
|
75
|
-
expected_url = 'http://my.search-endpoint.com/2011-02-01/search?q=Star
|
75
|
+
expected_url = 'http://my.search-endpoint.com/2011-02-01/search?q=Star+Wars&size=200'
|
76
76
|
assert_equal expected_url, url
|
77
77
|
end
|
78
78
|
|
79
79
|
def test_create_search_url_with_start_and_default_size
|
80
80
|
url = SearchUrlBuilder.build(query: ['Star Wars'], :arguments => { start: '20' })
|
81
|
-
expected_url = 'http://my.search-endpoint.com/2011-02-01/search?q=Star
|
81
|
+
expected_url = 'http://my.search-endpoint.com/2011-02-01/search?q=Star+Wars&start=20&size=10'
|
82
82
|
assert_equal expected_url, url
|
83
83
|
end
|
84
84
|
|
85
85
|
def test_create_search_url_with_start_and_size
|
86
86
|
url = SearchUrlBuilder.build(query: ['Star Wars'], :arguments => { start: '2', size: '200' })
|
87
|
-
expected_url = 'http://my.search-endpoint.com/2011-02-01/search?q=Star
|
87
|
+
expected_url = 'http://my.search-endpoint.com/2011-02-01/search?q=Star+Wars&start=2&size=200'
|
88
88
|
assert_equal expected_url, url
|
89
89
|
end
|
90
90
|
|
91
91
|
def test_create_correct_search_url_with_sanatised_query_string
|
92
92
|
url = SearchUrlBuilder.build(query: ['Star\' Wars'], filters: {genre: 'Anim\'ation'}, :arguments => { facet: 'ge\'nre', 'facet-genr\'e-constraints' => 'Anim\'ation', 'facet-gen\'re-top-n' => '\'5'}, return_fields: [ 't\'itle', 'y\'ear' ])
|
93
|
-
expected_url = 'http://my.search-endpoint.com/2011-02-01/search?bq
|
93
|
+
expected_url = 'http://my.search-endpoint.com/2011-02-01/search?bq=%28and+%27Star+Wars%27+genre%3A%27Animation%27%29&return-fields=title%2Cyear&facet=genre&facet-genre-constraints=Animation&facet-genre-top-n=5&size=10'
|
94
94
|
assert_equal expected_url, url
|
95
95
|
end
|
96
96
|
|
97
97
|
def test_create_search_url_with_filter_array
|
98
98
|
url = SearchUrlBuilder.build(query: ['Star Wars'], filters: {genre: ['Animation', 'Action']})
|
99
|
-
expected_url = 'http://my.search-endpoint.com/2011-02-01/search?bq
|
99
|
+
expected_url = 'http://my.search-endpoint.com/2011-02-01/search?bq=%28and+%27Star+Wars%27+%28or+genre%3A%27Animation%27+genre%3A%27Action%27%29%29&size=10'
|
100
100
|
assert_equal expected_url, url
|
101
101
|
end
|
102
102
|
|
@@ -12,7 +12,7 @@ module Inquisitio
|
|
12
12
|
|
13
13
|
def test_create_correct_search_url_with_single_criteria_query
|
14
14
|
url = SearchUrlBuilder.build(query: ['Star Wars'])
|
15
|
-
expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q=Star
|
15
|
+
expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q=Star+Wars&size=10'
|
16
16
|
assert_equal expected_url, url
|
17
17
|
end
|
18
18
|
|
@@ -24,80 +24,80 @@ module Inquisitio
|
|
24
24
|
|
25
25
|
def test_create_correct_search_url_with_multiple_criteria_should_create_boolean_query
|
26
26
|
url = SearchUrlBuilder.build(query: ['Star Wars', 'Episode One'])
|
27
|
-
expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q
|
27
|
+
expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q=%28and+%28or+%27Star+Wars%27+%27Episode+One%27%29%29&q.parser=structured&size=10'
|
28
28
|
assert_equal expected_url, url
|
29
29
|
end
|
30
30
|
|
31
31
|
def test_create_correct_search_url_with_multiple_criteria_with_ampersand
|
32
32
|
url = SearchUrlBuilder.build(query: ['Star&Wars', 'Episode One'])
|
33
|
-
expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q
|
33
|
+
expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q=%28and+%28or+%27Star%26Wars%27+%27Episode+One%27%29%29&q.parser=structured&size=10'
|
34
34
|
assert_equal expected_url, url
|
35
35
|
end
|
36
36
|
|
37
37
|
|
38
38
|
def test_create_correct_search_url_including_return_fields
|
39
39
|
url = SearchUrlBuilder.build(query: ['Star Wars'], return_fields: [ 'title', 'year', '%' ] )
|
40
|
-
expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q=Star
|
40
|
+
expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q=Star+Wars&return=title%2Cyear%2C%25&size=10'
|
41
41
|
assert_equal expected_url, url
|
42
42
|
end
|
43
43
|
|
44
44
|
def test_create_boolean_query_search_url_with_only_filters
|
45
45
|
url = SearchUrlBuilder.build(filters: {title: 'Star Wars'})
|
46
|
-
expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q
|
46
|
+
expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q=%28and+title%3A%27Star+Wars%27%29&q.parser=structured&size=10'
|
47
47
|
assert_equal expected_url, url
|
48
48
|
end
|
49
49
|
|
50
50
|
def test_create_boolean_query_search_url_with_query_and_filters
|
51
51
|
url = SearchUrlBuilder.build(query: ['Star Wars'], filters: {genre: 'Animation'})
|
52
|
-
expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q
|
52
|
+
expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q=%28and+%27Star+Wars%27+genre%3A%27Animation%27%29&q.parser=structured&size=10'
|
53
53
|
assert_equal expected_url, url
|
54
54
|
end
|
55
55
|
|
56
56
|
def test_create_boolean_query_search_url_with_query_and_filters_and_return_fields
|
57
57
|
url = SearchUrlBuilder.build(query: ['Star Wars'], filters: {genre: 'Animation'}, return_fields: [ 'title', 'year', '%' ])
|
58
|
-
expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q
|
58
|
+
expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q=%28and+%27Star+Wars%27+genre%3A%27Animation%27%29&q.parser=structured&return=title%2Cyear%2C%25&size=10'
|
59
59
|
assert_equal expected_url, url
|
60
60
|
end
|
61
61
|
|
62
62
|
def test_create_search_url_with_added_arguments
|
63
63
|
url = SearchUrlBuilder.build(query: ['Star Wars'], filters: {genre: 'Animation'}, :arguments => { facet: 'genre', 'facet-genre-constraints' => 'Animation', 'facet-genre-top-n' => '5'})
|
64
|
-
expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q
|
64
|
+
expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q=%28and+%27Star+Wars%27+genre%3A%27Animation%27%29&q.parser=structured&facet=genre&facet-genre-constraints=Animation&facet-genre-top-n=5&size=10'
|
65
65
|
assert_equal expected_url, url
|
66
66
|
end
|
67
67
|
|
68
68
|
def test_create_search_url_with_default_size
|
69
69
|
url = SearchUrlBuilder.build(query: ['Star Wars'])
|
70
|
-
expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q=Star
|
70
|
+
expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q=Star+Wars&size=10'
|
71
71
|
assert_equal expected_url, url
|
72
72
|
end
|
73
73
|
|
74
74
|
def test_create_search_url_overriding_default_size
|
75
75
|
url = SearchUrlBuilder.build(query: ['Star Wars'], :arguments => { size: '200' })
|
76
|
-
expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q=Star
|
76
|
+
expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q=Star+Wars&size=200'
|
77
77
|
assert_equal expected_url, url
|
78
78
|
end
|
79
79
|
|
80
80
|
def test_create_search_url_with_start_and_default_size
|
81
81
|
url = SearchUrlBuilder.build(query: ['Star Wars'], :arguments => { start: '20' })
|
82
|
-
expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q=Star
|
82
|
+
expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q=Star+Wars&start=20&size=10'
|
83
83
|
assert_equal expected_url, url
|
84
84
|
end
|
85
85
|
|
86
86
|
def test_create_search_url_with_start_and_size
|
87
87
|
url = SearchUrlBuilder.build(query: ['Star Wars'], :arguments => { start: '2', size: '200' })
|
88
|
-
expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q=Star
|
88
|
+
expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q=Star+Wars&start=2&size=200'
|
89
89
|
assert_equal expected_url, url
|
90
90
|
end
|
91
91
|
|
92
92
|
def test_create_correct_search_url_with_sanatised_query_string
|
93
93
|
url = SearchUrlBuilder.build(query: ['Star\' Wars'], filters: {genre: 'Anim\'ation'}, :arguments => { facet: 'ge\'nre', 'facet-genr\'e-constraints' => 'Anim\'ation', 'facet-gen\'re-top-n' => '\'5'}, return_fields: [ 't\'itle', 'y\'ear' ])
|
94
|
-
expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q
|
94
|
+
expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q=%28and+%27Star+Wars%27+genre%3A%27Animation%27%29&q.parser=structured&return=title%2Cyear&facet=genre&facet-genre-constraints=Animation&facet-genre-top-n=5&size=10'
|
95
95
|
assert_equal expected_url, url
|
96
96
|
end
|
97
97
|
|
98
98
|
def test_create_search_url_with_filter_array
|
99
99
|
url = SearchUrlBuilder.build(query: ['Star Wars'], filters: {genre: ['Animation', 'Action']})
|
100
|
-
expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q
|
100
|
+
expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q=%28and+%27Star+Wars%27+%28or+genre%3A%27Animation%27+genre%3A%27Action%27%29%29&q.parser=structured&size=10'
|
101
101
|
assert_equal expected_url, url
|
102
102
|
end
|
103
103
|
|
@@ -106,5 +106,11 @@ module Inquisitio
|
|
106
106
|
SearchUrlBuilder.build(query: ['Star Wars'], filters: {genre: {}})
|
107
107
|
end
|
108
108
|
end
|
109
|
+
|
110
|
+
def test_create_search_url_with_query_options
|
111
|
+
url = SearchUrlBuilder.build(query: ['Star Wars'], q_options: {fields: %w(title^2.0 plot^0.5)})
|
112
|
+
expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q=Star+Wars&q.options=%7Bfields%3A%5B%22title%5E2.0%22%2C+%22plot%5E0.5%22%5D%7D&size=10'
|
113
|
+
assert_equal expected_url, url
|
114
|
+
end
|
109
115
|
end
|
110
116
|
end
|
data/test/searcher_test.rb
CHANGED
@@ -98,18 +98,21 @@ module Inquisitio
|
|
98
98
|
|
99
99
|
def test_where_gets_correct_url
|
100
100
|
searcher = Searcher.where('Star Wars')
|
101
|
-
|
101
|
+
search_url = searcher.send(:search_url)
|
102
|
+
assert(search_url.include?('q=Star+Wars'), "Search url should include search term: #{search_url}")
|
102
103
|
end
|
103
104
|
|
104
105
|
def test_where_gets_correct_url_with_filters_for_2011
|
105
106
|
searcher = Searcher.where(title: 'Star Wars')
|
106
|
-
|
107
|
+
search_url = searcher.send(:search_url)
|
108
|
+
assert(search_url.include?('bq=%28and+%28or+title%3A%27Star+Wars%27%29%29'), "Search url should include query: #{search_url}")
|
107
109
|
end
|
108
110
|
|
109
111
|
def test_where_gets_correct_url_with_filters_for_2013
|
110
112
|
Inquisitio.config.api_version = '2013-01-01'
|
111
113
|
searcher = Searcher.where(title: 'Star Wars')
|
112
|
-
|
114
|
+
search_url = searcher.send(:search_url)
|
115
|
+
assert(search_url.include?('q=%28and+%28or+title%3A%27Star+Wars%27%29%29&q.parser=structured'), "Search url should include query: #{search_url}")
|
113
116
|
end
|
114
117
|
|
115
118
|
def test_where_works_with_array_in_a_hash
|
@@ -220,13 +223,15 @@ module Inquisitio
|
|
220
223
|
|
221
224
|
def test_returns_with_array_gets_correct_url_for_2011
|
222
225
|
searcher = Searcher.returns('id', 'foobar')
|
223
|
-
|
226
|
+
search_url = searcher.send(:search_url)
|
227
|
+
assert(search_url.include?('&return-fields=id%2Cfoobar'), "Search url should include return fields: #{search_url}")
|
224
228
|
end
|
225
229
|
|
226
230
|
def test_returns_with_array_gets_correct_url_for_2013
|
227
231
|
Inquisitio.config.api_version = '2013-01-01'
|
228
232
|
searcher = Searcher.returns('id', 'foobar')
|
229
|
-
|
233
|
+
search_url = searcher.send(:search_url)
|
234
|
+
assert(search_url.include?('&return=id%2Cfoobar'), "Search url should include return: #{search_url}")
|
230
235
|
end
|
231
236
|
|
232
237
|
def test_returns_appends_variable
|
@@ -327,7 +332,8 @@ module Inquisitio
|
|
327
332
|
def test_should_return_type_and_id_by_default_for_2011
|
328
333
|
searcher = Searcher.where('Star Wars')
|
329
334
|
assert_equal [], searcher.params[:returns]
|
330
|
-
|
335
|
+
search_url = searcher.send(:search_url)
|
336
|
+
assert(search_url.include?('&return-fields=type%2Cid'), "Search url should include return for type and id: #{search_url}")
|
331
337
|
end
|
332
338
|
|
333
339
|
def test_should_not_specify_return_by_default_for_2013
|
@@ -381,5 +387,24 @@ module Inquisitio
|
|
381
387
|
assert search_url.include?('sort=year%20desc,foo%20asc'), "search url should include sort parameter:\n#{search_url}"
|
382
388
|
end
|
383
389
|
|
390
|
+
def test_should_default_to_empty_options
|
391
|
+
searcher = Searcher.where('Star Wars')
|
392
|
+
search_url = searcher.send(:search_url)
|
393
|
+
refute search_url.include?('q.options='), "search url should not include q.options parameter:\n#{search_url}"
|
394
|
+
end
|
395
|
+
|
396
|
+
def test_should_support_options
|
397
|
+
searcher = Searcher.where('Star Wars').options(fields: %w(title^2 plot^0.5))
|
398
|
+
search_url = searcher.send(:search_url)
|
399
|
+
assert search_url.include?('q.options=%7Bfields%3A%5B%22title%5E2%22%2C+%22plot%5E0.5%22%5D%7D'), "search url should include q.options parameter:\n#{search_url}"
|
400
|
+
end
|
401
|
+
|
402
|
+
def test_options_doesnt_mutate_searcher
|
403
|
+
searcher = Searcher.where('star wars')
|
404
|
+
searcher.options(fields: %w(title^2.0 plot^0.5))
|
405
|
+
search_url = searcher.send(:search_url)
|
406
|
+
refute search_url.include?('q.options='), "search url should not include q.options parameter:\n#{search_url}"
|
407
|
+
end
|
408
|
+
|
384
409
|
end
|
385
410
|
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.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Walker
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2015-07-
|
14
|
+
date: 2015-07-14 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: excon
|