estraier 1.4.10
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.txt +0 -0
- data/History.txt +0 -0
- data/README.txt +107 -0
- data/Rakefile +100 -0
- data/bin/estcmd +695 -0
- data/examples/Makefile +31 -0
- data/examples/example001.rb +32 -0
- data/examples/example002.rb +42 -0
- data/ext/estraier.c +1258 -0
- data/ext/extconf.rb +16 -0
- data/lib/estraier.rb +1 -0
- data/lib/estraier/estraier-doc.rb +612 -0
- data/lib/estraier/version.rb +9 -0
- data/setup.rb +1585 -0
- data/test/test_estraier.rb +11 -0
- data/test/test_helper.rb +2 -0
- metadata +73 -0
data/examples/Makefile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Makefile for sample programs of the Ruby binding
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
#================================================================
|
6
|
+
# Setting Variables
|
7
|
+
#================================================================
|
8
|
+
|
9
|
+
|
10
|
+
# Generic settings
|
11
|
+
SHELL = /bin/sh
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
#================================================================
|
16
|
+
# Actions
|
17
|
+
#================================================================
|
18
|
+
|
19
|
+
|
20
|
+
all :
|
21
|
+
|
22
|
+
|
23
|
+
clean :
|
24
|
+
rm -rf *.exe *.o a.out check.out gmon.out leak.log casket *~
|
25
|
+
|
26
|
+
|
27
|
+
.PHONY : all clean
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
# END OF FILE
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "estraier"
|
2
|
+
include Estraier
|
3
|
+
|
4
|
+
# create the database object
|
5
|
+
db = Database::new
|
6
|
+
|
7
|
+
# open the database
|
8
|
+
unless db.open("casket", Database::DBWRITER | Database::DBCREAT)
|
9
|
+
printf("error: %s\n", db.err_msg(db.error))
|
10
|
+
exit
|
11
|
+
end
|
12
|
+
|
13
|
+
# create a document object
|
14
|
+
doc = Document::new
|
15
|
+
|
16
|
+
# add attributes to the document object
|
17
|
+
doc.add_attr("@uri", "http://estraier.gov/example.txt")
|
18
|
+
doc.add_attr("@title", "Over the Rainbow")
|
19
|
+
|
20
|
+
# add the body text to the document object
|
21
|
+
doc.add_text("Somewhere over the rainbow. Way up high.")
|
22
|
+
doc.add_text("There's a land that I heard of once in a lullaby.")
|
23
|
+
|
24
|
+
# register the document object to the database
|
25
|
+
unless db.put_doc(doc, Database::PDCLEAN)
|
26
|
+
printf("error: %s\n", db.err_msg(db.error))
|
27
|
+
end
|
28
|
+
|
29
|
+
# close the database
|
30
|
+
unless db.close
|
31
|
+
printf("error: %s\n", db.err_msg(db.error))
|
32
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require "estraier"
|
2
|
+
include Estraier
|
3
|
+
|
4
|
+
# create the database object
|
5
|
+
db = Database::new
|
6
|
+
|
7
|
+
# open the database
|
8
|
+
unless db.open("casket", Database::DBREADER)
|
9
|
+
printf("error: %s\n", db.err_msg(db.error))
|
10
|
+
exit
|
11
|
+
end
|
12
|
+
|
13
|
+
# create a search condition object
|
14
|
+
cond = Condition::new
|
15
|
+
|
16
|
+
# set the search phrase to the search condition object
|
17
|
+
cond.set_phrase("rainbow AND lullaby")
|
18
|
+
|
19
|
+
# get the result of search
|
20
|
+
result = db.search(cond)
|
21
|
+
|
22
|
+
# for each document in the result
|
23
|
+
dnum = result.doc_num
|
24
|
+
for i in 0...dnum
|
25
|
+
# retrieve the document object
|
26
|
+
doc = db.get_doc(result.get_doc_id(i), 0)
|
27
|
+
next unless doc
|
28
|
+
# display attributes
|
29
|
+
uri = doc.attr("@uri")
|
30
|
+
printf("URI: %s\n", uri) if uri
|
31
|
+
title = doc.attr("@title")
|
32
|
+
printf("Title: %s\n", title) if title
|
33
|
+
# display the body text
|
34
|
+
doc.texts.each do |text|
|
35
|
+
printf("%s\n", text)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# close the database
|
40
|
+
unless db.close
|
41
|
+
printf("error: %s\n", db.err_msg(db.error))
|
42
|
+
end
|
data/ext/estraier.c
ADDED
@@ -0,0 +1,1258 @@
|
|
1
|
+
/*************************************************************************************************
|
2
|
+
* Ruby binding of Hyper Estraier
|
3
|
+
* Copyright (C) 2004-2005 Mikio Hirabayashi
|
4
|
+
* This file is part of Hyper Estraier.
|
5
|
+
* Hyper Estraier is free software; you can redistribute it and/or modify it under the terms of
|
6
|
+
* the GNU Lesser General Public License as published by the Free Software Foundation; either
|
7
|
+
* version 2.1 of the License or any later version. Hyper Estraier is distributed in the hope
|
8
|
+
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
9
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
10
|
+
* License for more details.
|
11
|
+
* You should have received a copy of the GNU Lesser General Public License along with Hyper
|
12
|
+
* Estraier; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
13
|
+
* Boston, MA 02111-1307 USA.
|
14
|
+
*************************************************************************************************/
|
15
|
+
|
16
|
+
|
17
|
+
#include "ruby.h"
|
18
|
+
#include <estraier.h>
|
19
|
+
#include <estmtdb.h>
|
20
|
+
#include <cabin.h>
|
21
|
+
#include <stdlib.h>
|
22
|
+
|
23
|
+
#define VNDATA "@ptr"
|
24
|
+
#define VNINFO "@informer"
|
25
|
+
#define VNCOND "@cond"
|
26
|
+
|
27
|
+
typedef struct {
|
28
|
+
int *ids;
|
29
|
+
int *dbidxs;
|
30
|
+
int num;
|
31
|
+
CBMAP *hints;
|
32
|
+
} ESTRES;
|
33
|
+
|
34
|
+
typedef struct {
|
35
|
+
ESTMTDB *db;
|
36
|
+
int ecode;
|
37
|
+
} ESTDBMGR;
|
38
|
+
|
39
|
+
|
40
|
+
/* private function prototypes */
|
41
|
+
static void doc_init(void);
|
42
|
+
static VALUE doc_initialize(int argc, VALUE *argv, VALUE vself);
|
43
|
+
static VALUE doc_add_attr(VALUE vself, VALUE vname, VALUE vvalue);
|
44
|
+
static VALUE doc_add_text(VALUE vself, VALUE vtext);
|
45
|
+
static VALUE doc_add_hidden_text(VALUE vself, VALUE vtext);
|
46
|
+
static VALUE doc_set_keywords(VALUE vself, VALUE vkwords);
|
47
|
+
static VALUE doc_set_score(VALUE vself, VALUE vscore);
|
48
|
+
static VALUE doc_id(VALUE vself);
|
49
|
+
static VALUE doc_attr_names(VALUE vself);
|
50
|
+
static VALUE doc_attr(VALUE vself, VALUE vname);
|
51
|
+
static VALUE doc_texts(VALUE vself);
|
52
|
+
static VALUE doc_cat_texts(VALUE vself);
|
53
|
+
static VALUE doc_keywords(VALUE vself);
|
54
|
+
static VALUE doc_score(VALUE vself);
|
55
|
+
static VALUE doc_dump_draft(VALUE vself);
|
56
|
+
static VALUE doc_make_snippet(VALUE vself, VALUE vwords,
|
57
|
+
VALUE vwwidth, VALUE vhwidth, VALUE vawidth);
|
58
|
+
static void cond_init(void);
|
59
|
+
static VALUE cond_initialize(VALUE vself);
|
60
|
+
static VALUE cond_set_phrase(VALUE vself, VALUE vphrase);
|
61
|
+
static VALUE cond_add_attr(VALUE vself, VALUE vexpr);
|
62
|
+
static VALUE cond_set_order(VALUE vself, VALUE vexpr);
|
63
|
+
static VALUE cond_set_max(VALUE vself, VALUE vmax);
|
64
|
+
static VALUE cond_set_skip(VALUE vself, VALUE vskip);
|
65
|
+
static VALUE cond_set_options(VALUE vself, VALUE voptions);
|
66
|
+
static VALUE cond_set_auxiliary(VALUE vself, VALUE vmin);
|
67
|
+
static VALUE cond_set_eclipse(VALUE vself, VALUE vlimit);
|
68
|
+
static VALUE cond_set_distinct(VALUE vself, VALUE vname);
|
69
|
+
static VALUE cond_set_mask(VALUE vself, VALUE vmask);
|
70
|
+
static void res_init(void);
|
71
|
+
static VALUE res_initialize(VALUE vself);
|
72
|
+
static ESTRES *est_res_new(void);
|
73
|
+
static void est_res_delete(ESTRES *res);
|
74
|
+
static VALUE res_doc_num(VALUE vself);
|
75
|
+
static VALUE res_get_doc_id(VALUE vself, VALUE vindex);
|
76
|
+
static VALUE res_get_dbidx(VALUE vself, VALUE vindex);
|
77
|
+
static VALUE res_hint_words(VALUE vself);
|
78
|
+
static VALUE res_hint(VALUE vself, VALUE vword);
|
79
|
+
static VALUE res_get_score(VALUE vself, VALUE vindex);
|
80
|
+
static VALUE res_get_shadows(VALUE vself, VALUE vid);
|
81
|
+
static void db_init(void);
|
82
|
+
static VALUE db_initialize(VALUE vself);
|
83
|
+
static ESTDBMGR *est_dbmgr_new(void);
|
84
|
+
static void est_dbmgr_delete(ESTDBMGR *db);
|
85
|
+
static VALUE db_search_meta(VALUE vself, VALUE vdbs, VALUE vcond);
|
86
|
+
static VALUE db_err_msg(VALUE vself, VALUE vecode);
|
87
|
+
static VALUE db_open(VALUE vself, VALUE vname, VALUE vomode);
|
88
|
+
static VALUE db_close(VALUE vself);
|
89
|
+
static VALUE db_error(VALUE vself);
|
90
|
+
static VALUE db_fatal(VALUE vself);
|
91
|
+
static VALUE db_add_attr_index(VALUE vself, VALUE vname, VALUE vtype);
|
92
|
+
static VALUE db_flush(VALUE vself, VALUE vmax);
|
93
|
+
static VALUE db_sync(VALUE vself);
|
94
|
+
static VALUE db_optimize(VALUE vself, VALUE voptions);
|
95
|
+
static VALUE db_merge(VALUE vself, VALUE vname, VALUE voptions);
|
96
|
+
static VALUE db_put_doc(VALUE vself, VALUE vdoc, VALUE voptions);
|
97
|
+
static VALUE db_out_doc(VALUE vself, VALUE vid, VALUE voptions);
|
98
|
+
static VALUE db_edit_doc(VALUE vself, VALUE vdoc);
|
99
|
+
static VALUE db_get_doc(VALUE vself, VALUE vid, VALUE voptions);
|
100
|
+
static VALUE db_get_doc_attr(VALUE vself, VALUE vid, VALUE vname);
|
101
|
+
static VALUE db_uri_to_id(VALUE vself, VALUE vuri);
|
102
|
+
static VALUE db_name(VALUE vself);
|
103
|
+
static VALUE db_doc_num(VALUE vself);
|
104
|
+
static VALUE db_word_num(VALUE vself);
|
105
|
+
static VALUE db_size(VALUE vself);
|
106
|
+
static VALUE db_search(VALUE vself, VALUE vcond);
|
107
|
+
static VALUE db_scan_doc(VALUE vself, VALUE vdoc, VALUE vcond);
|
108
|
+
static VALUE db_set_cache_size(VALUE vself, VALUE vsize, VALUE vanum, VALUE vtnum, VALUE vrnum);
|
109
|
+
static VALUE db_add_pseudo_index(VALUE vself, VALUE vpath);
|
110
|
+
static VALUE db_set_wildmax(VALUE vself, VALUE vnum);
|
111
|
+
static VALUE db_set_informer(VALUE vself, VALUE vinformer);
|
112
|
+
static VALUE cblisttoobj(const CBLIST *list);
|
113
|
+
static CBLIST *objtocblist(VALUE obj);
|
114
|
+
static VALUE cbmaptoobj(CBMAP *map);
|
115
|
+
static CBMAP *objtocbmap(VALUE obj);
|
116
|
+
static void db_informer(const char *message, void *opaque);
|
117
|
+
static VALUE db_informer_process(VALUE arg);
|
118
|
+
static VALUE db_informer_resque(VALUE arg);
|
119
|
+
|
120
|
+
|
121
|
+
|
122
|
+
/*************************************************************************************************
|
123
|
+
* public objects
|
124
|
+
*************************************************************************************************/
|
125
|
+
|
126
|
+
|
127
|
+
VALUE mod_estraier;
|
128
|
+
VALUE cls_doc;
|
129
|
+
VALUE cls_doc_data;
|
130
|
+
VALUE cls_cond;
|
131
|
+
VALUE cls_cond_data;
|
132
|
+
VALUE cls_res;
|
133
|
+
VALUE cls_res_data;
|
134
|
+
VALUE cls_db;
|
135
|
+
VALUE cls_db_data;
|
136
|
+
|
137
|
+
|
138
|
+
int Init_estraier(void){
|
139
|
+
mod_estraier = rb_define_module("Estraier");
|
140
|
+
doc_init();
|
141
|
+
cond_init();
|
142
|
+
res_init();
|
143
|
+
db_init();
|
144
|
+
return 0;
|
145
|
+
}
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
/*************************************************************************************************
|
150
|
+
* private objects
|
151
|
+
*************************************************************************************************/
|
152
|
+
|
153
|
+
|
154
|
+
static void doc_init(void){
|
155
|
+
cls_doc = rb_define_class_under(mod_estraier, "Document", rb_cObject);
|
156
|
+
cls_doc_data = rb_define_class_under(mod_estraier, "Document_data", rb_cObject);
|
157
|
+
rb_define_private_method(cls_doc, "initialize", doc_initialize, -1);
|
158
|
+
rb_define_method(cls_doc, "add_attr", doc_add_attr, 2);
|
159
|
+
rb_define_method(cls_doc, "add_text", doc_add_text, 1);
|
160
|
+
rb_define_method(cls_doc, "add_hidden_text", doc_add_hidden_text, 1);
|
161
|
+
rb_define_method(cls_doc, "set_keywords", doc_set_keywords, 1);
|
162
|
+
rb_define_method(cls_doc, "set_score", doc_set_score, 1);
|
163
|
+
rb_define_method(cls_doc, "id", doc_id, 0);
|
164
|
+
rb_define_method(cls_doc, "attr_names", doc_attr_names, 0);
|
165
|
+
rb_define_method(cls_doc, "attr", doc_attr, 1);
|
166
|
+
rb_define_method(cls_doc, "texts", doc_texts, 0);
|
167
|
+
rb_define_method(cls_doc, "cat_texts", doc_cat_texts, 0);
|
168
|
+
rb_define_method(cls_doc, "keywords", doc_keywords, 0);
|
169
|
+
rb_define_method(cls_doc, "score", doc_score, 0);
|
170
|
+
rb_define_method(cls_doc, "dump_draft", doc_dump_draft, 0);
|
171
|
+
rb_define_method(cls_doc, "make_snippet", doc_make_snippet, 4);
|
172
|
+
}
|
173
|
+
|
174
|
+
|
175
|
+
static VALUE doc_initialize(int argc, VALUE *argv, VALUE vself){
|
176
|
+
VALUE vdraft, vdoc;
|
177
|
+
ESTDOC *doc;
|
178
|
+
rb_scan_args(argc, argv, "01", &vdraft);
|
179
|
+
if(vdraft != Qnil){
|
180
|
+
Check_Type(vdraft, T_STRING);
|
181
|
+
doc = est_doc_new_from_draft(StringValuePtr(vdraft));
|
182
|
+
} else {
|
183
|
+
doc = est_doc_new();
|
184
|
+
}
|
185
|
+
vdoc = Data_Wrap_Struct(cls_doc_data, 0, est_doc_delete, doc);
|
186
|
+
rb_iv_set(vself, VNDATA, vdoc);
|
187
|
+
return Qnil;
|
188
|
+
}
|
189
|
+
|
190
|
+
|
191
|
+
static VALUE doc_add_attr(VALUE vself, VALUE vname, VALUE vvalue){
|
192
|
+
VALUE vdoc;
|
193
|
+
ESTDOC *doc;
|
194
|
+
const char *value;
|
195
|
+
vdoc = rb_iv_get(vself, VNDATA);
|
196
|
+
Data_Get_Struct(vdoc, ESTDOC, doc);
|
197
|
+
Check_Type(vname, T_STRING);
|
198
|
+
if(vvalue != Qnil){
|
199
|
+
Check_Type(vvalue, T_STRING);
|
200
|
+
value = StringValuePtr(vvalue);
|
201
|
+
} else {
|
202
|
+
value = NULL;
|
203
|
+
}
|
204
|
+
est_doc_add_attr(doc, StringValuePtr(vname), value);
|
205
|
+
return Qnil;
|
206
|
+
}
|
207
|
+
|
208
|
+
|
209
|
+
static VALUE doc_add_text(VALUE vself, VALUE vtext){
|
210
|
+
VALUE vdoc;
|
211
|
+
ESTDOC *doc;
|
212
|
+
vdoc = rb_iv_get(vself, VNDATA);
|
213
|
+
Data_Get_Struct(vdoc, ESTDOC, doc);
|
214
|
+
Check_Type(vtext, T_STRING);
|
215
|
+
est_doc_add_text(doc, StringValuePtr(vtext));
|
216
|
+
return Qnil;
|
217
|
+
}
|
218
|
+
|
219
|
+
|
220
|
+
static VALUE doc_add_hidden_text(VALUE vself, VALUE vtext){
|
221
|
+
VALUE vdoc;
|
222
|
+
ESTDOC *doc;
|
223
|
+
vdoc = rb_iv_get(vself, VNDATA);
|
224
|
+
Data_Get_Struct(vdoc, ESTDOC, doc);
|
225
|
+
Check_Type(vtext, T_STRING);
|
226
|
+
est_doc_add_hidden_text(doc, StringValuePtr(vtext));
|
227
|
+
return Qnil;
|
228
|
+
}
|
229
|
+
|
230
|
+
|
231
|
+
static VALUE doc_set_keywords(VALUE vself, VALUE vkwords){
|
232
|
+
VALUE vdoc;
|
233
|
+
ESTDOC *doc;
|
234
|
+
CBMAP *kwords;
|
235
|
+
vdoc = rb_iv_get(vself, VNDATA);
|
236
|
+
Data_Get_Struct(vdoc, ESTDOC, doc);
|
237
|
+
Check_Type(vkwords, T_HASH);
|
238
|
+
kwords = objtocbmap(vkwords);
|
239
|
+
est_doc_set_keywords(doc, kwords);
|
240
|
+
cbmapclose(kwords);
|
241
|
+
return Qnil;
|
242
|
+
}
|
243
|
+
|
244
|
+
|
245
|
+
static VALUE doc_set_score(VALUE vself, VALUE vscore){
|
246
|
+
VALUE vdoc;
|
247
|
+
ESTDOC *doc;
|
248
|
+
vdoc = rb_iv_get(vself, VNDATA);
|
249
|
+
Data_Get_Struct(vdoc, ESTDOC, doc);
|
250
|
+
est_doc_set_score(doc, NUM2INT(vscore));
|
251
|
+
return Qnil;
|
252
|
+
}
|
253
|
+
|
254
|
+
|
255
|
+
static VALUE doc_id(VALUE vself){
|
256
|
+
VALUE vdoc;
|
257
|
+
ESTDOC *doc;
|
258
|
+
vdoc = rb_iv_get(vself, VNDATA);
|
259
|
+
Data_Get_Struct(vdoc, ESTDOC, doc);
|
260
|
+
return INT2NUM(est_doc_id(doc));
|
261
|
+
}
|
262
|
+
|
263
|
+
|
264
|
+
static VALUE doc_attr_names(VALUE vself){
|
265
|
+
VALUE vdoc, vnames;
|
266
|
+
ESTDOC *doc;
|
267
|
+
CBLIST *names;
|
268
|
+
vdoc = rb_iv_get(vself, VNDATA);
|
269
|
+
Data_Get_Struct(vdoc, ESTDOC, doc);
|
270
|
+
names = est_doc_attr_names(doc);
|
271
|
+
vnames = cblisttoobj(names);
|
272
|
+
cblistclose(names);
|
273
|
+
return vnames;
|
274
|
+
}
|
275
|
+
|
276
|
+
|
277
|
+
static VALUE doc_attr(VALUE vself, VALUE vname){
|
278
|
+
VALUE vdoc;
|
279
|
+
ESTDOC *doc;
|
280
|
+
const char *value;
|
281
|
+
vdoc = rb_iv_get(vself, VNDATA);
|
282
|
+
Data_Get_Struct(vdoc, ESTDOC, doc);
|
283
|
+
Check_Type(vname, T_STRING);
|
284
|
+
value = est_doc_attr(doc, StringValuePtr(vname));
|
285
|
+
return value ? rb_str_new2(value) : Qnil;
|
286
|
+
}
|
287
|
+
|
288
|
+
|
289
|
+
static VALUE doc_texts(VALUE vself){
|
290
|
+
VALUE vdoc;
|
291
|
+
ESTDOC *doc;
|
292
|
+
vdoc = rb_iv_get(vself, VNDATA);
|
293
|
+
Data_Get_Struct(vdoc, ESTDOC, doc);
|
294
|
+
return cblisttoobj(est_doc_texts(doc));
|
295
|
+
}
|
296
|
+
|
297
|
+
|
298
|
+
static VALUE doc_cat_texts(VALUE vself){
|
299
|
+
VALUE vdoc, vtexts;
|
300
|
+
ESTDOC *doc;
|
301
|
+
char *texts;
|
302
|
+
vdoc = rb_iv_get(vself, VNDATA);
|
303
|
+
Data_Get_Struct(vdoc, ESTDOC, doc);
|
304
|
+
texts = est_doc_cat_texts(doc);
|
305
|
+
vtexts = rb_str_new2(texts);
|
306
|
+
free(texts);
|
307
|
+
return vtexts;
|
308
|
+
}
|
309
|
+
|
310
|
+
|
311
|
+
static VALUE doc_keywords(VALUE vself){
|
312
|
+
VALUE vdoc;
|
313
|
+
ESTDOC *doc;
|
314
|
+
CBMAP *kwords;
|
315
|
+
vdoc = rb_iv_get(vself, VNDATA);
|
316
|
+
Data_Get_Struct(vdoc, ESTDOC, doc);
|
317
|
+
if(!(kwords = est_doc_keywords(doc))) return Qnil;
|
318
|
+
return cbmaptoobj(kwords);
|
319
|
+
}
|
320
|
+
|
321
|
+
|
322
|
+
static VALUE doc_score(VALUE vself){
|
323
|
+
VALUE vdoc;
|
324
|
+
ESTDOC *doc;
|
325
|
+
vdoc = rb_iv_get(vself, VNDATA);
|
326
|
+
Data_Get_Struct(vdoc, ESTDOC, doc);
|
327
|
+
return INT2NUM(est_doc_score(doc));
|
328
|
+
}
|
329
|
+
|
330
|
+
|
331
|
+
static VALUE doc_dump_draft(VALUE vself){
|
332
|
+
VALUE vdoc, vdraft;
|
333
|
+
ESTDOC *doc;
|
334
|
+
char *draft;
|
335
|
+
vdoc = rb_iv_get(vself, VNDATA);
|
336
|
+
Data_Get_Struct(vdoc, ESTDOC, doc);
|
337
|
+
draft = est_doc_dump_draft(doc);
|
338
|
+
vdraft = rb_str_new2(draft);
|
339
|
+
free(draft);
|
340
|
+
return vdraft;
|
341
|
+
}
|
342
|
+
|
343
|
+
|
344
|
+
static VALUE doc_make_snippet(VALUE vself, VALUE vwords,
|
345
|
+
VALUE vwwidth, VALUE vhwidth, VALUE vawidth){
|
346
|
+
VALUE vdoc, vsnippet;
|
347
|
+
ESTDOC *doc;
|
348
|
+
CBLIST *words;
|
349
|
+
int i, len;
|
350
|
+
char *snippet;
|
351
|
+
vdoc = rb_iv_get(vself, VNDATA);
|
352
|
+
Data_Get_Struct(vdoc, ESTDOC, doc);
|
353
|
+
Check_Type(vwords, T_ARRAY);
|
354
|
+
len = RARRAY(vwords)->len;
|
355
|
+
for(i = 0; i < len; i++){
|
356
|
+
Check_Type(rb_ary_entry(vwords, i), T_STRING);
|
357
|
+
}
|
358
|
+
words = objtocblist(vwords);
|
359
|
+
snippet = est_doc_make_snippet(doc, words,
|
360
|
+
NUM2INT(vwwidth), NUM2INT(vhwidth), NUM2INT(vawidth));
|
361
|
+
vsnippet = rb_str_new2(snippet);
|
362
|
+
free(snippet);
|
363
|
+
cblistclose(words);
|
364
|
+
return vsnippet;
|
365
|
+
}
|
366
|
+
|
367
|
+
|
368
|
+
static void cond_init(void){
|
369
|
+
cls_cond = rb_define_class_under(mod_estraier, "Condition", rb_cObject);
|
370
|
+
cls_cond_data = rb_define_class_under(mod_estraier, "Condition_data", rb_cObject);
|
371
|
+
rb_define_const(cls_cond, "SURE", INT2NUM(ESTCONDSURE));
|
372
|
+
rb_define_const(cls_cond, "USUAL", INT2NUM(ESTCONDUSUAL));
|
373
|
+
rb_define_const(cls_cond, "FAST", INT2NUM(ESTCONDFAST));
|
374
|
+
rb_define_const(cls_cond, "AGITO", INT2NUM(ESTCONDAGITO));
|
375
|
+
rb_define_const(cls_cond, "NOIDF", INT2NUM(ESTCONDNOIDF));
|
376
|
+
rb_define_const(cls_cond, "SIMPLE", INT2NUM(ESTCONDSIMPLE));
|
377
|
+
rb_define_const(cls_cond, "ROUGH", INT2NUM(ESTCONDROUGH));
|
378
|
+
rb_define_const(cls_cond, "UNION", INT2NUM(ESTCONDUNION));
|
379
|
+
rb_define_const(cls_cond, "ISECT", INT2NUM(ESTCONDISECT));
|
380
|
+
rb_define_const(cls_cond, "ECLSIMURL", rb_float_new(ESTECLSIMURL));
|
381
|
+
rb_define_const(cls_cond, "ECLSERV", rb_float_new(ESTECLSERV));
|
382
|
+
rb_define_const(cls_cond, "ECLDIR", rb_float_new(ESTECLDIR));
|
383
|
+
rb_define_const(cls_cond, "ECLFILE", rb_float_new(ESTECLFILE));
|
384
|
+
rb_define_private_method(cls_cond, "initialize", cond_initialize, 0);
|
385
|
+
rb_define_method(cls_cond, "set_phrase", cond_set_phrase, 1);
|
386
|
+
rb_define_method(cls_cond, "add_attr", cond_add_attr, 1);
|
387
|
+
rb_define_method(cls_cond, "set_order", cond_set_order, 1);
|
388
|
+
rb_define_method(cls_cond, "set_max", cond_set_max, 1);
|
389
|
+
rb_define_method(cls_cond, "set_skip", cond_set_skip, 1);
|
390
|
+
rb_define_method(cls_cond, "set_options", cond_set_options, 1);
|
391
|
+
rb_define_method(cls_cond, "set_auxiliary", cond_set_auxiliary, 1);
|
392
|
+
rb_define_method(cls_cond, "set_eclipse", cond_set_eclipse, 1);
|
393
|
+
rb_define_method(cls_cond, "set_distinct", cond_set_distinct, 1);
|
394
|
+
rb_define_method(cls_cond, "set_mask", cond_set_mask, 1);
|
395
|
+
}
|
396
|
+
|
397
|
+
|
398
|
+
static VALUE cond_initialize(VALUE vself){
|
399
|
+
VALUE vcond;
|
400
|
+
ESTCOND *cond;
|
401
|
+
cond = est_cond_new();
|
402
|
+
est_cond_set_options(cond, ESTCONDSCFB);
|
403
|
+
vcond = Data_Wrap_Struct(cls_cond_data, 0, est_cond_delete, cond);
|
404
|
+
rb_iv_set(vself, VNDATA, vcond);
|
405
|
+
return Qnil;
|
406
|
+
}
|
407
|
+
|
408
|
+
|
409
|
+
static VALUE cond_set_phrase(VALUE vself, VALUE vphrase){
|
410
|
+
VALUE vcond;
|
411
|
+
ESTCOND *cond;
|
412
|
+
vcond = rb_iv_get(vself, VNDATA);
|
413
|
+
Data_Get_Struct(vcond, ESTCOND, cond);
|
414
|
+
Check_Type(vphrase, T_STRING);
|
415
|
+
est_cond_set_phrase(cond, StringValuePtr(vphrase));
|
416
|
+
return Qnil;
|
417
|
+
}
|
418
|
+
|
419
|
+
|
420
|
+
static VALUE cond_add_attr(VALUE vself, VALUE vexpr){
|
421
|
+
VALUE vcond;
|
422
|
+
ESTCOND *cond;
|
423
|
+
vcond = rb_iv_get(vself, VNDATA);
|
424
|
+
Data_Get_Struct(vcond, ESTCOND, cond);
|
425
|
+
Check_Type(vexpr, T_STRING);
|
426
|
+
est_cond_add_attr(cond, StringValuePtr(vexpr));
|
427
|
+
return Qnil;
|
428
|
+
}
|
429
|
+
|
430
|
+
|
431
|
+
static VALUE cond_set_order(VALUE vself, VALUE vexpr){
|
432
|
+
VALUE vcond;
|
433
|
+
ESTCOND *cond;
|
434
|
+
vcond = rb_iv_get(vself, VNDATA);
|
435
|
+
Data_Get_Struct(vcond, ESTCOND, cond);
|
436
|
+
Check_Type(vexpr, T_STRING);
|
437
|
+
est_cond_set_order(cond, StringValuePtr(vexpr));
|
438
|
+
return Qnil;
|
439
|
+
}
|
440
|
+
|
441
|
+
|
442
|
+
static VALUE cond_set_max(VALUE vself, VALUE vmax){
|
443
|
+
VALUE vcond;
|
444
|
+
ESTCOND *cond;
|
445
|
+
int max;
|
446
|
+
vcond = rb_iv_get(vself, VNDATA);
|
447
|
+
Data_Get_Struct(vcond, ESTCOND, cond);
|
448
|
+
max = NUM2INT(vmax);
|
449
|
+
if(max < 0) rb_raise(rb_eArgError, "invalid argument");
|
450
|
+
est_cond_set_max(cond, max);
|
451
|
+
return Qnil;
|
452
|
+
}
|
453
|
+
|
454
|
+
|
455
|
+
static VALUE cond_set_skip(VALUE vself, VALUE vskip){
|
456
|
+
VALUE vcond;
|
457
|
+
ESTCOND *cond;
|
458
|
+
int skip;
|
459
|
+
vcond = rb_iv_get(vself, VNDATA);
|
460
|
+
Data_Get_Struct(vcond, ESTCOND, cond);
|
461
|
+
skip = NUM2INT(vskip);
|
462
|
+
if(skip < 0) rb_raise(rb_eArgError, "invalid argument");
|
463
|
+
est_cond_set_skip(cond, skip);
|
464
|
+
return Qnil;
|
465
|
+
}
|
466
|
+
|
467
|
+
|
468
|
+
static VALUE cond_set_options(VALUE vself, VALUE voptions){
|
469
|
+
VALUE vcond;
|
470
|
+
ESTCOND *cond;
|
471
|
+
vcond = rb_iv_get(vself, VNDATA);
|
472
|
+
Data_Get_Struct(vcond, ESTCOND, cond);
|
473
|
+
est_cond_set_options(cond, NUM2INT(voptions));
|
474
|
+
return Qnil;
|
475
|
+
}
|
476
|
+
|
477
|
+
|
478
|
+
static VALUE cond_set_auxiliary(VALUE vself, VALUE vmin){
|
479
|
+
VALUE vcond;
|
480
|
+
ESTCOND *cond;
|
481
|
+
vcond = rb_iv_get(vself, VNDATA);
|
482
|
+
Data_Get_Struct(vcond, ESTCOND, cond);
|
483
|
+
est_cond_set_auxiliary(cond, NUM2INT(vmin));
|
484
|
+
return Qnil;
|
485
|
+
}
|
486
|
+
|
487
|
+
|
488
|
+
static VALUE cond_set_eclipse(VALUE vself, VALUE vlimit){
|
489
|
+
VALUE vcond;
|
490
|
+
ESTCOND *cond;
|
491
|
+
vcond = rb_iv_get(vself, VNDATA);
|
492
|
+
Data_Get_Struct(vcond, ESTCOND, cond);
|
493
|
+
est_cond_set_eclipse(cond, NUM2DBL(vlimit));
|
494
|
+
return Qnil;
|
495
|
+
}
|
496
|
+
|
497
|
+
|
498
|
+
static VALUE cond_set_distinct(VALUE vself, VALUE vname){
|
499
|
+
VALUE vcond;
|
500
|
+
ESTCOND *cond;
|
501
|
+
vcond = rb_iv_get(vself, VNDATA);
|
502
|
+
Data_Get_Struct(vcond, ESTCOND, cond);
|
503
|
+
Check_Type(vname, T_STRING);
|
504
|
+
est_cond_set_distinct(cond, StringValuePtr(vname));
|
505
|
+
return Qnil;
|
506
|
+
}
|
507
|
+
|
508
|
+
|
509
|
+
static VALUE cond_set_mask(VALUE vself, VALUE vmask){
|
510
|
+
VALUE vcond;
|
511
|
+
ESTCOND *cond;
|
512
|
+
vcond = rb_iv_get(vself, VNDATA);
|
513
|
+
Data_Get_Struct(vcond, ESTCOND, cond);
|
514
|
+
est_cond_set_mask(cond, NUM2INT(vmask));
|
515
|
+
return Qnil;
|
516
|
+
}
|
517
|
+
|
518
|
+
|
519
|
+
static void res_init(void){
|
520
|
+
cls_res = rb_define_class_under(mod_estraier, "Result", rb_cObject);
|
521
|
+
cls_res_data = rb_define_class_under(mod_estraier, "Result_data", rb_cObject);
|
522
|
+
rb_define_private_method(cls_res, "initialize", res_initialize, 0);
|
523
|
+
rb_define_method(cls_res, "doc_num", res_doc_num, 0);
|
524
|
+
rb_define_method(cls_res, "get_doc_id", res_get_doc_id, 1);
|
525
|
+
rb_define_method(cls_res, "get_dbidx", res_get_dbidx, 1);
|
526
|
+
rb_define_method(cls_res, "hint_words", res_hint_words, 0);
|
527
|
+
rb_define_method(cls_res, "hint", res_hint, 1);
|
528
|
+
rb_define_method(cls_res, "get_score", res_get_score, 1);
|
529
|
+
rb_define_method(cls_res, "get_shadows", res_get_shadows, 1);
|
530
|
+
}
|
531
|
+
|
532
|
+
|
533
|
+
static VALUE res_initialize(VALUE vself){
|
534
|
+
VALUE vres;
|
535
|
+
ESTRES *res;
|
536
|
+
res = est_res_new();
|
537
|
+
vres = Data_Wrap_Struct(cls_res_data, 0, est_res_delete, res);
|
538
|
+
rb_iv_set(vself, VNDATA, vres);
|
539
|
+
return Qnil;
|
540
|
+
}
|
541
|
+
|
542
|
+
|
543
|
+
static ESTRES *est_res_new(void){
|
544
|
+
ESTRES *res;
|
545
|
+
res = cbmalloc(sizeof(ESTRES));
|
546
|
+
res->ids = NULL;
|
547
|
+
res->dbidxs = NULL;
|
548
|
+
res->num = 0;
|
549
|
+
res->hints = NULL;
|
550
|
+
return res;
|
551
|
+
}
|
552
|
+
|
553
|
+
|
554
|
+
static void est_res_delete(ESTRES *res){
|
555
|
+
if(res->hints) cbmapclose(res->hints);
|
556
|
+
if(res->dbidxs) free(res->dbidxs);
|
557
|
+
if(res->ids) free(res->ids);
|
558
|
+
free(res);
|
559
|
+
}
|
560
|
+
|
561
|
+
|
562
|
+
static VALUE res_doc_num(VALUE vself){
|
563
|
+
VALUE vres;
|
564
|
+
ESTRES *res;
|
565
|
+
vres = rb_iv_get(vself, VNDATA);
|
566
|
+
Data_Get_Struct(vres, ESTRES, res);
|
567
|
+
return INT2NUM(res->num);
|
568
|
+
}
|
569
|
+
|
570
|
+
|
571
|
+
static VALUE res_get_doc_id(VALUE vself, VALUE vindex){
|
572
|
+
VALUE vres;
|
573
|
+
ESTRES *res;
|
574
|
+
int index;
|
575
|
+
vres = rb_iv_get(vself, VNDATA);
|
576
|
+
Data_Get_Struct(vres, ESTRES, res);
|
577
|
+
index = NUM2INT(vindex);
|
578
|
+
if(!res->ids || index < 0 || index >= res->num) return -1;
|
579
|
+
return INT2NUM(res->ids[index]);
|
580
|
+
}
|
581
|
+
|
582
|
+
|
583
|
+
static VALUE res_get_dbidx(VALUE vself, VALUE vindex){
|
584
|
+
VALUE vres;
|
585
|
+
ESTRES *res;
|
586
|
+
int index;
|
587
|
+
vres = rb_iv_get(vself, VNDATA);
|
588
|
+
Data_Get_Struct(vres, ESTRES, res);
|
589
|
+
index = NUM2INT(vindex);
|
590
|
+
if(!res->dbidxs || index < 0 || index >= res->num) return -1;
|
591
|
+
return INT2NUM(res->dbidxs[index]);
|
592
|
+
}
|
593
|
+
|
594
|
+
|
595
|
+
static VALUE res_hint_words(VALUE vself){
|
596
|
+
VALUE vres, vwords;
|
597
|
+
ESTRES *res;
|
598
|
+
CBLIST *words;
|
599
|
+
const char *vbuf;
|
600
|
+
int i;
|
601
|
+
vres = rb_iv_get(vself, VNDATA);
|
602
|
+
Data_Get_Struct(vres, ESTRES, res);
|
603
|
+
if(!res->hints) return rb_ary_new();
|
604
|
+
words = cbmapkeys(res->hints);
|
605
|
+
for(i = 0; i < cblistnum(words); i++){
|
606
|
+
vbuf = cblistval(words, i, NULL);
|
607
|
+
if(vbuf[0] == '\0'){
|
608
|
+
free(cblistremove(words, i, NULL));
|
609
|
+
break;
|
610
|
+
}
|
611
|
+
}
|
612
|
+
vwords = cblisttoobj(words);
|
613
|
+
cblistclose(words);
|
614
|
+
return vwords;
|
615
|
+
}
|
616
|
+
|
617
|
+
|
618
|
+
static VALUE res_hint(VALUE vself, VALUE vword){
|
619
|
+
VALUE vres;
|
620
|
+
ESTRES *res;
|
621
|
+
const char *value;
|
622
|
+
vres = rb_iv_get(vself, VNDATA);
|
623
|
+
Data_Get_Struct(vres, ESTRES, res);
|
624
|
+
Check_Type(vword, T_STRING);
|
625
|
+
if(!res->hints) return INT2NUM(0);
|
626
|
+
if(!(value = cbmapget(res->hints, StringValuePtr(vword), -1, NULL))) return INT2NUM(0);
|
627
|
+
return INT2NUM(atoi(value));
|
628
|
+
}
|
629
|
+
|
630
|
+
|
631
|
+
static VALUE res_get_score(VALUE vself, VALUE vindex){
|
632
|
+
VALUE vres, vcond;
|
633
|
+
ESTRES *res;
|
634
|
+
ESTCOND *cond;
|
635
|
+
vres = rb_iv_get(vself, VNDATA);
|
636
|
+
Data_Get_Struct(vres, ESTRES, res);
|
637
|
+
vcond = rb_iv_get(vself, VNCOND);
|
638
|
+
Data_Get_Struct(vcond, ESTCOND, cond);
|
639
|
+
return INT2NUM(est_cond_score(cond, NUM2INT(vindex)));
|
640
|
+
}
|
641
|
+
|
642
|
+
|
643
|
+
static VALUE res_get_shadows(VALUE vself, VALUE vid){
|
644
|
+
VALUE vres, vcond, vary;
|
645
|
+
ESTRES *res;
|
646
|
+
ESTCOND *cond;
|
647
|
+
const int *ary;
|
648
|
+
int i, anum;
|
649
|
+
vres = rb_iv_get(vself, VNDATA);
|
650
|
+
Data_Get_Struct(vres, ESTRES, res);
|
651
|
+
vcond = rb_iv_get(vself, VNCOND);
|
652
|
+
Data_Get_Struct(vcond, ESTCOND, cond);
|
653
|
+
ary = est_cond_shadows(cond, NUM2INT(vid), &anum);
|
654
|
+
vary = rb_ary_new2(anum);
|
655
|
+
for(i = 0; i < anum; i++){
|
656
|
+
rb_ary_push(vary, INT2NUM(ary[i]));
|
657
|
+
}
|
658
|
+
return vary;
|
659
|
+
}
|
660
|
+
|
661
|
+
|
662
|
+
static void db_init(void){
|
663
|
+
cls_db = rb_define_class_under(mod_estraier, "Database", rb_cObject);
|
664
|
+
cls_db_data = rb_define_class_under(mod_estraier, "Database_data", rb_cObject);
|
665
|
+
rb_define_const(cls_db, "VERSION", rb_str_new2(est_version));
|
666
|
+
rb_define_const(cls_db, "ERRNOERR", INT2NUM(ESTENOERR));
|
667
|
+
rb_define_const(cls_db, "ERRINVAL", INT2NUM(ESTEINVAL));
|
668
|
+
rb_define_const(cls_db, "ERRACCES", INT2NUM(ESTEACCES));
|
669
|
+
rb_define_const(cls_db, "ERRLOCK", INT2NUM(ESTELOCK));
|
670
|
+
rb_define_const(cls_db, "ERRDB", INT2NUM(ESTEDB));
|
671
|
+
rb_define_const(cls_db, "ERRIO", INT2NUM(ESTEIO));
|
672
|
+
rb_define_const(cls_db, "ERRNOITEM", INT2NUM(ESTENOITEM));
|
673
|
+
rb_define_const(cls_db, "ERRMISC", INT2NUM(ESTEMISC));
|
674
|
+
rb_define_const(cls_db, "DBREADER", INT2NUM(ESTDBREADER));
|
675
|
+
rb_define_const(cls_db, "DBWRITER", INT2NUM(ESTDBWRITER));
|
676
|
+
rb_define_const(cls_db, "DBCREAT", INT2NUM(ESTDBCREAT));
|
677
|
+
rb_define_const(cls_db, "DBTRUNC", INT2NUM(ESTDBTRUNC));
|
678
|
+
rb_define_const(cls_db, "DBNOLCK", INT2NUM(ESTDBNOLCK));
|
679
|
+
rb_define_const(cls_db, "DBLCKNB", INT2NUM(ESTDBLCKNB));
|
680
|
+
rb_define_const(cls_db, "DBPERFNG", INT2NUM(ESTDBPERFNG));
|
681
|
+
rb_define_const(cls_db, "DBCHRCAT", INT2NUM(ESTDBCHRCAT));
|
682
|
+
rb_define_const(cls_db, "DBSMALL", INT2NUM(ESTDBSMALL));
|
683
|
+
rb_define_const(cls_db, "DBLARGE", INT2NUM(ESTDBLARGE));
|
684
|
+
rb_define_const(cls_db, "DBHUGE", INT2NUM(ESTDBHUGE));
|
685
|
+
rb_define_const(cls_db, "DBHUGE2", INT2NUM(ESTDBHUGE2));
|
686
|
+
rb_define_const(cls_db, "DBHUGE3", INT2NUM(ESTDBHUGE3));
|
687
|
+
rb_define_const(cls_db, "DBSCVOID", INT2NUM(ESTDBSCVOID));
|
688
|
+
rb_define_const(cls_db, "DBSCINT", INT2NUM(ESTDBSCINT));
|
689
|
+
rb_define_const(cls_db, "DBSCASIS", INT2NUM(ESTDBSCASIS));
|
690
|
+
rb_define_const(cls_db, "IDXATTRSEQ", INT2NUM(ESTIDXATTRSEQ));
|
691
|
+
rb_define_const(cls_db, "IDXATTRSTR", INT2NUM(ESTIDXATTRSTR));
|
692
|
+
rb_define_const(cls_db, "IDXATTRNUM", INT2NUM(ESTIDXATTRNUM));
|
693
|
+
rb_define_const(cls_db, "OPTNOPURGE", INT2NUM(ESTOPTNOPURGE));
|
694
|
+
rb_define_const(cls_db, "OPTNODBOPT", INT2NUM(ESTOPTNODBOPT));
|
695
|
+
rb_define_const(cls_db, "MGCLEAN", INT2NUM(ESTMGCLEAN));
|
696
|
+
rb_define_const(cls_db, "PDCLEAN", INT2NUM(ESTPDCLEAN));
|
697
|
+
rb_define_const(cls_db, "PDWEIGHT", INT2NUM(ESTPDWEIGHT));
|
698
|
+
rb_define_const(cls_db, "ODCLEAN", INT2NUM(ESTODCLEAN));
|
699
|
+
rb_define_const(cls_db, "GDNOATTR", INT2NUM(ESTGDNOATTR));
|
700
|
+
rb_define_const(cls_db, "GDNOTEXT", INT2NUM(ESTGDNOTEXT));
|
701
|
+
rb_define_const(cls_db, "GDNOKWD", INT2NUM(ESTGDNOKWD));
|
702
|
+
rb_define_private_method(cls_db, "initialize", db_initialize, 0);
|
703
|
+
rb_define_singleton_method(cls_db, "search_meta", db_search_meta, 2);
|
704
|
+
rb_define_method(cls_db, "err_msg", db_err_msg, 1);
|
705
|
+
rb_define_method(cls_db, "open", db_open, 2);
|
706
|
+
rb_define_method(cls_db, "close", db_close, 0);
|
707
|
+
rb_define_method(cls_db, "error", db_error, 0);
|
708
|
+
rb_define_method(cls_db, "fatal", db_fatal, 0);
|
709
|
+
rb_define_method(cls_db, "add_attr_index", db_add_attr_index, 2);
|
710
|
+
rb_define_method(cls_db, "flush", db_flush, 1);
|
711
|
+
rb_define_method(cls_db, "sync", db_sync, 0);
|
712
|
+
rb_define_method(cls_db, "optimize", db_optimize, 1);
|
713
|
+
rb_define_method(cls_db, "merge", db_merge, 2);
|
714
|
+
rb_define_method(cls_db, "put_doc", db_put_doc, 2);
|
715
|
+
rb_define_method(cls_db, "out_doc", db_out_doc, 2);
|
716
|
+
rb_define_method(cls_db, "edit_doc", db_edit_doc, 1);
|
717
|
+
rb_define_method(cls_db, "get_doc", db_get_doc, 2);
|
718
|
+
rb_define_method(cls_db, "get_doc_attr", db_get_doc_attr, 2);
|
719
|
+
rb_define_method(cls_db, "uri_to_id", db_uri_to_id, 1);
|
720
|
+
rb_define_method(cls_db, "name", db_name, 0);
|
721
|
+
rb_define_method(cls_db, "doc_num", db_doc_num, 0);
|
722
|
+
rb_define_method(cls_db, "word_num", db_word_num, 0);
|
723
|
+
rb_define_method(cls_db, "size", db_size, 0);
|
724
|
+
rb_define_method(cls_db, "search", db_search, 1);
|
725
|
+
rb_define_method(cls_db, "scan_doc", db_scan_doc, 2);
|
726
|
+
rb_define_method(cls_db, "set_cache_size", db_set_cache_size, 4);
|
727
|
+
rb_define_method(cls_db, "add_pseudo_index", db_add_pseudo_index, 1);
|
728
|
+
rb_define_method(cls_db, "set_wildmax", db_set_wildmax, 1);
|
729
|
+
rb_define_method(cls_db, "set_informer", db_set_informer, 1);
|
730
|
+
}
|
731
|
+
|
732
|
+
|
733
|
+
static VALUE db_initialize(VALUE vself){
|
734
|
+
VALUE vdb;
|
735
|
+
ESTDBMGR *db;
|
736
|
+
db = est_dbmgr_new();
|
737
|
+
vdb = Data_Wrap_Struct(cls_db_data, 0, est_dbmgr_delete, db);
|
738
|
+
rb_iv_set(vself, VNDATA, vdb);
|
739
|
+
return Qnil;
|
740
|
+
}
|
741
|
+
|
742
|
+
|
743
|
+
static ESTDBMGR *est_dbmgr_new(void){
|
744
|
+
ESTDBMGR *db;
|
745
|
+
db = cbmalloc(sizeof(ESTDBMGR));
|
746
|
+
db->db = NULL;
|
747
|
+
db->ecode = ESTENOERR;
|
748
|
+
return db;
|
749
|
+
}
|
750
|
+
|
751
|
+
|
752
|
+
static void est_dbmgr_delete(ESTDBMGR *db){
|
753
|
+
if(db->db) est_mtdb_close(db->db, &(db->ecode));
|
754
|
+
free(db);
|
755
|
+
}
|
756
|
+
|
757
|
+
|
758
|
+
static VALUE db_search_meta(VALUE vself, VALUE vdbs, VALUE vcond){
|
759
|
+
VALUE vdb, vres, tres, tcond;
|
760
|
+
ESTDBMGR *db;
|
761
|
+
ESTRES *ores;
|
762
|
+
ESTCOND *cond;
|
763
|
+
ESTMTDB **dbs;
|
764
|
+
CBMAP *hints;
|
765
|
+
int i, dnum, *res, rnum;
|
766
|
+
Check_Type(vdbs, T_ARRAY);
|
767
|
+
dnum = RARRAY(vdbs)->len;
|
768
|
+
dbs = cbmalloc(dnum * sizeof(ESTMTDB *) + 1);
|
769
|
+
for(i = 0; i < dnum; i++){
|
770
|
+
vdb = rb_ary_entry(vdbs, i);
|
771
|
+
if(rb_obj_is_instance_of(vdb, cls_db) != Qtrue){
|
772
|
+
free(dbs);
|
773
|
+
rb_raise(rb_eArgError, "invalid argument");
|
774
|
+
}
|
775
|
+
Data_Get_Struct(rb_iv_get(vdb, VNDATA), ESTDBMGR, db);
|
776
|
+
if(!db->db){
|
777
|
+
free(dbs);
|
778
|
+
rb_raise(rb_eArgError, "invalid argument");
|
779
|
+
}
|
780
|
+
dbs[i] = db->db;
|
781
|
+
}
|
782
|
+
if(rb_obj_is_instance_of(vcond, cls_cond) != Qtrue){
|
783
|
+
free(dbs);
|
784
|
+
rb_raise(rb_eArgError, "invalid argument");
|
785
|
+
}
|
786
|
+
Data_Get_Struct(rb_iv_get(vcond, VNDATA), ESTCOND, cond);
|
787
|
+
hints = cbmapopenex(31);
|
788
|
+
res = est_mtdb_search_meta(dbs, dnum, cond, &rnum, hints);
|
789
|
+
ores = est_res_new();
|
790
|
+
ores->ids = res;
|
791
|
+
ores->dbidxs = cbmalloc(rnum / 2 * sizeof(int) + 1);
|
792
|
+
for(i = 0; i < rnum; i += 2){
|
793
|
+
ores->dbidxs[i/2] = res[i];
|
794
|
+
ores->ids[i/2] = res[i+1];
|
795
|
+
}
|
796
|
+
ores->num = rnum / 2;
|
797
|
+
ores->hints = hints;
|
798
|
+
vres = rb_funcall(cls_res, rb_intern("new"), 0);
|
799
|
+
tres = Data_Wrap_Struct(cls_res_data, 0, est_res_delete, ores);
|
800
|
+
rb_iv_set(vres, VNDATA, tres);
|
801
|
+
tcond = Data_Wrap_Struct(cls_cond_data, 0, est_cond_delete, est_cond_dup(cond));
|
802
|
+
rb_iv_set(vres, VNCOND, tcond);
|
803
|
+
free(dbs);
|
804
|
+
return vres;
|
805
|
+
}
|
806
|
+
|
807
|
+
|
808
|
+
static VALUE db_err_msg(VALUE vself, VALUE vecode){
|
809
|
+
return rb_str_new2(est_err_msg(NUM2INT(vecode)));
|
810
|
+
}
|
811
|
+
|
812
|
+
|
813
|
+
static VALUE db_open(VALUE vself, VALUE vname, VALUE vomode){
|
814
|
+
VALUE vdb;
|
815
|
+
ESTDBMGR *db;
|
816
|
+
vdb = rb_iv_get(vself, VNDATA);
|
817
|
+
Data_Get_Struct(vdb, ESTDBMGR, db);
|
818
|
+
if(db->db && !est_mtdb_close(db->db, &(db->ecode))){
|
819
|
+
db->db = NULL;
|
820
|
+
return Qfalse;
|
821
|
+
}
|
822
|
+
Check_Type(vname, T_STRING);
|
823
|
+
if(!(db->db = est_mtdb_open(StringValuePtr(vname), NUM2INT(vomode), &(db->ecode))))
|
824
|
+
return Qfalse;
|
825
|
+
return Qtrue;
|
826
|
+
}
|
827
|
+
|
828
|
+
|
829
|
+
static VALUE db_close(VALUE vself){
|
830
|
+
VALUE vdb;
|
831
|
+
ESTDBMGR *db;
|
832
|
+
vdb = rb_iv_get(vself, VNDATA);
|
833
|
+
Data_Get_Struct(vdb, ESTDBMGR, db);
|
834
|
+
if(!db->db) rb_raise(rb_eArgError, "invalid argument");
|
835
|
+
if(!est_mtdb_close(db->db, &(db->ecode))){
|
836
|
+
db->db = NULL;
|
837
|
+
return Qfalse;
|
838
|
+
}
|
839
|
+
db->db = NULL;
|
840
|
+
return Qtrue;
|
841
|
+
}
|
842
|
+
|
843
|
+
|
844
|
+
static VALUE db_error(VALUE vself){
|
845
|
+
VALUE vdb;
|
846
|
+
ESTDBMGR *db;
|
847
|
+
vdb = rb_iv_get(vself, VNDATA);
|
848
|
+
Data_Get_Struct(vdb, ESTDBMGR, db);
|
849
|
+
return INT2NUM(db->ecode);
|
850
|
+
}
|
851
|
+
|
852
|
+
|
853
|
+
static VALUE db_fatal(VALUE vself){
|
854
|
+
VALUE vdb;
|
855
|
+
ESTDBMGR *db;
|
856
|
+
vdb = rb_iv_get(vself, VNDATA);
|
857
|
+
Data_Get_Struct(vdb, ESTDBMGR, db);
|
858
|
+
if(!db->db) return Qfalse;
|
859
|
+
return est_mtdb_fatal(db->db) ? Qtrue : Qfalse;
|
860
|
+
}
|
861
|
+
|
862
|
+
|
863
|
+
static VALUE db_add_attr_index(VALUE vself, VALUE vname, VALUE vtype){
|
864
|
+
VALUE vdb;
|
865
|
+
ESTDBMGR *db;
|
866
|
+
vdb = rb_iv_get(vself, VNDATA);
|
867
|
+
Data_Get_Struct(vdb, ESTDBMGR, db);
|
868
|
+
if(!db->db) return Qfalse;
|
869
|
+
Check_Type(vname, T_STRING);
|
870
|
+
if(!est_mtdb_add_attr_index(db->db, StringValuePtr(vname), NUM2INT(vtype))){
|
871
|
+
db->ecode = est_mtdb_error(db->db);
|
872
|
+
return Qfalse;
|
873
|
+
}
|
874
|
+
return Qtrue;
|
875
|
+
}
|
876
|
+
|
877
|
+
|
878
|
+
static VALUE db_flush(VALUE vself, VALUE vmax){
|
879
|
+
VALUE vdb;
|
880
|
+
ESTDBMGR *db;
|
881
|
+
vdb = rb_iv_get(vself, VNDATA);
|
882
|
+
Data_Get_Struct(vdb, ESTDBMGR, db);
|
883
|
+
if(!db->db) rb_raise(rb_eArgError, "invalid argument");
|
884
|
+
if(!est_mtdb_flush(db->db, NUM2INT(vmax))){
|
885
|
+
db->ecode = est_mtdb_error(db->db);
|
886
|
+
return Qfalse;
|
887
|
+
}
|
888
|
+
return Qtrue;
|
889
|
+
}
|
890
|
+
|
891
|
+
|
892
|
+
static VALUE db_sync(VALUE vself){
|
893
|
+
VALUE vdb;
|
894
|
+
ESTDBMGR *db;
|
895
|
+
vdb = rb_iv_get(vself, VNDATA);
|
896
|
+
Data_Get_Struct(vdb, ESTDBMGR, db);
|
897
|
+
if(!db->db) rb_raise(rb_eArgError, "invalid argument");
|
898
|
+
if(!est_mtdb_sync(db->db)){
|
899
|
+
db->ecode = est_mtdb_error(db->db);
|
900
|
+
return Qfalse;
|
901
|
+
}
|
902
|
+
return Qtrue;
|
903
|
+
}
|
904
|
+
|
905
|
+
|
906
|
+
static VALUE db_optimize(VALUE vself, VALUE voptions){
|
907
|
+
VALUE vdb;
|
908
|
+
ESTDBMGR *db;
|
909
|
+
vdb = rb_iv_get(vself, VNDATA);
|
910
|
+
Data_Get_Struct(vdb, ESTDBMGR, db);
|
911
|
+
if(!db->db) rb_raise(rb_eArgError, "invalid argument");
|
912
|
+
if(!est_mtdb_optimize(db->db, NUM2INT(voptions))){
|
913
|
+
db->ecode = est_mtdb_error(db->db);
|
914
|
+
return Qfalse;
|
915
|
+
}
|
916
|
+
return Qtrue;
|
917
|
+
}
|
918
|
+
|
919
|
+
|
920
|
+
static VALUE db_merge(VALUE vself, VALUE vname, VALUE voptions){
|
921
|
+
VALUE vdb;
|
922
|
+
ESTDBMGR *db;
|
923
|
+
vdb = rb_iv_get(vself, VNDATA);
|
924
|
+
Data_Get_Struct(vdb, ESTDBMGR, db);
|
925
|
+
if(!db->db) rb_raise(rb_eArgError, "invalid argument");
|
926
|
+
Check_Type(vname, T_STRING);
|
927
|
+
if(!est_mtdb_merge(db->db, StringValuePtr(vname), NUM2INT(voptions))){
|
928
|
+
db->ecode = est_mtdb_error(db->db);
|
929
|
+
return Qfalse;
|
930
|
+
}
|
931
|
+
return Qtrue;
|
932
|
+
}
|
933
|
+
|
934
|
+
|
935
|
+
static VALUE db_put_doc(VALUE vself, VALUE vdoc, VALUE voptions){
|
936
|
+
VALUE vdb;
|
937
|
+
ESTDBMGR *db;
|
938
|
+
ESTDOC *doc;
|
939
|
+
vdb = rb_iv_get(vself, VNDATA);
|
940
|
+
Data_Get_Struct(vdb, ESTDBMGR, db);
|
941
|
+
if(!db->db) rb_raise(rb_eArgError, "invalid argument");
|
942
|
+
if(rb_obj_is_instance_of(vdoc, cls_doc) != Qtrue) rb_raise(rb_eArgError, "invalid argument");
|
943
|
+
Data_Get_Struct(rb_iv_get(vdoc, VNDATA), ESTDOC, doc);
|
944
|
+
if(!est_mtdb_put_doc(db->db, doc, NUM2INT(voptions))){
|
945
|
+
db->ecode = est_mtdb_error(db->db);
|
946
|
+
return Qfalse;
|
947
|
+
}
|
948
|
+
return Qtrue;
|
949
|
+
}
|
950
|
+
|
951
|
+
|
952
|
+
static VALUE db_out_doc(VALUE vself, VALUE vid, VALUE voptions){
|
953
|
+
VALUE vdb;
|
954
|
+
ESTDBMGR *db;
|
955
|
+
int id;
|
956
|
+
vdb = rb_iv_get(vself, VNDATA);
|
957
|
+
Data_Get_Struct(vdb, ESTDBMGR, db);
|
958
|
+
if(!db->db) rb_raise(rb_eArgError, "invalid argument");
|
959
|
+
id = NUM2INT(vid);
|
960
|
+
if(id < 1) rb_raise(rb_eArgError, "invalid argument");
|
961
|
+
if(!est_mtdb_out_doc(db->db, id, NUM2INT(voptions))){
|
962
|
+
db->ecode = est_mtdb_error(db->db);
|
963
|
+
return Qfalse;
|
964
|
+
}
|
965
|
+
return Qtrue;
|
966
|
+
}
|
967
|
+
|
968
|
+
|
969
|
+
static VALUE db_edit_doc(VALUE vself, VALUE vdoc){
|
970
|
+
VALUE vdb;
|
971
|
+
ESTDBMGR *db;
|
972
|
+
ESTDOC *doc;
|
973
|
+
vdb = rb_iv_get(vself, VNDATA);
|
974
|
+
Data_Get_Struct(vdb, ESTDBMGR, db);
|
975
|
+
if(!db->db) rb_raise(rb_eArgError, "invalid argument");
|
976
|
+
if(rb_obj_is_instance_of(vdoc, cls_doc) != Qtrue) rb_raise(rb_eArgError, "invalid argument");
|
977
|
+
Data_Get_Struct(rb_iv_get(vdoc, VNDATA), ESTDOC, doc);
|
978
|
+
if(!est_mtdb_edit_doc(db->db, doc)){
|
979
|
+
db->ecode = est_mtdb_error(db->db);
|
980
|
+
return Qfalse;
|
981
|
+
}
|
982
|
+
return Qtrue;
|
983
|
+
}
|
984
|
+
|
985
|
+
|
986
|
+
static VALUE db_get_doc(VALUE vself, VALUE vid, VALUE voptions){
|
987
|
+
VALUE vdb, vdoc, tdoc;
|
988
|
+
ESTDBMGR *db;
|
989
|
+
ESTDOC *doc;
|
990
|
+
int id;
|
991
|
+
vdb = rb_iv_get(vself, VNDATA);
|
992
|
+
Data_Get_Struct(vdb, ESTDBMGR, db);
|
993
|
+
if(!db->db) rb_raise(rb_eArgError, "invalid argument");
|
994
|
+
id = NUM2INT(vid);
|
995
|
+
if(id < 1) rb_raise(rb_eArgError, "invalid argument");
|
996
|
+
if(!(doc = est_mtdb_get_doc(db->db, id, NUM2INT(voptions)))){
|
997
|
+
db->ecode = est_mtdb_error(db->db);
|
998
|
+
return Qnil;
|
999
|
+
}
|
1000
|
+
vdoc = rb_funcall(cls_doc, rb_intern("new"), 0);
|
1001
|
+
tdoc = Data_Wrap_Struct(cls_doc_data, 0, est_doc_delete, doc);
|
1002
|
+
rb_iv_set(vdoc, VNDATA, tdoc);
|
1003
|
+
return vdoc;
|
1004
|
+
}
|
1005
|
+
|
1006
|
+
|
1007
|
+
static VALUE db_get_doc_attr(VALUE vself, VALUE vid, VALUE vname){
|
1008
|
+
VALUE vdb, vvalue;
|
1009
|
+
ESTDBMGR *db;
|
1010
|
+
char *value;
|
1011
|
+
int id;
|
1012
|
+
vdb = rb_iv_get(vself, VNDATA);
|
1013
|
+
Data_Get_Struct(vdb, ESTDBMGR, db);
|
1014
|
+
if(!db->db) rb_raise(rb_eArgError, "invalid argument");
|
1015
|
+
Check_Type(vname, T_STRING);
|
1016
|
+
id = NUM2INT(vid);
|
1017
|
+
if(id < 1) rb_raise(rb_eArgError, "invalid argument");
|
1018
|
+
if(!(value = est_mtdb_get_doc_attr(db->db, id, StringValuePtr(vname)))){
|
1019
|
+
db->ecode = est_mtdb_error(db->db);
|
1020
|
+
return Qnil;
|
1021
|
+
}
|
1022
|
+
vvalue = rb_str_new2(value);
|
1023
|
+
free(value);
|
1024
|
+
return vvalue;
|
1025
|
+
}
|
1026
|
+
|
1027
|
+
|
1028
|
+
static VALUE db_uri_to_id(VALUE vself, VALUE vuri){
|
1029
|
+
VALUE vdb;
|
1030
|
+
ESTDBMGR *db;
|
1031
|
+
int id;
|
1032
|
+
vdb = rb_iv_get(vself, VNDATA);
|
1033
|
+
Data_Get_Struct(vdb, ESTDBMGR, db);
|
1034
|
+
if(!db->db) rb_raise(rb_eArgError, "invalid argument");
|
1035
|
+
Check_Type(vuri, T_STRING);
|
1036
|
+
if((id = est_mtdb_uri_to_id(db->db, StringValuePtr(vuri))) == -1){
|
1037
|
+
db->ecode = est_mtdb_error(db->db);
|
1038
|
+
return INT2NUM(-1);
|
1039
|
+
}
|
1040
|
+
return INT2NUM(id);
|
1041
|
+
}
|
1042
|
+
|
1043
|
+
|
1044
|
+
static VALUE db_name(VALUE vself){
|
1045
|
+
VALUE vdb;
|
1046
|
+
ESTDBMGR *db;
|
1047
|
+
vdb = rb_iv_get(vself, VNDATA);
|
1048
|
+
Data_Get_Struct(vdb, ESTDBMGR, db);
|
1049
|
+
if(!db->db) rb_raise(rb_eArgError, "invalid argument");
|
1050
|
+
return rb_str_new2(est_mtdb_name(db->db));
|
1051
|
+
}
|
1052
|
+
|
1053
|
+
|
1054
|
+
static VALUE db_doc_num(VALUE vself){
|
1055
|
+
VALUE vdb;
|
1056
|
+
ESTDBMGR *db;
|
1057
|
+
vdb = rb_iv_get(vself, VNDATA);
|
1058
|
+
Data_Get_Struct(vdb, ESTDBMGR, db);
|
1059
|
+
if(!db->db) rb_raise(rb_eArgError, "invalid argument");
|
1060
|
+
return INT2NUM(est_mtdb_doc_num(db->db));
|
1061
|
+
}
|
1062
|
+
|
1063
|
+
|
1064
|
+
static VALUE db_word_num(VALUE vself){
|
1065
|
+
VALUE vdb;
|
1066
|
+
ESTDBMGR *db;
|
1067
|
+
vdb = rb_iv_get(vself, VNDATA);
|
1068
|
+
Data_Get_Struct(vdb, ESTDBMGR, db);
|
1069
|
+
if(!db->db) rb_raise(rb_eArgError, "invalid argument");
|
1070
|
+
return INT2NUM(est_mtdb_word_num(db->db));
|
1071
|
+
}
|
1072
|
+
|
1073
|
+
|
1074
|
+
static VALUE db_size(VALUE vself){
|
1075
|
+
VALUE vdb;
|
1076
|
+
ESTDBMGR *db;
|
1077
|
+
vdb = rb_iv_get(vself, VNDATA);
|
1078
|
+
Data_Get_Struct(vdb, ESTDBMGR, db);
|
1079
|
+
if(!db->db) rb_raise(rb_eArgError, "invalid argument");
|
1080
|
+
return rb_float_new(est_mtdb_size(db->db));
|
1081
|
+
}
|
1082
|
+
|
1083
|
+
|
1084
|
+
static VALUE db_search(VALUE vself, VALUE vcond){
|
1085
|
+
VALUE vdb, vres, tres, tcond;
|
1086
|
+
ESTDBMGR *db;
|
1087
|
+
ESTRES *ores;
|
1088
|
+
ESTCOND *cond;
|
1089
|
+
CBMAP *hints;
|
1090
|
+
int *res, rnum;
|
1091
|
+
vdb = rb_iv_get(vself, VNDATA);
|
1092
|
+
Data_Get_Struct(vdb, ESTDBMGR, db);
|
1093
|
+
if(!db->db) rb_raise(rb_eArgError, "invalid argument");
|
1094
|
+
if(rb_obj_is_instance_of(vcond, cls_cond) != Qtrue) rb_raise(rb_eArgError, "invalid argument");
|
1095
|
+
Data_Get_Struct(rb_iv_get(vcond, VNDATA), ESTCOND, cond);
|
1096
|
+
hints = cbmapopenex(31);
|
1097
|
+
res = est_mtdb_search(db->db, cond, &rnum, hints);
|
1098
|
+
ores = est_res_new();
|
1099
|
+
ores->ids = res;
|
1100
|
+
ores->num = rnum;
|
1101
|
+
ores->hints = hints;
|
1102
|
+
vres = rb_funcall(cls_res, rb_intern("new"), 0);
|
1103
|
+
tres = Data_Wrap_Struct(cls_res_data, 0, est_res_delete, ores);
|
1104
|
+
rb_iv_set(vres, VNDATA, tres);
|
1105
|
+
tcond = Data_Wrap_Struct(cls_cond_data, 0, est_cond_delete, est_cond_dup(cond));
|
1106
|
+
rb_iv_set(vres, VNCOND, tcond);
|
1107
|
+
return vres;
|
1108
|
+
}
|
1109
|
+
|
1110
|
+
|
1111
|
+
static VALUE db_scan_doc(VALUE vself, VALUE vdoc, VALUE vcond){
|
1112
|
+
VALUE vdb;
|
1113
|
+
ESTDBMGR *db;
|
1114
|
+
ESTDOC *doc;
|
1115
|
+
ESTCOND *cond;
|
1116
|
+
vdb = rb_iv_get(vself, VNDATA);
|
1117
|
+
Data_Get_Struct(vdb, ESTDBMGR, db);
|
1118
|
+
if(!db->db) rb_raise(rb_eArgError, "invalid argument");
|
1119
|
+
if(rb_obj_is_instance_of(vdoc, cls_doc) != Qtrue) rb_raise(rb_eArgError, "invalid argument");
|
1120
|
+
if(rb_obj_is_instance_of(vcond, cls_cond) != Qtrue) rb_raise(rb_eArgError, "invalid argument");
|
1121
|
+
Data_Get_Struct(rb_iv_get(vdoc, VNDATA), ESTDOC, doc);
|
1122
|
+
Data_Get_Struct(rb_iv_get(vcond, VNDATA), ESTCOND, cond);
|
1123
|
+
return est_mtdb_scan_doc(db->db, doc, cond) ? Qtrue : Qfalse;
|
1124
|
+
}
|
1125
|
+
|
1126
|
+
|
1127
|
+
static VALUE db_set_cache_size(VALUE vself, VALUE vsize, VALUE vanum, VALUE vtnum, VALUE vrnum){
|
1128
|
+
VALUE vdb;
|
1129
|
+
ESTDBMGR *db;
|
1130
|
+
vdb = rb_iv_get(vself, VNDATA);
|
1131
|
+
Data_Get_Struct(vdb, ESTDBMGR, db);
|
1132
|
+
if(!db->db) rb_raise(rb_eArgError, "invalid argument");
|
1133
|
+
est_mtdb_set_cache_size(db->db, NUM2INT(vsize),
|
1134
|
+
NUM2INT(vanum), NUM2INT(vtnum), NUM2INT(vrnum));
|
1135
|
+
return Qnil;
|
1136
|
+
}
|
1137
|
+
|
1138
|
+
|
1139
|
+
static VALUE db_add_pseudo_index(VALUE vself, VALUE vpath){
|
1140
|
+
VALUE vdb;
|
1141
|
+
ESTDBMGR *db;
|
1142
|
+
vdb = rb_iv_get(vself, VNDATA);
|
1143
|
+
Data_Get_Struct(vdb, ESTDBMGR, db);
|
1144
|
+
if(!db->db) rb_raise(rb_eArgError, "invalid argument");
|
1145
|
+
Check_Type(vpath, T_STRING);
|
1146
|
+
return est_mtdb_add_pseudo_index(db->db, StringValuePtr(vpath)) ? Qtrue : Qfalse;
|
1147
|
+
}
|
1148
|
+
|
1149
|
+
|
1150
|
+
static VALUE db_set_wildmax(VALUE vself, VALUE vnum){
|
1151
|
+
VALUE vdb;
|
1152
|
+
ESTDBMGR *db;
|
1153
|
+
vdb = rb_iv_get(vself, VNDATA);
|
1154
|
+
Data_Get_Struct(vdb, ESTDBMGR, db);
|
1155
|
+
if(!db->db) rb_raise(rb_eArgError, "invalid argument");
|
1156
|
+
est_mtdb_set_wildmax(db->db, NUM2INT(vnum));
|
1157
|
+
return Qnil;
|
1158
|
+
}
|
1159
|
+
|
1160
|
+
|
1161
|
+
|
1162
|
+
static VALUE db_set_informer(VALUE vself, VALUE vinformer){
|
1163
|
+
VALUE vdb;
|
1164
|
+
ESTDBMGR *db;
|
1165
|
+
vdb = rb_iv_get(vself, VNDATA);
|
1166
|
+
Data_Get_Struct(vdb, ESTDBMGR, db);
|
1167
|
+
if(!db->db) rb_raise(rb_eArgError, "invalid argument");
|
1168
|
+
rb_iv_set(vself, VNINFO, vinformer);
|
1169
|
+
est_mtdb_set_informer(db->db, db_informer, (void *)vinformer);
|
1170
|
+
return Qnil;
|
1171
|
+
}
|
1172
|
+
|
1173
|
+
|
1174
|
+
static VALUE cblisttoobj(const CBLIST *list){
|
1175
|
+
const char *vbuf;
|
1176
|
+
int i, vsiz;
|
1177
|
+
VALUE obj;
|
1178
|
+
obj = rb_ary_new2(cblistnum(list));
|
1179
|
+
for(i = 0; i < cblistnum(list); i++){
|
1180
|
+
vbuf = cblistval(list, i, &vsiz);
|
1181
|
+
rb_ary_store(obj, i, rb_str_new(vbuf, vsiz));
|
1182
|
+
}
|
1183
|
+
return obj;
|
1184
|
+
}
|
1185
|
+
|
1186
|
+
|
1187
|
+
static CBLIST *objtocblist(VALUE obj){
|
1188
|
+
CBLIST *list;
|
1189
|
+
VALUE str;
|
1190
|
+
int i, len;
|
1191
|
+
list = cblistopen();
|
1192
|
+
len = RARRAY(obj)->len;
|
1193
|
+
for(i = 0; i < len; i++){
|
1194
|
+
str = rb_ary_entry(obj, i);
|
1195
|
+
cblistpush(list, RSTRING(str)->ptr, RSTRING(str)->len);
|
1196
|
+
}
|
1197
|
+
return list;
|
1198
|
+
}
|
1199
|
+
|
1200
|
+
|
1201
|
+
static VALUE cbmaptoobj(CBMAP *map){
|
1202
|
+
const char *kbuf, *vbuf;
|
1203
|
+
int ksiz, vsiz;
|
1204
|
+
VALUE obj;
|
1205
|
+
obj = rb_hash_new();
|
1206
|
+
cbmapiterinit(map);
|
1207
|
+
while((kbuf = cbmapiternext(map, &ksiz)) != NULL){
|
1208
|
+
vbuf = cbmapiterval(kbuf, &vsiz);
|
1209
|
+
rb_hash_aset(obj, rb_str_new(kbuf, ksiz), rb_str_new(vbuf, vsiz));
|
1210
|
+
}
|
1211
|
+
return obj;
|
1212
|
+
}
|
1213
|
+
|
1214
|
+
|
1215
|
+
static CBMAP *objtocbmap(VALUE obj){
|
1216
|
+
CBMAP *map;
|
1217
|
+
VALUE keys, key, val;
|
1218
|
+
int i, len;
|
1219
|
+
map = cbmapopenex(31);
|
1220
|
+
keys = rb_funcall(obj, rb_intern("keys"), 0);
|
1221
|
+
len = RARRAY(keys)->len;
|
1222
|
+
for(i = 0; i < len; i++){
|
1223
|
+
key = rb_ary_entry(keys, i);
|
1224
|
+
val = rb_hash_aref(obj, key);
|
1225
|
+
key = rb_String(key);
|
1226
|
+
val = rb_String(val);
|
1227
|
+
cbmapput(map, RSTRING(key)->ptr, RSTRING(key)->len,
|
1228
|
+
RSTRING(val)->ptr, RSTRING(val)->len, 0);
|
1229
|
+
}
|
1230
|
+
return map;
|
1231
|
+
}
|
1232
|
+
|
1233
|
+
|
1234
|
+
static void db_informer(const char *message, void *opaque){
|
1235
|
+
VALUE ary;
|
1236
|
+
ary = rb_ary_new2(2);
|
1237
|
+
rb_ary_push(ary, (VALUE)opaque);
|
1238
|
+
rb_ary_push(ary, rb_str_new2(message));
|
1239
|
+
rb_rescue(db_informer_process, ary, db_informer_resque, Qnil);
|
1240
|
+
}
|
1241
|
+
|
1242
|
+
|
1243
|
+
static VALUE db_informer_process(VALUE arg){
|
1244
|
+
VALUE informer, message;
|
1245
|
+
informer = rb_ary_shift(arg);
|
1246
|
+
message = rb_ary_shift(arg);
|
1247
|
+
rb_funcall(informer, rb_intern("inform"), 1, message);
|
1248
|
+
return Qnil;
|
1249
|
+
}
|
1250
|
+
|
1251
|
+
|
1252
|
+
static VALUE db_informer_resque(VALUE arg){
|
1253
|
+
return Qnil;
|
1254
|
+
}
|
1255
|
+
|
1256
|
+
|
1257
|
+
|
1258
|
+
/* END OF FILE */
|