rroonga 5.0.0 → 5.0.1

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.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +1 -0
  3. data/Rakefile +1 -10
  4. data/ext/groonga/extconf.rb +3 -1
  5. data/ext/groonga/rb-grn-array.c +1 -1
  6. data/ext/groonga/rb-grn-column.c +33 -67
  7. data/ext/groonga/rb-grn-context.c +5 -5
  8. data/ext/groonga/rb-grn-database.c +2 -2
  9. data/ext/groonga/rb-grn-double-array-trie.c +4 -2
  10. data/ext/groonga/rb-grn-encoding-support.c +7 -1
  11. data/ext/groonga/rb-grn-equal-operator.c +85 -0
  12. data/ext/groonga/rb-grn-exception.c +17 -0
  13. data/ext/groonga/rb-grn-expression.c +85 -43
  14. data/ext/groonga/rb-grn-greater-equal-operator.c +88 -0
  15. data/ext/groonga/rb-grn-greater-operator.c +85 -0
  16. data/ext/groonga/rb-grn-hash.c +1 -1
  17. data/ext/groonga/rb-grn-index-column.c +150 -11
  18. data/ext/groonga/rb-grn-less-equal-operator.c +88 -0
  19. data/ext/groonga/rb-grn-less-operator.c +85 -0
  20. data/ext/groonga/rb-grn-logger.c +5 -5
  21. data/ext/groonga/rb-grn-match-operator.c +86 -0
  22. data/ext/groonga/rb-grn-normalizer.c +8 -1
  23. data/ext/groonga/rb-grn-not-equal-operator.c +85 -0
  24. data/ext/groonga/rb-grn-object.c +170 -36
  25. data/ext/groonga/rb-grn-operator.c +395 -172
  26. data/ext/groonga/rb-grn-patricia-trie.c +10 -8
  27. data/ext/groonga/rb-grn-plugin.c +51 -3
  28. data/ext/groonga/rb-grn-prefix-operator.c +86 -0
  29. data/ext/groonga/rb-grn-procedure-type.c +4 -0
  30. data/ext/groonga/rb-grn-query-logger.c +4 -4
  31. data/ext/groonga/rb-grn-regexp-operator.c +85 -0
  32. data/ext/groonga/rb-grn-snippet.c +1 -1
  33. data/ext/groonga/rb-grn-table-key-support.c +9 -5
  34. data/ext/groonga/rb-grn-table.c +52 -66
  35. data/ext/groonga/rb-grn-type.c +1 -1
  36. data/ext/groonga/rb-grn-utils.c +22 -3
  37. data/ext/groonga/rb-grn.h +31 -4
  38. data/ext/groonga/rb-groonga.c +9 -9
  39. data/lib/groonga/context.rb +31 -0
  40. data/lib/groonga/expression-builder.rb +14 -1
  41. data/lib/groonga/record.rb +10 -8
  42. data/lib/groonga/schema.rb +3 -1
  43. data/rroonga-build.rb +2 -2
  44. data/rroonga.gemspec +3 -3
  45. data/test/groonga-test-utils.rb +4 -0
  46. data/test/test-column.rb +28 -26
  47. data/test/test-exception.rb +1 -0
  48. data/test/test-expression-builder.rb +83 -1
  49. data/test/test-expression.rb +80 -48
  50. data/test/test-index-column.rb +102 -29
  51. data/test/test-normalizer.rb +35 -29
  52. data/test/test-operator.rb +214 -0
  53. data/test/test-plugin.rb +24 -6
  54. data/test/test-procedure.rb +29 -0
  55. data/test/test-schema-type.rb +14 -0
  56. data/test/test-table-select-mecab.rb +1 -4
  57. data/test/test-table.rb +7 -0
  58. data/test/test-token-regexp.rb +30 -0
  59. data/test/test-type.rb +24 -0
  60. metadata +61 -49
  61. data/doc/text/news.textile +0 -1217
@@ -99,6 +99,7 @@ class ExceptionTest < Test::Unit::TestCase
99
99
  assert_const_defined(Groonga, :TokenFilterError)
100
100
  assert_const_defined(Groonga, :CommandError)
101
101
  assert_const_defined(Groonga, :PluginError)
102
+ assert_const_defined(Groonga, :ScorerError)
102
103
  end
103
104
  end
104
105
 
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  #
3
- # Copyright (C) 2014 Masafumi Yokoyama <myokoym@gmail.com>
3
+ # Copyright (C) 2014-2015 Masafumi Yokoyama <yokoyama@clear-code.com>
4
4
  # Copyright (C) 2009-2012 Kouhei Sutou <kou@clear-code.com>
5
5
  #
6
6
  # This library is free software; you can redistribute it and/or
@@ -248,6 +248,88 @@ class ExpressionBuilderTest < Test::Unit::TestCase
248
248
  end
249
249
  end
250
250
 
251
+ class RegexpSearchTest < self
252
+ def setup_tables
253
+ Groonga::Schema.define do |schema|
254
+ schema.create_table("Users",
255
+ :type => :hash,
256
+ :key_type => "ShortText") do |table|
257
+ table.short_text("name")
258
+ end
259
+
260
+ schema.create_table("Terms",
261
+ :type => :patricia_trie,
262
+ :key_type => "ShortText",
263
+ :default_tokenizer => "TokenRegexp",
264
+ :normalizer => "NormalizerAuto") do |table|
265
+ table.index("Users.name")
266
+ end
267
+ end
268
+
269
+ @users = Groonga["Users"]
270
+ end
271
+
272
+ def setup_data
273
+ @users.add("sato", :name => "kazuki sato")
274
+ @users.add("suzuki", :name => "Shiro SUZUKI")
275
+ @users.add("ito", :name => "Takashi Ito")
276
+ end
277
+
278
+ class BlockTest < self
279
+ def test_match
280
+ result = @users.select do |record|
281
+ record["name"] =~ /sh/
282
+ end
283
+ assert_equal(["ito", "suzuki"],
284
+ result.collect {|record| record.key.key}.sort)
285
+ end
286
+
287
+ def test_not_match
288
+ result = @users.select do |record|
289
+ record["name"] =~ /abcabcabc/
290
+ end
291
+ assert_equal([],
292
+ result.collect {|record| record.key.key}.sort)
293
+ end
294
+
295
+ def test_beginning_of_text
296
+ result = @users.select do |record|
297
+ record["name"] =~ /\Ash/
298
+ end
299
+ assert_equal(["suzuki"],
300
+ result.collect {|record| record.key.key}.sort)
301
+ end
302
+
303
+ def test_end_of_text
304
+ result = @users.select do |record|
305
+ record["name"] =~ /ki\z/
306
+ end
307
+ assert_equal(["suzuki"],
308
+ result.collect {|record| record.key.key}.sort)
309
+ end
310
+ end
311
+
312
+ class QueryStringTest < self
313
+ def test_match
314
+ result = @users.select("name:~t")
315
+ assert_equal(["ito", "sato"],
316
+ result.collect {|record| record.key.key}.sort)
317
+ end
318
+
319
+ def test_not_match
320
+ result = @users.select("name:~x")
321
+ assert_equal([],
322
+ result.collect {|record| record.key.key}.sort)
323
+ end
324
+
325
+ def test_beginning_of_text
326
+ result = @users.select("name:~\\\\As")
327
+ assert_equal(["suzuki"],
328
+ result.collect {|record| record.key.key}.sort)
329
+ end
330
+ end
331
+ end
332
+
251
333
  class PrefixSearchTest < self
252
334
  def setup_tables
253
335
  Groonga::Schema.define do |schema|
@@ -78,15 +78,14 @@ class ExpressionTest < Test::Unit::TestCase
78
78
  expression.compile
79
79
 
80
80
  assert_equal(<<-INSPECTED.chomp, expression.inspect)
81
- #<Groonga::Expression #<expr
81
+ #<Groonga::Expression
82
82
  vars:{
83
83
  },
84
84
  codes:{
85
- 0:<push(), modify:2, value:1>,
86
- 1:<push(), modify:0, value:1>,
87
- 2:<plus(), modify:0, value:(NULL)>
88
- }
89
- >>
85
+ 0:<push n_args:1, flags:0, modify:2, value:1>,
86
+ 1:<push n_args:1, flags:0, modify:0, value:1>,
87
+ 2:<plus n_args:2, flags:0, modify:0, value:(NULL)>
88
+ }>
90
89
  INSPECTED
91
90
  end
92
91
 
@@ -172,26 +171,24 @@ class ExpressionTest < Test::Unit::TestCase
172
171
  Groonga::Operator::PUSH,
173
172
  1)
174
173
  assert_equal(<<-INSPECTED.chomp, @expression.inspect)
175
- #<Groonga::Expression #<expr
174
+ #<Groonga::Expression
176
175
  vars:{
177
176
  },
178
177
  codes:{
179
- 0:<push(), modify:0, value:#<proc:tokenizer TokenBigram arguments:[$1, $2, $3]>>
180
- }
181
- >>
178
+ 0:<push n_args:1, flags:0, modify:0, value:#<proc:tokenizer TokenBigram arguments:[$1, $2, $3]>>
179
+ }>
182
180
  INSPECTED
183
181
  end
184
182
 
185
183
  def test_name
186
184
  @expression.append_object(Groonga["TokenBigram"], "push", 1)
187
185
  assert_equal(<<-INSPECTED.chomp, @expression.inspect)
188
- #<Groonga::Expression #<expr
186
+ #<Groonga::Expression
189
187
  vars:{
190
188
  },
191
189
  codes:{
192
- 0:<push(), modify:0, value:#<proc:tokenizer TokenBigram arguments:[$1, $2, $3]>>
193
- }
194
- >>
190
+ 0:<push n_args:1, flags:0, modify:0, value:#<proc:tokenizer TokenBigram arguments:[$1, $2, $3]>>
191
+ }>
195
192
  INSPECTED
196
193
  end
197
194
  end
@@ -207,67 +204,102 @@ class ExpressionTest < Test::Unit::TestCase
207
204
  def test_constant
208
205
  @expression.append_constant(29, Groonga::Operator::PUSH, 1)
209
206
  assert_equal(<<-INSPECTED.chomp, @expression.inspect)
210
- #<Groonga::Expression #<expr
207
+ #<Groonga::Expression
211
208
  vars:{
212
209
  },
213
210
  codes:{
214
- 0:<push(), modify:0, value:29>
215
- }
216
- >>
211
+ 0:<push n_args:1, flags:0, modify:0, value:29>
212
+ }>
217
213
  INSPECTED
218
214
  end
219
215
 
220
216
  def test_name
221
217
  @expression.append_constant(29, "push", 1)
222
218
  assert_equal(<<-INSPECTED.chomp, @expression.inspect)
223
- #<Groonga::Expression #<expr
219
+ #<Groonga::Expression
224
220
  vars:{
225
221
  },
226
222
  codes:{
227
- 0:<push(), modify:0, value:29>
228
- }
229
- >>
223
+ 0:<push n_args:1, flags:0, modify:0, value:29>
224
+ }>
230
225
  INSPECTED
231
226
  end
232
227
  end
233
228
  end
234
229
 
235
230
  class AppendOperatorTest < self
236
- setup
237
- def setup_expression
238
- @expression = Groonga::Expression.new
239
- @expression.append_constant(29)
240
- @expression.append_constant(92)
241
- end
231
+ class PlusTest < self
232
+ setup
233
+ def setup_expression
234
+ @expression = Groonga::Expression.new
235
+ @expression.append_constant(29)
236
+ @expression.append_constant(92)
237
+ end
238
+
239
+ def test_constant
240
+ @expression.append_operation(Groonga::Operator::PLUS, 2)
241
+ assert_equal(<<-INSPECTED.chomp, @expression.inspect)
242
+ #<Groonga::Expression
243
+ vars:{
244
+ },
245
+ codes:{
246
+ 0:<push n_args:1, flags:0, modify:2, value:29>,
247
+ 1:<push n_args:1, flags:0, modify:0, value:92>,
248
+ 2:<plus n_args:2, flags:0, modify:0, value:(NULL)>
249
+ }>
250
+ INSPECTED
251
+ end
242
252
 
243
- def test_constant
244
- @expression.append_operation(Groonga::Operator::PLUS, 2)
245
- assert_equal(<<-INSPECTED.chomp, @expression.inspect)
246
- #<Groonga::Expression #<expr
253
+ def test_name
254
+ @expression.append_operation("plus", 2)
255
+ assert_equal(<<-INSPECTED.chomp, @expression.inspect)
256
+ #<Groonga::Expression
247
257
  vars:{
248
258
  },
249
259
  codes:{
250
- 0:<push(), modify:2, value:29>,
251
- 1:<push(), modify:0, value:92>,
252
- 2:<plus(), modify:0, value:(NULL)>
253
- }
254
- >>
255
- INSPECTED
260
+ 0:<push n_args:1, flags:0, modify:2, value:29>,
261
+ 1:<push n_args:1, flags:0, modify:0, value:92>,
262
+ 2:<plus n_args:2, flags:0, modify:0, value:(NULL)>
263
+ }>
264
+ INSPECTED
265
+ end
256
266
  end
257
267
 
258
- def test_name
259
- @expression.append_operation("plus", 2)
260
- assert_equal(<<-INSPECTED.chomp, @expression.inspect)
261
- #<Groonga::Expression #<expr
268
+ class RegexpTest < self
269
+ setup
270
+ def setup_expression
271
+ @expression = Groonga::Expression.new
272
+ @expression.append_constant("Alice")
273
+ @expression.append_constant(/\A[aA].*l/.source)
274
+ end
275
+
276
+ def test_constant
277
+ @expression.append_operation(Groonga::Operator::REGEXP, 2)
278
+ assert_equal(<<-INSPECTED.chomp, @expression.inspect)
279
+ #<Groonga::Expression
262
280
  vars:{
263
281
  },
264
282
  codes:{
265
- 0:<push(), modify:2, value:29>,
266
- 1:<push(), modify:0, value:92>,
267
- 2:<plus(), modify:0, value:(NULL)>
268
- }
269
- >>
270
- INSPECTED
283
+ 0:<push n_args:1, flags:0, modify:2, value:"Alice">,
284
+ 1:<push n_args:1, flags:0, modify:0, value:"\\\\A[aA].*l">,
285
+ 2:<regexp n_args:2, flags:0, modify:0, value:(NULL)>
286
+ }>
287
+ INSPECTED
288
+ end
289
+
290
+ def test_name
291
+ @expression.append_operation("regexp", 2)
292
+ assert_equal(<<-INSPECTED.chomp, @expression.inspect)
293
+ #<Groonga::Expression
294
+ vars:{
295
+ },
296
+ codes:{
297
+ 0:<push n_args:1, flags:0, modify:2, value:"Alice">,
298
+ 1:<push n_args:1, flags:0, modify:0, value:"\\\\A[aA].*l">,
299
+ 2:<regexp n_args:2, flags:0, modify:0, value:(NULL)>
300
+ }>
301
+ INSPECTED
302
+ end
271
303
  end
272
304
  end
273
305
 
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  #
3
- # Copyright (C) 2009-2014 Kouhei Sutou <kou@clear-code.com>
3
+ # Copyright (C) 2009-2015 Kouhei Sutou <kou@clear-code.com>
4
4
  #
5
5
  # This library is free software; you can redistribute it and/or
6
6
  # modify it under the terms of the GNU Lesser General Public
@@ -502,43 +502,116 @@ class IndexColumnTest < Test::Unit::TestCase
502
502
  end
503
503
 
504
504
  class EstimateSizeTest < self
505
- setup
506
- def setup_schema
507
- Groonga::Schema.define do |schema|
508
- schema.create_table("Articles") do |table|
509
- table.text("content")
510
- end
505
+ sub_test_case "token ID" do
506
+ setup
507
+ def setup_schema
508
+ Groonga::Schema.define do |schema|
509
+ schema.create_table("Articles") do |table|
510
+ table.text("content")
511
+ end
511
512
 
512
- schema.create_table("Terms",
513
- :type => :hash,
514
- :key_type => "ShortText",
515
- :default_tokenizer => "TokenBigram",
516
- :normalizer => "NormalizerAuto") do |table|
517
- table.index("Articles.content",
518
- :name => "articles_content",
519
- :with_position => true,
520
- :with_section => true)
513
+ schema.create_table("Terms",
514
+ :type => :hash,
515
+ :key_type => "ShortText",
516
+ :default_tokenizer => "TokenBigram",
517
+ :normalizer => "NormalizerAuto") do |table|
518
+ table.index("Articles.content",
519
+ :name => "articles_content",
520
+ :with_position => true,
521
+ :with_section => true)
522
+ end
521
523
  end
524
+
525
+ @articles = Groonga["Articles"]
526
+ @terms = Groonga["Terms"]
527
+ @index = Groonga["Terms.articles_content"]
522
528
  end
523
529
 
524
- @articles = Groonga["Articles"]
525
- @terms = Groonga["Terms"]
526
- @index = Groonga["Terms.articles_content"]
527
- end
530
+ setup
531
+ def setup_data
532
+ @articles.add(:content => "Groonga is fast")
533
+ @articles.add(:content => "Rroonga is fast")
534
+ @articles.add(:content => "Mroonga is fast")
535
+ end
528
536
 
529
- setup
530
- def setup_data
531
- @articles.add(:content => "Groonga is fast")
532
- @articles.add(:content => "Rroonga is fast")
533
- @articles.add(:content => "Mroonga is fast")
537
+ def test_id
538
+ assert_equal(7, @index.estimate_size(@terms["fast"].id))
539
+ end
540
+
541
+ def test_record
542
+ assert_equal(7, @index.estimate_size(@terms["fast"]))
543
+ end
534
544
  end
535
545
 
536
- def test_id
537
- assert_equal(7, @index.estimate_size(@terms["fast"].id))
546
+ sub_test_case "query" do
547
+ setup
548
+ def setup_schema
549
+ Groonga::Schema.define do |schema|
550
+ schema.create_table("Articles") do |table|
551
+ table.text("content")
552
+ end
553
+
554
+ schema.create_table("Terms",
555
+ :type => :hash,
556
+ :key_type => "ShortText",
557
+ :default_tokenizer => "TokenBigramSplitSymbolAlpha",
558
+ :normalizer => "NormalizerAuto") do |table|
559
+ table.index("Articles.content",
560
+ :name => "articles_content",
561
+ :with_position => true,
562
+ :with_section => true)
563
+ end
564
+ end
565
+
566
+ @articles = Groonga["Articles"]
567
+ @index = Groonga["Terms.articles_content"]
568
+ end
569
+
570
+ setup
571
+ def setup_data
572
+ @articles.add(:content => "Groonga is fast")
573
+ @articles.add(:content => "Rroonga is fast")
574
+ @articles.add(:content => "Mroonga is fast")
575
+ end
576
+
577
+ def test_query
578
+ assert_equal(6, @index.estimate_size("roonga"))
579
+ end
538
580
  end
539
581
 
540
- def test_record
541
- assert_equal(7, @index.estimate_size(@terms["fast"]))
582
+ sub_test_case "lexicon cursor" do
583
+ setup
584
+ def setup_schema
585
+ Groonga::Schema.define do |schema|
586
+ schema.create_table("Memos") do |table|
587
+ table.short_text("tags", :type => :vector)
588
+ end
589
+
590
+ schema.create_table("Tags",
591
+ :type => :patricia_trie,
592
+ :key_type => "ShortText") do |table|
593
+ table.index("Memos.tags",
594
+ :name => "memos_tags")
595
+ end
596
+ end
597
+
598
+ @memos = Groonga["Memos"]
599
+ @tags = Groonga["Tags"]
600
+ @index = Groonga["Tags.memos_tags"]
601
+ end
602
+
603
+ setup
604
+ def setup_data
605
+ @memos.add(:tags => ["Groonga"])
606
+ @memos.add(:tags => ["Rroonga", "Ruby"])
607
+ @memos.add(:tags => ["grndump", "Rroonga"])
608
+ end
609
+
610
+ def test_query
611
+ @tags.open_prefix_cursor("R") do |cursor|
612
+ assert_equal(5, @index.estimate_size(cursor))
613
+ end
614
+ end
542
615
  end
543
616
  end
544
617
  end
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  #
3
- # Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
3
+ # Copyright (C) 2012-2015 Kouhei Sutou <kou@clear-code.com>
4
4
  #
5
5
  # This library is free software; you can redistribute it and/or
6
6
  # modify it under the terms of the GNU Lesser General Public
@@ -20,33 +20,39 @@ class NormalizerTest < Test::Unit::TestCase
20
20
 
21
21
  setup :setup_database
22
22
 
23
- def test_normalize
24
- assert_equal("abc", Groonga::Normalizer.normalize("AbC"))
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("~~〜"))
23
+ sub_test_case(".normalize") do
24
+ def test_normal
25
+ assert_equal("abc", Groonga::Normalizer.normalize("AbC"))
26
+ end
27
+
28
+ def test_space
29
+ assert_equal("abcdefgh", Groonga::Normalizer.normalize("AbC Def gh"))
30
+ end
31
+
32
+ def test_remove_blank
33
+ assert_equal("abcdefgh",
34
+ Groonga::Normalizer.normalize("AbC Def gh",
35
+ :remove_blank => true))
36
+ end
37
+
38
+ def test_group_text
39
+ assert_equal("キロメートルキロメートルキロメートルキロメートル",
40
+ Groonga::Normalizer.normalize("㌖㌖㌖㌖"));
41
+ end
42
+
43
+ def test_keep_space
44
+ # full width space => half width space
45
+ assert_equal("abc def gh",
46
+ Groonga::Normalizer.normalize("AbC Def gh",
47
+ :remove_blank => false))
48
+ end
49
+
50
+ def test_tilda
51
+ assert_equal("~~~", Groonga::Normalizer.normalize("~~〜"))
52
+ end
53
+
54
+ def test_empty
55
+ assert_equal("", Groonga::Normalizer.normalize(""))
56
+ end
51
57
  end
52
58
  end