rroonga 4.0.6 → 4.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0e374f62d1dc60540f41658d346241ed699fb853
4
- data.tar.gz: a41b8257c7716190ea709d516fd34e4229c36c38
3
+ metadata.gz: 21a2beefeeeffe25a4ebeecbad4934aa49a64dad
4
+ data.tar.gz: ff7dda3b86483ab0c6c72d46afb77e3bdb4c1205
5
5
  SHA512:
6
- metadata.gz: 325d4a719363ba06a78c9e8109926b6312d2f677650f85b242d889c7b2145963323e4c5c347e691c75f0c917bbb32c74513401eae7fc0220050efa0dcaa50515
7
- data.tar.gz: aecc0398616ba0b886db0eae9bba0599af1d414f2a70be4c79139a2402aaedae9966b600033559c7509328324637e5ab4642af44e8bab86a6155963caa424123
6
+ metadata.gz: 22514a54cff330d7efdd782b01864c20eb9f6b04b70ff76ca7cbbf56369afcbc4129ad710fd66308bfbc58011960afc1b9085e737a96c814caff4127427094fb
7
+ data.tar.gz: de929ed9ed74bdc1fb168ecc7ff4fa69f929ad949f9a5d6f1275c9b66aef6b9932d83a0db54ffb4e633b5dde95b0ed90ccfbc0faff772b2650f9b5bc0b1714f2
data/README.md CHANGED
@@ -40,7 +40,7 @@ contributed patches.)
40
40
  ## Dependencies
41
41
 
42
42
  * Ruby >= 1.9.3
43
- * Groonga >= 4.0.4
43
+ * Groonga >= 4.0.7
44
44
 
45
45
  ## Install
46
46
 
@@ -1,5 +1,17 @@
1
1
  h1. NEWS
2
2
 
3
+ h2(#4-0-7). 4.0.7: 2014-12-12
4
+
5
+ h3. Improvements
6
+
7
+ * Supported Groonga 4.0.8. Groonga 4.0.7 or older aren't supported.
8
+ * Added @:reuse_posting_object@ option to
9
+ {Groonga::IndexCursor#each}. The option improves performance by
10
+ reducing memory allocation. The option is disabled by default because
11
+ reusing the same object isn't Rubyish.
12
+ * Added {Groonga::IndexCursor#estimate_size}. [GitHub#38]
13
+ * Accepted string for integer, unsigned integer and float type key.
14
+
3
15
  h2(#4-0-6). 4.0.6: 2014-11-06
4
16
 
5
17
  h3. Improvements
@@ -11,8 +23,8 @@ h3. Improvements
11
23
  ** Supported @:lz4@ in {Groonga::VariableSizeColumn#compressed?} options.
12
24
  ** Added {Groonga::LZ4Error}.
13
25
  ** [grndump] Supported @COMPRESS_ZLIB@ and @COMPRESS_LZ4@ flags.
14
- ** Added {Groonga::TableKeySupport#token_filters}.
15
- ** Added {Groonga::TableKeySupport#token_filters=}.
26
+ ** Added {Groonga::Table::KeySupport#token_filters}.
27
+ ** Added {Groonga::Table::KeySupport#token_filters=}.
16
28
  ** Supported @:token_filters@ in {Groonga::Hash.create} options.
17
29
  ** Supported @:token_filters@ in {Groonga::PatriciaTrie.create} options.
18
30
  ** Supported @:token_filters@ in {Groonga::DoubleArrayTrie.create} options.
@@ -283,9 +283,6 @@ have_func("rb_sym2str", "ruby.h")
283
283
  have_func("rb_to_symbol", "ruby.h")
284
284
  have_type("enum ruby_value_type", "ruby.h")
285
285
 
286
- # TODO: Remove me after Groogna 4.0.8 is released.
287
- have_func("grn_expr_dump_plan", "groonga.h")
288
-
289
286
  checking_for(checking_message("--enable-debug-log option")) do
290
287
  enable_debug_log = enable_config("debug-log", false)
291
288
  if enable_debug_log
@@ -498,13 +498,11 @@ rb_grn_expression_compile (VALUE self)
498
498
  * Dump execution plan of the `expression` in string.
499
499
  *
500
500
  * @overload dump_plan
501
- * @since 4.0.8
501
+ * @since 4.0.7
502
502
  */
503
503
  static VALUE
504
504
  rb_grn_expression_dump_plan (VALUE self)
505
505
  {
506
- /* TODO: Remove me after Groogna 4.0.8 is released. */
507
- #ifdef HAVE_GRN_EXPR_DUMP_PLAN
508
506
  grn_ctx *context = NULL;
509
507
  grn_obj *expression;
510
508
  grn_obj dumped_plan;
@@ -520,9 +518,6 @@ rb_grn_expression_dump_plan (VALUE self)
520
518
  grn_obj_unlink(context, &dumped_plan);
521
519
 
522
520
  return rb_dumped_plan;
523
- #else
524
- return rb_str_new2("");
525
- #endif
526
521
  }
527
522
 
528
523
  /*
@@ -955,6 +955,99 @@ rb_grn_index_column_open_cursor (int argc, VALUE *argv, VALUE self)
955
955
  return rb_cursor;
956
956
  }
957
957
 
958
+ /*
959
+ * Estimates the number of documents found by the given token ID.
960
+ *
961
+ * @example Token ID style
962
+ * # Define schema
963
+ * Groonga::Schema.define do |schema|
964
+ * schema.create_table("Articles") do |table|
965
+ * table.text("content")
966
+ * end
967
+ *
968
+ * schema.create_table("Terms",
969
+ * :type => :hash,
970
+ * :key_type => "ShortText",
971
+ * :default_tokenizer => "TokenBigram",
972
+ * :normalizer => "NormalizerAuto") do |table|
973
+ * table.index("Articles.content",
974
+ * :name => "articles_content",
975
+ * :with_position => true,
976
+ * :with_section => true)
977
+ * end
978
+ * end
979
+ * articles = Groonga["Articles"]
980
+ * terms = Groonga["Terms"]
981
+ * index = Groonga["Terms.articles_content"]
982
+ *
983
+ * # Add data
984
+ * articles.add(:content => "Groonga is fast")
985
+ * articles.add(:content => "Rroonga is fast")
986
+ * articles.add(:content => "Mroonga is fast")
987
+ *
988
+ * # Estimate the number of documents found by token ID
989
+ * p @index.estimate_size(@terms["fast"].id) # => 7
990
+ * p @index.estimate_size(@terms["Groonga"].id) # => 1
991
+ *
992
+ * @example Token record style
993
+ * # Define schema
994
+ * Groonga::Schema.define do |schema|
995
+ * schema.create_table("Articles") do |table|
996
+ * table.text("content")
997
+ * end
998
+ *
999
+ * schema.create_table("Terms",
1000
+ * :type => :hash,
1001
+ * :key_type => "ShortText",
1002
+ * :default_tokenizer => "TokenBigram",
1003
+ * :normalizer => "NormalizerAuto") do |table|
1004
+ * table.index("Articles.content",
1005
+ * :name => "articles_content",
1006
+ * :with_position => true,
1007
+ * :with_section => true)
1008
+ * end
1009
+ * end
1010
+ * articles = Groonga["Articles"]
1011
+ * terms = Groonga["Terms"]
1012
+ * index = Groonga["Terms.articles_content"]
1013
+ *
1014
+ * # Add data
1015
+ * articles.add(:content => "Groonga is fast")
1016
+ * articles.add(:content => "Rroonga is fast")
1017
+ * articles.add(:content => "Mroonga is fast")
1018
+ *
1019
+ * # Estimate the number of documents found by token record
1020
+ * p @index.estimate_size(@terms["fast"]) # => 7
1021
+ * p @index.estimate_size(@terms["Groonga"]) # => 1
1022
+ *
1023
+ * @overload estimate_size(token_id)
1024
+ * @param [Integer, Record] token_id The token ID to be estimated.
1025
+ * @return [Integer] The estimated number of documents found by the
1026
+ * given token ID.
1027
+ *
1028
+ * @since 4.0.7
1029
+ */
1030
+ static VALUE
1031
+ rb_grn_index_column_estimate_size (VALUE self, VALUE rb_token_id)
1032
+ {
1033
+ grn_ctx *context;
1034
+ grn_obj *column;
1035
+ grn_obj *domain_object;
1036
+ grn_id token_id;
1037
+ unsigned int size;
1038
+
1039
+ rb_grn_index_column_deconstruct(SELF(self), &column, &context,
1040
+ NULL, &domain_object,
1041
+ NULL, NULL, NULL,
1042
+ NULL, NULL,
1043
+ NULL, NULL);
1044
+
1045
+ token_id = RVAL2GRNID(rb_token_id, context, domain_object, self);
1046
+ size = grn_ii_estimate_size(context, (grn_ii *)column, token_id);
1047
+
1048
+ return UINT2NUM(size);
1049
+ }
1050
+
958
1051
  void
959
1052
  rb_grn_init_index_column (VALUE mGrn)
960
1053
  {
@@ -990,4 +1083,7 @@ rb_grn_init_index_column (VALUE mGrn)
990
1083
 
991
1084
  rb_define_method(rb_cGrnIndexColumn, "open_cursor",
992
1085
  rb_grn_index_column_open_cursor, -1);
1086
+
1087
+ rb_define_method(rb_cGrnIndexColumn, "estimate_size",
1088
+ rb_grn_index_column_estimate_size, 1);
993
1089
  }
@@ -57,7 +57,8 @@ rb_grn_index_cursor_deconstruct (RbGrnIndexCursor *rb_grn_index_cursor,
57
57
  }
58
58
 
59
59
  static VALUE
60
- next_value (grn_ctx *context, grn_obj *cursor, VALUE rb_table, VALUE rb_lexicon)
60
+ next_value (VALUE rb_posting,
61
+ grn_ctx *context, grn_obj *cursor, VALUE rb_table, VALUE rb_lexicon)
61
62
  {
62
63
  grn_posting *posting;
63
64
  grn_id term_id;
@@ -67,7 +68,12 @@ next_value (grn_ctx *context, grn_obj *cursor, VALUE rb_table, VALUE rb_lexicon)
67
68
  return Qnil;
68
69
  }
69
70
 
70
- return rb_grn_posting_new(posting, term_id, rb_table, rb_lexicon);
71
+ if (NIL_P(rb_posting)) {
72
+ return rb_grn_posting_new(posting, term_id, rb_table, rb_lexicon);
73
+ } else {
74
+ rb_grn_posting_update(rb_posting, posting, term_id);
75
+ return rb_posting;
76
+ }
71
77
  }
72
78
 
73
79
  static VALUE
@@ -84,7 +90,7 @@ rb_grn_index_cursor_next (VALUE self)
84
90
  VALUE rb_lexicon;
85
91
  rb_table = rb_iv_get(self, "@table");
86
92
  rb_lexicon = rb_iv_get(self, "@lexicon");
87
- rb_posting = next_value(context, cursor, rb_table, rb_lexicon);
93
+ rb_posting = next_value(Qnil, context, cursor, rb_table, rb_lexicon);
88
94
  }
89
95
 
90
96
  return rb_posting;
@@ -92,14 +98,24 @@ rb_grn_index_cursor_next (VALUE self)
92
98
  }
93
99
 
94
100
  static VALUE
95
- rb_grn_index_cursor_each (VALUE self)
101
+ rb_grn_index_cursor_each (int argc, VALUE *argv, VALUE self)
96
102
  {
97
103
  grn_obj *cursor;
98
104
  grn_ctx *context;
105
+ grn_bool reuse_posting_object;
106
+ VALUE rb_options;
107
+ VALUE rb_reuse_posting_object;
99
108
  VALUE rb_table;
100
109
  VALUE rb_lexicon;
110
+ VALUE rb_posting = Qnil;
111
+
112
+ RETURN_ENUMERATOR(self, argc, argv);
113
+
114
+ rb_scan_args(argc, argv, "01", &rb_options);
101
115
 
102
- RETURN_ENUMERATOR(self, 0, NULL);
116
+ rb_grn_scan_options(rb_options,
117
+ "reuse_posting_object", &rb_reuse_posting_object,
118
+ NULL);
103
119
 
104
120
  rb_grn_index_cursor_deconstruct(SELF(self), &cursor, &context,
105
121
  NULL, NULL, NULL, NULL);
@@ -114,9 +130,17 @@ rb_grn_index_cursor_each (VALUE self)
114
130
 
115
131
  rb_table = rb_iv_get(self, "@table");
116
132
  rb_lexicon = rb_iv_get(self, "@lexicon");
133
+ reuse_posting_object = RVAL2CBOOL(rb_reuse_posting_object);
134
+
135
+ if (reuse_posting_object) {
136
+ rb_posting = rb_grn_posting_new(NULL, GRN_ID_NIL, rb_table, rb_lexicon);
137
+ }
117
138
  while (GRN_TRUE) {
118
- VALUE rb_posting;
119
- rb_posting = next_value(context, cursor, rb_table, rb_lexicon);
139
+ if (!reuse_posting_object) {
140
+ rb_posting = Qnil;
141
+ }
142
+ rb_posting = next_value(rb_posting,
143
+ context, cursor, rb_table, rb_lexicon);
120
144
  if (NIL_P(rb_posting)) {
121
145
  break;
122
146
  }
@@ -135,5 +159,5 @@ rb_grn_init_index_cursor (VALUE mGrn)
135
159
  rb_include_module(rb_cGrnIndexCursor, rb_mEnumerable);
136
160
 
137
161
  rb_define_method(rb_cGrnIndexCursor, "next", rb_grn_index_cursor_next, 0);
138
- rb_define_method(rb_cGrnIndexCursor, "each", rb_grn_index_cursor_each, 0);
162
+ rb_define_method(rb_cGrnIndexCursor, "each", rb_grn_index_cursor_each, -1);
139
163
  }
@@ -32,13 +32,15 @@ rb_grn_posting_new (grn_posting *posting, grn_id term_id,
32
32
  #define SET_PARAMETER(key, value) \
33
33
  rb_hash_aset(parameters, RB_GRN_INTERN(key), INT2NUM((value)))
34
34
 
35
- SET_PARAMETER("record_id", posting->rid);
36
- SET_PARAMETER("section_id", posting->sid);
35
+ if (posting) {
36
+ SET_PARAMETER("record_id", posting->rid);
37
+ SET_PARAMETER("section_id", posting->sid);
38
+ SET_PARAMETER("position", posting->pos);
39
+ SET_PARAMETER("term_frequency", posting->tf);
40
+ SET_PARAMETER("weight", posting->weight);
41
+ SET_PARAMETER("n_rest_postings", posting->rest);
42
+ }
37
43
  SET_PARAMETER("term_id", term_id);
38
- SET_PARAMETER("position", posting->pos);
39
- SET_PARAMETER("term_frequency", posting->tf);
40
- SET_PARAMETER("weight", posting->weight);
41
- SET_PARAMETER("n_rest_postings", posting->rest);
42
44
 
43
45
  #undef SET_PARAMETER
44
46
 
@@ -49,6 +51,24 @@ rb_grn_posting_new (grn_posting *posting, grn_id term_id,
49
51
  parameters);
50
52
  }
51
53
 
54
+ void
55
+ rb_grn_posting_update (VALUE self, grn_posting *posting, grn_id term_id)
56
+ {
57
+ #define SET_PARAMETER(key, value) \
58
+ rb_funcall(self, rb_intern(key "="), 1, INT2NUM(value));
59
+
60
+ SET_PARAMETER("record_id", posting->rid);
61
+ SET_PARAMETER("section_id", posting->sid);
62
+ SET_PARAMETER("position", posting->pos);
63
+ SET_PARAMETER("term_frequency", posting->tf);
64
+ SET_PARAMETER("weight", posting->weight);
65
+ SET_PARAMETER("n_rest_postings", posting->rest);
66
+
67
+ SET_PARAMETER("term_id", term_id);
68
+
69
+ #undef SET_PARAMETER
70
+ }
71
+
52
72
  void
53
73
  rb_grn_init_posting (VALUE mGrn)
54
74
  {
@@ -481,46 +481,73 @@ rb_grn_bulk_from_ruby_object_with_type (VALUE object, grn_ctx *context,
481
481
 
482
482
  switch (type_id) {
483
483
  case GRN_DB_INT8:
484
+ if (string_p) {
485
+ object = rb_Integer(object);
486
+ }
484
487
  value.int8_value = NUM2SHORT(object);
485
488
  string = (const char *)&(value.int8_value);
486
489
  size = sizeof(value.int8_value);
487
490
  break;
488
491
  case GRN_DB_UINT8:
492
+ if (string_p) {
493
+ object = rb_Integer(object);
494
+ }
489
495
  value.uint8_value = NUM2USHORT(object);
490
496
  string = (const char *)&(value.uint8_value);
491
497
  size = sizeof(value.uint8_value);
492
498
  break;
493
499
  case GRN_DB_INT16:
500
+ if (string_p) {
501
+ object = rb_Integer(object);
502
+ }
494
503
  value.int16_value = NUM2SHORT(object);
495
504
  string = (const char *)&(value.int16_value);
496
505
  size = sizeof(value.int16_value);
497
506
  break;
498
507
  case GRN_DB_UINT16:
508
+ if (string_p) {
509
+ object = rb_Integer(object);
510
+ }
499
511
  value.uint16_value = NUM2USHORT(object);
500
512
  string = (const char *)&(value.uint16_value);
501
513
  size = sizeof(value.uint16_value);
502
514
  break;
503
515
  case GRN_DB_INT32:
516
+ if (string_p) {
517
+ object = rb_Integer(object);
518
+ }
504
519
  value.int32_value = NUM2INT(object);
505
520
  string = (const char *)&(value.int32_value);
506
521
  size = sizeof(value.int32_value);
507
522
  break;
508
523
  case GRN_DB_UINT32:
524
+ if (string_p) {
525
+ object = rb_Integer(object);
526
+ }
509
527
  value.uint32_value = NUM2UINT(object);
510
528
  string = (const char *)&(value.uint32_value);
511
529
  size = sizeof(value.uint32_value);
512
530
  break;
513
531
  case GRN_DB_INT64:
532
+ if (string_p) {
533
+ object = rb_Integer(object);
534
+ }
514
535
  value.int64_value = NUM2LL(object);
515
536
  string = (const char *)&(value.int64_value);
516
537
  size = sizeof(value.int64_value);
517
538
  break;
518
539
  case GRN_DB_UINT64:
540
+ if (string_p) {
541
+ object = rb_Integer(object);
542
+ }
519
543
  value.uint64_value = NUM2ULL(object);
520
544
  string = (const char *)&(value.uint64_value);
521
545
  size = sizeof(value.uint64_value);
522
546
  break;
523
547
  case GRN_DB_FLOAT:
548
+ if (string_p) {
549
+ object = rb_Float(object);
550
+ }
524
551
  value.double_value = NUM2DBL(object);
525
552
  string = (const char *)&(value.double_value);
526
553
  size = sizeof(value.double_value);
data/ext/groonga/rb-grn.h CHANGED
@@ -92,7 +92,7 @@ RB_GRN_BEGIN_DECLS
92
92
 
93
93
  #define RB_GRN_MAJOR_VERSION 4
94
94
  #define RB_GRN_MINOR_VERSION 0
95
- #define RB_GRN_MICRO_VERSION 6
95
+ #define RB_GRN_MICRO_VERSION 7
96
96
 
97
97
  #define RB_GRN_QUERY_DEFAULT_MAX_EXPRESSIONS 32
98
98
 
@@ -568,6 +568,9 @@ VALUE rb_grn_posting_new (grn_posting *posting,
568
568
  grn_id term_id,
569
569
  VALUE rb_table,
570
570
  VALUE rb_lexicon);
571
+ void rb_grn_posting_update (VALUE rb_posting,
572
+ grn_posting *posting,
573
+ grn_id term_id);
571
574
 
572
575
  VALUE rb_grn_tokyo_geo_point_new (int latitude,
573
576
  int longitude);
data/rroonga-build.rb CHANGED
@@ -19,15 +19,15 @@ module RroongaBuild
19
19
  module RequiredGroongaVersion
20
20
  MAJOR = 4
21
21
  MINOR = 0
22
- MICRO = 7
22
+ MICRO = 8
23
23
  VERSION = [MAJOR, MINOR, MICRO]
24
- RELEASED_DATE = Time.utc(2014, 10, 29)
24
+ RELEASED_DATE = Time.utc(2014, 11, 29)
25
25
  end
26
26
 
27
27
  module LatestGroongaVersion
28
28
  MAJOR = 4
29
29
  MINOR = 0
30
- MICRO = 7
30
+ MICRO = 8
31
31
  VERSION = [MAJOR, MINOR, MICRO]
32
32
  end
33
33
 
data/test/test-column.rb CHANGED
@@ -169,9 +169,18 @@ class ColumnTest < Test::Unit::TestCase
169
169
  result.records.collect do |record|
170
170
  record["body"]
171
171
  end)
172
- assert_equal("#<Groonga::Expression noname($1:null)" +
173
- "{2body GET_VALUE,0\"drive\",0MATCH}>",
174
- result.expression.inspect)
172
+ assert_equal(<<-INSPECTED.chomp, result.expression.inspect)
173
+ #<Groonga::Expression #<expr
174
+ vars:{
175
+ $1:#<record:hash:Posts id:0(nonexistent)>
176
+ },
177
+ codes:{
178
+ 0:<get_value(), modify:2, value:#<column:var_size Posts.body range:Text type:scalar compress:none>>,
179
+ 1:<push(), modify:0, value:"drive">,
180
+ 2:<match(), modify:0, value:(NULL)>
181
+ }
182
+ >>
183
+ INSPECTED
175
184
  end
176
185
 
177
186
  def test_select_query_from_ctx
@@ -200,9 +209,18 @@ class ColumnTest < Test::Unit::TestCase
200
209
  result.records.collect do |record|
201
210
  record["body"]
202
211
  end)
203
- assert_equal("#<Groonga::Expression noname($1:null)" +
204
- "{2body GET_VALUE,0\"drive\",0MATCH}>",
205
- result.expression.inspect)
212
+ assert_equal(<<-INSPECTED.chomp, result.expression.inspect)
213
+ #<Groonga::Expression #<expr
214
+ vars:{
215
+ $1:#<record:hash:Posts id:0(nonexistent)>
216
+ },
217
+ codes:{
218
+ 0:<get_value(), modify:2, value:#<column:var_size Posts.body range:Text type:scalar compress:none>>,
219
+ 1:<push(), modify:0, value:"drive">,
220
+ 2:<match(), modify:0, value:(NULL)>
221
+ }
222
+ >>
223
+ INSPECTED
206
224
  end
207
225
 
208
226
  def test_select_expression
@@ -218,9 +236,19 @@ class ColumnTest < Test::Unit::TestCase
218
236
  result.records.collect do |record|
219
237
  record["body"]
220
238
  end)
221
- assert_equal("#<Groonga::Expression noname($1:null)" +
222
- "{0null,2body GET_VALUE,0\"drive\",0MATCH}>",
223
- result.expression.inspect)
239
+ assert_equal(<<-INSPECTED.chomp, result.expression.inspect)
240
+ #<Groonga::Expression #<expr
241
+ vars:{
242
+ $1:#<record:hash:Posts id:0(nonexistent)>
243
+ },
244
+ codes:{
245
+ 0:<push(), modify:0, value:#<record:hash:Posts id:0(nonexistent)>>,
246
+ 1:<get_value(), modify:2, value:#<column:var_size Posts.body range:Text type:scalar compress:none>>,
247
+ 2:<push(), modify:0, value:"drive">,
248
+ 3:<match(), modify:0, value:(NULL)>
249
+ }
250
+ >>
251
+ INSPECTED
224
252
  end
225
253
 
226
254
  def test_select_with_block
@@ -233,9 +261,19 @@ class ColumnTest < Test::Unit::TestCase
233
261
  result.records.collect do |record|
234
262
  record["body"]
235
263
  end)
236
- assert_equal("#<Groonga::Expression noname($1:null)" +
237
- "{1null,2body GET_VALUE,0\"drive\",0MATCH}>",
238
- result.expression.inspect)
264
+ assert_equal(<<-INSPECTED.chomp, result.expression.inspect)
265
+ #<Groonga::Expression #<expr
266
+ vars:{
267
+ $1:#<record:hash:Posts id:0(nonexistent)>
268
+ },
269
+ codes:{
270
+ 0:<push(), modify:1, value:#<record:hash:Posts id:0(nonexistent)>>,
271
+ 1:<get_value(), modify:2, value:#<column:var_size Posts.body range:Text type:scalar compress:none>>,
272
+ 2:<push(), modify:0, value:"drive">,
273
+ 3:<match(), modify:0, value:(NULL)>
274
+ }
275
+ >>
276
+ INSPECTED
239
277
  end
240
278
 
241
279
  def test_set_time
@@ -77,8 +77,17 @@ class ExpressionTest < Test::Unit::TestCase
77
77
  expression.append_operation(Groonga::Operation::PLUS, 2)
78
78
  expression.compile
79
79
 
80
- assert_equal("#<Groonga::Expression noname(){21,01,0PLUS}>",
81
- expression.inspect)
80
+ assert_equal(<<-INSPECTED.chomp, expression.inspect)
81
+ #<Groonga::Expression #<expr
82
+ vars:{
83
+ },
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
+ >>
90
+ INSPECTED
82
91
  end
83
92
 
84
93
  def test_snippet
@@ -162,14 +171,28 @@ class ExpressionTest < Test::Unit::TestCase
162
171
  @expression.append_object(Groonga["TokenBigram"],
163
172
  Groonga::Operator::PUSH,
164
173
  1)
165
- assert_equal("#<Groonga::Expression noname(){0TokenBigram}>",
166
- @expression.inspect)
174
+ assert_equal(<<-INSPECTED.chomp, @expression.inspect)
175
+ #<Groonga::Expression #<expr
176
+ vars:{
177
+ },
178
+ codes:{
179
+ 0:<push(), modify:0, value:#<proc:tokenizer TokenBigram arguments:[$1, $2, $3]>>
180
+ }
181
+ >>
182
+ INSPECTED
167
183
  end
168
184
 
169
185
  def test_name
170
186
  @expression.append_object(Groonga["TokenBigram"], "push", 1)
171
- assert_equal("#<Groonga::Expression noname(){0TokenBigram}>",
172
- @expression.inspect)
187
+ assert_equal(<<-INSPECTED.chomp, @expression.inspect)
188
+ #<Groonga::Expression #<expr
189
+ vars:{
190
+ },
191
+ codes:{
192
+ 0:<push(), modify:0, value:#<proc:tokenizer TokenBigram arguments:[$1, $2, $3]>>
193
+ }
194
+ >>
195
+ INSPECTED
173
196
  end
174
197
  end
175
198
  end
@@ -183,14 +206,28 @@ class ExpressionTest < Test::Unit::TestCase
183
206
  class OperatorTest < self
184
207
  def test_constant
185
208
  @expression.append_constant(29, Groonga::Operator::PUSH, 1)
186
- assert_equal("#<Groonga::Expression noname(){029}>",
187
- @expression.inspect)
209
+ assert_equal(<<-INSPECTED.chomp, @expression.inspect)
210
+ #<Groonga::Expression #<expr
211
+ vars:{
212
+ },
213
+ codes:{
214
+ 0:<push(), modify:0, value:29>
215
+ }
216
+ >>
217
+ INSPECTED
188
218
  end
189
219
 
190
220
  def test_name
191
221
  @expression.append_constant(29, "push", 1)
192
- assert_equal("#<Groonga::Expression noname(){029}>",
193
- @expression.inspect)
222
+ assert_equal(<<-INSPECTED.chomp, @expression.inspect)
223
+ #<Groonga::Expression #<expr
224
+ vars:{
225
+ },
226
+ codes:{
227
+ 0:<push(), modify:0, value:29>
228
+ }
229
+ >>
230
+ INSPECTED
194
231
  end
195
232
  end
196
233
  end
@@ -205,14 +242,32 @@ class ExpressionTest < Test::Unit::TestCase
205
242
 
206
243
  def test_constant
207
244
  @expression.append_operation(Groonga::Operator::PLUS, 2)
208
- assert_equal("#<Groonga::Expression noname(){229,092,0PLUS}>",
209
- @expression.inspect)
245
+ assert_equal(<<-INSPECTED.chomp, @expression.inspect)
246
+ #<Groonga::Expression #<expr
247
+ vars:{
248
+ },
249
+ 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
210
256
  end
211
257
 
212
258
  def test_name
213
259
  @expression.append_operation("plus", 2)
214
- assert_equal("#<Groonga::Expression noname(){229,092,0PLUS}>",
215
- @expression.inspect)
260
+ assert_equal(<<-INSPECTED.chomp, @expression.inspect)
261
+ #<Groonga::Expression #<expr
262
+ vars:{
263
+ },
264
+ 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
216
271
  end
217
272
  end
218
273
 
@@ -244,48 +299,48 @@ class ExpressionTest < Test::Unit::TestCase
244
299
 
245
300
  class DefaultOperatorTest < self
246
301
  def test_nil
247
- assert_equal("AND", parse(nil))
302
+ assert_equal("and", parse(nil))
248
303
  end
249
304
 
250
305
  def test_name
251
- assert_equal("OR", parse("or"))
306
+ assert_equal("or", parse("or"))
252
307
  end
253
308
 
254
309
  def test_name_symbol
255
- assert_equal("OR", parse(:or))
310
+ assert_equal("or", parse(:or))
256
311
  end
257
312
 
258
313
  def test_symbol
259
- assert_equal("OR", parse("||"))
314
+ assert_equal("or", parse("||"))
260
315
  end
261
316
 
262
317
  def test_integer
263
- assert_equal("ADJUST", parse(Groonga::Operator::ADJUST))
318
+ assert_equal("adjust", parse(Groonga::Operator::ADJUST))
264
319
  end
265
320
 
266
321
  private
267
322
  def parse(default_operator)
268
323
  @expression.parse("_id:1 _id:2", :default_operator => default_operator)
269
- operator = @expression.inspect[/\d([a-zA-Z_-]+)}/, 1]
324
+ operator = @expression.inspect[/6:<([a-zA-Z_-]+)/, 1]
270
325
  operator
271
326
  end
272
327
  end
273
328
 
274
329
  class DefaultModeTest < self
275
330
  def test_nil
276
- assert_equal("MATCH", parse(nil))
331
+ assert_equal("match", parse(nil))
277
332
  end
278
333
 
279
334
  def test_name
280
- assert_equal("EQUAL", parse("equal"))
335
+ assert_equal("equal", parse("equal"))
281
336
  end
282
337
 
283
338
  def test_symbol
284
- assert_equal("EQUAL", parse(:equal))
339
+ assert_equal("equal", parse(:equal))
285
340
  end
286
341
 
287
342
  def test_integer
288
- assert_equal("EQUAL", parse(Groonga::Operator::EQUAL))
343
+ assert_equal("equal", parse(Groonga::Operator::EQUAL))
289
344
  end
290
345
 
291
346
  private
@@ -293,7 +348,7 @@ class ExpressionTest < Test::Unit::TestCase
293
348
  @expression.parse("query",
294
349
  :default_column => "_id",
295
350
  :default_mode => default_mode)
296
- operator = @expression.inspect[/\d([a-zA-Z_-]+)}/, 1]
351
+ operator = @expression.inspect[/2:<([a-zA-Z_-]+)/, 1]
297
352
  operator
298
353
  end
299
354
  end
@@ -500,4 +500,45 @@ class IndexColumnTest < Test::Unit::TestCase
500
500
  end
501
501
  end
502
502
  end
503
+
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
511
+
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)
521
+ end
522
+ end
523
+
524
+ @articles = Groonga["Articles"]
525
+ @terms = Groonga["Terms"]
526
+ @index = Groonga["Terms.articles_content"]
527
+ end
528
+
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")
534
+ end
535
+
536
+ def test_id
537
+ assert_equal(7, @index.estimate_size(@terms["fast"].id))
538
+ end
539
+
540
+ def test_record
541
+ assert_equal(7, @index.estimate_size(@terms["fast"]))
542
+ end
543
+ end
503
544
  end
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
1
+ # Copyright (C) 2012-2014 Kouhei Sutou <kou@clear-code.com>
2
2
  #
3
3
  # This library is free software; you can redistribute it and/or
4
4
  # modify it under the terms of the GNU Lesser General Public
@@ -66,6 +66,26 @@ class IndexCursorTest < Test::Unit::TestCase
66
66
  assert_true(opened)
67
67
  end
68
68
 
69
+ def test_each_reuse_posting_object
70
+ opened = false
71
+ @terms.open_cursor do |table_cursor|
72
+ @content_index.open_cursor(table_cursor) do |cursor|
73
+ posting_object_ids = []
74
+ postings = []
75
+ cursor.each(:reuse_posting_object => true) do |posting|
76
+ posting_object_ids << posting.object_id
77
+ postings << posting.to_hash
78
+ end
79
+ assert_equal([posting_object_ids.first] * posting_object_ids.size,
80
+ posting_object_ids)
81
+ assert_equal(expected_postings, postings)
82
+ opened = true
83
+ end
84
+ end
85
+
86
+ assert_true(opened)
87
+ end
88
+
69
89
  def test_record
70
90
  record = nil
71
91
  @terms.open_cursor do |table_cursor|
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2013 Kouhei Sutou <kou@clear-code.com>
1
+ # Copyright (C) 2013-2014 Kouhei Sutou <kou@clear-code.com>
2
2
  #
3
3
  # This library is free software; you can redistribute it and/or
4
4
  # modify it under the terms of the GNU Lesser General Public
@@ -76,6 +76,64 @@ class TableKeySupportTest < Test::Unit::TestCase
76
76
  end
77
77
  end
78
78
 
79
+ class CastTest < self
80
+ def test_int8
81
+ key = "-1"
82
+ ids = Groonga::Hash.create(:name => "IDs", :key_type => "Int8")
83
+ id = ids.add(key)
84
+ assert_equal(key.to_i, id.key)
85
+ end
86
+
87
+ def test_uint8
88
+ key = "1"
89
+ ids = Groonga::Hash.create(:name => "IDs", :key_type => "UInt8")
90
+ id = ids.add(key)
91
+ assert_equal(key.to_i, id.key)
92
+ end
93
+
94
+ def test_int16
95
+ key = (-(2 ** 8)).to_s
96
+ ids = Groonga::Hash.create(:name => "IDs", :key_type => "Int16")
97
+ id = ids.add(key)
98
+ assert_equal(key.to_i, id.key)
99
+ end
100
+
101
+ def test_uint16
102
+ key = (2 ** 8).to_s
103
+ ids = Groonga::Hash.create(:name => "IDs", :key_type => "UInt16")
104
+ id = ids.add(key)
105
+ assert_equal(key.to_i, id.key)
106
+ end
107
+
108
+ def test_int32
109
+ key = (-(2 ** 16)).to_s
110
+ ids = Groonga::Hash.create(:name => "IDs", :key_type => "Int32")
111
+ id = ids.add(key)
112
+ assert_equal(key.to_i, id.key)
113
+ end
114
+
115
+ def test_uint32
116
+ key = (2 ** 16).to_s
117
+ ids = Groonga::Hash.create(:name => "IDs", :key_type => "UInt32")
118
+ id = ids.add(key)
119
+ assert_equal(key.to_i, id.key)
120
+ end
121
+
122
+ def test_int64
123
+ key = (-(2 ** 32)).to_s
124
+ ids = Groonga::Hash.create(:name => "IDs", :key_type => "Int64")
125
+ id = ids.add(key)
126
+ assert_equal(key.to_i, id.key)
127
+ end
128
+
129
+ def test_uint64
130
+ key = (2 ** 32).to_s
131
+ ids = Groonga::Hash.create(:name => "IDs", :key_type => "UInt64")
132
+ id = ids.add(key)
133
+ assert_equal(key.to_i, id.key)
134
+ end
135
+ end
136
+
79
137
  class TokenizeTest < self
80
138
  class TableTypeTest < self
81
139
  def test_hash
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rroonga
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.6
4
+ version: 4.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kouhei Sutou
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2014-11-06 00:00:00.000000000 Z
15
+ date: 2014-12-12 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: pkg-config
@@ -194,10 +194,10 @@ email:
194
194
  - y.hayamizu@gmail.com
195
195
  - dara@shidara.net
196
196
  executables:
197
- - groonga-index-dump
197
+ - grntest-log-analyze
198
198
  - grndump
199
199
  - groonga-database-inspect
200
- - grntest-log-analyze
200
+ - groonga-index-dump
201
201
  extensions:
202
202
  - ext/groonga/extconf.rb
203
203
  extra_rdoc_files:
@@ -375,57 +375,57 @@ specification_version: 4
375
375
  summary: Ruby bindings for Groonga that provide full text search and column store
376
376
  features.
377
377
  test_files:
378
- - test/test-schema.rb
378
+ - test/test-schema-create-table.rb
379
+ - test/test-type.rb
380
+ - test/test-table-select.rb
381
+ - test/test-variable-size-column.rb
382
+ - test/test-table-select-normalize.rb
383
+ - test/test-lock-timeout.rb
384
+ - test/test-record.rb
385
+ - test/test-plugin.rb
386
+ - test/groonga-test-utils.rb
387
+ - test/test-logger.rb
379
388
  - test/test-snippet.rb
389
+ - test/test-memory-pool.rb
390
+ - test/test-command-select.rb
391
+ - test/test-expression-builder.rb
392
+ - test/test-database-dumper.rb
393
+ - test/test-encoding.rb
380
394
  - test/test-variable.rb
381
- - test/test-geo-point.rb
382
- - test/test-plugin.rb
383
- - test/test-accessor.rb
395
+ - test/test-context.rb
396
+ - test/run-test.rb
397
+ - test/test-index-cursor.rb
398
+ - test/test-table-select-mecab.rb
384
399
  - test/test-double-array-trie.rb
385
- - test/test-pagination.rb
386
- - test/test-memory-pool.rb
400
+ - test/test-sub-records.rb
401
+ - test/test-table-offset-and-limit.rb
402
+ - test/test-table-select-weight.rb
403
+ - test/test-convert.rb
387
404
  - test/test-column.rb
405
+ - test/test-table.rb
406
+ - test/test-gqtp.rb
388
407
  - test/test-table-traverse.rb
389
- - test/test-expression.rb
390
- - test/test-table-select.rb
391
- - test/test-encoding.rb
392
- - test/test-logger.rb
393
- - test/test-schema-create-table.rb
394
- - test/test-hash.rb
395
- - test/test-type.rb
396
- - test/test-table-offset-and-limit.rb
408
+ - test/test-schema.rb
397
409
  - test/test-version.rb
398
- - test/test-lock-timeout.rb
410
+ - test/test-exception.rb
411
+ - test/test-array.rb
412
+ - test/test-patricia-trie.rb
413
+ - test/test-schema-type.rb
414
+ - test/test-database.rb
399
415
  - test/test-index-column.rb
400
- - test/test-table-key-support.rb
401
- - test/test-vector-column.rb
402
416
  - test/test-normalizer.rb
403
- - test/test-table-select-weight.rb
404
- - test/test-schema-type.rb
405
- - test/test-sub-records.rb
406
- - test/test-procedure.rb
407
- - test/test-context.rb
408
- - test/test-gqtp.rb
409
- - test/test-remote.rb
410
- - test/test-database-dumper.rb
417
+ - test/test-vector-column.rb
411
418
  - test/test-database-inspector.rb
412
- - test/test-patricia-trie.rb
413
- - test/run-test.rb
414
- - test/test-fix-size-column.rb
419
+ - test/test-pagination.rb
420
+ - test/test-procedure.rb
421
+ - test/test-geo-point.rb
422
+ - test/test-table-key-support.rb
415
423
  - test/test-statistic-measurer.rb
416
- - test/test-array.rb
417
- - test/test-table.rb
418
- - test/groonga-test-utils.rb
419
- - test/test-record.rb
420
- - test/test-exception.rb
421
- - test/test-table-select-normalize.rb
424
+ - test/test-fix-size-column.rb
425
+ - test/test-accessor.rb
426
+ - test/test-hash.rb
427
+ - test/test-expression.rb
428
+ - test/test-remote.rb
422
429
  - test/test-schema-dumper.rb
423
430
  - test/test-table-dumper.rb
424
- - test/test-database.rb
425
- - test/test-variable-size-column.rb
426
- - test/test-table-select-mecab.rb
427
- - test/test-expression-builder.rb
428
- - test/test-convert.rb
429
- - test/test-index-cursor.rb
430
- - test/test-command-select.rb
431
431
  has_rdoc: