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,36 @@
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) ((RbGrnVariableSizeColumn *)DATA_PTR(object))
22
+
23
+ VALUE rb_cGrnVariableSizeColumn;
24
+
25
+ /*
26
+ * Document-class: Groonga::VariableSizeColumn < Groonga::Column
27
+ *
28
+ * 可変長データ用のカラム。
29
+ */
30
+
31
+ void
32
+ rb_grn_init_variable_size_column (VALUE mGrn)
33
+ {
34
+ rb_cGrnVariableSizeColumn =
35
+ rb_define_class_under(mGrn, "VariableSizeColumn", rb_cGrnColumn);
36
+ }
@@ -0,0 +1,108 @@
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) ((RbGrnVariable *)DATA_PTR(object))
22
+
23
+ VALUE rb_cGrnVariable;
24
+
25
+ /*
26
+ * Document-class: Groonga::Variable < Groonga::Object
27
+ *
28
+ * Groonga::Expressionで使われる変数。
29
+ */
30
+
31
+ grn_obj *
32
+ rb_grn_variable_from_ruby_object (VALUE variable, grn_ctx **context)
33
+ {
34
+ return rb_grn_object_from_ruby_object(variable, context);
35
+ }
36
+
37
+ VALUE
38
+ rb_grn_variable_to_ruby_object (grn_ctx *context, grn_obj *variable)
39
+ {
40
+ return rb_grn_object_to_ruby_object(rb_cGrnVariable, context, variable,
41
+ RB_GRN_TRUE);
42
+ }
43
+
44
+ void
45
+ rb_grn_variable_deconstruct (RbGrnVariable *rb_grn_variable,
46
+ grn_obj **variable,
47
+ grn_ctx **context,
48
+ grn_id *domain_id,
49
+ grn_obj **domain,
50
+ grn_id *range_id,
51
+ grn_obj **range)
52
+ {
53
+ RbGrnObject *rb_grn_object;
54
+
55
+ rb_grn_object = RB_GRN_OBJECT(rb_grn_variable);
56
+ rb_grn_object_deconstruct(rb_grn_object, variable, context,
57
+ domain_id, domain,
58
+ range_id, range);
59
+ }
60
+
61
+ /*
62
+ * call-seq:
63
+ * variable.value -> Groonga::Object
64
+ *
65
+ * 変数の値を返す。
66
+ */
67
+ static VALUE
68
+ rb_grn_variable_get_value (VALUE self)
69
+ {
70
+ grn_ctx *context = NULL;
71
+ grn_obj *variable;
72
+
73
+ rb_grn_variable_deconstruct(SELF(self), &variable, &context,
74
+ NULL, NULL,
75
+ NULL, NULL);
76
+
77
+ return GRNOBJ2RVAL(Qnil, context, variable, self);
78
+ }
79
+
80
+ /*
81
+ * call-seq:
82
+ * variable.value=(value)
83
+ *
84
+ * 変数の値を_value_に設定する。
85
+ */
86
+ static VALUE
87
+ rb_grn_variable_set_value (VALUE self, VALUE value)
88
+ {
89
+ grn_ctx *context = NULL;
90
+ grn_obj *variable;
91
+
92
+ rb_grn_variable_deconstruct(SELF(self), &variable, &context,
93
+ NULL, NULL,
94
+ NULL, NULL);
95
+ RVAL2GRNOBJ(value, context, &variable);
96
+ return Qnil;
97
+ }
98
+
99
+ void
100
+ rb_grn_init_variable (VALUE mGrn)
101
+ {
102
+ rb_cGrnVariable = rb_define_class_under(mGrn, "Variable", rb_cGrnObject);
103
+
104
+ rb_define_method(rb_cGrnVariable, "value",
105
+ rb_grn_variable_get_value, 0);
106
+ rb_define_method(rb_cGrnVariable, "value=",
107
+ rb_grn_variable_set_value, 1);
108
+ }
@@ -0,0 +1,53 @@
1
+ /* -*- c-file-style: "ruby" -*- */
2
+ /*
3
+ Copyright (C) 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) (RVAL2GRNVIEWACCESSOR(object))
22
+
23
+ VALUE rb_cGrnViewAccessor;
24
+
25
+ grn_obj *
26
+ rb_grn_view_accessor_from_ruby_object (VALUE object)
27
+ {
28
+ if (!RVAL2CBOOL(rb_obj_is_kind_of(object, rb_cGrnViewAccessor))) {
29
+ rb_raise(rb_eTypeError, "not a groonga accessor view");
30
+ }
31
+
32
+ return RVAL2GRNOBJECT(object, NULL);
33
+ }
34
+
35
+ VALUE
36
+ rb_grn_view_accessor_to_ruby_object (grn_ctx *context, grn_obj *table,
37
+ rb_grn_boolean owner)
38
+ {
39
+ return GRNOBJECT2RVAL(rb_cGrnViewAccessor, context, table, owner);
40
+ }
41
+
42
+ /*
43
+ * Document-class: Groonga::ViewAccessor < Groonga::Object
44
+ *
45
+ * キー、値、スコアなど種々の値へのアクセスをカプセル化した
46
+ * オブジェクト。Groonga::Table#columnで取得できる。
47
+ */
48
+ void
49
+ rb_grn_init_view_accessor (VALUE mGrn)
50
+ {
51
+ rb_cGrnViewAccessor =
52
+ rb_define_class_under(mGrn, "ViewAccessor", rb_cGrnObject);
53
+ }
@@ -0,0 +1,35 @@
1
+ /* -*- c-file-style: "ruby" -*- */
2
+ /*
3
+ Copyright (C) 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_cGrnViewCursor;
22
+
23
+ /*
24
+ * Document-class: Groonga::ViewCursor < Groonga::TableCursor
25
+ *
26
+ * Groonga::Viewからレコードを順番に取り出すためのオブジェク
27
+ * ト。利用できるメソッドはGroonga::TableCursorを参照。
28
+ */
29
+
30
+ void
31
+ rb_grn_init_view_cursor (VALUE mGrn)
32
+ {
33
+ rb_cGrnViewCursor =
34
+ rb_define_class_under(mGrn, "ViewCursor", rb_cGrnTableCursor);
35
+ }
@@ -0,0 +1,41 @@
1
+ /* -*- c-file-style: "ruby" -*- */
2
+ /*
3
+ Copyright (C) 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_cGrnViewRecord;
22
+
23
+ VALUE
24
+ rb_grn_view_record_new (VALUE view, grn_obj *id)
25
+ {
26
+ return rb_grn_view_record_new_raw(view,
27
+ rb_str_new(GRN_TEXT_VALUE(id),
28
+ GRN_TEXT_LEN(id)));
29
+ }
30
+
31
+ VALUE
32
+ rb_grn_view_record_new_raw (VALUE view, VALUE rb_id)
33
+ {
34
+ return rb_funcall(rb_cGrnViewRecord, rb_intern("new"), 2, view, rb_id);
35
+ }
36
+
37
+ void
38
+ rb_grn_init_view_record (VALUE mGrn)
39
+ {
40
+ rb_cGrnViewRecord = rb_const_get(mGrn, rb_intern("ViewRecord"));
41
+ }
@@ -0,0 +1,421 @@
1
+ /* -*- c-file-style: "ruby" -*- */
2
+ /*
3
+ Copyright (C) 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
+ /* FIXME */
22
+ grn_id grn_view_add(grn_ctx *ctx, grn_obj *view, grn_obj *table);
23
+ grn_rc grn_table_cursor_next_o(grn_ctx *ctx, grn_table_cursor *tc, grn_obj *id);
24
+ grn_obj *grn_obj_get_value_o(grn_ctx *ctx, grn_obj *obj, grn_obj *id, grn_obj *value);
25
+
26
+ #define SELF(object) ((RbGrnTable *)DATA_PTR(object))
27
+
28
+ VALUE rb_cGrnView;
29
+
30
+ /*
31
+ * Document-class: Groonga::View < Groonga::Table
32
+ *
33
+ * 複数のテーブルを1つのテーブルとして扱う仮想的なテーブル
34
+ * (ビュー)。
35
+ */
36
+
37
+ /*
38
+ * call-seq:
39
+ * Groonga::View.create(options={}) -> Groonga::View
40
+ * Groonga::View.create(options={}) {|table| ... }
41
+ *
42
+ * 複数のテーブルを1つのテーブルとして扱う仮想的なテーブル
43
+ * (ビュー)を生成する。ブロックを指定すると、そのブロック
44
+ * に生成したテーブルが渡され、ブロックを抜けると自動的にテー
45
+ * ブルが破棄される。
46
+ *
47
+ * ビューにテーブルを追加するときはGroonga::View#add_tableを
48
+ * 使う。
49
+ *
50
+ * _options_に指定可能な値は以下の通り。
51
+ *
52
+ * [+:context+]
53
+ * ビューが利用するGroonga::Context。省略すると
54
+ * Groonga::Context.defaultを用いる。
55
+ *
56
+ * [+:name+]
57
+ * ビューの名前。名前をつけると、Groonga::Context#[]に名
58
+ * 前を指定してビューを取得することができる。省略すると
59
+ * 無名ビューになり、ビューIDでのみ取得できる。
60
+ *
61
+ * [+:path+]
62
+ * ビューを保存するパス。パスを指定すると永続ビューとな
63
+ * り、プロセス終了後もレコードは保持される。次回起動時に
64
+ * Groonga::View.openで保存されたビューを利用することが
65
+ * できる。省略すると一時ビューになり、プロセスが終了する
66
+ * とビューは破棄される。
67
+ *
68
+ * [+:persistent+]
69
+ * +true+を指定すると永続ビューとなる。+path+を省略した
70
+ * 場合は自動的にパスが付加される。+:context+で指定した
71
+ * Groonga::Contextに結びついているデータベースが一時デー
72
+ * タベースの場合は例外が発生する。
73
+ *
74
+ * 使用例:
75
+ *
76
+ * 無名一時ビューを生成する。
77
+ * Groonga::View.create
78
+ *
79
+ * 無名永続ブーを生成する。
80
+ * Groonga::View.create(:path => "/tmp/view.grn")
81
+ *
82
+ * 名前付き永続ビューを生成する。ただし、ファイル名は気に
83
+ * しない。
84
+ * Groonga::View.create(:name => "Entries",
85
+ * :persistent => true)
86
+ *
87
+ * +Users+テーブルと+Dogs+テーブルを横断検索するための
88
+ * るビューを生成する。
89
+ * entries = Groonga::View.create(:name => "Entries")
90
+ * entries.add_table("Users")
91
+ * entries.add_table("Dogs")
92
+ */
93
+ static VALUE
94
+ rb_grn_view_s_create (int argc, VALUE *argv, VALUE klass)
95
+ {
96
+ grn_ctx *context;
97
+ grn_obj *table;
98
+ const char *name = NULL, *path = NULL;
99
+ unsigned name_size = 0;
100
+ grn_obj_flags flags = GRN_TABLE_VIEW;
101
+ VALUE rb_table;
102
+ VALUE options, rb_context, rb_name, rb_path, rb_persistent;
103
+
104
+ rb_scan_args(argc, argv, "01", &options);
105
+
106
+ rb_grn_scan_options(options,
107
+ "context", &rb_context,
108
+ "name", &rb_name,
109
+ "path", &rb_path,
110
+ "persistent", &rb_persistent,
111
+ NULL);
112
+
113
+ context = rb_grn_context_ensure(&rb_context);
114
+
115
+ if (!NIL_P(rb_name)) {
116
+ name = StringValuePtr(rb_name);
117
+ name_size = RSTRING_LEN(rb_name);
118
+ flags |= GRN_OBJ_PERSISTENT;
119
+ }
120
+
121
+ if (!NIL_P(rb_path)) {
122
+ path = StringValueCStr(rb_path);
123
+ flags |= GRN_OBJ_PERSISTENT;
124
+ }
125
+
126
+ if (RVAL2CBOOL(rb_persistent))
127
+ flags |= GRN_OBJ_PERSISTENT;
128
+
129
+ table = grn_table_create(context, name, name_size, path, flags, NULL, NULL);
130
+ if (!table)
131
+ rb_grn_context_check(context, rb_ary_new4(argc, argv));
132
+ rb_table = GRNOBJECT2RVAL(klass, context, table, RB_GRN_TRUE);
133
+
134
+ if (rb_block_given_p())
135
+ return rb_ensure(rb_yield, rb_table, rb_grn_object_close, rb_table);
136
+ else
137
+ return rb_table;
138
+ }
139
+
140
+ /*
141
+ * call-seq:
142
+ * view.add_table(table)
143
+ *
144
+ * _table_をビューからアクセスできるようにする。
145
+ */
146
+ static VALUE
147
+ rb_grn_view_add_table (VALUE self, VALUE rb_table)
148
+ {
149
+ #ifdef WIN32
150
+ rb_raise(rb_eNotImpError, "grn_view_add() isn't available on Windows.");
151
+ #else
152
+ grn_ctx *context = NULL;
153
+ grn_obj *view, *table;
154
+
155
+ rb_grn_table_deconstruct(SELF(self), &view, &context,
156
+ NULL, NULL,
157
+ NULL, NULL, NULL,
158
+ NULL);
159
+ table = RVAL2GRNOBJECT(rb_table, &context);
160
+ grn_view_add(context, view, table);
161
+ rb_grn_context_check(context, self);
162
+ #endif
163
+
164
+ return Qnil;
165
+ }
166
+
167
+ /*
168
+ * call-seq:
169
+ * view.each {|record| ...}
170
+ *
171
+ * ビューに登録されているテーブルのレコードを順番にブロック
172
+ * に渡す。
173
+ */
174
+ static VALUE
175
+ rb_grn_view_each (VALUE self)
176
+ {
177
+ #ifdef WIN32
178
+ rb_raise(rb_eNotImpError,
179
+ "grn_table_cursor_next_o() isn't available on Windows.");
180
+ #else
181
+ RbGrnTable *rb_grn_view;
182
+ RbGrnObject *rb_grn_object;
183
+ grn_ctx *context = NULL;
184
+ grn_obj *view;
185
+ grn_table_cursor *cursor;
186
+ VALUE rb_cursor;
187
+ grn_obj id;
188
+ grn_rc rc = GRN_SUCCESS;
189
+
190
+ rb_grn_view = SELF(self);
191
+ rb_grn_table_deconstruct(rb_grn_view, &view, &context,
192
+ NULL, NULL,
193
+ NULL, NULL, NULL,
194
+ NULL);
195
+ cursor = grn_table_cursor_open(context, view, NULL, 0, NULL, 0,
196
+ 0, -1, GRN_CURSOR_ASCENDING);
197
+ rb_cursor = GRNTABLECURSOR2RVAL(Qnil, context, cursor);
198
+ rb_grn_object = RB_GRN_OBJECT(rb_grn_view);
199
+ GRN_TEXT_INIT(&id, 0);
200
+ while (rb_grn_object->object &&
201
+ (rc = grn_table_cursor_next_o(context, cursor, &id)) == GRN_SUCCESS) {
202
+ rb_yield(rb_grn_view_record_new(self, &id));
203
+ }
204
+ GRN_OBJ_FIN(context, &id);
205
+ rb_grn_object_close(rb_cursor);
206
+
207
+ if (!(rc == GRN_SUCCESS || rc == GRN_END_OF_DATA)) {
208
+ rb_grn_context_check(context, self);
209
+ }
210
+ #endif
211
+
212
+ return Qnil;
213
+ }
214
+
215
+ /*
216
+ * Document-method: column_value
217
+ *
218
+ * call-seq:
219
+ * view.column_value(id, name) -> 値
220
+ *
221
+ * _view_の_id_に対応するカラム_name_の値を返す。
222
+ */
223
+ static VALUE
224
+ rb_grn_view_get_column_value (VALUE self, VALUE rb_id, VALUE rb_name)
225
+ {
226
+ VALUE rb_value = Qnil;
227
+ #ifdef WIN32
228
+ rb_raise(rb_eNotImpError,
229
+ "grn_obj_get_value_o() isn't available on Windows.");
230
+ #else
231
+ RbGrnTable *rb_view;
232
+ grn_ctx *context = NULL;
233
+ grn_obj *view, *value, *accessor;
234
+ grn_obj id;
235
+
236
+ rb_view = SELF(self);
237
+ rb_grn_table_deconstruct(rb_view, &view, &context,
238
+ NULL, NULL,
239
+ &value, NULL, NULL,
240
+ NULL);
241
+ GRN_BULK_REWIND(value);
242
+ GRN_TEXT_INIT(&id, 0);
243
+ GRN_TEXT_PUT(context, &id, RSTRING_PTR(rb_id), RSTRING_LEN(rb_id));
244
+ accessor = grn_obj_column(context, view,
245
+ RSTRING_PTR(rb_name), RSTRING_LEN(rb_name));
246
+ grn_obj_get_value_o(context, accessor, &id, value);
247
+ grn_obj_unlink(context, accessor);
248
+ rb_value = GRNOBJ2RVAL(Qnil, context, value, self);
249
+ GRN_OBJ_FIN(context, &id);
250
+ #endif
251
+
252
+ return rb_value;
253
+ }
254
+
255
+ /*
256
+ * call-seq:
257
+ * view.sort(keys, options={}) -> Groonga::ViewRecordの配列
258
+ *
259
+ * テーブルに登録されているレコードを_keys_で指定されたルー
260
+ * ルに従ってソートしたレコードの配列を返す。
261
+ *
262
+ * [
263
+ * {:key => "カラム名", :order => :asc, :ascending,
264
+ * :desc, :descendingのいずれか},
265
+ * {:key => "カラム名", :order => :asc, :ascending,
266
+ * :desc, :descendingのいずれか},
267
+ * ...,
268
+ * ]
269
+ *
270
+ * _options_に指定可能な値は以下の通り。
271
+ *
272
+ * [+:offset+]
273
+ * ソートされたレコードのうち、(0ベースで)_:offset_番目
274
+ * からレコードを取り出す。
275
+ *
276
+ * [+:limit+]
277
+ * ソートされたレコードのうち、_:limit_件のみを取り出す。
278
+ * 省略された場合または-1が指定された場合は、全件が指定され
279
+ * たものとみなす。
280
+ */
281
+ /* FIXME: DON'T WORK!!! */
282
+ static VALUE
283
+ rb_grn_view_sort (int argc, VALUE *argv, VALUE self)
284
+ {
285
+ VALUE rb_result = Qnil;
286
+
287
+ #ifdef WIN32
288
+ rb_raise(rb_eNotImpError, "grn_view_add() isn't available on Windows.");
289
+ #else
290
+ grn_ctx *context = NULL;
291
+ grn_obj *view;
292
+ grn_obj *result;
293
+ grn_table_sort_key *keys;
294
+ int i, n_keys;
295
+ int n_records, offset = 0, limit = -1;
296
+ VALUE rb_keys, options;
297
+ VALUE rb_offset, rb_limit;
298
+ VALUE *rb_sort_keys;
299
+ grn_table_cursor *cursor;
300
+ VALUE exception;
301
+ grn_obj id;
302
+
303
+ rb_grn_table_deconstruct(SELF(self), &view, &context,
304
+ NULL, NULL,
305
+ NULL, NULL, NULL,
306
+ NULL);
307
+
308
+ rb_scan_args(argc, argv, "11", &rb_keys, &options);
309
+
310
+ if (!RVAL2CBOOL(rb_obj_is_kind_of(rb_keys, rb_cArray)))
311
+ rb_raise(rb_eArgError, "keys should be an array of key: <%s>",
312
+ rb_grn_inspect(rb_keys));
313
+
314
+ n_keys = RARRAY_LEN(rb_keys);
315
+ rb_sort_keys = RARRAY_PTR(rb_keys);
316
+ keys = ALLOCA_N(grn_table_sort_key, n_keys);
317
+ for (i = 0; i < n_keys; i++) {
318
+ VALUE rb_sort_options, rb_key, rb_resolved_key, rb_order;
319
+
320
+ if (RVAL2CBOOL(rb_obj_is_kind_of(rb_sort_keys[i], rb_cHash))) {
321
+ rb_sort_options = rb_sort_keys[i];
322
+ } else if (RVAL2CBOOL(rb_obj_is_kind_of(rb_sort_keys[i], rb_cArray))) {
323
+ rb_sort_options = rb_hash_new();
324
+ rb_hash_aset(rb_sort_options,
325
+ RB_GRN_INTERN("key"),
326
+ rb_ary_entry(rb_sort_keys[i], 0));
327
+ rb_hash_aset(rb_sort_options,
328
+ RB_GRN_INTERN("order"),
329
+ rb_ary_entry(rb_sort_keys[i], 1));
330
+ } else {
331
+ rb_sort_options = rb_hash_new();
332
+ rb_hash_aset(rb_sort_options,
333
+ RB_GRN_INTERN("key"),
334
+ rb_sort_keys[i]);
335
+ }
336
+ rb_grn_scan_options(rb_sort_options,
337
+ "key", &rb_key,
338
+ "order", &rb_order,
339
+ NULL);
340
+ if (RVAL2CBOOL(rb_obj_is_kind_of(rb_key, rb_cString))) {
341
+ rb_resolved_key = rb_grn_table_get_column(self, rb_key);
342
+ } else {
343
+ rb_resolved_key = rb_key;
344
+ }
345
+ keys[i].key = RVAL2GRNOBJECT(rb_resolved_key, &context);
346
+ if (!keys[i].key) {
347
+ rb_raise(rb_eGrnNoSuchColumn,
348
+ "no such column: <%s>: <%s>",
349
+ rb_grn_inspect(rb_key), rb_grn_inspect(self));
350
+ }
351
+ if (NIL_P(rb_order)) {
352
+ keys[i].flags = 0;
353
+ } else if (rb_grn_equal_option(rb_order, "desc") ||
354
+ rb_grn_equal_option(rb_order, "descending")) {
355
+ keys[i].flags = GRN_TABLE_SORT_DESC;
356
+ } else if (rb_grn_equal_option(rb_order, "asc") ||
357
+ rb_grn_equal_option(rb_order, "ascending")) {
358
+ keys[i].flags = GRN_TABLE_SORT_ASC;
359
+ } else {
360
+ rb_raise(rb_eArgError,
361
+ "order should be one of "
362
+ "[nil, :desc, :descending, :asc, :ascending]: %s",
363
+ rb_grn_inspect(rb_order));
364
+ }
365
+ }
366
+
367
+ rb_grn_scan_options(options,
368
+ "offset", &rb_offset,
369
+ "limit", &rb_limit,
370
+ NULL);
371
+
372
+ if (!NIL_P(rb_offset))
373
+ offset = NUM2INT(rb_offset);
374
+ if (!NIL_P(rb_limit))
375
+ limit = NUM2INT(rb_limit);
376
+
377
+ result = grn_table_create(context, NULL, 0, NULL, GRN_TABLE_VIEW,
378
+ NULL, NULL);
379
+ grn_view_add(context, result,
380
+ grn_table_create(context, NULL, 0, NULL, GRN_TABLE_NO_KEY,
381
+ NULL, grn_ctx_get(context, "People", strlen("People"))));
382
+ grn_view_add(context, result,
383
+ grn_table_create(context, NULL, 0, NULL, GRN_TABLE_NO_KEY,
384
+ NULL, grn_ctx_get(context, "People", strlen("People"))));
385
+ n_records = grn_table_sort(context, view, offset, limit,
386
+ result, keys, n_keys);
387
+ exception = rb_grn_context_to_exception(context, self);
388
+ if (!NIL_P(exception)) {
389
+ grn_obj_unlink(context, result);
390
+ rb_exc_raise(exception);
391
+ }
392
+
393
+ rb_result = rb_ary_new();
394
+ cursor = grn_table_cursor_open(context, result, NULL, 0, NULL, 0,
395
+ 0, -1, GRN_CURSOR_ASCENDING);
396
+ GRN_TEXT_INIT(&id, 0);
397
+ while (grn_table_cursor_next_o(context, cursor, &id) == GRN_SUCCESS) {
398
+ rb_ary_push(rb_result, rb_grn_view_record_new(self, &id));
399
+ }
400
+ GRN_OBJ_FIN(context, &id);
401
+ grn_table_cursor_close(context, cursor);
402
+ grn_obj_unlink(context, result);
403
+ #endif
404
+
405
+ return rb_result;
406
+ }
407
+
408
+ void
409
+ rb_grn_init_view (VALUE mGrn)
410
+ {
411
+ rb_cGrnView = rb_define_class_under(mGrn, "View", rb_cGrnTable);
412
+
413
+ rb_define_singleton_method(rb_cGrnView, "create",
414
+ rb_grn_view_s_create, -1);
415
+
416
+ rb_define_method(rb_cGrnView, "add_table", rb_grn_view_add_table, 1);
417
+ rb_define_method(rb_cGrnView, "each", rb_grn_view_each, 0);
418
+ rb_define_method(rb_cGrnView, "column_value",
419
+ rb_grn_view_get_column_value, 2);
420
+ rb_define_method(rb_cGrnView, "sort", rb_grn_view_sort, -1);
421
+ }