groonga 0.9.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
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,52 +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) (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
- }
data/ext/rb-grn-query.c DELETED
@@ -1,260 +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
- /*
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
- }
data/ext/rb-grn-record.c DELETED
@@ -1,40 +0,0 @@
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
- }
data/ext/rb-grn-snippet.c DELETED
@@ -1,328 +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) (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
- rb_grn_snippet = SELF(self);
288
- context = rb_grn_snippet->context;
289
- snippet = rb_grn_snippet->snippet;
290
-
291
- #ifdef HAVE_RUBY_ENCODING_H
292
- rb_string = rb_grn_context_rb_string_encode(context, rb_string);
293
- #endif
294
- string = StringValuePtr(rb_string);
295
- string_length = RSTRING_LEN(rb_string);
296
-
297
- rc = grn_snip_exec(context, snippet, string, string_length,
298
- &n_results, &max_tagged_length);
299
- rb_grn_rc_check(rc, self);
300
-
301
- rb_results = rb_ary_new2(n_results);
302
- result = ALLOCA_N(char, max_tagged_length);
303
- for (i = 0; i < n_results; i++) {
304
- VALUE rb_result;
305
- unsigned result_length;
306
-
307
- rc = grn_snip_get_result(context, snippet, i, result, &result_length);
308
- rb_grn_rc_check(rc, self);
309
- rb_result = rb_grn_context_rb_string_new(context, result, result_length);
310
- rb_ary_push(rb_results, rb_result);
311
- }
312
-
313
- return rb_results;
314
- }
315
-
316
- void
317
- rb_grn_init_snippet (VALUE mGrn)
318
- {
319
- rb_cGrnSnippet = rb_define_class_under(mGrn, "Snippet", rb_cObject);
320
- rb_define_alloc_func(rb_cGrnSnippet, rb_grn_snippet_alloc);
321
-
322
- rb_define_method(rb_cGrnSnippet, "initialize",
323
- rb_grn_snippet_initialize, -1);
324
- rb_define_method(rb_cGrnSnippet, "add_keyword",
325
- rb_grn_snippet_add_keyword, -1);
326
- rb_define_method(rb_cGrnSnippet, "execute",
327
- rb_grn_snippet_execute, 1);
328
- }