rroonga 2.0.5 → 2.0.6

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 (40) hide show
  1. data/Rakefile +5 -1
  2. data/ext/groonga/extconf.rb +36 -4
  3. data/ext/groonga/rb-grn-accessor.c +8 -10
  4. data/ext/groonga/rb-grn-array-cursor.c +2 -2
  5. data/ext/groonga/rb-grn-array.c +35 -59
  6. data/ext/groonga/rb-grn-column.c +105 -192
  7. data/ext/groonga/rb-grn-context.c +60 -63
  8. data/ext/groonga/rb-grn-database.c +27 -37
  9. data/ext/groonga/rb-grn-double-array-trie-cursor.c +3 -3
  10. data/ext/groonga/rb-grn-double-array-trie.c +75 -126
  11. data/ext/groonga/rb-grn-encoding.c +27 -27
  12. data/ext/groonga/rb-grn-expression.c +29 -24
  13. data/ext/groonga/rb-grn-fix-size-column.c +7 -9
  14. data/ext/groonga/rb-grn-hash-cursor.c +3 -3
  15. data/ext/groonga/rb-grn-hash.c +57 -108
  16. data/ext/groonga/rb-grn-index-column.c +17 -29
  17. data/ext/groonga/rb-grn-logger.c +11 -14
  18. data/ext/groonga/rb-grn-object.c +51 -94
  19. data/ext/groonga/rb-grn-patricia-trie-cursor.c +2 -2
  20. data/ext/groonga/rb-grn-patricia-trie.c +161 -276
  21. data/ext/groonga/rb-grn-plugin.c +6 -10
  22. data/ext/groonga/rb-grn-table-cursor.c +14 -21
  23. data/ext/groonga/rb-grn-table-key-support.c +32 -35
  24. data/ext/groonga/rb-grn-table.c +149 -252
  25. data/ext/groonga/rb-grn-variable.c +6 -7
  26. data/ext/groonga/rb-grn-view-accessor.c +1 -1
  27. data/ext/groonga/rb-grn-view-cursor.c +2 -2
  28. data/ext/groonga/rb-grn-view.c +28 -45
  29. data/ext/groonga/rb-grn.h +1 -1
  30. data/ext/groonga/rb-groonga.c +6 -6
  31. data/lib/groonga/database.rb +1 -1
  32. data/lib/groonga/dumper.rb +109 -33
  33. data/lib/groonga/expression-builder.rb +24 -0
  34. data/lib/groonga/pagination.rb +30 -24
  35. data/lib/groonga/record.rb +21 -18
  36. data/lib/groonga/schema.rb +156 -140
  37. data/test/test-command-select.rb +66 -1
  38. data/test/test-database-dumper.rb +50 -10
  39. data/test/test-expression-builder.rb +41 -0
  40. metadata +4 -4
@@ -25,7 +25,7 @@ VALUE rb_cGrnVariable;
25
25
  /*
26
26
  * Document-class: Groonga::Variable < Groonga::Object
27
27
  *
28
- * Groonga::Expressionで使われる変数。
28
+ * {Groonga::Expression} で使われる変数。
29
29
  */
30
30
 
31
31
  grn_obj *
@@ -59,10 +59,10 @@ rb_grn_variable_deconstruct (RbGrnVariable *rb_grn_variable,
59
59
  }
60
60
 
61
61
  /*
62
- * call-seq:
63
- * variable.value -> Groonga::Object
64
- *
65
62
  * 変数の値を返す。
63
+ *
64
+ * @overload value
65
+ * @return [Groonga::Object]
66
66
  */
67
67
  static VALUE
68
68
  rb_grn_variable_get_value (VALUE self)
@@ -78,10 +78,9 @@ rb_grn_variable_get_value (VALUE self)
78
78
  }
79
79
 
80
80
  /*
81
- * call-seq:
82
- * variable.value=(value)
83
- *
84
81
  * 変数の値を _value_ に設定する。
82
+ *
83
+ * @overload value=(value)
85
84
  */
86
85
  static VALUE
87
86
  rb_grn_variable_set_value (VALUE self, VALUE value)
@@ -43,7 +43,7 @@ rb_grn_view_accessor_to_ruby_object (grn_ctx *context, grn_obj *table,
43
43
  * Document-class: Groonga::ViewAccessor < Groonga::Object
44
44
  *
45
45
  * キー、値、スコアなど種々の値へのアクセスをカプセル化した
46
- * オブジェクト。Groonga::Table#columnで取得できる。
46
+ * オブジェクト。 {Groonga::Table#column} で取得できる。
47
47
  */
48
48
  void
49
49
  rb_grn_init_view_accessor (VALUE mGrn)
@@ -23,8 +23,8 @@ VALUE rb_cGrnViewCursor;
23
23
  /*
24
24
  * Document-class: Groonga::ViewCursor < Groonga::TableCursor
25
25
  *
26
- * Groonga::Viewからレコードを順番に取り出すためのオブジェク
27
- * ト。利用できるメソッドはGroonga::TableCursorを参照。
26
+ * {Groonga::View} からレコードを順番に取り出すためのオブジェク
27
+ * ト。利用できるメソッドは {Groonga::TableCursor} を参照。
28
28
  */
29
29
 
30
30
  void
@@ -40,7 +40,7 @@ VALUE rb_cGrnView;
40
40
  * に生成したテーブルが渡され、ブロックを抜けると自動的にテー
41
41
  * ブルが破棄される。
42
42
  *
43
- * ビューにテーブルを追加するときはGroonga::View#add_tableを
43
+ * ビューにテーブルを追加するときは {#add_table}
44
44
  * 使う。
45
45
  *
46
46
  * @example 無名一時ビューを生成する。
@@ -60,46 +60,30 @@ VALUE rb_cGrnView;
60
60
  *
61
61
  * @overload create(options={})
62
62
  * @return [Groonga::View]
63
- * @param options [::Hash] The name and value
64
- * pairs. Omitted names are initialized as the default value
65
- * @option options :context (Groonga::Context.default)
66
- * ビューが利用するGroonga::Context
67
- * @option options :name
68
- * ビューの名前。名前をつけると、Groonga::Context#[]に名
69
- * 前を指定してビューを取得することができる。省略すると
70
- * 無名ビューになり、ビューIDでのみ取得できる。
71
- * @option options :path
72
- * ビューを保存するパス。パスを指定すると永続ビューとな
73
- * り、プロセス終了後もレコードは保持される。次回起動時に
74
- * Groonga::View.openで保存されたビューを利用することが
75
- * できる。省略すると一時ビューになり、プロセスが終了する
76
- * とビューは破棄される。
77
- * @option options :persistent
78
- * +true+ を指定すると永続ビューとなる。 +path+ を省略した
79
- * 場合は自動的にパスが付加される。 +:context+ で指定した
80
- * Groonga::Contextに結びついているデータベースが一時デー
81
- * タベースの場合は例外が発生する。
63
+ * @!macro [new] view.create.options
64
+ * @param options [::Hash] The name and value
65
+ * pairs. Omitted names are initialized as the default value
66
+ * @option options :context (Groonga::Context.default)
67
+ * ビューが利用する {Groonga::Context}
68
+ * @option options :name
69
+ * ビューの名前。名前をつけると、 {Groonga::Context#[]} に名
70
+ * 前を指定してビューを取得することができる。省略すると
71
+ * 無名ビューになり、ビューIDでのみ取得できる。
72
+ * @option options :path
73
+ * ビューを保存するパス。パスを指定すると永続ビューとな
74
+ * り、プロセス終了後もレコードは保持される。次回起動時に
75
+ * {Groonga::View.open} で保存されたビューを利用することが
76
+ * できる。省略すると一時ビューになり、プロセスが終了する
77
+ * とビューは破棄される。
78
+ * @option options :persistent
79
+ * +true+ を指定すると永続ビューとなる。 +path+ を省略した
80
+ * 場合は自動的にパスが付加される。 +:context+ で指定した
81
+ * {Groonga::Context} に結びついているデータベースが一時デー
82
+ * タベースの場合は例外が発生する。
83
+ * @!macro view.create.options
82
84
  * @overload create(options={})
83
85
  * @yield [table]
84
- * @param options [::Hash] The name and value
85
- * pairs. Omitted names are initialized as the default value
86
- * @option options :context (Groonga::Context.default)
87
- * ビューが利用するGroonga::Context。
88
- * @option options :name
89
- * ビューの名前。名前をつけると、Groonga::Context#[]に名
90
- * 前を指定してビューを取得することができる。省略すると
91
- * 無名ビューになり、ビューIDでのみ取得できる。
92
- * @option options :path
93
- * ビューを保存するパス。パスを指定すると永続ビューとな
94
- * り、プロセス終了後もレコードは保持される。次回起動時に
95
- * Groonga::View.openで保存されたビューを利用することが
96
- * できる。省略すると一時ビューになり、プロセスが終了する
97
- * とビューは破棄される。
98
- * @option options :persistent
99
- * +true+ を指定すると永続ビューとなる。 +path+ を省略した
100
- * 場合は自動的にパスが付加される。 +:context+ で指定した
101
- * Groonga::Contextに結びついているデータベースが一時デー
102
- * タベースの場合は例外が発生する。
86
+ * @!macro view.create.options
103
87
  */
104
88
  static VALUE
105
89
  rb_grn_view_s_create (int argc, VALUE *argv, VALUE klass)
@@ -149,10 +133,9 @@ rb_grn_view_s_create (int argc, VALUE *argv, VALUE klass)
149
133
  }
150
134
 
151
135
  /*
152
- * call-seq:
153
- * view.add_table(table)
154
- *
155
136
  * _table_ をビューからアクセスできるようにする。
137
+ *
138
+ * @overload add_table(table)
156
139
  */
157
140
  static VALUE
158
141
  rb_grn_view_add_table (VALUE self, VALUE rb_table)
@@ -176,11 +159,11 @@ rb_grn_view_add_table (VALUE self, VALUE rb_table)
176
159
  }
177
160
 
178
161
  /*
179
- * call-seq:
180
- * view.each {|record| ...}
181
- *
182
162
  * ビューに登録されているテーブルのレコードを順番にブロック
183
163
  * に渡す。
164
+ *
165
+ * @overload each
166
+ * @yield [record]
184
167
  */
185
168
  static VALUE
186
169
  rb_grn_view_each (VALUE self)
data/ext/groonga/rb-grn.h CHANGED
@@ -76,7 +76,7 @@ RB_GRN_BEGIN_DECLS
76
76
 
77
77
  #define RB_GRN_MAJOR_VERSION 2
78
78
  #define RB_GRN_MINOR_VERSION 0
79
- #define RB_GRN_MICRO_VERSION 5
79
+ #define RB_GRN_MICRO_VERSION 6
80
80
 
81
81
  #define RB_GRN_QUERY_DEFAULT_MAX_EXPRESSIONS 32
82
82
 
@@ -70,8 +70,8 @@ rb_grn_init_runtime_version (VALUE mGrn)
70
70
 
71
71
  rb_obj_freeze(runtime_version);
72
72
  /*
73
- * 利用しているgroongaのバージョン。<tt>[メジャーバージョ
74
- * ン, マイナーバージョン, マイクロバージョン, タグ]</tt>の
73
+ * 利用しているgroongaのバージョン。 @[メジャーバージョ
74
+ * ン, マイナーバージョン, マイクロバージョン, タグ]@ の
75
75
  * 配列。
76
76
  */
77
77
  rb_define_const(mGrn, "VERSION", runtime_version);
@@ -90,8 +90,8 @@ rb_grn_init_version (VALUE mGrn)
90
90
  INT2NUM(GRN_MICRO_VERSION));
91
91
  rb_obj_freeze(build_version);
92
92
  /*
93
- * ビルドしたgroongaのバージョン。<tt>[メジャーバージョン,
94
- * マイナーバージョン, マイクロバージョン]</tt>の配列。
93
+ * ビルドしたgroongaのバージョン。 @[メジャーバージョン,
94
+ * マイナーバージョン, マイクロバージョン]@ の配列。
95
95
  */
96
96
  rb_define_const(mGrn, "BUILD_VERSION", build_version);
97
97
 
@@ -101,8 +101,8 @@ rb_grn_init_version (VALUE mGrn)
101
101
  INT2NUM(RB_GRN_MICRO_VERSION));
102
102
  rb_obj_freeze(bindings_version);
103
103
  /*
104
- * rroongaのバージョン。<tt>[メジャーバージョン, マ
105
- * イナーバージョン, マイクロバージョン]</tt>の配列。
104
+ * rroongaのバージョン。 @[メジャーバージョン, マ
105
+ * イナーバージョン, マイクロバージョン]@ の配列。
106
106
  */
107
107
  rb_define_const(mGrn, "BINDINGS_VERSION", bindings_version);
108
108
  }
@@ -17,7 +17,7 @@
17
17
 
18
18
  module Groonga
19
19
  class Database
20
- # @return [Array<Groonga::Table] tables defined in the database
20
+ # @return [Array<Groonga::Table>] tables defined in the database.
21
21
  def tables
22
22
  find_all do |object|
23
23
  object.is_a?(Groonga::Table)
@@ -48,9 +48,20 @@ module Groonga
48
48
  options[:dump_schema] = true if options[:dump_schema].nil?
49
49
  options[:dump_tables] = true if options[:dump_tables].nil?
50
50
 
51
+ if options[:dump_schema]
52
+ schema_dumper = SchemaDumper.new(options.merge(:syntax => :command))
53
+ end
51
54
  dump_plugins(options) if options[:dump_plugins]
52
- dump_schema(options) if options[:dump_schema]
55
+ if options[:dump_schema]
56
+ schema_dumper.dump_tables
57
+ options[:output].write("\n")
58
+ schema_dumper.dump_reference_columns
59
+ end
53
60
  dump_tables(options) if options[:dump_tables]
61
+ if options[:dump_schema]
62
+ options[:output].write("\n")
63
+ schema_dumper.dump_index_columns
64
+ end
54
65
 
55
66
  if have_output
56
67
  nil
@@ -74,10 +85,6 @@ module Groonga
74
85
  options[:output].write("\n") unless plugin_paths.empty?
75
86
  end
76
87
 
77
- def dump_schema(options)
78
- SchemaDumper.new(options.merge(:syntax => :command)).dump
79
- end
80
-
81
88
  def dump_tables(options)
82
89
  first_table = true
83
90
  options[:database].each(each_options(:order_by => :key)) do |object|
@@ -125,6 +132,40 @@ module Groonga
125
132
  end
126
133
 
127
134
  def dump
135
+ run do |syntax|
136
+ syntax.dump
137
+ end
138
+ end
139
+
140
+ def dump_tables
141
+ run do |syntax|
142
+ syntax.dump_tables
143
+ end
144
+ end
145
+
146
+ def dump_reference_columns
147
+ run do |syntax|
148
+ syntax.dump_reference_columns
149
+ end
150
+ end
151
+
152
+ def dump_index_columns
153
+ run do |syntax|
154
+ syntax.dump_index_columns
155
+ end
156
+ end
157
+
158
+ private
159
+ def create_syntax(database, output)
160
+ case @options[:syntax]
161
+ when :command
162
+ CommandSyntax.new(database, output)
163
+ else
164
+ RubySyntax.new(database, output)
165
+ end
166
+ end
167
+
168
+ def run
128
169
  database = @options[:database]
129
170
  if database.nil?
130
171
  context = @options[:context] || Groonga::Context.default
@@ -135,7 +176,7 @@ module Groonga
135
176
  output = @options[:output]
136
177
  have_output = !output.nil?
137
178
  output ||= Dumper.default_output
138
- result = syntax(database, output).dump
179
+ result = yield(create_syntax(database, output))
139
180
  if have_output
140
181
  result
141
182
  else
@@ -143,24 +184,12 @@ module Groonga
143
184
  end
144
185
  end
145
186
 
146
- private
147
- def syntax(database, output)
148
- case @options[:syntax]
149
- when :command
150
- CommandSyntax.new(database, output)
151
- else
152
- RubySyntax.new(database, output)
153
- end
154
- end
155
-
156
187
  # @private
157
188
  class BaseSyntax
158
189
  def initialize(database, output)
159
190
  @database = database
160
191
  @output = output
161
192
  @table_defined = false
162
- @index_columns = []
163
- @reference_columns = []
164
193
  end
165
194
 
166
195
  def dump
@@ -176,14 +205,13 @@ module Groonga
176
205
  end
177
206
 
178
207
  def dump_tables
179
- each_options = {:order_by => :key, :ignore_missing_object => true}
180
- @database.each(each_options) do |object|
181
- create_table(object) if object.is_a?(Groonga::Table)
208
+ each_table do |table|
209
+ create_table(table)
182
210
  end
183
211
  end
184
212
 
185
213
  def dump_reference_columns
186
- group_columns(@reference_columns).each do |table, columns|
214
+ group_columns(reference_columns).each do |table, columns|
187
215
  change_table(table) do
188
216
  columns.each do |column|
189
217
  define_reference_column(table, column)
@@ -193,7 +221,7 @@ module Groonga
193
221
  end
194
222
 
195
223
  def dump_index_columns
196
- group_columns(@index_columns).each do |table, columns|
224
+ group_columns(index_columns).each do |table, columns|
197
225
  change_table(table) do
198
226
  columns.each do |column|
199
227
  define_index_column(table, column)
@@ -215,6 +243,40 @@ module Groonga
215
243
  write("")
216
244
  end
217
245
 
246
+ def each_table
247
+ each_options = {:order_by => :key, :ignore_missing_object => true}
248
+ @database.each(each_options) do |object|
249
+ yield(object) if object.is_a?(Groonga::Table)
250
+ end
251
+ end
252
+
253
+ def each_column(table, &block)
254
+ sorted_columns = table.columns.sort_by {|column| column.local_name}
255
+ sorted_columns.each(&block)
256
+ end
257
+
258
+ def collect_columns
259
+ columns = []
260
+ each_table do |table|
261
+ each_column(table) do |column|
262
+ columns << column if yield(column)
263
+ end
264
+ end
265
+ columns
266
+ end
267
+
268
+ def reference_columns
269
+ @reference_columns ||= collect_columns do |column|
270
+ reference_column?(column)
271
+ end
272
+ end
273
+
274
+ def index_columns
275
+ @index_columns ||= collect_columns do |column|
276
+ index_column?(column)
277
+ end
278
+ end
279
+
218
280
  def group_columns(columns)
219
281
  grouped_columns = columns.group_by do |column|
220
282
  column.table
@@ -239,19 +301,33 @@ module Groonga
239
301
  write("\n")
240
302
  end
241
303
 
304
+ def column_type(column)
305
+ if column.is_a?(Groonga::IndexColumn)
306
+ :index
307
+ elsif column.range.is_a?(Groonga::Table)
308
+ :reference
309
+ else
310
+ :normal
311
+ end
312
+ end
313
+
314
+ def index_column?(column)
315
+ column_type(column) == :index
316
+ end
317
+
318
+ def reference_column?(column)
319
+ column_type(column) == :reference
320
+ end
321
+
322
+ def normal_column?(column)
323
+ column_type(column) == :normal
324
+ end
325
+
242
326
  def create_table(table)
243
327
  table_separator if @table_defined
244
328
  create_table_header(table)
245
- table.columns.sort_by {|column| column.local_name}.each do |column|
246
- if column.is_a?(Groonga::IndexColumn)
247
- @index_columns << column
248
- else
249
- if column.range.is_a?(Groonga::Table)
250
- @reference_columns << column
251
- else
252
- define_column(table, column)
253
- end
254
- end
329
+ each_column(table) do |column|
330
+ define_column(table, column) if normal_column?(column)
255
331
  end
256
332
  create_table_footer(table)
257
333
  @table_defined = true
@@ -24,6 +24,7 @@ module Groonga
24
24
  attr_accessor :allow_pragma
25
25
  attr_accessor :allow_column
26
26
  attr_accessor :allow_update
27
+ attr_accessor :allow_leading_not
27
28
  attr_accessor :default_column
28
29
 
29
30
  VALID_COLUMN_NAME_RE = /\A[a-zA-Z\d_]+\z/
@@ -36,6 +37,7 @@ module Groonga
36
37
  @allow_pragma = nil
37
38
  @allow_column = nil
38
39
  @allow_update = nil
40
+ @allow_leading_not = nil
39
41
  @default_column = nil
40
42
  end
41
43
 
@@ -60,6 +62,7 @@ module Groonga
60
62
  :allow_pragma => @allow_pragma,
61
63
  :allow_column => @allow_column,
62
64
  :allow_update => @allow_update,
65
+ :allow_leading_not => @allow_leading_not,
63
66
  :default_column => @default_column,
64
67
  }
65
68
  end
@@ -230,6 +233,16 @@ module Groonga
230
233
  SimilarSearchExpressionBuilder.new(self, normalize(other))
231
234
  end
232
235
 
236
+ def term_extract(other)
237
+ if @column_name == "_key"
238
+ TermExtractExpressionBuilder.new(self, normalize(other))
239
+ else
240
+ message = "term extraction supports _key column only: " +
241
+ "<#{@column_name}>"
242
+ raise ArgumentError, message
243
+ end
244
+ end
245
+
233
246
  private
234
247
  def normalize(other)
235
248
  if @range.is_a?(Groonga::Table)
@@ -417,6 +430,13 @@ module Groonga
417
430
  super(Groonga::Operation::SIMILAR, column_value_builder, value)
418
431
  end
419
432
  end
433
+
434
+ # @private
435
+ class TermExtractExpressionBuilder < BinaryExpressionBuilder
436
+ def initialize(column_value_builder, value)
437
+ super(Groonga::Operation::TERM_EXTRACT, column_value_builder, value)
438
+ end
439
+ end
420
440
  end
421
441
 
422
442
  # @private
@@ -586,6 +606,10 @@ module Groonga
586
606
  column_expression_builder.similar_search(text)
587
607
  end
588
608
 
609
+ def term_extract(text)
610
+ column_expression_builder.term_extract(text)
611
+ end
612
+
589
613
  private
590
614
  def column_expression_builder
591
615
  ColumnValueExpressionBuilder.new(@default_column,