groonga 0.9.1 → 1.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.
Files changed (186) hide show
  1. metadata +38 -227
  2. data/AUTHORS +0 -5
  3. data/NEWS.ja.rdoc +0 -114
  4. data/NEWS.rdoc +0 -116
  5. data/README.ja.rdoc +0 -63
  6. data/README.rdoc +0 -64
  7. data/Rakefile +0 -216
  8. data/benchmark/common.rb +0 -49
  9. data/benchmark/read-write-many-small-items.rb +0 -144
  10. data/benchmark/write-many-small-items.rb +0 -135
  11. data/example/bookmark.rb +0 -161
  12. data/example/index-html.rb +0 -89
  13. data/example/search/config.ru +0 -211
  14. data/example/search/public/css/groonga.css +0 -122
  15. data/ext/.gitignore +0 -2
  16. data/ext/rb-grn-accessor.c +0 -52
  17. data/ext/rb-grn-array-cursor.c +0 -36
  18. data/ext/rb-grn-array.c +0 -210
  19. data/ext/rb-grn-column.c +0 -570
  20. data/ext/rb-grn-context.c +0 -655
  21. data/ext/rb-grn-database.c +0 -415
  22. data/ext/rb-grn-encoding-support.c +0 -64
  23. data/ext/rb-grn-encoding.c +0 -257
  24. data/ext/rb-grn-exception.c +0 -1110
  25. data/ext/rb-grn-expression-builder.c +0 -75
  26. data/ext/rb-grn-expression.c +0 -732
  27. data/ext/rb-grn-fix-size-column.c +0 -166
  28. data/ext/rb-grn-hash-cursor.c +0 -38
  29. data/ext/rb-grn-hash.c +0 -294
  30. data/ext/rb-grn-index-column.c +0 -488
  31. data/ext/rb-grn-logger.c +0 -325
  32. data/ext/rb-grn-object.c +0 -1335
  33. data/ext/rb-grn-operation.c +0 -198
  34. data/ext/rb-grn-patricia-trie-cursor.c +0 -39
  35. data/ext/rb-grn-patricia-trie.c +0 -488
  36. data/ext/rb-grn-procedure.c +0 -52
  37. data/ext/rb-grn-query.c +0 -260
  38. data/ext/rb-grn-record.c +0 -40
  39. data/ext/rb-grn-snippet.c +0 -328
  40. data/ext/rb-grn-table-cursor-key-support.c +0 -69
  41. data/ext/rb-grn-table-cursor.c +0 -246
  42. data/ext/rb-grn-table-key-support.c +0 -731
  43. data/ext/rb-grn-table.c +0 -2038
  44. data/ext/rb-grn-type.c +0 -181
  45. data/ext/rb-grn-utils.c +0 -769
  46. data/ext/rb-grn-variable-size-column.c +0 -36
  47. data/ext/rb-grn-variable.c +0 -108
  48. data/ext/rb-grn.h +0 -684
  49. data/ext/rb-groonga.c +0 -113
  50. data/extconf.rb +0 -216
  51. data/html/bar.svg +0 -153
  52. data/html/developer.html +0 -121
  53. data/html/developer.svg +0 -469
  54. data/html/download.svg +0 -253
  55. data/html/favicon.ico +0 -0
  56. data/html/favicon.xcf +0 -0
  57. data/html/footer.html.erb +0 -28
  58. data/html/head.html.erb +0 -4
  59. data/html/header.html.erb +0 -17
  60. data/html/index.html +0 -147
  61. data/html/install.svg +0 -636
  62. data/html/logo.xcf +0 -0
  63. data/html/ranguba.css +0 -248
  64. data/html/tutorial.svg +0 -559
  65. data/lib/groonga.rb +0 -83
  66. data/lib/groonga/expression-builder.rb +0 -285
  67. data/lib/groonga/patricia-trie.rb +0 -53
  68. data/lib/groonga/record.rb +0 -276
  69. data/lib/groonga/schema.rb +0 -916
  70. data/license/GPL +0 -340
  71. data/license/LGPL +0 -504
  72. data/license/RUBY +0 -59
  73. data/misc/grnop2ruby.rb +0 -49
  74. data/pkg-config.rb +0 -333
  75. data/src/rb-grn-table-cursor.c +0 -296
  76. data/test-unit/Rakefile +0 -40
  77. data/test-unit/TODO +0 -5
  78. data/test-unit/bin/testrb +0 -5
  79. data/test-unit/html/classic.html +0 -15
  80. data/test-unit/html/index.html +0 -25
  81. data/test-unit/html/index.html.ja +0 -27
  82. data/test-unit/lib/test/unit.rb +0 -323
  83. data/test-unit/lib/test/unit/assertionfailederror.rb +0 -25
  84. data/test-unit/lib/test/unit/assertions.rb +0 -1230
  85. data/test-unit/lib/test/unit/attribute.rb +0 -125
  86. data/test-unit/lib/test/unit/autorunner.rb +0 -353
  87. data/test-unit/lib/test/unit/collector.rb +0 -36
  88. data/test-unit/lib/test/unit/collector/descendant.rb +0 -23
  89. data/test-unit/lib/test/unit/collector/dir.rb +0 -108
  90. data/test-unit/lib/test/unit/collector/load.rb +0 -136
  91. data/test-unit/lib/test/unit/collector/objectspace.rb +0 -34
  92. data/test-unit/lib/test/unit/color-scheme.rb +0 -102
  93. data/test-unit/lib/test/unit/color.rb +0 -96
  94. data/test-unit/lib/test/unit/diff.rb +0 -724
  95. data/test-unit/lib/test/unit/error.rb +0 -130
  96. data/test-unit/lib/test/unit/exceptionhandler.rb +0 -39
  97. data/test-unit/lib/test/unit/failure.rb +0 -136
  98. data/test-unit/lib/test/unit/fixture.rb +0 -176
  99. data/test-unit/lib/test/unit/notification.rb +0 -129
  100. data/test-unit/lib/test/unit/omission.rb +0 -191
  101. data/test-unit/lib/test/unit/pending.rb +0 -150
  102. data/test-unit/lib/test/unit/priority.rb +0 -181
  103. data/test-unit/lib/test/unit/runner/console.rb +0 -52
  104. data/test-unit/lib/test/unit/runner/emacs.rb +0 -8
  105. data/test-unit/lib/test/unit/runner/tap.rb +0 -8
  106. data/test-unit/lib/test/unit/testcase.rb +0 -476
  107. data/test-unit/lib/test/unit/testresult.rb +0 -89
  108. data/test-unit/lib/test/unit/testsuite.rb +0 -110
  109. data/test-unit/lib/test/unit/ui/console/outputlevel.rb +0 -14
  110. data/test-unit/lib/test/unit/ui/console/testrunner.rb +0 -464
  111. data/test-unit/lib/test/unit/ui/emacs/testrunner.rb +0 -63
  112. data/test-unit/lib/test/unit/ui/tap/testrunner.rb +0 -92
  113. data/test-unit/lib/test/unit/ui/testrunner.rb +0 -28
  114. data/test-unit/lib/test/unit/ui/testrunnermediator.rb +0 -77
  115. data/test-unit/lib/test/unit/ui/testrunnerutilities.rb +0 -41
  116. data/test-unit/lib/test/unit/util/backtracefilter.rb +0 -41
  117. data/test-unit/lib/test/unit/util/method-owner-finder.rb +0 -28
  118. data/test-unit/lib/test/unit/util/observable.rb +0 -90
  119. data/test-unit/lib/test/unit/util/procwrapper.rb +0 -48
  120. data/test-unit/lib/test/unit/version.rb +0 -7
  121. data/test-unit/sample/adder.rb +0 -13
  122. data/test-unit/sample/subtracter.rb +0 -12
  123. data/test-unit/sample/test_adder.rb +0 -20
  124. data/test-unit/sample/test_subtracter.rb +0 -20
  125. data/test-unit/sample/test_user.rb +0 -23
  126. data/test-unit/test/collector/test-descendant.rb +0 -133
  127. data/test-unit/test/collector/test-load.rb +0 -329
  128. data/test-unit/test/collector/test_dir.rb +0 -406
  129. data/test-unit/test/collector/test_objectspace.rb +0 -100
  130. data/test-unit/test/run-test.rb +0 -15
  131. data/test-unit/test/test-attribute.rb +0 -86
  132. data/test-unit/test/test-color-scheme.rb +0 -67
  133. data/test-unit/test/test-color.rb +0 -47
  134. data/test-unit/test/test-diff.rb +0 -518
  135. data/test-unit/test/test-emacs-runner.rb +0 -60
  136. data/test-unit/test/test-fixture.rb +0 -287
  137. data/test-unit/test/test-notification.rb +0 -33
  138. data/test-unit/test/test-omission.rb +0 -81
  139. data/test-unit/test/test-pending.rb +0 -70
  140. data/test-unit/test/test-priority.rb +0 -119
  141. data/test-unit/test/test-testcase.rb +0 -554
  142. data/test-unit/test/test_assertions.rb +0 -1151
  143. data/test-unit/test/test_error.rb +0 -26
  144. data/test-unit/test/test_failure.rb +0 -33
  145. data/test-unit/test/test_testresult.rb +0 -113
  146. data/test-unit/test/test_testsuite.rb +0 -129
  147. data/test-unit/test/testunit-test-util.rb +0 -14
  148. data/test-unit/test/ui/test_testrunmediator.rb +0 -20
  149. data/test-unit/test/util/test-method-owner-finder.rb +0 -38
  150. data/test-unit/test/util/test_backtracefilter.rb +0 -41
  151. data/test-unit/test/util/test_observable.rb +0 -102
  152. data/test-unit/test/util/test_procwrapper.rb +0 -36
  153. data/test/.gitignore +0 -1
  154. data/test/groonga-test-utils.rb +0 -106
  155. data/test/run-test.rb +0 -58
  156. data/test/test-array.rb +0 -97
  157. data/test/test-column.rb +0 -298
  158. data/test/test-context.rb +0 -73
  159. data/test/test-database.rb +0 -113
  160. data/test/test-encoding.rb +0 -33
  161. data/test/test-exception.rb +0 -93
  162. data/test/test-expression-builder.rb +0 -156
  163. data/test/test-expression.rb +0 -133
  164. data/test/test-fix-size-column.rb +0 -65
  165. data/test/test-gqtp.rb +0 -70
  166. data/test/test-hash.rb +0 -312
  167. data/test/test-index-column.rb +0 -81
  168. data/test/test-patricia-trie.rb +0 -189
  169. data/test/test-procedure.rb +0 -37
  170. data/test/test-query.rb +0 -22
  171. data/test/test-record.rb +0 -268
  172. data/test/test-remote.rb +0 -53
  173. data/test/test-schema.rb +0 -416
  174. data/test/test-snippet.rb +0 -121
  175. data/test/test-table-cursor.rb +0 -153
  176. data/test/test-table-offset-and-limit.rb +0 -102
  177. data/test/test-table-select-normalize.rb +0 -48
  178. data/test/test-table-select.rb +0 -145
  179. data/test/test-table.rb +0 -642
  180. data/test/test-type.rb +0 -61
  181. data/test/test-variable-size-column.rb +0 -98
  182. data/test/test-variable.rb +0 -28
  183. data/test/test-vector-column.rb +0 -76
  184. data/test/test-version.rb +0 -31
  185. data/text/TUTORIAL.ja.rdoc +0 -392
  186. data/text/expression.rdoc +0 -284
@@ -1,166 +0,0 @@
1
- /* -*- c-file-style: "ruby" -*- */
2
- /*
3
- Copyright (C) 2009 Kouhei Sutou <kou@clear-code.com>
4
-
5
- This library is free software; you can redistribute it and/or
6
- modify it under the terms of the GNU Lesser General Public
7
- License version 2.1 as published by the Free Software Foundation.
8
-
9
- This library is distributed in the hope that it will be useful,
10
- but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
- Lesser General Public License for more details.
13
-
14
- You should have received a copy of the GNU Lesser General Public
15
- License along with this library; if not, write to the Free Software
16
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
- */
18
-
19
- #include "rb-grn.h"
20
-
21
- #define SELF(object) ((RbGrnColumn *)DATA_PTR(object))
22
-
23
- VALUE rb_cGrnFixSizeColumn;
24
-
25
- /*
26
- * Document-class: Groonga::FixSizeColumn < Groonga::Column
27
- *
28
- * 固定長データ用のカラム。
29
- */
30
-
31
- /*
32
- * call-seq:
33
- * column[id] -> 値
34
- *
35
- * _column_の_id_に対応する値を返す。
36
- */
37
- VALUE
38
- rb_grn_fix_size_column_array_reference (VALUE self, VALUE rb_id)
39
- {
40
- grn_id id;
41
- grn_ctx *context;
42
- grn_obj *fix_size_column;
43
- grn_obj *range;
44
- grn_obj *value;
45
-
46
- rb_grn_column_deconstruct(SELF(self), &fix_size_column, &context,
47
- NULL, NULL,
48
- &value, NULL, &range);
49
-
50
- id = NUM2UINT(rb_id);
51
- GRN_BULK_REWIND(value);
52
- grn_obj_get_value(context, fix_size_column, id, value);
53
- rb_grn_context_check(context, self);
54
-
55
- return GRNVALUE2RVAL(context, value, range, self);
56
- }
57
-
58
- /*
59
- * call-seq:
60
- * column[id] = value
61
- *
62
- * _column_の_id_に対応する値を設定する。
63
- */
64
- static VALUE
65
- rb_grn_fix_size_column_array_set (VALUE self, VALUE rb_id, VALUE rb_value)
66
- {
67
- grn_ctx *context = NULL;
68
- grn_obj *column;
69
- grn_id domain_id, range_id;
70
- grn_obj *domain, *range;
71
- grn_obj *value;
72
- grn_rc rc;
73
- grn_id id;
74
-
75
- rb_grn_column_deconstruct(SELF(self), &column, &context,
76
- &domain_id, &domain,
77
- &value, &range_id, &range);
78
-
79
- id = NUM2UINT(rb_id);
80
- RVAL2GRNBULK(rb_value, context, value);
81
- if ((value->header.domain == GRN_DB_INT32 ||
82
- value->header.domain == GRN_DB_UINT32) &&
83
- (GRN_TABLE_HASH_KEY <= range->header.type &&
84
- range->header.type <= GRN_TABLE_VIEW)) {
85
- value->header.domain = range_id;
86
- }
87
-
88
- rc = grn_obj_set_value(context, column, id, value, GRN_OBJ_SET);
89
- rb_grn_context_check(context, self);
90
- rb_grn_rc_check(rc, self);
91
-
92
- return Qnil;
93
- }
94
-
95
- static VALUE
96
- rb_grn_fix_size_column_integer_set (int argc, VALUE *argv, VALUE self, int flags)
97
- {
98
- grn_ctx *context = NULL;
99
- grn_obj *column;
100
- grn_obj *value;
101
- grn_rc rc;
102
- grn_id id;
103
- VALUE rb_id, rb_delta;
104
-
105
- rb_scan_args(argc, argv, "11", &rb_id, &rb_delta);
106
-
107
- rb_grn_column_deconstruct(SELF(self), &column, &context,
108
- NULL, NULL,
109
- &value, NULL, NULL);
110
-
111
- id = NUM2UINT(rb_id);
112
- if (NIL_P(rb_delta))
113
- rb_delta = INT2NUM(1);
114
-
115
- GRN_BULK_REWIND(value);
116
- RVAL2GRNBULK(rb_delta, context, value);
117
-
118
- rc = grn_obj_set_value(context, column, id, value, flags);
119
- rb_grn_context_check(context, self);
120
- rb_grn_rc_check(rc, self);
121
-
122
- return Qnil;
123
- }
124
-
125
- /*
126
- * call-seq:
127
- * column.increment!(id, delta=nil)
128
- *
129
- * _column_の_id_に対応する値を_delta_だけ増加する。_delta_
130
- * が+nil+の場合は1増加する。
131
- */
132
- static VALUE
133
- rb_grn_fix_size_column_increment (int argc, VALUE *argv, VALUE self)
134
- {
135
- return rb_grn_fix_size_column_integer_set(argc, argv, self, GRN_OBJ_INCR);
136
- }
137
-
138
- /*
139
- * call-seq:
140
- * column.decrement!(id, delta=nil)
141
- *
142
- * _column_の_id_に対応する値を_delta_だけ減少する。_delta_
143
- * が+nil+の場合は1減少する。
144
- */
145
- static VALUE
146
- rb_grn_fix_size_column_decrement (int argc, VALUE *argv, VALUE self)
147
- {
148
- return rb_grn_fix_size_column_integer_set(argc, argv, self, GRN_OBJ_DECR);
149
- }
150
-
151
- void
152
- rb_grn_init_fix_size_column (VALUE mGrn)
153
- {
154
- rb_cGrnFixSizeColumn =
155
- rb_define_class_under(mGrn, "FixSizeColumn", rb_cGrnColumn);
156
-
157
- rb_define_method(rb_cGrnFixSizeColumn, "[]",
158
- rb_grn_fix_size_column_array_reference, 1);
159
- rb_define_method(rb_cGrnFixSizeColumn, "[]=",
160
- rb_grn_fix_size_column_array_set, 2);
161
-
162
- rb_define_method(rb_cGrnFixSizeColumn, "increment!",
163
- rb_grn_fix_size_column_increment, -1);
164
- rb_define_method(rb_cGrnFixSizeColumn, "decrement!",
165
- rb_grn_fix_size_column_decrement, -1);
166
- }
@@ -1,38 +0,0 @@
1
- /* -*- c-file-style: "ruby" -*- */
2
- /*
3
- Copyright (C) 2009 Kouhei Sutou <kou@clear-code.com>
4
-
5
- This library is free software; you can redistribute it and/or
6
- modify it under the terms of the GNU Lesser General Public
7
- License version 2.1 as published by the Free Software Foundation.
8
-
9
- This library is distributed in the hope that it will be useful,
10
- but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
- Lesser General Public License for more details.
13
-
14
- You should have received a copy of the GNU Lesser General Public
15
- License along with this library; if not, write to the Free Software
16
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
- */
18
-
19
- #include "rb-grn.h"
20
-
21
- VALUE rb_cGrnHashCursor;
22
-
23
- /*
24
- * Document-class: Groonga::HashCursor < Groonga::TableCursor
25
- *
26
- * Groonga::Hashに登録されているレコードを順番に取り出すため
27
- * のオブジェクト。利用できるメソッドはGroonga::TableCursor
28
- * とGroonga::TableCursorKeySupportを参照。
29
- */
30
-
31
- void
32
- rb_grn_init_hash_cursor (VALUE mGrn)
33
- {
34
- rb_cGrnHashCursor =
35
- rb_define_class_under(mGrn, "HashCursor", rb_cGrnTableCursor);
36
-
37
- rb_include_module(rb_cGrnHashCursor, rb_mGrnTableCursorKeySupport);
38
- }
data/ext/rb-grn-hash.c DELETED
@@ -1,294 +0,0 @@
1
- /* -*- c-file-style: "ruby" -*- */
2
- /*
3
- Copyright (C) 2009 Kouhei Sutou <kou@clear-code.com>
4
-
5
- This library is free software; you can redistribute it and/or
6
- modify it under the terms of the GNU Lesser General Public
7
- License version 2.1 as published by the Free Software Foundation.
8
-
9
- This library is distributed in the hope that it will be useful,
10
- but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
- Lesser General Public License for more details.
13
-
14
- You should have received a copy of the GNU Lesser General Public
15
- License along with this library; if not, write to the Free Software
16
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
- */
18
-
19
- #include "rb-grn.h"
20
-
21
- #define SELF(object) ((RbGrnTableKeySupport *)DATA_PTR(object))
22
-
23
- VALUE rb_cGrnHash;
24
-
25
- /*
26
- * Document-class: Groonga::Hash < Groonga::Table
27
- *
28
- * 各レコードをキーで管理するテーブル。キーと完全一致するレ
29
- * コードを非常に高速に検索できる。
30
- */
31
-
32
- /*
33
- * call-seq:
34
- * Groonga::Hash.create(options={}) -> Groonga::Hash
35
- * Groonga::Hash.create(options={}) {|table| ... }
36
- *
37
- * 各レコードをキーで管理するテーブルを生成する。ブロックを指
38
- * 定すると、そのブロックに生成したテーブルが渡され、ブロック
39
- * を抜けると自動的にテーブルが破棄される。
40
- *
41
- * _options_に指定可能な値は以下の通り。
42
- *
43
- * [+:context+]
44
- * テーブルが利用するGroonga::Context。省略すると
45
- * Groonga::Context.defaultを用いる。
46
- *
47
- * [+:name+]
48
- * テーブルの名前。名前をつけると、Groonga::Context#[]に名
49
- * 前を指定してテーブルを取得することができる。省略すると
50
- * 無名テーブルになり、テーブルIDでのみ取得できる。
51
- *
52
- * [+:path+]
53
- * テーブルを保存するパス。パスを指定すると永続テーブルとな
54
- * り、プロセス終了後もレコードは保持される。次回起動時に
55
- * Groonga::Hash.openで保存されたレコードを利用することが
56
- * できる。省略すると一時テーブルになり、プロセスが終了する
57
- * とレコードは破棄される。
58
- *
59
- * [+:persistent+]
60
- * +true+を指定すると永続テーブルとなる。+path+を省略した
61
- * 場合は自動的にパスが付加される。+:context+で指定した
62
- * Groonga::Contextに結びついているデータベースが一時デー
63
- * タベースの場合は例外が発生する。
64
- *
65
- * [+:key_type+]
66
- * キーの種類を示すオブジェクトを指定する。キーの種類には型
67
- * 名("Int32"や"ShortText"など)またはGroonga::Typeまたは
68
- * テーブル(Groonga::Array、Groonga::Hash、
69
- * Groonga::PatriciaTrieのどれか)を指定する。
70
- *
71
- * Groonga::Typeを指定した場合は、その型が示す範囲の値をキー
72
- * として使用する。ただし、キーの最大サイズは4096バイトで
73
- * あるため、Groonga::Type::TEXTやGroonga::Type::LONG_TEXT
74
- * は使用できない。
75
- *
76
- * テーブルを指定した場合はレコードIDをキーとして使用する。
77
- * 指定したテーブルのGroonga::Recordをキーとして使用するこ
78
- * ともでき、その場合は自動的にGroonga::Recordからレコード
79
- * IDを取得する。
80
- *
81
- * 省略した場合は文字列をキーとして使用する。この場合、
82
- * 4096バイトまで使用可能である。
83
- *
84
- * [+:value_type+]
85
- * 値の型を指定する。省略すると値のための領域を確保しない。
86
- * 値を保存したい場合は必ず指定すること。
87
- *
88
- * 参考: Groonga::Type.new
89
- *
90
- * [+:default_tokenizer+]
91
- * Groonga::IndexColumnで使用するトークナイザを指定する。
92
- * デフォルトでは何も設定されていないので、テーブルに
93
- * Groonga::IndexColumnを定義する場合は
94
- * <tt>"TokenBigram"</tt>などを指定する必要がある。
95
- *
96
- * [+:sub_records+]
97
- * +true+を指定すると#groupでグループ化したときに、
98
- * Groonga::Record#n_sub_recordsでグループに含まれるレコー
99
- * ドの件数を取得できる。
100
- *
101
- * 使用例:
102
- *
103
- * 無名一時テーブルを生成する。
104
- * Groonga::Hash.create
105
- *
106
- * 無名永続テーブルを生成する。
107
- * Groonga::Hash.create(:path => "/tmp/hash.grn")
108
- *
109
- * 名前付き永続テーブルを生成する。ただし、ファイル名は気に
110
- * しない。
111
- * Groonga::Hash.create(:name => "Bookmarks",
112
- * :persistent => true)
113
- *
114
- * それぞれのレコードに512バイトの値を格納できる無名一時テー
115
- * ブルを生成する。
116
- * Groonga::Hash.create(:value => 512)
117
- *
118
- * キーとして文字列を使用する無名一時テーブルを生成する。
119
- * Groonga::Hash.create(:key_type => Groonga::Type::SHORT_TEXT)
120
- *
121
- * キーとして文字列を使用する無名一時テーブルを生成する。
122
- * (キーの種類を表すオブジェクトは文字列で指定。)
123
- * Groonga::Hash.create(:key_type => "ShortText")
124
- *
125
- * キーとして<tt>Bookmarks</tt>テーブルのレコードを使用す
126
- * る無名一時テーブルを生成する。
127
- * bookmarks = Groonga::Hash.create(:name => "Bookmarks")
128
- * Groonga::Hash.create(:key_type => bookmarks)
129
- *
130
- * キーとして<tt>Bookmarks</tt>テーブルのレコードを使用す
131
- * る無名一時テーブルを生成する。
132
- * (テーブルは文字列で指定。)
133
- * Groonga::Hash.create(:name => "Bookmarks")
134
- * Groonga::Hash.create(:key_type => "Bookmarks")
135
- *
136
- * 全文検索用のトークンをバイグラムで切り出す無名一時テーブ
137
- * ルを生成する。
138
- * bookmarks = Groonga::Hash.create(:name => "Bookmarks")
139
- * bookmarks.define_column("comment", "Text")
140
- * terms = Groonga::Hash.create(:name => "Terms",
141
- * :default_tokenizer => "TokenBigram")
142
- * terms.define_index_column("content", bookmarks,
143
- * :source => "Bookmarks.comment")
144
- */
145
- static VALUE
146
- rb_grn_hash_s_create (int argc, VALUE *argv, VALUE klass)
147
- {
148
- grn_ctx *context;
149
- grn_obj *key_type = NULL, *value_type = NULL, *table;
150
- const char *name = NULL, *path = NULL;
151
- unsigned name_size = 0;
152
- grn_obj_flags flags = GRN_TABLE_HASH_KEY;
153
- VALUE rb_table;
154
- VALUE options, rb_context, rb_name, rb_path, rb_persistent;
155
- VALUE rb_key_type, rb_value_type, rb_default_tokenizer;
156
- VALUE rb_sub_records;
157
-
158
- rb_scan_args(argc, argv, "01", &options);
159
-
160
- rb_grn_scan_options(options,
161
- "context", &rb_context,
162
- "name", &rb_name,
163
- "path", &rb_path,
164
- "persistent", &rb_persistent,
165
- "key_type", &rb_key_type,
166
- "value_type", &rb_value_type,
167
- "default_tokenizer", &rb_default_tokenizer,
168
- "sub_records", &rb_sub_records,
169
- NULL);
170
-
171
- context = rb_grn_context_ensure(&rb_context);
172
-
173
- if (!NIL_P(rb_name)) {
174
- name = StringValuePtr(rb_name);
175
- name_size = RSTRING_LEN(rb_name);
176
- flags |= GRN_OBJ_PERSISTENT;
177
- }
178
-
179
- if (!NIL_P(rb_path)) {
180
- path = StringValueCStr(rb_path);
181
- flags |= GRN_OBJ_PERSISTENT;
182
- }
183
-
184
- if (RVAL2CBOOL(rb_persistent))
185
- flags |= GRN_OBJ_PERSISTENT;
186
-
187
- if (NIL_P(rb_key_type)) {
188
- flags |= GRN_OBJ_KEY_VAR_SIZE;
189
- } else {
190
- key_type = RVAL2GRNOBJECT(rb_key_type, &context);
191
- }
192
-
193
- if (!NIL_P(rb_value_type))
194
- value_type = RVAL2GRNOBJECT(rb_value_type, &context);
195
-
196
- if (RVAL2CBOOL(rb_sub_records))
197
- flags |= GRN_OBJ_WITH_SUBREC;
198
-
199
- table = grn_table_create(context, name, name_size, path,
200
- flags, key_type, value_type);
201
- if (!table)
202
- rb_grn_context_check(context, rb_ary_new4(argc, argv));
203
- rb_table = GRNOBJECT2RVAL(klass, context, table, RB_GRN_TRUE);
204
-
205
- if (!NIL_P(rb_default_tokenizer))
206
- rb_funcall(rb_table, rb_intern("default_tokenizer="), 1,
207
- rb_default_tokenizer);
208
-
209
- if (rb_block_given_p())
210
- return rb_ensure(rb_yield, rb_table, rb_grn_object_close, rb_table);
211
- else
212
- return rb_table;
213
- }
214
-
215
- /*
216
- * call-seq:
217
- * hash.search(key, options=nil) -> Groonga::Hash
218
- *
219
- * _key_にマッチするレコードのIDがキーに入っている
220
- * Groonga::Hashを返す。マッチするレコードがない場合は空の
221
- * Groonga::Hashが返る。
222
- *
223
- * _options_で+:result+を指定することにより、そのテーブルにマッ
224
- * チしたレコードIDがキーのレコードを追加することができる。
225
- * +:result+にテーブルを指定した場合は、そのテーブルが返る。
226
- *
227
- * _options_に指定可能な値は以下の通り。
228
- *
229
- * [+:result+]
230
- * 結果を格納するテーブル。
231
- *
232
- * 複数のキーで検索し、結果を1つのテーブルに集める。
233
- * result = nil
234
- * keys = ["morita", "gunyara-kun", "yu"]
235
- * keys.each do |key|
236
- * result = users.search(key, :result => result)
237
- * end
238
- * result.each do |record|
239
- * user = record.key
240
- * p user.key # -> "morita"または"gunyara-kun"または"yu"
241
- * end
242
- */
243
- static VALUE
244
- rb_grn_hash_search (int argc, VALUE *argv, VALUE self)
245
- {
246
- grn_rc rc;
247
- grn_ctx *context;
248
- grn_obj *table;
249
- grn_id domain_id;
250
- grn_obj *key, *domain, *result;
251
- VALUE rb_key, options, rb_result;
252
-
253
- rb_grn_table_key_support_deconstruct(SELF(self), &table, &context,
254
- &key, &domain_id, &domain,
255
- NULL, NULL, NULL,
256
- NULL);
257
-
258
- rb_scan_args(argc, argv, "11", &rb_key, &options);
259
-
260
- RVAL2GRNKEY(rb_key, context, key, domain_id, domain, self);
261
-
262
- rb_grn_scan_options(options,
263
- "result", &rb_result,
264
- NULL);
265
-
266
- if (NIL_P(rb_result)) {
267
- result = grn_table_create(context, NULL, 0, NULL,
268
- GRN_OBJ_TABLE_HASH_KEY | GRN_OBJ_WITH_SUBREC,
269
- table, 0);
270
- rb_grn_context_check(context, self);
271
- rb_result = GRNOBJECT2RVAL(Qnil, context, result, RB_GRN_TRUE);
272
- } else {
273
- result = RVAL2GRNOBJECT(rb_result, &context);
274
- }
275
-
276
- rc = grn_obj_search(context, table, key,
277
- result, GRN_OP_OR, NULL);
278
- rb_grn_rc_check(rc, self);
279
-
280
- return rb_result;
281
- }
282
-
283
- void
284
- rb_grn_init_hash (VALUE mGrn)
285
- {
286
- rb_cGrnHash = rb_define_class_under(mGrn, "Hash", rb_cGrnTable);
287
-
288
- rb_include_module(rb_cGrnHash, rb_mGrnTableKeySupport);
289
-
290
- rb_define_singleton_method(rb_cGrnHash, "create",
291
- rb_grn_hash_s_create, -1);
292
-
293
- rb_define_method(rb_cGrnHash, "search", rb_grn_hash_search, -1);
294
- }