rroonga 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (198) hide show
  1. data/AUTHORS +5 -0
  2. data/NEWS.ja.rdoc +114 -0
  3. data/NEWS.rdoc +116 -0
  4. data/README.ja.rdoc +65 -0
  5. data/README.rdoc +66 -0
  6. data/Rakefile +205 -0
  7. data/benchmark/common.rb +49 -0
  8. data/benchmark/read-write-many-small-items.rb +144 -0
  9. data/benchmark/write-many-small-items.rb +135 -0
  10. data/example/bookmark.rb +161 -0
  11. data/example/index-html.rb +89 -0
  12. data/example/search/config.ru +230 -0
  13. data/example/search/public/css/groonga.css +122 -0
  14. data/ext/.gitignore +2 -0
  15. data/ext/groonga/extconf.rb +93 -0
  16. data/ext/groonga/mkmf.log +99 -0
  17. data/ext/groonga/rb-grn-accessor.c +52 -0
  18. data/ext/groonga/rb-grn-array-cursor.c +36 -0
  19. data/ext/groonga/rb-grn-array.c +210 -0
  20. data/ext/groonga/rb-grn-column.c +573 -0
  21. data/ext/groonga/rb-grn-context.c +662 -0
  22. data/ext/groonga/rb-grn-database.c +472 -0
  23. data/ext/groonga/rb-grn-encoding-support.c +64 -0
  24. data/ext/groonga/rb-grn-encoding.c +257 -0
  25. data/ext/groonga/rb-grn-exception.c +1110 -0
  26. data/ext/groonga/rb-grn-expression-builder.c +75 -0
  27. data/ext/groonga/rb-grn-expression.c +731 -0
  28. data/ext/groonga/rb-grn-fix-size-column.c +166 -0
  29. data/ext/groonga/rb-grn-hash-cursor.c +38 -0
  30. data/ext/groonga/rb-grn-hash.c +294 -0
  31. data/ext/groonga/rb-grn-index-column.c +488 -0
  32. data/ext/groonga/rb-grn-logger.c +504 -0
  33. data/ext/groonga/rb-grn-object.c +1369 -0
  34. data/ext/groonga/rb-grn-operation.c +198 -0
  35. data/ext/groonga/rb-grn-patricia-trie-cursor.c +39 -0
  36. data/ext/groonga/rb-grn-patricia-trie.c +488 -0
  37. data/ext/groonga/rb-grn-procedure.c +52 -0
  38. data/ext/groonga/rb-grn-query.c +260 -0
  39. data/ext/groonga/rb-grn-record.c +40 -0
  40. data/ext/groonga/rb-grn-snippet.c +334 -0
  41. data/ext/groonga/rb-grn-table-cursor-key-support.c +69 -0
  42. data/ext/groonga/rb-grn-table-cursor.c +247 -0
  43. data/ext/groonga/rb-grn-table-key-support.c +714 -0
  44. data/ext/groonga/rb-grn-table.c +1977 -0
  45. data/ext/groonga/rb-grn-type.c +181 -0
  46. data/ext/groonga/rb-grn-utils.c +769 -0
  47. data/ext/groonga/rb-grn-variable-size-column.c +36 -0
  48. data/ext/groonga/rb-grn-variable.c +108 -0
  49. data/ext/groonga/rb-grn-view-accessor.c +53 -0
  50. data/ext/groonga/rb-grn-view-cursor.c +35 -0
  51. data/ext/groonga/rb-grn-view-record.c +41 -0
  52. data/ext/groonga/rb-grn-view.c +421 -0
  53. data/ext/groonga/rb-grn.h +698 -0
  54. data/ext/groonga/rb-groonga.c +107 -0
  55. data/extconf.rb +130 -0
  56. data/html/bar.svg +153 -0
  57. data/html/developer.html +117 -0
  58. data/html/developer.svg +469 -0
  59. data/html/download.svg +253 -0
  60. data/html/favicon.ico +0 -0
  61. data/html/favicon.xcf +0 -0
  62. data/html/footer.html.erb +28 -0
  63. data/html/head.html.erb +4 -0
  64. data/html/header.html.erb +17 -0
  65. data/html/index.html +147 -0
  66. data/html/install.svg +636 -0
  67. data/html/logo.xcf +0 -0
  68. data/html/ranguba.css +250 -0
  69. data/html/tutorial.svg +559 -0
  70. data/lib/groonga.rb +90 -0
  71. data/lib/groonga/context.rb +184 -0
  72. data/lib/groonga/expression-builder.rb +324 -0
  73. data/lib/groonga/patricia-trie.rb +85 -0
  74. data/lib/groonga/record.rb +311 -0
  75. data/lib/groonga/schema.rb +1191 -0
  76. data/lib/groonga/view-record.rb +56 -0
  77. data/license/GPL +340 -0
  78. data/license/LGPL +504 -0
  79. data/license/RUBY +59 -0
  80. data/misc/grnop2ruby.rb +49 -0
  81. data/pkg-config.rb +333 -0
  82. data/rroonga-build.rb +57 -0
  83. data/test-unit/Rakefile +40 -0
  84. data/test-unit/TODO +5 -0
  85. data/test-unit/bin/testrb +5 -0
  86. data/test-unit/html/classic.html +15 -0
  87. data/test-unit/html/index.html +25 -0
  88. data/test-unit/html/index.html.ja +27 -0
  89. data/test-unit/lib/test/unit.rb +323 -0
  90. data/test-unit/lib/test/unit/assertionfailederror.rb +25 -0
  91. data/test-unit/lib/test/unit/assertions.rb +1230 -0
  92. data/test-unit/lib/test/unit/attribute.rb +125 -0
  93. data/test-unit/lib/test/unit/autorunner.rb +360 -0
  94. data/test-unit/lib/test/unit/collector.rb +36 -0
  95. data/test-unit/lib/test/unit/collector/descendant.rb +23 -0
  96. data/test-unit/lib/test/unit/collector/dir.rb +108 -0
  97. data/test-unit/lib/test/unit/collector/load.rb +144 -0
  98. data/test-unit/lib/test/unit/collector/objectspace.rb +34 -0
  99. data/test-unit/lib/test/unit/color-scheme.rb +102 -0
  100. data/test-unit/lib/test/unit/color.rb +96 -0
  101. data/test-unit/lib/test/unit/diff.rb +724 -0
  102. data/test-unit/lib/test/unit/error.rb +130 -0
  103. data/test-unit/lib/test/unit/exceptionhandler.rb +39 -0
  104. data/test-unit/lib/test/unit/failure.rb +136 -0
  105. data/test-unit/lib/test/unit/fixture.rb +176 -0
  106. data/test-unit/lib/test/unit/notification.rb +129 -0
  107. data/test-unit/lib/test/unit/omission.rb +191 -0
  108. data/test-unit/lib/test/unit/pending.rb +150 -0
  109. data/test-unit/lib/test/unit/priority.rb +180 -0
  110. data/test-unit/lib/test/unit/runner/console.rb +52 -0
  111. data/test-unit/lib/test/unit/runner/emacs.rb +8 -0
  112. data/test-unit/lib/test/unit/runner/tap.rb +8 -0
  113. data/test-unit/lib/test/unit/testcase.rb +476 -0
  114. data/test-unit/lib/test/unit/testresult.rb +89 -0
  115. data/test-unit/lib/test/unit/testsuite.rb +110 -0
  116. data/test-unit/lib/test/unit/ui/console/outputlevel.rb +14 -0
  117. data/test-unit/lib/test/unit/ui/console/testrunner.rb +466 -0
  118. data/test-unit/lib/test/unit/ui/emacs/testrunner.rb +63 -0
  119. data/test-unit/lib/test/unit/ui/tap/testrunner.rb +92 -0
  120. data/test-unit/lib/test/unit/ui/testrunner.rb +28 -0
  121. data/test-unit/lib/test/unit/ui/testrunnermediator.rb +77 -0
  122. data/test-unit/lib/test/unit/ui/testrunnerutilities.rb +41 -0
  123. data/test-unit/lib/test/unit/util/backtracefilter.rb +41 -0
  124. data/test-unit/lib/test/unit/util/method-owner-finder.rb +28 -0
  125. data/test-unit/lib/test/unit/util/observable.rb +90 -0
  126. data/test-unit/lib/test/unit/util/procwrapper.rb +48 -0
  127. data/test-unit/lib/test/unit/version.rb +7 -0
  128. data/test-unit/sample/adder.rb +13 -0
  129. data/test-unit/sample/subtracter.rb +12 -0
  130. data/test-unit/sample/test_adder.rb +20 -0
  131. data/test-unit/sample/test_subtracter.rb +20 -0
  132. data/test-unit/sample/test_user.rb +23 -0
  133. data/test-unit/test/collector/test-descendant.rb +133 -0
  134. data/test-unit/test/collector/test-load.rb +442 -0
  135. data/test-unit/test/collector/test_dir.rb +406 -0
  136. data/test-unit/test/collector/test_objectspace.rb +100 -0
  137. data/test-unit/test/run-test.rb +15 -0
  138. data/test-unit/test/test-attribute.rb +86 -0
  139. data/test-unit/test/test-color-scheme.rb +67 -0
  140. data/test-unit/test/test-color.rb +47 -0
  141. data/test-unit/test/test-diff.rb +518 -0
  142. data/test-unit/test/test-emacs-runner.rb +60 -0
  143. data/test-unit/test/test-fixture.rb +287 -0
  144. data/test-unit/test/test-notification.rb +33 -0
  145. data/test-unit/test/test-omission.rb +81 -0
  146. data/test-unit/test/test-pending.rb +70 -0
  147. data/test-unit/test/test-priority.rb +119 -0
  148. data/test-unit/test/test-testcase.rb +544 -0
  149. data/test-unit/test/test_assertions.rb +1151 -0
  150. data/test-unit/test/test_error.rb +26 -0
  151. data/test-unit/test/test_failure.rb +33 -0
  152. data/test-unit/test/test_testresult.rb +113 -0
  153. data/test-unit/test/test_testsuite.rb +129 -0
  154. data/test-unit/test/testunit-test-util.rb +14 -0
  155. data/test-unit/test/ui/test_testrunmediator.rb +20 -0
  156. data/test-unit/test/util/test-method-owner-finder.rb +38 -0
  157. data/test-unit/test/util/test_backtracefilter.rb +41 -0
  158. data/test-unit/test/util/test_observable.rb +102 -0
  159. data/test-unit/test/util/test_procwrapper.rb +36 -0
  160. data/test/.gitignore +1 -0
  161. data/test/groonga-test-utils.rb +134 -0
  162. data/test/run-test.rb +58 -0
  163. data/test/test-array.rb +90 -0
  164. data/test/test-column.rb +316 -0
  165. data/test/test-context-select.rb +93 -0
  166. data/test/test-context.rb +73 -0
  167. data/test/test-database.rb +113 -0
  168. data/test/test-encoding.rb +33 -0
  169. data/test/test-exception.rb +93 -0
  170. data/test/test-expression-builder.rb +217 -0
  171. data/test/test-expression.rb +134 -0
  172. data/test/test-fix-size-column.rb +65 -0
  173. data/test/test-gqtp.rb +72 -0
  174. data/test/test-hash.rb +305 -0
  175. data/test/test-index-column.rb +81 -0
  176. data/test/test-logger.rb +37 -0
  177. data/test/test-patricia-trie.rb +205 -0
  178. data/test/test-procedure.rb +37 -0
  179. data/test/test-query.rb +22 -0
  180. data/test/test-record.rb +243 -0
  181. data/test/test-remote.rb +54 -0
  182. data/test/test-schema-view.rb +90 -0
  183. data/test/test-schema.rb +459 -0
  184. data/test/test-snippet.rb +130 -0
  185. data/test/test-table-cursor.rb +153 -0
  186. data/test/test-table-offset-and-limit.rb +102 -0
  187. data/test/test-table-select-normalize.rb +53 -0
  188. data/test/test-table-select.rb +150 -0
  189. data/test/test-table.rb +594 -0
  190. data/test/test-type.rb +71 -0
  191. data/test/test-variable-size-column.rb +98 -0
  192. data/test/test-variable.rb +28 -0
  193. data/test/test-vector-column.rb +76 -0
  194. data/test/test-version.rb +31 -0
  195. data/test/test-view.rb +72 -0
  196. data/text/TUTORIAL.ja.rdoc +392 -0
  197. data/text/expression.rdoc +284 -0
  198. metadata +275 -0
@@ -0,0 +1,166 @@
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
+ }
@@ -0,0 +1,38 @@
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
+ }
@@ -0,0 +1,294 @@
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::Context#[]で保存されたレコードを利用することが
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
+ }