rroonga 0.9.2-x86-mingw32

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 (199) 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 +206 -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/rb-grn-accessor.c +52 -0
  17. data/ext/groonga/rb-grn-array-cursor.c +36 -0
  18. data/ext/groonga/rb-grn-array.c +210 -0
  19. data/ext/groonga/rb-grn-column.c +573 -0
  20. data/ext/groonga/rb-grn-context.c +662 -0
  21. data/ext/groonga/rb-grn-database.c +472 -0
  22. data/ext/groonga/rb-grn-encoding-support.c +64 -0
  23. data/ext/groonga/rb-grn-encoding.c +257 -0
  24. data/ext/groonga/rb-grn-exception.c +1110 -0
  25. data/ext/groonga/rb-grn-expression-builder.c +75 -0
  26. data/ext/groonga/rb-grn-expression.c +731 -0
  27. data/ext/groonga/rb-grn-fix-size-column.c +166 -0
  28. data/ext/groonga/rb-grn-hash-cursor.c +38 -0
  29. data/ext/groonga/rb-grn-hash.c +294 -0
  30. data/ext/groonga/rb-grn-index-column.c +488 -0
  31. data/ext/groonga/rb-grn-logger.c +504 -0
  32. data/ext/groonga/rb-grn-object.c +1369 -0
  33. data/ext/groonga/rb-grn-operation.c +198 -0
  34. data/ext/groonga/rb-grn-patricia-trie-cursor.c +39 -0
  35. data/ext/groonga/rb-grn-patricia-trie.c +488 -0
  36. data/ext/groonga/rb-grn-procedure.c +52 -0
  37. data/ext/groonga/rb-grn-query.c +260 -0
  38. data/ext/groonga/rb-grn-record.c +40 -0
  39. data/ext/groonga/rb-grn-snippet.c +334 -0
  40. data/ext/groonga/rb-grn-table-cursor-key-support.c +69 -0
  41. data/ext/groonga/rb-grn-table-cursor.c +247 -0
  42. data/ext/groonga/rb-grn-table-key-support.c +714 -0
  43. data/ext/groonga/rb-grn-table.c +1977 -0
  44. data/ext/groonga/rb-grn-type.c +181 -0
  45. data/ext/groonga/rb-grn-utils.c +769 -0
  46. data/ext/groonga/rb-grn-variable-size-column.c +36 -0
  47. data/ext/groonga/rb-grn-variable.c +108 -0
  48. data/ext/groonga/rb-grn-view-accessor.c +53 -0
  49. data/ext/groonga/rb-grn-view-cursor.c +35 -0
  50. data/ext/groonga/rb-grn-view-record.c +41 -0
  51. data/ext/groonga/rb-grn-view.c +421 -0
  52. data/ext/groonga/rb-grn.h +698 -0
  53. data/ext/groonga/rb-groonga.c +107 -0
  54. data/extconf.rb +130 -0
  55. data/html/bar.svg +153 -0
  56. data/html/developer.html +117 -0
  57. data/html/developer.svg +469 -0
  58. data/html/download.svg +253 -0
  59. data/html/favicon.ico +0 -0
  60. data/html/favicon.xcf +0 -0
  61. data/html/footer.html.erb +28 -0
  62. data/html/head.html.erb +4 -0
  63. data/html/header.html.erb +17 -0
  64. data/html/index.html +147 -0
  65. data/html/install.svg +636 -0
  66. data/html/logo.xcf +0 -0
  67. data/html/ranguba.css +250 -0
  68. data/html/tutorial.svg +559 -0
  69. data/lib/1.8/groonga.so +0 -0
  70. data/lib/1.9/groonga.so +0 -0
  71. data/lib/groonga.rb +90 -0
  72. data/lib/groonga/context.rb +184 -0
  73. data/lib/groonga/expression-builder.rb +324 -0
  74. data/lib/groonga/patricia-trie.rb +85 -0
  75. data/lib/groonga/record.rb +311 -0
  76. data/lib/groonga/schema.rb +1191 -0
  77. data/lib/groonga/view-record.rb +56 -0
  78. data/license/GPL +340 -0
  79. data/license/LGPL +504 -0
  80. data/license/RUBY +59 -0
  81. data/misc/grnop2ruby.rb +49 -0
  82. data/pkg-config.rb +333 -0
  83. data/rroonga-build.rb +57 -0
  84. data/test-unit/Rakefile +40 -0
  85. data/test-unit/TODO +5 -0
  86. data/test-unit/bin/testrb +5 -0
  87. data/test-unit/html/classic.html +15 -0
  88. data/test-unit/html/index.html +25 -0
  89. data/test-unit/html/index.html.ja +27 -0
  90. data/test-unit/lib/test/unit.rb +323 -0
  91. data/test-unit/lib/test/unit/assertionfailederror.rb +25 -0
  92. data/test-unit/lib/test/unit/assertions.rb +1230 -0
  93. data/test-unit/lib/test/unit/attribute.rb +125 -0
  94. data/test-unit/lib/test/unit/autorunner.rb +360 -0
  95. data/test-unit/lib/test/unit/collector.rb +36 -0
  96. data/test-unit/lib/test/unit/collector/descendant.rb +23 -0
  97. data/test-unit/lib/test/unit/collector/dir.rb +108 -0
  98. data/test-unit/lib/test/unit/collector/load.rb +144 -0
  99. data/test-unit/lib/test/unit/collector/objectspace.rb +34 -0
  100. data/test-unit/lib/test/unit/color-scheme.rb +102 -0
  101. data/test-unit/lib/test/unit/color.rb +96 -0
  102. data/test-unit/lib/test/unit/diff.rb +724 -0
  103. data/test-unit/lib/test/unit/error.rb +130 -0
  104. data/test-unit/lib/test/unit/exceptionhandler.rb +39 -0
  105. data/test-unit/lib/test/unit/failure.rb +136 -0
  106. data/test-unit/lib/test/unit/fixture.rb +176 -0
  107. data/test-unit/lib/test/unit/notification.rb +129 -0
  108. data/test-unit/lib/test/unit/omission.rb +191 -0
  109. data/test-unit/lib/test/unit/pending.rb +150 -0
  110. data/test-unit/lib/test/unit/priority.rb +180 -0
  111. data/test-unit/lib/test/unit/runner/console.rb +52 -0
  112. data/test-unit/lib/test/unit/runner/emacs.rb +8 -0
  113. data/test-unit/lib/test/unit/runner/tap.rb +8 -0
  114. data/test-unit/lib/test/unit/testcase.rb +476 -0
  115. data/test-unit/lib/test/unit/testresult.rb +89 -0
  116. data/test-unit/lib/test/unit/testsuite.rb +110 -0
  117. data/test-unit/lib/test/unit/ui/console/outputlevel.rb +14 -0
  118. data/test-unit/lib/test/unit/ui/console/testrunner.rb +466 -0
  119. data/test-unit/lib/test/unit/ui/emacs/testrunner.rb +63 -0
  120. data/test-unit/lib/test/unit/ui/tap/testrunner.rb +92 -0
  121. data/test-unit/lib/test/unit/ui/testrunner.rb +28 -0
  122. data/test-unit/lib/test/unit/ui/testrunnermediator.rb +77 -0
  123. data/test-unit/lib/test/unit/ui/testrunnerutilities.rb +41 -0
  124. data/test-unit/lib/test/unit/util/backtracefilter.rb +41 -0
  125. data/test-unit/lib/test/unit/util/method-owner-finder.rb +28 -0
  126. data/test-unit/lib/test/unit/util/observable.rb +90 -0
  127. data/test-unit/lib/test/unit/util/procwrapper.rb +48 -0
  128. data/test-unit/lib/test/unit/version.rb +7 -0
  129. data/test-unit/sample/adder.rb +13 -0
  130. data/test-unit/sample/subtracter.rb +12 -0
  131. data/test-unit/sample/test_adder.rb +20 -0
  132. data/test-unit/sample/test_subtracter.rb +20 -0
  133. data/test-unit/sample/test_user.rb +23 -0
  134. data/test-unit/test/collector/test-descendant.rb +133 -0
  135. data/test-unit/test/collector/test-load.rb +442 -0
  136. data/test-unit/test/collector/test_dir.rb +406 -0
  137. data/test-unit/test/collector/test_objectspace.rb +100 -0
  138. data/test-unit/test/run-test.rb +15 -0
  139. data/test-unit/test/test-attribute.rb +86 -0
  140. data/test-unit/test/test-color-scheme.rb +67 -0
  141. data/test-unit/test/test-color.rb +47 -0
  142. data/test-unit/test/test-diff.rb +518 -0
  143. data/test-unit/test/test-emacs-runner.rb +60 -0
  144. data/test-unit/test/test-fixture.rb +287 -0
  145. data/test-unit/test/test-notification.rb +33 -0
  146. data/test-unit/test/test-omission.rb +81 -0
  147. data/test-unit/test/test-pending.rb +70 -0
  148. data/test-unit/test/test-priority.rb +119 -0
  149. data/test-unit/test/test-testcase.rb +544 -0
  150. data/test-unit/test/test_assertions.rb +1151 -0
  151. data/test-unit/test/test_error.rb +26 -0
  152. data/test-unit/test/test_failure.rb +33 -0
  153. data/test-unit/test/test_testresult.rb +113 -0
  154. data/test-unit/test/test_testsuite.rb +129 -0
  155. data/test-unit/test/testunit-test-util.rb +14 -0
  156. data/test-unit/test/ui/test_testrunmediator.rb +20 -0
  157. data/test-unit/test/util/test-method-owner-finder.rb +38 -0
  158. data/test-unit/test/util/test_backtracefilter.rb +41 -0
  159. data/test-unit/test/util/test_observable.rb +102 -0
  160. data/test-unit/test/util/test_procwrapper.rb +36 -0
  161. data/test/.gitignore +1 -0
  162. data/test/groonga-test-utils.rb +134 -0
  163. data/test/run-test.rb +58 -0
  164. data/test/test-array.rb +90 -0
  165. data/test/test-column.rb +316 -0
  166. data/test/test-context-select.rb +93 -0
  167. data/test/test-context.rb +73 -0
  168. data/test/test-database.rb +113 -0
  169. data/test/test-encoding.rb +33 -0
  170. data/test/test-exception.rb +93 -0
  171. data/test/test-expression-builder.rb +217 -0
  172. data/test/test-expression.rb +134 -0
  173. data/test/test-fix-size-column.rb +65 -0
  174. data/test/test-gqtp.rb +72 -0
  175. data/test/test-hash.rb +305 -0
  176. data/test/test-index-column.rb +81 -0
  177. data/test/test-logger.rb +37 -0
  178. data/test/test-patricia-trie.rb +205 -0
  179. data/test/test-procedure.rb +37 -0
  180. data/test/test-query.rb +22 -0
  181. data/test/test-record.rb +243 -0
  182. data/test/test-remote.rb +54 -0
  183. data/test/test-schema-view.rb +90 -0
  184. data/test/test-schema.rb +459 -0
  185. data/test/test-snippet.rb +130 -0
  186. data/test/test-table-cursor.rb +153 -0
  187. data/test/test-table-offset-and-limit.rb +102 -0
  188. data/test/test-table-select-normalize.rb +53 -0
  189. data/test/test-table-select.rb +150 -0
  190. data/test/test-table.rb +594 -0
  191. data/test/test-type.rb +71 -0
  192. data/test/test-variable-size-column.rb +98 -0
  193. data/test/test-variable.rb +28 -0
  194. data/test/test-vector-column.rb +76 -0
  195. data/test/test-version.rb +31 -0
  196. data/test/test-view.rb +72 -0
  197. data/text/TUTORIAL.ja.rdoc +392 -0
  198. data/text/expression.rdoc +284 -0
  199. metadata +276 -0
@@ -0,0 +1,52 @@
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) (RVAL2GRNPROCEDURE(object))
22
+
23
+ VALUE rb_cGrnProcedure;
24
+
25
+ grn_obj *
26
+ rb_grn_procedure_from_ruby_object (VALUE object)
27
+ {
28
+ if (!RVAL2CBOOL(rb_obj_is_kind_of(object, rb_cGrnProcedure))) {
29
+ rb_raise(rb_eTypeError, "not a groonga procedure");
30
+ }
31
+
32
+ return RVAL2GRNOBJECT(object, NULL);
33
+ }
34
+
35
+ VALUE
36
+ rb_grn_procedure_to_ruby_object (grn_ctx *context, grn_obj *procedure,
37
+ rb_grn_boolean owner)
38
+ {
39
+ return GRNOBJECT2RVAL(rb_cGrnProcedure, context, procedure, owner);
40
+ }
41
+
42
+ void
43
+ rb_grn_init_procedure (VALUE mGrn)
44
+ {
45
+ rb_cGrnProcedure = rb_define_class_under(mGrn, "Procedure", rb_cGrnObject);
46
+
47
+ rb_define_const(rb_cGrnProcedure, "DELIMIT", INT2NUM(GRN_DB_DELIMIT));
48
+ rb_define_const(rb_cGrnProcedure, "UNIGRAM", INT2NUM(GRN_DB_UNIGRAM));
49
+ rb_define_const(rb_cGrnProcedure, "BIGRAM", INT2NUM(GRN_DB_BIGRAM));
50
+ rb_define_const(rb_cGrnProcedure, "TRIGRAM", INT2NUM(GRN_DB_TRIGRAM));
51
+ rb_define_const(rb_cGrnProcedure, "MECAB", INT2NUM(GRN_DB_MECAB));
52
+ }
@@ -0,0 +1,260 @@
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
+ /*
22
+ * Document-class: Groonga::Query
23
+ *
24
+ * インデックスを用いた検索用のクエリのためのオブジェクト。
25
+ * Groonga::IndexColumn#searchに渡すことができる。(このクラ
26
+ * スは非推奨で、代わりにGroonga::Expressionを使用すること)
27
+ *
28
+ */
29
+
30
+ #define SELF(object) (rb_rb_grn_query_from_ruby_object(object))
31
+
32
+ typedef struct _RbGrnQuery RbGrnQuery;
33
+ struct _RbGrnQuery
34
+ {
35
+ grn_ctx *context;
36
+ grn_query *query;
37
+ rb_grn_boolean owner;
38
+ };
39
+
40
+ VALUE rb_cGrnQuery;
41
+
42
+ static RbGrnQuery *
43
+ rb_rb_grn_query_from_ruby_object (VALUE object)
44
+ {
45
+ RbGrnQuery *rb_grn_query;
46
+
47
+ if (!RVAL2CBOOL(rb_obj_is_kind_of(object, rb_cGrnQuery))) {
48
+ rb_raise(rb_eTypeError, "not a groonga query");
49
+ }
50
+
51
+ Data_Get_Struct(object, RbGrnQuery, rb_grn_query);
52
+ if (!rb_grn_query)
53
+ rb_raise(rb_eGrnError, "groonga query is NULL");
54
+
55
+ return rb_grn_query;
56
+ }
57
+
58
+ grn_query *
59
+ rb_grn_query_from_ruby_object (VALUE object)
60
+ {
61
+ if (NIL_P(object))
62
+ return NULL;
63
+
64
+ return SELF(object)->query;
65
+ }
66
+
67
+ static void
68
+ rb_rb_grn_query_free (void *object)
69
+ {
70
+ RbGrnQuery *rb_grn_query = object;
71
+
72
+ if (rb_grn_query->owner && rb_grn_query->context && rb_grn_query->query)
73
+ grn_query_close(rb_grn_query->context, rb_grn_query->query);
74
+
75
+ xfree(object);
76
+ }
77
+
78
+ VALUE
79
+ rb_grn_query_to_ruby_object (grn_ctx *context, grn_query *query)
80
+ {
81
+ RbGrnQuery *rb_grn_query;
82
+
83
+ if (!query)
84
+ return Qnil;
85
+
86
+ rb_grn_query = ALLOC(RbGrnQuery);
87
+ rb_grn_query->context = context;
88
+ rb_grn_query->query = query;
89
+ rb_grn_query->owner = RB_GRN_FALSE;
90
+
91
+ return Data_Wrap_Struct(rb_cGrnQuery, NULL,
92
+ rb_rb_grn_query_free, rb_grn_query);
93
+ }
94
+
95
+ static VALUE
96
+ rb_grn_query_alloc (VALUE klass)
97
+ {
98
+ return Data_Wrap_Struct(klass, NULL, rb_rb_grn_query_free, NULL);
99
+ }
100
+
101
+ grn_operator
102
+ rb_grn_operator_from_ruby_object (VALUE rb_operator)
103
+ {
104
+ grn_operator operator = GRN_OP_OR;
105
+
106
+ if (NIL_P(rb_operator) ||
107
+ rb_grn_equal_option(rb_operator, "or") ||
108
+ rb_grn_equal_option(rb_operator, "||")) {
109
+ operator = GRN_OP_OR;
110
+ } else if (rb_grn_equal_option(rb_operator, "and") ||
111
+ rb_grn_equal_option(rb_operator, "+") ||
112
+ rb_grn_equal_option(rb_operator, "&&")) {
113
+ operator = GRN_OP_AND;
114
+ } else if (rb_grn_equal_option(rb_operator, "but") ||
115
+ rb_grn_equal_option(rb_operator, "not") ||
116
+ rb_grn_equal_option(rb_operator, "-")) {
117
+ operator = GRN_OP_BUT;
118
+ } else if (rb_grn_equal_option(rb_operator, "adjust") ||
119
+ rb_grn_equal_option(rb_operator, ">")) {
120
+ operator = GRN_OP_ADJUST;
121
+ } else {
122
+ rb_raise(rb_eArgError,
123
+ "operator should be one of "
124
+ "[:or, :||, :and, :+, :&&, :but, :not, :-, :adjust, :>]: <%s>",
125
+ rb_grn_inspect(rb_operator));
126
+ }
127
+
128
+ return operator;
129
+ }
130
+
131
+ /*
132
+ * call-seq:
133
+ * query.new(string, options={})
134
+ *
135
+ * _string_をパースした上で、クエリを作成する。作成されたオ
136
+ * ブジェクトはGroonga::IndexColumn#searchに渡すことで使用す
137
+ * ることができる。
138
+ *
139
+ * _options_に指定可能な値は以下の通り。
140
+ *
141
+ * [+:context+]
142
+ * クエリが利用するGroonga::Context。省略すると
143
+ * Groonga::Context.defaultを用いる。
144
+ *
145
+ * [+:default_operator+]
146
+ * 演算子の既定値(演算子を省略した場合にどの演算を行うか)
147
+ * を指定する。
148
+ *
149
+ * [Groonga::Operation::OR]
150
+ * [Groonga::Operation::AND]
151
+ * [Groonga::Operation::BUT]
152
+ * [Groonga::Operation::ADJUST]
153
+ * (FIXME: 挙動の違いを検証する必要性あり?
154
+ * Groonga::Expressionとの関連性は?)
155
+ *
156
+ * [+:max_expressions+]
157
+ * 検索クエリに指定する式の最大値を指定する。
158
+ */
159
+ static VALUE
160
+ rb_grn_query_initialize (int argc, VALUE *argv, VALUE self)
161
+ {
162
+ RbGrnQuery *rb_grn_query;
163
+ grn_ctx *context = NULL;
164
+ grn_query *query;
165
+ char *query_string;
166
+ unsigned int query_string_length;
167
+ grn_operator default_operator;
168
+ int max_expressions = RB_GRN_QUERY_DEFAULT_MAX_EXPRESSIONS;
169
+ VALUE rb_query_string, options, rb_context, rb_default_operator;
170
+ VALUE rb_max_expressions;
171
+
172
+ rb_scan_args(argc, argv, "11", &rb_query_string, &options);
173
+
174
+ query_string = StringValuePtr(rb_query_string);
175
+ query_string_length = RSTRING_LEN(rb_query_string);
176
+
177
+ rb_grn_scan_options(options,
178
+ "context", &rb_context,
179
+ "default_operator", &rb_default_operator,
180
+ "max_expressions", &rb_max_expressions,
181
+ NULL);
182
+
183
+ context = rb_grn_context_ensure(&rb_context);
184
+
185
+ default_operator = RVAL2GRNOPERATOR(rb_default_operator);
186
+
187
+ if (!NIL_P(rb_max_expressions))
188
+ max_expressions = NUM2INT(rb_max_expressions);
189
+
190
+ query = grn_query_open(context, query_string, query_string_length,
191
+ default_operator, max_expressions);
192
+ rb_grn_context_check(context, rb_ary_new4(argc, argv));
193
+
194
+ rb_grn_query = ALLOC(RbGrnQuery);
195
+ DATA_PTR(self) = rb_grn_query;
196
+ rb_grn_query->context = context;
197
+ rb_grn_query->query = query;
198
+ rb_grn_query->owner = RB_GRN_TRUE;
199
+
200
+ rb_iv_set(self, "@context", rb_context);
201
+
202
+ return Qnil;
203
+ }
204
+
205
+ /*
206
+ * call-seq:
207
+ * query.close
208
+ *
209
+ * _query_が使用しているリソースを開放する。これ以降_query_を
210
+ * 使うことはできない。
211
+ */
212
+ static VALUE
213
+ rb_grn_query_close (VALUE self)
214
+ {
215
+ RbGrnQuery *rb_grn_query;
216
+
217
+ rb_grn_query = SELF(self);
218
+ if (rb_grn_query->context && rb_grn_query->query) {
219
+ grn_rc rc;
220
+
221
+ rc = grn_query_close(rb_grn_query->context, rb_grn_query->query);
222
+ rb_grn_query->context = NULL;
223
+ rb_grn_query->query = NULL;
224
+ rb_grn_rc_check(rc, self);
225
+ }
226
+ return Qnil;
227
+ }
228
+
229
+ /*
230
+ * call-seq:
231
+ * query.closed? -> true/false
232
+ *
233
+ * _query_が開放済みの場合は+true+を返し、そうでない場合は
234
+ * +false+を返す。
235
+ */
236
+ static VALUE
237
+ rb_grn_query_closed_p (VALUE self)
238
+ {
239
+ RbGrnQuery *rb_grn_query;
240
+
241
+ rb_grn_query = SELF(self);
242
+ if (rb_grn_query->context && rb_grn_query->query)
243
+ return Qfalse;
244
+ else
245
+ return Qtrue;
246
+ }
247
+
248
+ void
249
+ rb_grn_init_query (VALUE mGrn)
250
+ {
251
+ rb_cGrnQuery = rb_define_class_under(mGrn, "Query", rb_cObject);
252
+ rb_define_alloc_func(rb_cGrnQuery, rb_grn_query_alloc);
253
+
254
+ rb_define_method(rb_cGrnQuery, "initialize",
255
+ rb_grn_query_initialize, -1);
256
+ rb_define_method(rb_cGrnQuery, "close",
257
+ rb_grn_query_close, 0);
258
+ rb_define_method(rb_cGrnQuery, "closed?",
259
+ rb_grn_query_closed_p, 0);
260
+ }
@@ -0,0 +1,40 @@
1
+ /* -*- c-file-style: "ruby" -*- */
2
+ /*
3
+ Copyright (C) 2009-2010 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_cGrnRecord;
22
+
23
+ VALUE
24
+ rb_grn_record_new (VALUE table, grn_id id, VALUE values)
25
+ {
26
+ return rb_grn_record_new_raw(table, UINT2NUM(id), values);
27
+ }
28
+
29
+ VALUE
30
+ rb_grn_record_new_raw (VALUE table, VALUE rb_id, VALUE values)
31
+ {
32
+ return rb_funcall(rb_cGrnRecord, rb_intern("new"), 3,
33
+ table, rb_id, values);
34
+ }
35
+
36
+ void
37
+ rb_grn_init_record (VALUE mGrn)
38
+ {
39
+ rb_cGrnRecord = rb_const_get(mGrn, rb_intern("Record"));
40
+ }
@@ -0,0 +1,334 @@
1
+ /* -*- c-file-style: "ruby" -*- */
2
+ /*
3
+ Copyright (C) 2009-2010 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) (rb_rb_grn_snippet_from_ruby_object(object))
22
+
23
+ typedef struct _RbGrnSnippet RbGrnSnippet;
24
+ struct _RbGrnSnippet
25
+ {
26
+ grn_ctx *context;
27
+ grn_snip *snippet;
28
+ rb_grn_boolean owner;
29
+ };
30
+
31
+ VALUE rb_cGrnSnippet;
32
+
33
+ /*
34
+ * Document-class: Groonga::Snippet
35
+ *
36
+ * スニペット(検索語周辺のテキスト)を生成するためのオブジェクト。
37
+ */
38
+
39
+ static RbGrnSnippet *
40
+ rb_rb_grn_snippet_from_ruby_object (VALUE object)
41
+ {
42
+ RbGrnSnippet *rb_grn_snippet;
43
+
44
+ if (!RVAL2CBOOL(rb_obj_is_kind_of(object, rb_cGrnSnippet))) {
45
+ rb_raise(rb_eTypeError, "not a groonga snippet");
46
+ }
47
+
48
+ Data_Get_Struct(object, RbGrnSnippet, rb_grn_snippet);
49
+ if (!rb_grn_snippet)
50
+ rb_raise(rb_eGrnError, "groonga snippet is NULL");
51
+
52
+ return rb_grn_snippet;
53
+ }
54
+
55
+ grn_snip *
56
+ rb_grn_snippet_from_ruby_object (VALUE object)
57
+ {
58
+ if (NIL_P(object))
59
+ return NULL;
60
+
61
+ return SELF(object)->snippet;
62
+ }
63
+
64
+ static void
65
+ rb_rb_grn_snippet_free (void *object)
66
+ {
67
+ RbGrnSnippet *rb_grn_snippet = object;
68
+
69
+ if (rb_grn_snippet->owner &&
70
+ rb_grn_snippet->context && rb_grn_snippet->snippet)
71
+ grn_snip_close(rb_grn_snippet->context,
72
+ rb_grn_snippet->snippet);
73
+
74
+ xfree(object);
75
+ }
76
+
77
+ VALUE
78
+ rb_grn_snippet_to_ruby_object (grn_ctx *context, grn_snip *snippet,
79
+ rb_grn_boolean owner)
80
+ {
81
+ RbGrnSnippet *rb_grn_snippet;
82
+
83
+ if (!snippet)
84
+ return Qnil;
85
+
86
+ rb_grn_snippet = ALLOC(RbGrnSnippet);
87
+ rb_grn_snippet->context = context;
88
+ rb_grn_snippet->snippet = snippet;
89
+ rb_grn_snippet->owner = owner;
90
+
91
+ return Data_Wrap_Struct(rb_cGrnSnippet, NULL,
92
+ rb_rb_grn_snippet_free, rb_grn_snippet);
93
+ }
94
+
95
+ static VALUE
96
+ rb_grn_snippet_alloc (VALUE klass)
97
+ {
98
+ return Data_Wrap_Struct(klass, NULL, rb_rb_grn_snippet_free, NULL);
99
+ }
100
+
101
+ /*
102
+ * call-seq:
103
+ * Groonga::Snippet.new(options={})
104
+ *
105
+ * スニペットを作成する。_options_に指定可能な値は以下の通
106
+ * り。
107
+ *
108
+ * [+:context+]
109
+ * スキーマ作成時に使用するGroonga::Contextを指定する。
110
+ * 省略した場合はGroonga::Context.defaultを使用する。
111
+ *
112
+ * [+:normalize+]
113
+ * キーワード文字列・スニペット元の文字列を正規化するかど
114
+ * うか。省略した場合は+false+で正規化しない。
115
+ *
116
+ * [+:skip_leading_spaces+]
117
+ * 先頭の空白を無視するかどうか。省略した場合は+false+で無
118
+ * 視しない。
119
+ *
120
+ * [+:width+]
121
+ * スニペット文字列の長さ。省略した場合は100文字。
122
+ *
123
+ * [+:max_results+]
124
+ * 生成するスニペットの最大数。省略した場合は3。
125
+ *
126
+ * [+:html_escape+]
127
+ * スニペット内の+<+, +>+, +&+, +"+をHTMLエスケープするか
128
+ * どうか。省略した場合は+false+で、HTMLエスケープしない。
129
+ *
130
+ * [+:default_open_tag+]
131
+ * デフォルトの開始タグ。省略した場合は""(空文字列)
132
+ *
133
+ * [+:default_close_tag+]
134
+ * デフォルトの終了タグ。省略した場合は""(空文字列)
135
+ */
136
+ static VALUE
137
+ rb_grn_snippet_initialize (int argc, VALUE *argv, VALUE self)
138
+ {
139
+ RbGrnSnippet *rb_grn_snippet;
140
+ grn_ctx *context = NULL;
141
+ grn_snip *snippet = NULL;
142
+ VALUE options;
143
+ VALUE rb_context, rb_normalize, rb_skip_leading_spaces;
144
+ VALUE rb_width, rb_max_results, rb_default_open_tag, rb_default_close_tag;
145
+ VALUE rb_html_escape;
146
+ int flags = GRN_SNIP_COPY_TAG;
147
+ unsigned int width = 100;
148
+ unsigned int max_results = 3;
149
+ char *default_open_tag = NULL;
150
+ unsigned int default_open_tag_length = 0;
151
+ char *default_close_tag = NULL;
152
+ unsigned int default_close_tag_length = 0;
153
+ grn_snip_mapping *mapping = NULL;
154
+
155
+ rb_scan_args(argc, argv, "01", &options);
156
+
157
+ rb_grn_scan_options(options,
158
+ "context", &rb_context,
159
+ "normalize", &rb_normalize,
160
+ "skip_leading_spaces", &rb_skip_leading_spaces,
161
+ "width", &rb_width,
162
+ "max_results", &rb_max_results,
163
+ "default_open_tag", &rb_default_open_tag,
164
+ "default_close_tag", &rb_default_close_tag,
165
+ "html_escape", &rb_html_escape,
166
+ NULL);
167
+
168
+ context = rb_grn_context_ensure(&rb_context);
169
+
170
+ if (RVAL2CBOOL(rb_normalize))
171
+ flags |= GRN_SNIP_NORMALIZE;
172
+ if (RVAL2CBOOL(rb_skip_leading_spaces))
173
+ flags |= GRN_SNIP_SKIP_LEADING_SPACES;
174
+
175
+ if (!NIL_P(rb_width))
176
+ width = NUM2UINT(rb_width);
177
+
178
+ if (!NIL_P(rb_max_results))
179
+ max_results = NUM2UINT(rb_max_results);
180
+
181
+ if (!NIL_P(rb_default_open_tag)) {
182
+ default_open_tag = StringValuePtr(rb_default_open_tag);
183
+ default_open_tag_length = RSTRING_LEN(rb_default_open_tag);
184
+ }
185
+
186
+ if (!NIL_P(rb_default_close_tag)) {
187
+ default_close_tag = StringValuePtr(rb_default_close_tag);
188
+ default_close_tag_length = RSTRING_LEN(rb_default_close_tag);
189
+ }
190
+
191
+ if (RVAL2CBOOL(rb_html_escape))
192
+ mapping = (grn_snip_mapping *)-1;
193
+
194
+ snippet = grn_snip_open(context, flags, width, max_results,
195
+ default_open_tag, default_open_tag_length,
196
+ default_close_tag, default_close_tag_length,
197
+ mapping);
198
+ rb_grn_context_check(context, rb_ary_new4(argc, argv));
199
+
200
+ rb_grn_snippet = ALLOC(RbGrnSnippet);
201
+ DATA_PTR(self) = rb_grn_snippet;
202
+ rb_grn_snippet->context = context;
203
+ rb_grn_snippet->snippet = snippet;
204
+ rb_grn_snippet->owner = RB_GRN_TRUE;
205
+
206
+ rb_iv_set(self, "@context", rb_context);
207
+
208
+ return Qnil;
209
+ }
210
+
211
+ /*
212
+ * call-seq:
213
+ * snippet.add_keyword(keyword, options={})
214
+ *
215
+ * _keyword_を追加する。_options_に指定可能な値は以下の通
216
+ * り。
217
+ *
218
+ * [+:open_tag+]
219
+ * 開始タグ。省略した場合はGroonga::Snippet.newで指定し
220
+ * た+:default_open_tag+。
221
+ *
222
+ * [+:close_tag+]
223
+ * 終了タグ。省略した場合はGroonga::Snippet.newで指定し
224
+ * た+:default_close_tag+。
225
+ */
226
+ static VALUE
227
+ rb_grn_snippet_add_keyword (int argc, VALUE *argv, VALUE self)
228
+ {
229
+ RbGrnSnippet *rb_grn_snippet;
230
+ grn_rc rc;
231
+ VALUE rb_keyword, options;
232
+ VALUE rb_open_tag, rb_close_tag;
233
+ char *keyword, *open_tag = NULL, *close_tag = NULL;
234
+ unsigned int keyword_length, open_tag_length = 0, close_tag_length = 0;
235
+
236
+ rb_scan_args(argc, argv, "11", &rb_keyword, &options);
237
+
238
+ rb_grn_snippet = SELF(self);
239
+
240
+ keyword = StringValuePtr(rb_keyword);
241
+ keyword_length = RSTRING_LEN(rb_keyword);
242
+
243
+ rb_grn_scan_options(options,
244
+ "open_tag", &rb_open_tag,
245
+ "close_tag", &rb_close_tag,
246
+ NULL);
247
+
248
+ if (!NIL_P(rb_open_tag)) {
249
+ open_tag = StringValuePtr(rb_open_tag);
250
+ open_tag_length = RSTRING_LEN(rb_open_tag);
251
+ }
252
+
253
+ if (!NIL_P(rb_close_tag)) {
254
+ close_tag = StringValuePtr(rb_close_tag);
255
+ close_tag_length = RSTRING_LEN(rb_close_tag);
256
+ }
257
+
258
+ rc = grn_snip_add_cond(rb_grn_snippet->context,
259
+ rb_grn_snippet->snippet,
260
+ keyword, keyword_length,
261
+ open_tag, open_tag_length,
262
+ close_tag, close_tag_length);
263
+ rb_grn_rc_check(rc, self);
264
+
265
+ return Qnil;
266
+ }
267
+
268
+ /*
269
+ * call-seq:
270
+ * snippet.execute(string) -> スニペットの配列
271
+ *
272
+ * _string_を走査し、スニペットを作成する。
273
+ */
274
+ static VALUE
275
+ rb_grn_snippet_execute (VALUE self, VALUE rb_string)
276
+ {
277
+ RbGrnSnippet *rb_grn_snippet;
278
+ grn_rc rc;
279
+ grn_ctx *context;
280
+ grn_snip *snippet;
281
+ char *string;
282
+ unsigned int string_length;
283
+ unsigned int i, n_results, max_tagged_length;
284
+ VALUE rb_results;
285
+ char *result;
286
+
287
+ if (TYPE(rb_string) != T_STRING) {
288
+ rb_raise(rb_eGrnInvalidArgument,
289
+ "snippet text must be String: <%s>",
290
+ rb_grn_inspect(rb_string));
291
+ }
292
+
293
+ rb_grn_snippet = SELF(self);
294
+ context = rb_grn_snippet->context;
295
+ snippet = rb_grn_snippet->snippet;
296
+
297
+ #ifdef HAVE_RUBY_ENCODING_H
298
+ rb_string = rb_grn_context_rb_string_encode(context, rb_string);
299
+ #endif
300
+ string = StringValuePtr(rb_string);
301
+ string_length = RSTRING_LEN(rb_string);
302
+
303
+ rc = grn_snip_exec(context, snippet, string, string_length,
304
+ &n_results, &max_tagged_length);
305
+ rb_grn_rc_check(rc, self);
306
+
307
+ rb_results = rb_ary_new2(n_results);
308
+ result = ALLOCA_N(char, max_tagged_length);
309
+ for (i = 0; i < n_results; i++) {
310
+ VALUE rb_result;
311
+ unsigned result_length;
312
+
313
+ rc = grn_snip_get_result(context, snippet, i, result, &result_length);
314
+ rb_grn_rc_check(rc, self);
315
+ rb_result = rb_grn_context_rb_string_new(context, result, result_length);
316
+ rb_ary_push(rb_results, rb_result);
317
+ }
318
+
319
+ return rb_results;
320
+ }
321
+
322
+ void
323
+ rb_grn_init_snippet (VALUE mGrn)
324
+ {
325
+ rb_cGrnSnippet = rb_define_class_under(mGrn, "Snippet", rb_cObject);
326
+ rb_define_alloc_func(rb_cGrnSnippet, rb_grn_snippet_alloc);
327
+
328
+ rb_define_method(rb_cGrnSnippet, "initialize",
329
+ rb_grn_snippet_initialize, -1);
330
+ rb_define_method(rb_cGrnSnippet, "add_keyword",
331
+ rb_grn_snippet_add_keyword, -1);
332
+ rb_define_method(rb_cGrnSnippet, "execute",
333
+ rb_grn_snippet_execute, 1);
334
+ }