inquisitio 1.4.1 → 1.5.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 +4 -0
- data/lib/inquisitio/search_url_builder.rb +11 -6
- data/lib/inquisitio/searcher.rb +7 -0
- data/lib/inquisitio/version.rb +1 -1
- data/test/search_url_builder_for_2013_test.rb +20 -1
- data/test/searcher_test.rb +21 -1
- 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: 44d14d9abac6f0abd9b664a401bdf7f1b33669d6
|
4
|
+
data.tar.gz: 96cbec3963eabe249499d6b1f127d484419c8292
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f21bef26aaabfb05976b59383fc37eca267808167a45fb2ef821cb4a3c095bfb88e3a0ed33e02af69e89f4f2c61760f70cc3b5b6cbe8999939b7a70136d6758
|
7
|
+
data.tar.gz: 4b53556037160c92ed3c8f824473ce08b8e7b71155d703fef576b1d18ef08f1b0a3354aca1733690c3e2fe865135b24bcf3d84a88e59bd3fc306c224db5648ff
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
1.5.0 / 2015-07-17
|
2
|
+
[FEATURE] Searcher now supports q.parser option as Search#parser
|
3
|
+
[BUGFIX] Searcher no longer removes ' from simple queries
|
4
|
+
|
1
5
|
1.4.1 / 2015-07-15
|
2
6
|
[FEATURE] Searcher now supports #expressions(hash) which maps to expr. expressions in the 2013 api
|
3
7
|
|
@@ -15,16 +15,17 @@ module Inquisitio
|
|
15
15
|
@size = options[:size] || Inquisitio.config.default_search_size
|
16
16
|
@start = options[:start] || 0
|
17
17
|
@sort = options[:sort] || {}
|
18
|
+
@q_parser = options[:q_parser] || (is_simple? ? nil : :structured)
|
18
19
|
end
|
19
20
|
|
20
21
|
def build
|
21
22
|
components = [url_root]
|
22
|
-
|
23
|
-
components <<
|
23
|
+
components << (is_simple? ? simple_query : boolean_query)
|
24
|
+
components << "&q.parser=#{@q_parser}" if @q_parser && Inquisitio.config.api_version == '2013-01-01'
|
24
25
|
components << return_fields_query_string
|
25
26
|
components << arguments
|
26
|
-
components << '&q.options=' + CGI::escape(@q_options.
|
27
|
-
@expressions.each do |name,expression|
|
27
|
+
components << '&q.options=' + CGI::escape(@q_options.to_json) unless @q_options.empty?
|
28
|
+
@expressions.each do |name, expression|
|
28
29
|
components << "&expr.#{name}=" + CGI::escape(expression)
|
29
30
|
end
|
30
31
|
components << "&size=#{@size}" unless @arguments[:size]
|
@@ -33,9 +34,13 @@ module Inquisitio
|
|
33
34
|
components.join('')
|
34
35
|
end
|
35
36
|
|
37
|
+
def is_simple?
|
38
|
+
@filters.empty? && Array(@query).size == 1
|
39
|
+
end
|
40
|
+
|
36
41
|
private
|
37
42
|
def simple_query
|
38
|
-
"q=#{CGI::escape(
|
43
|
+
"q=#{CGI::escape(@query.first)}"
|
39
44
|
end
|
40
45
|
|
41
46
|
def boolean_query
|
@@ -63,7 +68,7 @@ module Inquisitio
|
|
63
68
|
if Inquisitio.config.api_version == '2011-02-01'
|
64
69
|
"bq=#{CGI::escape("(and #{query_blocks.join(' ')})").gsub('&', '%26')}"
|
65
70
|
elsif Inquisitio.config.api_version == '2013-01-01'
|
66
|
-
"q=#{CGI::escape("(and #{query_blocks.join(' ')})").gsub('&', '%26')}
|
71
|
+
"q=#{CGI::escape("(and #{query_blocks.join(' ')})").gsub('&', '%26')}"
|
67
72
|
end
|
68
73
|
end
|
69
74
|
|
data/lib/inquisitio/searcher.rb
CHANGED
@@ -97,6 +97,12 @@ module Inquisitio
|
|
97
97
|
end
|
98
98
|
end
|
99
99
|
|
100
|
+
def parser(value)
|
101
|
+
clone do |s|
|
102
|
+
s.params[:q_parser] = value
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
100
106
|
def per(value)
|
101
107
|
clone do |s|
|
102
108
|
s.params[:per] = value.to_i
|
@@ -182,6 +188,7 @@ module Inquisitio
|
|
182
188
|
sort: params[:sort],
|
183
189
|
q_options: params[:q_options],
|
184
190
|
expressions: params[:expressions],
|
191
|
+
q_parser: params[:q_parser],
|
185
192
|
return_fields: return_fields
|
186
193
|
)
|
187
194
|
end
|
data/lib/inquisitio/version.rb
CHANGED
@@ -109,7 +109,13 @@ module Inquisitio
|
|
109
109
|
|
110
110
|
def test_create_search_url_with_query_options
|
111
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=%
|
112
|
+
expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q=Star+Wars&q.options=%7B%22fields%22%3A%5B%22title%5E2.0%22%2C%22plot%5E0.5%22%5D%7D&size=10'
|
113
|
+
assert_equal expected_url, url
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_create_search_url_with_query_defaultoperator_option
|
117
|
+
url = SearchUrlBuilder.build(query: ['Star Wars'], q_options: {defaultOperator: 'or'})
|
118
|
+
expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q=Star+Wars&q.options=%7B%22defaultOperator%22%3A%22or%22%7D&size=10'
|
113
119
|
assert_equal expected_url, url
|
114
120
|
end
|
115
121
|
|
@@ -118,5 +124,18 @@ module Inquisitio
|
|
118
124
|
expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q=Star+Wars&expr.rank1=log10%28clicks%29%2A_score&expr.rank2=cos%28+_score%29&size=10'
|
119
125
|
assert_equal expected_url, url
|
120
126
|
end
|
127
|
+
|
128
|
+
def test_create_url_with_parser
|
129
|
+
url = SearchUrlBuilder.build(query: ['Star Wars'], q_parser: :structured)
|
130
|
+
expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q=Star+Wars&q.parser=structured&size=10'
|
131
|
+
assert_equal expected_url, url
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_create_url_with_overridden_parser
|
135
|
+
url = SearchUrlBuilder.build(query: ['Star Wars', 'Star Trek'], q_parser: :simple)
|
136
|
+
expected_url = 'http://my.search-endpoint.com/2013-01-01/search?q=%28and+%28or+%27Star+Wars%27+%27Star+Trek%27%29%29&q.parser=simple&size=10'
|
137
|
+
assert_equal expected_url, url
|
138
|
+
end
|
139
|
+
|
121
140
|
end
|
122
141
|
end
|
data/test/searcher_test.rb
CHANGED
@@ -396,7 +396,13 @@ module Inquisitio
|
|
396
396
|
def test_should_support_options
|
397
397
|
searcher = Searcher.where('Star Wars').options(fields: %w(title^2 plot^0.5))
|
398
398
|
search_url = searcher.send(:search_url)
|
399
|
-
assert search_url.include?('q.options=%
|
399
|
+
assert search_url.include?('q.options=%7B%22fields%22%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_should_support_operator_in_options
|
403
|
+
searcher = Searcher.where('Star Wars').options(defaultOperator: 'or')
|
404
|
+
search_url = searcher.send(:search_url)
|
405
|
+
assert search_url =~ /(\?|&)q.options=%7B%22defaultOperator%22%3A%22or%22%7D(&|$)/, "search url should include q.options parameter:\n#{search_url}"
|
400
406
|
end
|
401
407
|
|
402
408
|
def test_options_doesnt_mutate_searcher
|
@@ -432,5 +438,19 @@ module Inquisitio
|
|
432
438
|
assert search_url =~ /(\?|&)expr\.rank1=log10%28clicks%29%2A_score(&|$)/, "search url should include expr.rank1 parameter:\n#{search_url}"
|
433
439
|
assert search_url =~ /(\?|&)expr\.rank2=cos%28\+_score%29(&|$)/, "search url should include expr.rank1 parameter:\n#{search_url}"
|
434
440
|
end
|
441
|
+
|
442
|
+
def test_should_support_structured_parser
|
443
|
+
Inquisitio.config.api_version = '2013-01-01'
|
444
|
+
searcher = Searcher.where('star wars').parser(:structured)
|
445
|
+
search_url = searcher.send(:search_url)
|
446
|
+
assert search_url =~ /(\?|&)q\.parser=structured(&|$)/, "search url should include q.parser parameter:\n#{search_url}"
|
447
|
+
end
|
448
|
+
|
449
|
+
def test_should_support_any_parser
|
450
|
+
Inquisitio.config.api_version = '2013-01-01'
|
451
|
+
searcher = Searcher.where('star wars').parser(:foo_bar_baz)
|
452
|
+
search_url = searcher.send(:search_url)
|
453
|
+
assert search_url =~ /(\?|&)q\.parser=foo_bar_baz(&|$)/, "search url should include q.parser parameter:\n#{search_url}"
|
454
|
+
end
|
435
455
|
end
|
436
456
|
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.5.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-17 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: excon
|