groonga-command 1.4.0 → 1.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/doc/text/news.md +7 -0
- data/lib/groonga/command/base.rb +1 -1
- data/lib/groonga/command/format/elasticsearch.rb +49 -53
- data/lib/groonga/command/version.rb +1 -1
- data/test/command/test-base.rb +50 -8
- 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: 90745a99d72f93d9d719234502ba3647dcb1925c
|
4
|
+
data.tar.gz: ae6c07674439ffecdccacb23a24522dc342859d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bcc65e519bb8f64dfc51dd8b71d4070bcefd3a7a730c2bf96c161d953a9a7da5d5e05b475fbcc8dfca3c2a3f6ee1980455ebccb1aefd1e44d9c21bcb267c41c8
|
7
|
+
data.tar.gz: fad54dfbfe207833888e7d7681c9fa9a2109c20aef29cbf602984b048b082e57ef4079e0add7c051755727cbb1165b3e26a4c9b7f77b4fe3d47c5e76fe537fbf
|
data/doc/text/news.md
CHANGED
data/lib/groonga/command/base.rb
CHANGED
@@ -18,71 +18,67 @@ module Groonga
|
|
18
18
|
module Command
|
19
19
|
module Format
|
20
20
|
class Elasticsearch
|
21
|
-
def initialize(
|
22
|
-
@
|
23
|
-
@arguments = arguments
|
21
|
+
def initialize(command)
|
22
|
+
@command = command
|
24
23
|
end
|
25
24
|
|
26
25
|
def json(options={})
|
27
|
-
return nil unless @
|
26
|
+
return nil unless @command.is_a?(Load)
|
28
27
|
|
29
28
|
components = []
|
30
|
-
|
29
|
+
action = build_action(options)
|
30
|
+
each_source do |source|
|
31
|
+
components << JSON.generate(action)
|
32
|
+
components << JSON.generate(source)
|
33
|
+
end
|
34
|
+
components.join("\n")
|
35
|
+
end
|
31
36
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
case elasticsearch_version
|
37
|
-
when 7
|
38
|
-
header = {
|
39
|
-
"index" => {
|
40
|
-
"_index" => value.downcase,
|
41
|
-
"_type"=>"_doc",
|
42
|
-
}
|
43
|
-
}
|
44
|
-
when 8
|
45
|
-
header = {
|
46
|
-
"index" => {
|
47
|
-
"_index" => value.downcase,
|
48
|
-
}
|
49
|
-
}
|
50
|
-
else
|
51
|
-
# Version 5.x or 6.x
|
52
|
-
header = {
|
53
|
-
"index" => {
|
54
|
-
"_index" => value.downcase,
|
55
|
-
"_type" => "groonga",
|
56
|
-
}
|
57
|
-
}
|
58
|
-
end
|
59
|
-
components << JSON.generate(header)
|
60
|
-
when :values
|
61
|
-
record = JSON.parse(value)
|
37
|
+
private
|
38
|
+
def elasticsearch_version(options)
|
39
|
+
options[:version] || 5
|
40
|
+
end
|
62
41
|
|
63
|
-
|
64
|
-
|
42
|
+
def build_action(options)
|
43
|
+
index_name = @command.table.downcase
|
44
|
+
case elasticsearch_version(options)
|
45
|
+
when 5, 6
|
46
|
+
{
|
47
|
+
"index" => {
|
48
|
+
"_index" => index_name,
|
49
|
+
"_type" => "groonga",
|
50
|
+
}
|
51
|
+
}
|
52
|
+
when 7
|
53
|
+
{
|
54
|
+
"index" => {
|
55
|
+
"_index" => index_name,
|
56
|
+
"_type"=>"_doc",
|
57
|
+
}
|
58
|
+
}
|
59
|
+
else
|
60
|
+
{
|
61
|
+
"index" => {
|
62
|
+
"_index" => index_name,
|
63
|
+
}
|
64
|
+
}
|
65
|
+
end
|
66
|
+
end
|
65
67
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
column_names.zip(column_values) do |column_name, column_value|
|
74
|
-
body[column_name] = column_value
|
75
|
-
end
|
76
|
-
components << JSON.generate(body)
|
77
|
-
end
|
68
|
+
def each_source
|
69
|
+
columns = @command.columns
|
70
|
+
values = @command.values || []
|
71
|
+
values.each do |value|
|
72
|
+
if value.is_a?(::Array)
|
73
|
+
if columns.nil?
|
74
|
+
columns = value
|
78
75
|
else
|
79
|
-
|
80
|
-
components << JSON.generate(load_value)
|
81
|
-
end
|
76
|
+
yield(Hash[columns.zip(value)])
|
82
77
|
end
|
78
|
+
else
|
79
|
+
yield(value)
|
83
80
|
end
|
84
81
|
end
|
85
|
-
components.join("\n")
|
86
82
|
end
|
87
83
|
end
|
88
84
|
end
|
data/test/command/test-base.rb
CHANGED
@@ -134,13 +134,53 @@ select \\
|
|
134
134
|
end
|
135
135
|
end
|
136
136
|
|
137
|
+
sub_test_case("no use :columns") do
|
138
|
+
def single_record
|
139
|
+
load = Groonga::Command::Load.new("load",
|
140
|
+
:table => "Site",
|
141
|
+
:values => <<-VALUES)
|
142
|
+
[
|
143
|
+
["_key", "title"]
|
144
|
+
["http://example.org/","This is test record 1!"]
|
145
|
+
]
|
146
|
+
VALUES
|
147
|
+
|
148
|
+
expected = <<-OUTPUT.chomp
|
149
|
+
{"index":{"_index":"site","_type":"groonga"}}
|
150
|
+
{"_key":"http://example.org/","title":"This is test record 1!"}
|
151
|
+
OUTPUT
|
152
|
+
|
153
|
+
assert_equal(expected, load.to_elasticsearch_format)
|
154
|
+
end
|
155
|
+
|
156
|
+
def multiple_records
|
157
|
+
load = Groonga::Command::Load.new("load",
|
158
|
+
:table => "Site",
|
159
|
+
:columns => "_key,title",
|
160
|
+
:values => <<-VALUES)
|
161
|
+
[
|
162
|
+
["http://example.org/","This is test record 1!"],
|
163
|
+
["http://example.net/","This is test record 2!"]
|
164
|
+
]
|
165
|
+
VALUES
|
166
|
+
|
167
|
+
expected = <<-OUTPUT.chomp
|
168
|
+
{"index":{"_index":"site","_type":"groonga"}}
|
169
|
+
{"_key":"http://example.org/","title":"This is test record 1!"}
|
170
|
+
{"_key":"http://example.net/","title":"This is test record 2!"}
|
171
|
+
OUTPUT
|
172
|
+
|
173
|
+
assert_equal(expected, load.to_elasticsearch_format)
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
137
177
|
sub_test_case("single record") do
|
138
178
|
def test_brackets_format
|
139
|
-
load = Groonga::Command::
|
179
|
+
load = Groonga::Command::Load.new("load",
|
140
180
|
:table => "Site",
|
181
|
+
:columns => "_key,title",
|
141
182
|
:values => <<-VALUES)
|
142
183
|
[
|
143
|
-
["_key","title"],
|
144
184
|
["http://example.org/","This is test record 1!"]
|
145
185
|
]
|
146
186
|
VALUES
|
@@ -154,7 +194,7 @@ select \\
|
|
154
194
|
end
|
155
195
|
|
156
196
|
def test_curly_brackets_format
|
157
|
-
load = Groonga::Command::
|
197
|
+
load = Groonga::Command::Load.new("load",
|
158
198
|
:table => "Site",
|
159
199
|
:values => <<-VALUES)
|
160
200
|
[
|
@@ -173,11 +213,11 @@ select \\
|
|
173
213
|
|
174
214
|
sub_test_case("multiple records") do
|
175
215
|
def test_brackets_format
|
176
|
-
load = Groonga::Command::
|
216
|
+
load = Groonga::Command::Load.new("load",
|
177
217
|
:table => "Site",
|
218
|
+
:columns => "_key,title",
|
178
219
|
:values => <<-VALUES)
|
179
220
|
[
|
180
|
-
["_key","title"],
|
181
221
|
["http://example.org/","This is test record 1!"],
|
182
222
|
["http://example.net/","This is test record 2!"]
|
183
223
|
]
|
@@ -186,6 +226,7 @@ select \\
|
|
186
226
|
expected = <<-OUTPUT.chomp
|
187
227
|
{"index":{"_index":"site","_type":"groonga"}}
|
188
228
|
{"_key":"http://example.org/","title":"This is test record 1!"}
|
229
|
+
{"index":{"_index":"site","_type":"groonga"}}
|
189
230
|
{"_key":"http://example.net/","title":"This is test record 2!"}
|
190
231
|
OUTPUT
|
191
232
|
|
@@ -193,7 +234,7 @@ select \\
|
|
193
234
|
end
|
194
235
|
|
195
236
|
def test_curly_brackets_format
|
196
|
-
load = Groonga::Command::
|
237
|
+
load = Groonga::Command::Load.new("load",
|
197
238
|
:table => "Site",
|
198
239
|
:values => <<-VALUES)
|
199
240
|
[
|
@@ -205,6 +246,7 @@ select \\
|
|
205
246
|
expected = <<-OUTPUT.chomp
|
206
247
|
{"index":{"_index":"site","_type":"groonga"}}
|
207
248
|
{"_key":"http://example.org/","title":"This is test record 1!"}
|
249
|
+
{"index":{"_index":"site","_type":"groonga"}}
|
208
250
|
{"_key":"http://example.net/","title":"This is test record 2!"}
|
209
251
|
OUTPUT
|
210
252
|
|
@@ -213,11 +255,11 @@ select \\
|
|
213
255
|
end
|
214
256
|
|
215
257
|
def setup
|
216
|
-
@load = Groonga::Command::
|
258
|
+
@load = Groonga::Command::Load.new("load",
|
217
259
|
:table => "Site",
|
260
|
+
:columns =>"_key,title",
|
218
261
|
:values => <<-VALUES)
|
219
262
|
[
|
220
|
-
["_key","title"],
|
221
263
|
["http://example.org/","This is test record 1!"]
|
222
264
|
]
|
223
265
|
VALUES
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: groonga-command
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kouhei Sutou
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-03-
|
11
|
+
date: 2019-03-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|