groonga 0.0.2 → 0.0.3
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.
- data/NEWS.ja.rdoc +18 -3
- data/NEWS.rdoc +18 -3
- data/README.ja.rdoc +2 -0
- data/README.rdoc +2 -0
- data/Rakefile +14 -5
- data/TUTORIAL.ja.rdoc +82 -16
- data/benchmark/{read-write-small-many-items.rb → read-write-many-small-items.rb} +26 -23
- data/benchmark/{write-small-many-items.rb → write-many-small-items.rb} +26 -23
- data/example/bookmark.rb +49 -5
- data/ext/rb-grn-array.c +11 -1
- data/ext/rb-grn-column.c +132 -5
- data/ext/rb-grn-context.c +85 -80
- data/ext/rb-grn-database.c +182 -9
- data/ext/rb-grn-expression-builder.c +69 -0
- data/ext/rb-grn-expression.c +314 -0
- data/ext/rb-grn-fix-size-column.c +68 -89
- data/ext/rb-grn-hash.c +14 -5
- data/ext/rb-grn-index-column.c +14 -55
- data/ext/rb-grn-object.c +206 -75
- data/ext/rb-grn-operation.c +92 -0
- data/ext/rb-grn-patricia-trie.c +10 -32
- data/ext/rb-grn-query.c +9 -9
- data/ext/rb-grn-table-cursor.c +19 -80
- data/ext/rb-grn-table-key-support.c +33 -39
- data/ext/rb-grn-table.c +436 -79
- data/ext/rb-grn-type.c +10 -3
- data/ext/rb-grn-utils.c +131 -4
- data/ext/rb-grn-variable-size-column.c +36 -0
- data/ext/rb-grn-variable.c +90 -0
- data/ext/rb-grn.h +109 -56
- data/ext/rb-groonga.c +4 -0
- data/extconf.rb +39 -13
- data/html/index.html +2 -2
- data/lib/groonga.rb +22 -0
- data/lib/groonga/expression-builder.rb +141 -0
- data/lib/groonga/record.rb +25 -1
- data/lib/groonga/schema.rb +418 -0
- data/test/test-column.rb +11 -23
- data/test/test-context.rb +1 -1
- data/test/test-database.rb +60 -19
- data/test/test-expression-builder.rb +114 -0
- data/test/test-expression.rb +55 -0
- data/test/test-fix-size-column.rb +53 -0
- data/test/test-hash.rb +10 -3
- data/test/test-index-column.rb +24 -0
- data/test/test-patricia-trie.rb +9 -0
- data/test/test-procedure.rb +5 -5
- data/test/test-record.rb +71 -4
- data/test/test-schema.rb +207 -0
- data/test/test-table.rb +94 -12
- data/test/test-type.rb +18 -11
- data/test/test-variable-size-column.rb +53 -0
- data/test/test-variable.rb +28 -0
- metadata +18 -5
@@ -0,0 +1,92 @@
|
|
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_mGrnOperation;
|
22
|
+
|
23
|
+
void
|
24
|
+
rb_grn_init_operation (VALUE mGrn)
|
25
|
+
{
|
26
|
+
rb_mGrnOperation = rb_define_module_under(mGrn, "Operation");
|
27
|
+
|
28
|
+
rb_define_const(rb_mGrnOperation, "NO_OPERATION",
|
29
|
+
UINT2NUM(GRN_OP_NOP));
|
30
|
+
rb_define_const(rb_mGrnOperation, "PUSH",
|
31
|
+
UINT2NUM(GRN_OP_PUSH));
|
32
|
+
rb_define_const(rb_mGrnOperation, "POP",
|
33
|
+
UINT2NUM(GRN_OP_POP));
|
34
|
+
rb_define_const(rb_mGrnOperation, "CALL",
|
35
|
+
UINT2NUM(GRN_OP_CALL));
|
36
|
+
rb_define_const(rb_mGrnOperation, "INTERN",
|
37
|
+
UINT2NUM(GRN_OP_INTERN));
|
38
|
+
rb_define_const(rb_mGrnOperation, "TABLE_CREATE",
|
39
|
+
UINT2NUM(GRN_OP_TABLE_CREATE));
|
40
|
+
rb_define_const(rb_mGrnOperation, "EXPRESSION_GET_VARIABLE",
|
41
|
+
UINT2NUM(GRN_OP_EXPR_GET_VAR));
|
42
|
+
rb_define_const(rb_mGrnOperation, "VARIABLE_SET_VALUE",
|
43
|
+
UINT2NUM(GRN_OP_VAR_SET_VALUE));
|
44
|
+
rb_define_const(rb_mGrnOperation, "OBJECT_GET_VALUE",
|
45
|
+
UINT2NUM(GRN_OP_OBJ_GET_VALUE));
|
46
|
+
rb_define_const(rb_mGrnOperation, "OBJECT_SET_VALUE",
|
47
|
+
UINT2NUM(GRN_OP_OBJ_SET_VALUE));
|
48
|
+
rb_define_const(rb_mGrnOperation, "OBJECT_SEARCH",
|
49
|
+
UINT2NUM(GRN_OP_OBJ_SEARCH));
|
50
|
+
rb_define_const(rb_mGrnOperation, "TABLE_SELECT",
|
51
|
+
UINT2NUM(GRN_OP_TABLE_SELECT));
|
52
|
+
rb_define_const(rb_mGrnOperation, "TABLE_SORT",
|
53
|
+
UINT2NUM(GRN_OP_TABLE_SORT));
|
54
|
+
rb_define_const(rb_mGrnOperation, "TABLE_GROUP",
|
55
|
+
UINT2NUM(GRN_OP_TABLE_GROUP));
|
56
|
+
rb_define_const(rb_mGrnOperation, "JSON_PUT",
|
57
|
+
UINT2NUM(GRN_OP_JSON_PUT));
|
58
|
+
rb_define_const(rb_mGrnOperation, "AND",
|
59
|
+
UINT2NUM(GRN_OP_AND));
|
60
|
+
rb_define_const(rb_mGrnOperation, "OR",
|
61
|
+
UINT2NUM(GRN_OP_OR));
|
62
|
+
rb_define_const(rb_mGrnOperation, "EQUAL",
|
63
|
+
UINT2NUM(GRN_OP_EQUAL));
|
64
|
+
rb_define_const(rb_mGrnOperation, "NOT_EQUAL",
|
65
|
+
UINT2NUM(GRN_OP_NOT_EQUAL));
|
66
|
+
rb_define_const(rb_mGrnOperation, "LESS",
|
67
|
+
UINT2NUM(GRN_OP_LESS));
|
68
|
+
rb_define_const(rb_mGrnOperation, "GREATER",
|
69
|
+
UINT2NUM(GRN_OP_GREATER));
|
70
|
+
rb_define_const(rb_mGrnOperation, "LESS_EQUAL",
|
71
|
+
UINT2NUM(GRN_OP_LESS_EQUAL));
|
72
|
+
rb_define_const(rb_mGrnOperation, "GREATER_EQUAL",
|
73
|
+
UINT2NUM(GRN_OP_GREATER_EQUAL));
|
74
|
+
rb_define_const(rb_mGrnOperation, "MATCH",
|
75
|
+
UINT2NUM(GRN_OP_MATCH));
|
76
|
+
/*
|
77
|
+
rb_define_const(rb_mGrnOperation, "GEO_DISTANCE1",
|
78
|
+
UINT2NUM(GRN_OP_GEO_DISTANCE1));
|
79
|
+
rb_define_const(rb_mGrnOperation, "GEO_DISTANCE2",
|
80
|
+
UINT2NUM(GRN_OP_GEO_DISTANCE2));
|
81
|
+
rb_define_const(rb_mGrnOperation, "GEO_DISTANCE3",
|
82
|
+
UINT2NUM(GRN_OP_GEO_DISTANCE3));
|
83
|
+
rb_define_const(rb_mGrnOperation, "GEO_DISTANCE4",
|
84
|
+
UINT2NUM(GRN_OP_GEO_DISTANCE4));
|
85
|
+
rb_define_const(rb_mGrnOperation, "GEO_WITHINP5",
|
86
|
+
UINT2NUM(GRN_OP_GEO_WITHINP5));
|
87
|
+
rb_define_const(rb_mGrnOperation, "GEO_WITHINP6",
|
88
|
+
UINT2NUM(GRN_OP_GEO_WITHINP6));
|
89
|
+
rb_define_const(rb_mGrnOperation, "GEO_WITHINP8",
|
90
|
+
UINT2NUM(GRN_OP_GEO_WITHINP8));
|
91
|
+
*/
|
92
|
+
}
|
data/ext/rb-grn-patricia-trie.c
CHANGED
@@ -33,7 +33,7 @@ rb_grn_patricia_trie_s_create (int argc, VALUE *argv, VALUE self)
|
|
33
33
|
VALUE rb_table;
|
34
34
|
VALUE options, rb_context, rb_name, rb_path, rb_persistent;
|
35
35
|
VALUE rb_key_normalize, rb_key_with_sis, rb_key_type, rb_value_size;
|
36
|
-
VALUE rb_default_tokenizer;
|
36
|
+
VALUE rb_default_tokenizer, rb_sub_records;
|
37
37
|
|
38
38
|
rb_scan_args(argc, argv, "01", &options);
|
39
39
|
|
@@ -47,6 +47,7 @@ rb_grn_patricia_trie_s_create (int argc, VALUE *argv, VALUE self)
|
|
47
47
|
"key_type", &rb_key_type,
|
48
48
|
"value_size", &rb_value_size,
|
49
49
|
"default_tokenizer", &rb_default_tokenizer,
|
50
|
+
"sub_records", &rb_sub_records,
|
50
51
|
NULL);
|
51
52
|
|
52
53
|
context = rb_grn_context_ensure(&rb_context);
|
@@ -54,6 +55,7 @@ rb_grn_patricia_trie_s_create (int argc, VALUE *argv, VALUE self)
|
|
54
55
|
if (!NIL_P(rb_name)) {
|
55
56
|
name = StringValuePtr(rb_name);
|
56
57
|
name_size = RSTRING_LEN(rb_name);
|
58
|
+
flags |= GRN_OBJ_PERSISTENT;
|
57
59
|
}
|
58
60
|
|
59
61
|
if (!NIL_P(rb_path)) {
|
@@ -79,13 +81,15 @@ rb_grn_patricia_trie_s_create (int argc, VALUE *argv, VALUE self)
|
|
79
81
|
if (!NIL_P(rb_value_size))
|
80
82
|
value_size = NUM2UINT(rb_value_size);
|
81
83
|
|
84
|
+
if (RVAL2CBOOL(rb_sub_records))
|
85
|
+
flags |= GRN_OBJ_WITH_SUBREC;
|
86
|
+
|
82
87
|
table = grn_table_create(context, name, name_size, path,
|
83
88
|
flags, key_type, value_size);
|
84
89
|
if (!table)
|
85
90
|
rb_grn_context_check(context, rb_ary_new4(argc, argv));
|
86
|
-
rb_table =
|
87
|
-
|
88
|
-
RB_GRN_TRUE);
|
91
|
+
rb_table = rb_grn_object_alloc(self);
|
92
|
+
rb_grn_object_assign(Qnil, rb_table, rb_context, context, table);
|
89
93
|
rb_grn_context_check(context, rb_table);
|
90
94
|
|
91
95
|
if (!NIL_P(rb_default_tokenizer))
|
@@ -106,7 +110,7 @@ rb_grn_patricia_trie_search (int argc, VALUE *argv, VALUE self)
|
|
106
110
|
grn_obj *table;
|
107
111
|
grn_id domain_id;
|
108
112
|
grn_obj *key, *domain, *result;
|
109
|
-
|
113
|
+
grn_operator operator;
|
110
114
|
grn_search_optarg search_options;
|
111
115
|
rb_grn_boolean search_options_is_set = RB_GRN_TRUE;
|
112
116
|
VALUE rb_key, options, rb_result, rb_operator, rb_type;
|
@@ -135,32 +139,7 @@ rb_grn_patricia_trie_search (int argc, VALUE *argv, VALUE self)
|
|
135
139
|
result = RVAL2GRNOBJECT(rb_result, &context);
|
136
140
|
}
|
137
141
|
|
138
|
-
operator =
|
139
|
-
|
140
|
-
search_options.flags = 0;
|
141
|
-
if (NIL_P(rb_type)) {
|
142
|
-
search_options_is_set = RB_GRN_FALSE;
|
143
|
-
} else if (rb_grn_equal_option(rb_type, "exact")) {
|
144
|
-
search_options.flags |= GRN_SEARCH_EXACT;
|
145
|
-
} else if (rb_grn_equal_option(rb_type, "longest_common_prefix") ||
|
146
|
-
rb_grn_equal_option(rb_type, "longest-common-prefix")) {
|
147
|
-
search_options.flags |= GRN_SEARCH_LCP;
|
148
|
-
} else if (rb_grn_equal_option(rb_type, "suffix")) {
|
149
|
-
search_options.flags |= GRN_SEARCH_SUFFIX;
|
150
|
-
} else if (rb_grn_equal_option(rb_type, "prefix")) {
|
151
|
-
search_options.flags |= GRN_SEARCH_PREFIX;
|
152
|
-
} else if (rb_grn_equal_option(rb_type, "term_extract") ||
|
153
|
-
rb_grn_equal_option(rb_type, "term-extract")) {
|
154
|
-
search_options.flags |= GRN_SEARCH_TERM_EXTRACT;
|
155
|
-
} else if (rb_grn_equal_option(rb_type, "suffix")) {
|
156
|
-
search_options.flags |= GRN_SEARCH_SUFFIX;
|
157
|
-
} else {
|
158
|
-
rb_raise(rb_eArgError,
|
159
|
-
"search type should be one of "
|
160
|
-
"[nil, :exact, :longest_common_prefix, :suffix, "
|
161
|
-
":prefix, :term_extract]: %s",
|
162
|
-
rb_grn_inspect(rb_type));
|
163
|
-
}
|
142
|
+
operator = RVAL2GRNOPERATOR(rb_operator);
|
164
143
|
|
165
144
|
rc = grn_obj_search(context, table, key,
|
166
145
|
result, operator,
|
@@ -175,7 +154,6 @@ rb_grn_init_patricia_trie (VALUE mGrn)
|
|
175
154
|
{
|
176
155
|
rb_cGrnPatriciaTrie =
|
177
156
|
rb_define_class_under(mGrn, "PatriciaTrie", rb_cGrnTable);
|
178
|
-
rb_define_alloc_func(rb_cGrnPatriciaTrie, rb_grn_table_key_support_alloc);
|
179
157
|
|
180
158
|
rb_include_module(rb_cGrnPatriciaTrie, rb_mGrnTableKeySupport);
|
181
159
|
rb_define_singleton_method(rb_cGrnPatriciaTrie, "create",
|
data/ext/rb-grn-query.c
CHANGED
@@ -89,26 +89,26 @@ rb_grn_query_alloc (VALUE klass)
|
|
89
89
|
return Data_Wrap_Struct(klass, NULL, rb_rb_grn_query_free, NULL);
|
90
90
|
}
|
91
91
|
|
92
|
-
|
93
|
-
|
92
|
+
grn_operator
|
93
|
+
rb_grn_operator_from_ruby_object (VALUE rb_operator)
|
94
94
|
{
|
95
|
-
|
95
|
+
grn_operator operator = GRN_OP_OR;
|
96
96
|
|
97
97
|
if (NIL_P(rb_operator) ||
|
98
98
|
rb_grn_equal_option(rb_operator, "or") ||
|
99
99
|
rb_grn_equal_option(rb_operator, "||")) {
|
100
|
-
operator =
|
100
|
+
operator = GRN_OP_OR;
|
101
101
|
} else if (rb_grn_equal_option(rb_operator, "and") ||
|
102
102
|
rb_grn_equal_option(rb_operator, "+") ||
|
103
103
|
rb_grn_equal_option(rb_operator, "&&")) {
|
104
|
-
operator =
|
104
|
+
operator = GRN_OP_AND;
|
105
105
|
} else if (rb_grn_equal_option(rb_operator, "but") ||
|
106
106
|
rb_grn_equal_option(rb_operator, "not") ||
|
107
107
|
rb_grn_equal_option(rb_operator, "-")) {
|
108
|
-
operator =
|
108
|
+
operator = GRN_OP_BUT;
|
109
109
|
} else if (rb_grn_equal_option(rb_operator, "adjust") ||
|
110
110
|
rb_grn_equal_option(rb_operator, ">")) {
|
111
|
-
operator =
|
111
|
+
operator = GRN_OP_ADJUST;
|
112
112
|
} else {
|
113
113
|
rb_raise(rb_eArgError,
|
114
114
|
"operator should be one of "
|
@@ -127,7 +127,7 @@ rb_grn_query_initialize (int argc, VALUE *argv, VALUE self)
|
|
127
127
|
grn_query *query;
|
128
128
|
char *query_string;
|
129
129
|
unsigned int query_string_length;
|
130
|
-
|
130
|
+
grn_operator default_operator;
|
131
131
|
int max_expressions = RB_GRN_QUERY_DEFAULT_MAX_EXPRESSIONS;
|
132
132
|
VALUE rb_query_string, options, rb_context, rb_default_operator;
|
133
133
|
VALUE rb_max_expressions;
|
@@ -145,7 +145,7 @@ rb_grn_query_initialize (int argc, VALUE *argv, VALUE self)
|
|
145
145
|
|
146
146
|
context = rb_grn_context_ensure(&rb_context);
|
147
147
|
|
148
|
-
default_operator =
|
148
|
+
default_operator = RVAL2GRNOPERATOR(rb_default_operator);
|
149
149
|
|
150
150
|
if (!NIL_P(rb_max_expressions))
|
151
151
|
max_expressions = NUM2INT(rb_max_expressions);
|
data/ext/rb-grn-table-cursor.c
CHANGED
@@ -32,91 +32,14 @@ rb_grn_table_cursor_from_ruby_object (VALUE object, grn_ctx **context)
|
|
32
32
|
return RVAL2GRNOBJECT(object, context);
|
33
33
|
}
|
34
34
|
|
35
|
-
VALUE
|
36
|
-
rb_grn_table_cursor_to_ruby_class (grn_obj *object)
|
37
|
-
{
|
38
|
-
VALUE klass = Qnil;
|
39
|
-
|
40
|
-
switch (object->header.type) {
|
41
|
-
case GRN_CURSOR_TABLE_HASH_KEY:
|
42
|
-
klass = rb_cGrnHashCursor;
|
43
|
-
break;
|
44
|
-
case GRN_CURSOR_TABLE_PAT_KEY:
|
45
|
-
klass = rb_cGrnPatriciaTrieCursor;
|
46
|
-
break;
|
47
|
-
case GRN_CURSOR_TABLE_NO_KEY:
|
48
|
-
klass = rb_cGrnArrayCursor;
|
49
|
-
break;
|
50
|
-
default:
|
51
|
-
rb_raise(rb_eTypeError,
|
52
|
-
"unsupported groonga object type: %d",
|
53
|
-
object->header.type);
|
54
|
-
break;
|
55
|
-
}
|
56
|
-
|
57
|
-
return klass;
|
58
|
-
}
|
59
|
-
|
60
35
|
VALUE
|
61
36
|
rb_grn_table_cursor_to_ruby_object (VALUE klass, grn_ctx *context,
|
62
37
|
grn_table_cursor *cursor,
|
63
38
|
rb_grn_boolean owner)
|
64
39
|
{
|
65
|
-
if (NIL_P(klass))
|
66
|
-
klass = rb_grn_table_cursor_to_ruby_class(cursor);
|
67
40
|
return GRNOBJECT2RVAL(klass, context, cursor, owner);
|
68
41
|
}
|
69
42
|
|
70
|
-
void
|
71
|
-
rb_grn_table_cursor_unbind (RbGrnTableCursor *rb_grn_table_cursor)
|
72
|
-
{
|
73
|
-
RbGrnObject *rb_grn_object;
|
74
|
-
|
75
|
-
rb_grn_object = RB_GRN_OBJECT(rb_grn_table_cursor);
|
76
|
-
rb_grn_object_unbind(rb_grn_object);
|
77
|
-
}
|
78
|
-
|
79
|
-
static void
|
80
|
-
rb_grn_table_cursor_free (void *object)
|
81
|
-
{
|
82
|
-
RbGrnTableCursor *rb_grn_table_cursor = object;
|
83
|
-
|
84
|
-
rb_grn_table_cursor_unbind(rb_grn_table_cursor);
|
85
|
-
xfree(rb_grn_table_cursor);
|
86
|
-
}
|
87
|
-
|
88
|
-
VALUE
|
89
|
-
rb_grn_table_cursor_alloc (VALUE klass)
|
90
|
-
{
|
91
|
-
return Data_Wrap_Struct(klass, NULL, rb_grn_table_cursor_free, NULL);
|
92
|
-
}
|
93
|
-
|
94
|
-
void
|
95
|
-
rb_grn_table_cursor_bind (RbGrnTableCursor *rb_grn_table_cursor,
|
96
|
-
grn_ctx *context, grn_table_cursor *cursor,
|
97
|
-
rb_grn_boolean owner)
|
98
|
-
{
|
99
|
-
RbGrnObject *rb_grn_object;
|
100
|
-
|
101
|
-
rb_grn_object = RB_GRN_OBJECT(rb_grn_table_cursor);
|
102
|
-
rb_grn_object_bind(rb_grn_object, context, cursor, owner);
|
103
|
-
rb_grn_object->unbind = RB_GRN_UNBIND_FUNCTION(rb_grn_table_cursor_unbind);
|
104
|
-
}
|
105
|
-
|
106
|
-
void
|
107
|
-
rb_grn_table_cursor_assign (VALUE self, VALUE rb_context,
|
108
|
-
grn_ctx *context, grn_table_cursor *cursor,
|
109
|
-
rb_grn_boolean owner)
|
110
|
-
{
|
111
|
-
RbGrnTableCursor *rb_grn_table_cursor;
|
112
|
-
|
113
|
-
rb_grn_table_cursor = ALLOC(RbGrnTableCursor);
|
114
|
-
DATA_PTR(self) = rb_grn_table_cursor;
|
115
|
-
rb_grn_table_cursor_bind(rb_grn_table_cursor, context, cursor, owner);
|
116
|
-
|
117
|
-
rb_iv_set(self, "context", rb_context);
|
118
|
-
}
|
119
|
-
|
120
43
|
void
|
121
44
|
rb_grn_table_cursor_deconstruct (RbGrnTableCursor *rb_grn_table_cursor,
|
122
45
|
grn_table_cursor **cursor,
|
@@ -137,7 +60,23 @@ rb_grn_table_cursor_deconstruct (RbGrnTableCursor *rb_grn_table_cursor,
|
|
137
60
|
VALUE
|
138
61
|
rb_grn_table_cursor_close (VALUE self)
|
139
62
|
{
|
140
|
-
|
63
|
+
RbGrnTableCursor *rb_grn_table_cursor;
|
64
|
+
grn_table_cursor *cursor;
|
65
|
+
grn_ctx *context;
|
66
|
+
|
67
|
+
rb_grn_table_cursor = SELF(self);
|
68
|
+
rb_grn_table_cursor_deconstruct(rb_grn_table_cursor, &cursor, &context,
|
69
|
+
NULL, NULL, NULL, NULL);
|
70
|
+
|
71
|
+
if (context && cursor) {
|
72
|
+
RbGrnObject *rb_grn_object;
|
73
|
+
|
74
|
+
rb_grn_object = RB_GRN_OBJECT(rb_grn_table_cursor);
|
75
|
+
grn_obj_close(context, cursor);
|
76
|
+
rb_grn_object->context = NULL;
|
77
|
+
rb_grn_object->object = NULL;
|
78
|
+
}
|
79
|
+
|
141
80
|
return Qnil;
|
142
81
|
}
|
143
82
|
|
@@ -259,8 +198,8 @@ rb_grn_table_cursor_each (VALUE self)
|
|
259
198
|
void
|
260
199
|
rb_grn_init_table_cursor (VALUE mGrn)
|
261
200
|
{
|
262
|
-
rb_cGrnTableCursor = rb_define_class_under(mGrn, "
|
263
|
-
rb_define_alloc_func(rb_cGrnTableCursor,
|
201
|
+
rb_cGrnTableCursor = rb_define_class_under(mGrn, "TableCursor", rb_cObject);
|
202
|
+
rb_define_alloc_func(rb_cGrnTableCursor, rb_grn_object_alloc);
|
264
203
|
|
265
204
|
rb_include_module(rb_cGrnTableCursor, rb_mEnumerable);
|
266
205
|
|
@@ -45,34 +45,26 @@ rb_grn_table_key_support_deconstruct (RbGrnTableKeySupport *rb_grn_table_key_sup
|
|
45
45
|
*key = rb_grn_table_key_support->key;
|
46
46
|
}
|
47
47
|
|
48
|
-
|
49
|
-
|
48
|
+
void
|
49
|
+
rb_grn_table_key_support_finalizer (grn_ctx *context,
|
50
|
+
grn_obj *grn_object,
|
51
|
+
RbGrnTableKeySupport *rb_grn_table_key_support)
|
50
52
|
{
|
51
|
-
|
52
|
-
|
53
|
-
RbGrnTableKeySupport *rb_grn_table_key_support = object;
|
54
|
-
grn_ctx *context;
|
53
|
+
if (!context)
|
54
|
+
return;
|
55
55
|
|
56
|
-
|
57
|
-
if (context)
|
56
|
+
if (rb_grn_table_key_support->key)
|
58
57
|
grn_obj_close(context, rb_grn_table_key_support->key);
|
58
|
+
rb_grn_table_key_support->key = NULL;
|
59
59
|
|
60
|
-
|
61
|
-
|
62
|
-
xfree(rb_grn_table_key_support);
|
63
|
-
}
|
64
|
-
|
65
|
-
VALUE
|
66
|
-
rb_grn_table_key_support_alloc (VALUE klass)
|
67
|
-
{
|
68
|
-
return Data_Wrap_Struct(klass, NULL, rb_grn_table_key_support_free, NULL);
|
60
|
+
rb_grn_table_finalizer(context, grn_object,
|
61
|
+
RB_GRN_TABLE(rb_grn_table_key_support));
|
69
62
|
}
|
70
63
|
|
71
64
|
void
|
72
65
|
rb_grn_table_key_support_bind (RbGrnTableKeySupport *rb_grn_table_key_support,
|
73
66
|
grn_ctx *context,
|
74
|
-
grn_obj *table_key_support
|
75
|
-
rb_grn_boolean owner)
|
67
|
+
grn_obj *table_key_support)
|
76
68
|
{
|
77
69
|
RbGrnObject *rb_grn_object;
|
78
70
|
RbGrnTable *rb_grn_table;
|
@@ -80,29 +72,12 @@ rb_grn_table_key_support_bind (RbGrnTableKeySupport *rb_grn_table_key_support,
|
|
80
72
|
rb_grn_object = RB_GRN_OBJECT(rb_grn_table_key_support);
|
81
73
|
|
82
74
|
rb_grn_table = RB_GRN_TABLE(rb_grn_table_key_support);
|
83
|
-
rb_grn_table_bind(rb_grn_table, context, table_key_support
|
75
|
+
rb_grn_table_bind(rb_grn_table, context, table_key_support);
|
84
76
|
|
85
77
|
rb_grn_table_key_support->key =
|
86
78
|
grn_obj_open(context, GRN_BULK, 0, rb_grn_object->domain_id);
|
87
79
|
}
|
88
80
|
|
89
|
-
void
|
90
|
-
rb_grn_table_key_support_assign (VALUE self, VALUE rb_context,
|
91
|
-
grn_ctx *context,
|
92
|
-
grn_obj *table_key_support,
|
93
|
-
rb_grn_boolean owner)
|
94
|
-
{
|
95
|
-
RbGrnTableKeySupport *rb_grn_table_key_support;
|
96
|
-
|
97
|
-
rb_grn_table_key_support = ALLOC(RbGrnTableKeySupport);
|
98
|
-
DATA_PTR(self) = rb_grn_table_key_support;
|
99
|
-
|
100
|
-
rb_grn_table_key_support_bind(rb_grn_table_key_support,
|
101
|
-
context, table_key_support, owner);
|
102
|
-
|
103
|
-
rb_iv_set(self, "context", rb_context);
|
104
|
-
}
|
105
|
-
|
106
81
|
static VALUE
|
107
82
|
rb_grn_table_key_support_initialize (int argc, VALUE *argv, VALUE self)
|
108
83
|
{
|
@@ -112,8 +87,7 @@ rb_grn_table_key_support_initialize (int argc, VALUE *argv, VALUE self)
|
|
112
87
|
|
113
88
|
table = rb_grn_table_open_raw(argc, argv, &context, &rb_context);
|
114
89
|
rb_grn_context_check(context, self);
|
115
|
-
|
116
|
-
table, RB_GRN_TRUE);
|
90
|
+
rb_grn_object_assign(Qnil, self, rb_context, context, table);
|
117
91
|
|
118
92
|
return Qnil;
|
119
93
|
}
|
@@ -182,6 +156,24 @@ rb_grn_table_key_support_get_key (VALUE self, VALUE rb_id)
|
|
182
156
|
return rb_key;
|
183
157
|
}
|
184
158
|
|
159
|
+
static VALUE
|
160
|
+
rb_grn_table_key_support_has_key (VALUE self, VALUE rb_key)
|
161
|
+
{
|
162
|
+
grn_ctx *context;
|
163
|
+
grn_obj *table, *key, *domain;
|
164
|
+
grn_id id, domain_id;
|
165
|
+
|
166
|
+
rb_grn_table_key_support_deconstruct(SELF(self), &table, &context,
|
167
|
+
&key, &domain_id, &domain,
|
168
|
+
NULL, NULL, NULL);
|
169
|
+
|
170
|
+
GRN_BULK_REWIND(key);
|
171
|
+
RVAL2GRNKEY(rb_key, context, key, domain_id, domain, self);
|
172
|
+
id = grn_table_get(context, table, GRN_BULK_HEAD(key), GRN_BULK_VSIZE(key));
|
173
|
+
|
174
|
+
return id == GRN_ID_NIL ? Qfalse : Qtrue;
|
175
|
+
}
|
176
|
+
|
185
177
|
static VALUE
|
186
178
|
rb_grn_table_key_support_delete_by_key (VALUE self, VALUE rb_key)
|
187
179
|
{
|
@@ -383,6 +375,8 @@ rb_grn_init_table_key_support (VALUE mGrn)
|
|
383
375
|
rb_grn_table_key_support_add, -1);
|
384
376
|
rb_define_method(rb_mGrnTableKeySupport, "key",
|
385
377
|
rb_grn_table_key_support_get_key, 1);
|
378
|
+
rb_define_method(rb_mGrnTableKeySupport, "has_key?",
|
379
|
+
rb_grn_table_key_support_has_key, 1);
|
386
380
|
|
387
381
|
rb_define_method(rb_mGrnTableKeySupport, "delete",
|
388
382
|
rb_grn_table_key_support_delete, 1);
|