rroonga 4.0.8 → 5.0.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/README.md +2 -2
- data/doc/text/news.textile +19 -0
- data/ext/groonga/rb-grn-exception.c +35 -1
- data/ext/groonga/rb-grn-normalizer.c +37 -7
- data/ext/groonga/rb-grn-table.c +106 -35
- data/ext/groonga/rb-grn.h +3 -2
- data/lib/groonga/record.rb +45 -1
- data/rroonga-build.rb +6 -5
- data/test/groonga-test-utils.rb +9 -0
- data/test/test-array.rb +11 -0
- data/test/test-exception.rb +3 -1
- data/test/test-normalizer.rb +28 -0
- data/test/test-record.rb +34 -0
- data/test/test-table-group.rb +366 -0
- data/test/test-table.rb +0 -182
- metadata +45 -43
data/rroonga-build.rb
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
#
|
|
3
|
+
# Copyright (C) 2015 Masafumi Yokoyama <yokoyama@clear-code.com>
|
|
3
4
|
# Copyright (C) 2009-2014 Kouhei Sutou <kou@clear-code.com>
|
|
4
5
|
#
|
|
5
6
|
# This library is free software; you can redistribute it and/or
|
|
@@ -17,17 +18,17 @@
|
|
|
17
18
|
|
|
18
19
|
module RroongaBuild
|
|
19
20
|
module RequiredGroongaVersion
|
|
20
|
-
MAJOR =
|
|
21
|
+
MAJOR = 5
|
|
21
22
|
MINOR = 0
|
|
22
|
-
MICRO =
|
|
23
|
+
MICRO = 0
|
|
23
24
|
VERSION = [MAJOR, MINOR, MICRO]
|
|
24
|
-
RELEASED_DATE = Time.utc(
|
|
25
|
+
RELEASED_DATE = Time.utc(2015, 2, 9)
|
|
25
26
|
end
|
|
26
27
|
|
|
27
28
|
module LatestGroongaVersion
|
|
28
|
-
MAJOR =
|
|
29
|
+
MAJOR = 5
|
|
29
30
|
MINOR = 0
|
|
30
|
-
MICRO =
|
|
31
|
+
MICRO = 0
|
|
31
32
|
VERSION = [MAJOR, MINOR, MICRO]
|
|
32
33
|
end
|
|
33
34
|
|
data/test/groonga-test-utils.rb
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# Copyright (C) 2015 Masafumi Yokoyama <yokoyama@clear-code.com>
|
|
1
2
|
# Copyright (C) 2009-2014 Kouhei Sutou <kou@clear-code.com>
|
|
2
3
|
#
|
|
3
4
|
# This library is free software; you can redistribute it and/or
|
|
@@ -165,6 +166,14 @@ module GroongaTestUtils
|
|
|
165
166
|
omit("Ruby 1.9 is needed.") unless ruby19?
|
|
166
167
|
end
|
|
167
168
|
|
|
169
|
+
def linux?
|
|
170
|
+
/linux/ =~ RUBY_PLATFORM
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
def only_linux
|
|
174
|
+
omit("This test is only for Linux system.") unless linux?
|
|
175
|
+
end
|
|
176
|
+
|
|
168
177
|
def support_self_recursive_equal?
|
|
169
178
|
self_recursive_hash1 = {}
|
|
170
179
|
self_recursive_hash1["next"] = self_recursive_hash1
|
data/test/test-array.rb
CHANGED
|
@@ -242,6 +242,17 @@ EXPECTED_OUTPUT
|
|
|
242
242
|
$stdout.sync = true
|
|
243
243
|
|
|
244
244
|
base_dir = #{base_dir.dump}
|
|
245
|
+
|
|
246
|
+
groonga_command_dir = File.join(base_dir, "..", "groonga-command")
|
|
247
|
+
if File.exist?(groonga_command_dir)
|
|
248
|
+
$LOAD_PATH.unshift(File.join(groonga_command_dir, "lib"))
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
groonga_client_dir = File.join(base_dir, "..", "groonga-client")
|
|
252
|
+
if File.exist?(groonga_client_dir)
|
|
253
|
+
$LOAD_PATH.unshift(File.join(groonga_client_dir, "lib"))
|
|
254
|
+
end
|
|
255
|
+
|
|
245
256
|
ext_dir = File.join(base_dir, "ext", "groonga")
|
|
246
257
|
lib_dir = File.join(base_dir, "lib")
|
|
247
258
|
|
data/test/test-exception.rb
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
# Copyright (C) 2014-2015 Masafumi Yokoyama <yokoyama@clear-code.com>
|
|
1
2
|
# Copyright (C) 2009-2014 Kouhei Sutou <kou@clear-code.com>
|
|
2
|
-
# Copyright (C) 2014 Masafumi Yokoyama <myokoym@gmail.com>
|
|
3
3
|
#
|
|
4
4
|
# This library is free software; you can redistribute it and/or
|
|
5
5
|
# modify it under the terms of the GNU Lesser General Public
|
|
@@ -97,6 +97,8 @@ class ExceptionTest < Test::Unit::TestCase
|
|
|
97
97
|
assert_const_defined(Groonga, :UnsupportedCommandVersion)
|
|
98
98
|
assert_const_defined(Groonga, :NormalizerError)
|
|
99
99
|
assert_const_defined(Groonga, :TokenFilterError)
|
|
100
|
+
assert_const_defined(Groonga, :CommandError)
|
|
101
|
+
assert_const_defined(Groonga, :PluginError)
|
|
100
102
|
end
|
|
101
103
|
end
|
|
102
104
|
|
data/test/test-normalizer.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
#
|
|
1
3
|
# Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
|
|
2
4
|
#
|
|
3
5
|
# This library is free software; you can redistribute it and/or
|
|
@@ -21,4 +23,30 @@ class NormalizerTest < Test::Unit::TestCase
|
|
|
21
23
|
def test_normalize
|
|
22
24
|
assert_equal("abc", Groonga::Normalizer.normalize("AbC"))
|
|
23
25
|
end
|
|
26
|
+
|
|
27
|
+
def test_normalize_with_space
|
|
28
|
+
assert_equal("abcdefgh", Groonga::Normalizer.normalize("AbC Def gh"))
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def test_normalize_with_space_explicitly
|
|
32
|
+
assert_equal("abcdefgh",
|
|
33
|
+
Groonga::Normalizer.normalize("AbC Def gh",
|
|
34
|
+
:remove_blank => true))
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def test_normalize_group_text
|
|
38
|
+
assert_equal("キロメートルキロメートルキロメートルキロメートル",
|
|
39
|
+
Groonga::Normalizer.normalize("㌖㌖㌖㌖"));
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def test_normalize_keep_space
|
|
43
|
+
# full width space => half width space
|
|
44
|
+
assert_equal("abc def gh",
|
|
45
|
+
Groonga::Normalizer.normalize("AbC Def gh",
|
|
46
|
+
:remove_blank => false))
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def test_normalize_tilda
|
|
50
|
+
assert_equal("~~~", Groonga::Normalizer.normalize("~~〜"))
|
|
51
|
+
end
|
|
24
52
|
end
|
data/test/test-record.rb
CHANGED
|
@@ -619,6 +619,11 @@ class RecordTest < Test::Unit::TestCase
|
|
|
619
619
|
def setup
|
|
620
620
|
setup_database
|
|
621
621
|
setup_schema
|
|
622
|
+
setup_tz
|
|
623
|
+
end
|
|
624
|
+
|
|
625
|
+
def teardown
|
|
626
|
+
teardown_tz
|
|
622
627
|
end
|
|
623
628
|
|
|
624
629
|
def setup_schema
|
|
@@ -633,6 +638,14 @@ class RecordTest < Test::Unit::TestCase
|
|
|
633
638
|
@bookmarks = Groonga["Bookmarks"]
|
|
634
639
|
end
|
|
635
640
|
|
|
641
|
+
def setup_tz
|
|
642
|
+
@tz_original = ENV["TZ"]
|
|
643
|
+
end
|
|
644
|
+
|
|
645
|
+
def teardown_tz
|
|
646
|
+
ENV["TZ"] = @tz_original
|
|
647
|
+
end
|
|
648
|
+
|
|
636
649
|
def test_to_json
|
|
637
650
|
ENV["TZ"] = "Japan"
|
|
638
651
|
created_at = Time.parse("2013-05-16T16:57:34+09:00")
|
|
@@ -652,5 +665,26 @@ class RecordTest < Test::Unit::TestCase
|
|
|
652
665
|
}.to_json
|
|
653
666
|
assert_equal(expected, groonga.to_json)
|
|
654
667
|
end
|
|
668
|
+
|
|
669
|
+
def test_to_json_with_leap_second
|
|
670
|
+
only_linux
|
|
671
|
+
ENV["TZ"] = "right/Japan"
|
|
672
|
+
created_at = Time.parse("2012-07-01T08:59:60+09:00")
|
|
673
|
+
values = {
|
|
674
|
+
"uri" => "http://groonga.org/",
|
|
675
|
+
"rate" => 5,
|
|
676
|
+
"comment" => "Great!",
|
|
677
|
+
"created_at" => created_at,
|
|
678
|
+
}
|
|
679
|
+
groonga = @bookmarks.add(values)
|
|
680
|
+
expected = {
|
|
681
|
+
"_id" => groonga.id,
|
|
682
|
+
"comment" => values["comment"],
|
|
683
|
+
"created_at" => created_at.iso8601,
|
|
684
|
+
"rate" => values["rate"],
|
|
685
|
+
"uri" => values["uri"],
|
|
686
|
+
}.to_json
|
|
687
|
+
assert_equal(expected, groonga.to_json)
|
|
688
|
+
end
|
|
655
689
|
end
|
|
656
690
|
end
|
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
# Copyright (C) 2015 Masafumi Yokoyama <yokoyama@clear-code.com>
|
|
2
|
+
# Copyright (C) 2009-2013 Kouhei Sutou <kou@clear-code.com>
|
|
3
|
+
#
|
|
4
|
+
# This library is free software; you can redistribute it and/or
|
|
5
|
+
# modify it under the terms of the GNU Lesser General Public
|
|
6
|
+
# License version 2.1 as published by the Free Software Foundation.
|
|
7
|
+
#
|
|
8
|
+
# This library is distributed in the hope that it will be useful,
|
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
11
|
+
# Lesser General Public License for more details.
|
|
12
|
+
#
|
|
13
|
+
# You should have received a copy of the GNU Lesser General Public
|
|
14
|
+
# License along with this library; if not, write to the Free Software
|
|
15
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
16
|
+
|
|
17
|
+
class TableGroupTest < Test::Unit::TestCase
|
|
18
|
+
include GroongaTestUtils
|
|
19
|
+
|
|
20
|
+
setup :setup_database
|
|
21
|
+
|
|
22
|
+
class MaxNSubRecordsTest < self
|
|
23
|
+
setup
|
|
24
|
+
def setup_schema
|
|
25
|
+
Groonga::Schema.define do |schema|
|
|
26
|
+
schema.create_table("Bookmarks", :type => :hash) do |table|
|
|
27
|
+
table.text("title")
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
schema.create_table("Comments", :type => :array) do |table|
|
|
31
|
+
table.reference("bookmark")
|
|
32
|
+
table.text("content")
|
|
33
|
+
table.int32("rank")
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
setup
|
|
39
|
+
def setup_data
|
|
40
|
+
setup_bookmarks
|
|
41
|
+
setup_comments
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def setup_bookmarks
|
|
45
|
+
@bookmarks = Groonga["Bookmarks"]
|
|
46
|
+
@groonga = @bookmarks.add("http://groonga.org/", :title => "groonga")
|
|
47
|
+
@ruby = @bookmarks.add("http://ruby-lang.org/", :title => "Ruby")
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def setup_comments
|
|
51
|
+
@comments = Groonga["Comments"]
|
|
52
|
+
@comments.add(:bookmark => @groonga,
|
|
53
|
+
:content => "garbage comment1",
|
|
54
|
+
:rank => 0)
|
|
55
|
+
@comments.add(:bookmark => @groonga,
|
|
56
|
+
:content => "garbage comment2",
|
|
57
|
+
:rank => 0)
|
|
58
|
+
@comments.add(:bookmark => @groonga,
|
|
59
|
+
:content => "full-text search",
|
|
60
|
+
:rank => 1)
|
|
61
|
+
@comments.add(:bookmark => @groonga,
|
|
62
|
+
:content => "column store",
|
|
63
|
+
:rank => 5)
|
|
64
|
+
@comments.add(:bookmark => @ruby,
|
|
65
|
+
:content => "object oriented script language",
|
|
66
|
+
:rank => 100)
|
|
67
|
+
@comments.add(:bookmark => @ruby,
|
|
68
|
+
:content => "multi paradigm programming language",
|
|
69
|
+
:rank => 80)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
setup
|
|
73
|
+
def setup_searched
|
|
74
|
+
@records = @comments.select do |record|
|
|
75
|
+
record.rank > 0
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def test_upper_limit
|
|
80
|
+
grouped_records = @records.group("bookmark", :max_n_sub_records => 2)
|
|
81
|
+
groups = grouped_records.collect do |record|
|
|
82
|
+
sub_record_contents = record.sub_records.collect do |sub_record|
|
|
83
|
+
sub_record.content
|
|
84
|
+
end
|
|
85
|
+
[record.title, sub_record_contents]
|
|
86
|
+
end
|
|
87
|
+
assert_equal([
|
|
88
|
+
[
|
|
89
|
+
"groonga",
|
|
90
|
+
[
|
|
91
|
+
"full-text search",
|
|
92
|
+
"column store",
|
|
93
|
+
],
|
|
94
|
+
],
|
|
95
|
+
[
|
|
96
|
+
"Ruby",
|
|
97
|
+
[
|
|
98
|
+
"object oriented script language",
|
|
99
|
+
"multi paradigm programming language",
|
|
100
|
+
],
|
|
101
|
+
],
|
|
102
|
+
],
|
|
103
|
+
groups)
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def test_less_than_limit
|
|
107
|
+
sorted = @records.sort([{:key => "rank", :order => :descending}],
|
|
108
|
+
:limit => 3, :offset => 0)
|
|
109
|
+
grouped_records = sorted.group("bookmark", :max_n_sub_records => 2)
|
|
110
|
+
groups = grouped_records.collect do |record|
|
|
111
|
+
sub_record_ranks = record.sub_records.collect do |sub_record|
|
|
112
|
+
sub_record.rank
|
|
113
|
+
end
|
|
114
|
+
[record.title, sub_record_ranks]
|
|
115
|
+
end
|
|
116
|
+
assert_equal([
|
|
117
|
+
["Ruby", [100, 80]],
|
|
118
|
+
["groonga", [5]]
|
|
119
|
+
],
|
|
120
|
+
groups)
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
class KeyTest < self
|
|
125
|
+
setup
|
|
126
|
+
def setup_schema
|
|
127
|
+
Groonga::Schema.define do |schema|
|
|
128
|
+
schema.create_table("Bookmarks", :type => :hash) do |table|
|
|
129
|
+
table.text("title")
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
schema.create_table("Comments", :type => :array) do |table|
|
|
133
|
+
table.reference("bookmark")
|
|
134
|
+
table.text("content")
|
|
135
|
+
table.int32("rank")
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
setup
|
|
141
|
+
def setup_data
|
|
142
|
+
setup_bookmarks
|
|
143
|
+
setup_comments
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def setup_bookmarks
|
|
147
|
+
@bookmarks = Groonga["Bookmarks"]
|
|
148
|
+
@groonga = @bookmarks.add("http://groonga.org/", :title => "groonga")
|
|
149
|
+
@ruby = @bookmarks.add("http://ruby-lang.org/", :title => "Ruby")
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
def setup_comments
|
|
153
|
+
@comments = Groonga["Comments"]
|
|
154
|
+
@comments.add(:bookmark => @groonga,
|
|
155
|
+
:content => "full-text search")
|
|
156
|
+
@comments.add(:bookmark => @groonga,
|
|
157
|
+
:content => "column store")
|
|
158
|
+
@comments.add(:bookmark => @ruby,
|
|
159
|
+
:content => "object oriented script language")
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
def test_string
|
|
163
|
+
grouped_records = @comments.group("bookmark").collect do |record|
|
|
164
|
+
bookmark = record.key
|
|
165
|
+
[
|
|
166
|
+
record.n_sub_records,
|
|
167
|
+
bookmark["title"],
|
|
168
|
+
bookmark.key,
|
|
169
|
+
]
|
|
170
|
+
end
|
|
171
|
+
assert_equal([
|
|
172
|
+
[2, "groonga", "http://groonga.org/"],
|
|
173
|
+
[1, "Ruby", "http://ruby-lang.org/"],
|
|
174
|
+
],
|
|
175
|
+
grouped_records)
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
def test_array
|
|
179
|
+
grouped_records = @comments.group(["bookmark"]).collect do |record|
|
|
180
|
+
bookmark = record.key
|
|
181
|
+
[
|
|
182
|
+
record.n_sub_records,
|
|
183
|
+
bookmark["title"],
|
|
184
|
+
bookmark.key,
|
|
185
|
+
]
|
|
186
|
+
end
|
|
187
|
+
assert_equal([
|
|
188
|
+
[2, "groonga", "http://groonga.org/"],
|
|
189
|
+
[1, "Ruby", "http://ruby-lang.org/"],
|
|
190
|
+
],
|
|
191
|
+
grouped_records)
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
def test_accessor
|
|
195
|
+
grouped_records = @comments.group("bookmark._key").collect do |record|
|
|
196
|
+
[
|
|
197
|
+
record.n_sub_records,
|
|
198
|
+
record.key
|
|
199
|
+
]
|
|
200
|
+
end
|
|
201
|
+
assert_equal([
|
|
202
|
+
[2, "http://groonga.org/"],
|
|
203
|
+
[1, "http://ruby-lang.org/"],
|
|
204
|
+
],
|
|
205
|
+
grouped_records)
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
def test_nonexistent
|
|
209
|
+
message = "unknown group key: <\"nonexistent\">: <#{@comments.inspect}>"
|
|
210
|
+
assert_raise(ArgumentError.new(message)) do
|
|
211
|
+
@comments.group("nonexistent")
|
|
212
|
+
end
|
|
213
|
+
end
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
class MultipleKeyTest < self
|
|
217
|
+
setup
|
|
218
|
+
def setup_schema
|
|
219
|
+
Groonga::Schema.define do |schema|
|
|
220
|
+
schema.create_table("Memos", :type => :hash) do |table|
|
|
221
|
+
table.short_text("tag")
|
|
222
|
+
table.int64("priority")
|
|
223
|
+
end
|
|
224
|
+
end
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
setup
|
|
228
|
+
def setup_data
|
|
229
|
+
setup_memos
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
def setup_memos
|
|
233
|
+
@memos = Groonga["Memos"]
|
|
234
|
+
@memos.add("Groonga1",
|
|
235
|
+
:tag => "Groonga",
|
|
236
|
+
:priority => 10)
|
|
237
|
+
@memos.add("Groonga2",
|
|
238
|
+
:tag => "Groonga",
|
|
239
|
+
:priority => 20)
|
|
240
|
+
@memos.add("Mroonga1",
|
|
241
|
+
:tag => "Mroonga",
|
|
242
|
+
:priority => 10)
|
|
243
|
+
@memos.add("Mroonga2",
|
|
244
|
+
:tag => "Mroonga",
|
|
245
|
+
:priority => 10)
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
def test_two_keys
|
|
249
|
+
keys = ["tag", "priority"]
|
|
250
|
+
grouped_records = @memos.group(keys).collect do |record|
|
|
251
|
+
sub_record = record.sub_records.first
|
|
252
|
+
[
|
|
253
|
+
record.n_sub_records,
|
|
254
|
+
sub_record.tag,
|
|
255
|
+
sub_record.priority,
|
|
256
|
+
]
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
assert_equal([
|
|
260
|
+
[1, "Groonga", 10],
|
|
261
|
+
[1, "Groonga", 20],
|
|
262
|
+
[2, "Mroonga", 10],
|
|
263
|
+
],
|
|
264
|
+
grouped_records)
|
|
265
|
+
end
|
|
266
|
+
end
|
|
267
|
+
|
|
268
|
+
class CalculationTest < self
|
|
269
|
+
setup
|
|
270
|
+
def setup_schema
|
|
271
|
+
Groonga::Schema.define do |schema|
|
|
272
|
+
schema.create_table("Tags", :type => :hash)
|
|
273
|
+
|
|
274
|
+
schema.create_table("Memos", :type => :hash) do |table|
|
|
275
|
+
table.reference("tag")
|
|
276
|
+
table.int64("priority")
|
|
277
|
+
end
|
|
278
|
+
end
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
setup
|
|
282
|
+
def setup_data
|
|
283
|
+
setup_tags
|
|
284
|
+
setup_memos
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
def setup_tags
|
|
288
|
+
@tags = Groonga["Tags"]
|
|
289
|
+
@groonga = @tags.add("Groonga")
|
|
290
|
+
@mroonga = @tags.add("Mroonga")
|
|
291
|
+
@rroonga = @tags.add("Rroonga")
|
|
292
|
+
end
|
|
293
|
+
|
|
294
|
+
def setup_memos
|
|
295
|
+
@memos = Groonga["Memos"]
|
|
296
|
+
@memos.add("Groonga1",
|
|
297
|
+
:tag => @groonga,
|
|
298
|
+
:priority => 10)
|
|
299
|
+
@memos.add("Groonga2",
|
|
300
|
+
:tag => @groonga,
|
|
301
|
+
:priority => 20)
|
|
302
|
+
@memos.add("Groonga3",
|
|
303
|
+
:tag => @groonga,
|
|
304
|
+
:priority => 40)
|
|
305
|
+
@memos.add("Mroonga1",
|
|
306
|
+
:tag => @mroonga,
|
|
307
|
+
:priority => 50)
|
|
308
|
+
@memos.add("Mroonga2",
|
|
309
|
+
:tag => @mroonga,
|
|
310
|
+
:priority => 25)
|
|
311
|
+
@memos.add("Mroonga3",
|
|
312
|
+
:tag => @mroonga,
|
|
313
|
+
:priority => 10)
|
|
314
|
+
@memos.add("Rroonga1",
|
|
315
|
+
:tag => @rroonga,
|
|
316
|
+
:priority => 25)
|
|
317
|
+
@memos.add("Rroonga2",
|
|
318
|
+
:tag => @rroonga,
|
|
319
|
+
:priority => -25)
|
|
320
|
+
@memos.add("Rroonga3",
|
|
321
|
+
:tag => @rroonga,
|
|
322
|
+
:priority => 0)
|
|
323
|
+
end
|
|
324
|
+
|
|
325
|
+
def test_max
|
|
326
|
+
grouped_records = @memos.group("tag",
|
|
327
|
+
:calc_target => "priority",
|
|
328
|
+
:calc_types => [:max]).collect do |group|
|
|
329
|
+
tag = group.key
|
|
330
|
+
[
|
|
331
|
+
tag.key,
|
|
332
|
+
group.max,
|
|
333
|
+
]
|
|
334
|
+
end
|
|
335
|
+
|
|
336
|
+
assert_equal([
|
|
337
|
+
["Groonga", 40],
|
|
338
|
+
["Mroonga", 50],
|
|
339
|
+
["Rroonga", 25],
|
|
340
|
+
],
|
|
341
|
+
grouped_records)
|
|
342
|
+
end
|
|
343
|
+
|
|
344
|
+
def test_all_types
|
|
345
|
+
grouped_records = @memos.group("tag",
|
|
346
|
+
:calc_target => "priority",
|
|
347
|
+
:calc_types => [:max, :min, :sum, :average]).collect do |group|
|
|
348
|
+
tag = group.key
|
|
349
|
+
[
|
|
350
|
+
tag.key,
|
|
351
|
+
group.max,
|
|
352
|
+
group.min,
|
|
353
|
+
group.sum,
|
|
354
|
+
group.average.round(3),
|
|
355
|
+
]
|
|
356
|
+
end
|
|
357
|
+
|
|
358
|
+
assert_equal([
|
|
359
|
+
["Groonga", 40, 10, 70, 23.333],
|
|
360
|
+
["Mroonga", 50, 10, 85, 28.333],
|
|
361
|
+
["Rroonga", 25, -25, 0, 0.0],
|
|
362
|
+
],
|
|
363
|
+
grouped_records)
|
|
364
|
+
end
|
|
365
|
+
end
|
|
366
|
+
end
|