1
/*************************************************************************************************
2
* Perl 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
*************************************************************************************************/
27
/*************************************************************************************************
29
*************************************************************************************************/
32
static AV *cblisttoav(const CBLIST *names);
33
static CBLIST *avtocblist(AV *av);
34
static HV *cbmaptohv(CBMAP *kwords);
35
static CBMAP *hvtocbmap(HV *hv);
36
static void dbinform(const char *message, void *opaque);
39
static AV *cblisttoav(const CBLIST *names){
44
for(i = 0; i < cblistnum(names); i++){
45
buf = cblistval(names, i, &size);
46
av_push(av, newSVpvn(buf, size));
52
static CBLIST *avtocblist(AV *av){
59
if((num = av_len(av)) < 0) return list;
60
for(i = 0; i <= num; i++){
61
val = *av_fetch(av, i, 0);
62
buf = SvPV(val, size);
63
cblistpush(list, buf, (int)size);
69
static HV *cbmaptohv(CBMAP *kwords){
71
const char *kbuf, *vbuf;
74
cbmapiterinit(kwords);
75
while((kbuf = cbmapiternext(kwords, &ksiz)) != NULL){
76
vbuf = cbmapiterval(kbuf, &vsiz);
77
hv_store(hv, kbuf, ksiz, newSVpvn(vbuf, vsiz), 0);
83
static CBMAP *hvtocbmap(HV *hv){
90
map = cbmapopenex(31);
92
while((entry = hv_iternext(hv)) != NULL){
93
kbuf = hv_iterkey(entry, &ksiz);
94
val = hv_iterval(hv, entry);
95
vbuf = SvPV(val, vsiz);
96
cbmapput(map, kbuf, (int)ksiz, vbuf, (int)vsiz, FALSE);
102
static void dbinform(const char *message, void *opaque){
107
XPUSHs(sv_2mortal(newSVpv(message, 0)));
109
perl_call_pv(opaque, G_DISCARD | G_EVAL);
116
/*************************************************************************************************
118
*************************************************************************************************/
121
MODULE = Estraier PACKAGE = Estraier
128
RETVAL = est_doc_new();
134
doc_new_from_draft(draft)
137
RETVAL = est_doc_new_from_draft(draft);
150
doc_add_attr(doc, name, value)
155
if(!strcmp(value, "\t(NULL)\t")) value = NULL;
156
est_doc_add_attr(doc, name, value);
160
doc_add_text(doc, text)
164
est_doc_add_text(doc, text);
168
doc_add_hidden_text(doc, text)
172
est_doc_add_hidden_text(doc, text);
176
doc_set_keywords(doc, kwords)
182
tkwords = hvtocbmap(kwords);
183
est_doc_set_keywords(doc, tkwords);
188
doc_set_score(doc, score)
192
est_doc_set_score(doc, score);
199
RETVAL = est_doc_id(doc);
210
names = est_doc_attr_names(doc);
211
XPUSHs(sv_2mortal(newRV_noinc((SV *)cblisttoav(names))));
221
RETVAL = est_doc_attr(doc, name);
232
texts = est_doc_texts(doc);
233
XPUSHs(sv_2mortal(newRV_noinc((SV *)cblisttoav(texts))));
243
texts = est_doc_cat_texts(doc);
244
XPUSHs(sv_2mortal(newSVpv(texts, 0)));
255
if((kwords = est_doc_keywords(doc)) != NULL){
256
XPUSHs(sv_2mortal(newRV_noinc((SV *)cbmaptohv(kwords))));
258
XPUSHs((SV *)&PL_sv_undef);
267
RETVAL = est_doc_score(doc);
273
doc_make_snippet(doc, words, wwidth, hwidth, awidth)
283
twords = avtocblist(words);
284
snippet = est_doc_make_snippet(doc, twords, wwidth, hwidth, awidth);
285
XPUSHs(sv_2mortal(newSVpv(snippet, 0)));
297
draft = est_doc_dump_draft(doc);
298
XPUSHs(sv_2mortal(newSVpv(draft, 0)));
308
cond = est_cond_new();
309
est_cond_set_options(cond, ESTCONDSCFB);
319
est_cond_delete(cond);
323
cond_set_phrase(cond, phrase)
327
est_cond_set_phrase(cond, phrase);
331
cond_add_attr(cond, expr)
335
est_cond_add_attr(cond, expr);
339
cond_set_order(cond, expr)
343
est_cond_set_order(cond, expr);
347
cond_set_max(cond, max)
351
est_cond_set_max(cond, max);
355
cond_set_skip(cond, skip)
359
est_cond_set_skip(cond, skip);
363
cond_set_options(cond, options)
367
est_cond_set_options(cond, options);
371
cond_set_auxiliary(cond, min)
375
est_cond_set_auxiliary(cond, min);
379
cond_set_eclipse(cond, limit)
383
est_cond_set_eclipse(cond, limit);
387
cond_set_distinct(cond, name)
391
est_cond_set_distinct(cond, name);
395
res_delete(resptr, idxsptr, hints, cond)
401
est_cond_delete(cond);
408
res_get_doc_id(resptr, index)
412
RETVAL = ((int *)resptr)[index];
418
res_get_dbidx(idxsptr, index)
422
RETVAL = ((int *)idxsptr)[index];
428
res_hint_words(hints)
435
words = cbmapkeys(hints);
436
for(i = 0; i < cblistnum(words); i++){
437
vbuf = cblistval(words, i, NULL);
439
free(cblistremove(words, i, NULL));
443
XPUSHs(sv_2mortal(newRV_noinc((SV *)cblisttoav(words))));
449
res_hint(hints, word)
455
value = cbmapget(hints, word, -1, NULL);
456
RETVAL = value ? atoi(value) : 0;
462
res_get_score(cond, index)
466
RETVAL = est_cond_score(cond, index);
472
res_get_shadows(cond, id)
480
ary = est_cond_shadows(cond, id, &anum);
482
for(i = 0; i < anum; i++){
483
av_push(av, newSViv(ary[i]));
485
XPUSHs(sv_2mortal(newRV_noinc((SV *)av)));
492
RETVAL = est_version;
498
db_search_meta(dbav, cond)
504
int i, dbnum, *res, rnum, *idxs;
506
dbnum = av_len(dbav) + 1;
507
dbs = cbmalloc(dbnum * sizeof(ESTMTDB *) + 1);
508
for(i = 0; i < dbnum; i++){
509
dbs[i] = (ESTMTDB *)SvIV(*av_fetch(dbav, i, 0));
511
hints = cbmapopenex(31);
512
res = est_mtdb_search_meta(dbs, dbnum, cond, &rnum, hints);
513
idxs = cbmalloc(rnum / 2 * sizeof(int) + 1);
514
for(i = 0; i < rnum; i += 2){
519
XPUSHs(sv_2mortal(newSViv((IV)res)));
520
XPUSHs(sv_2mortal(newSViv((IV)idxs)));
521
XPUSHs(sv_2mortal(newSViv((IV)(rnum / 2))));
522
XPUSHs(sv_2mortal(newSViv((IV)hints)));
523
XPUSHs(sv_2mortal(newSViv((IV)est_cond_dup(cond))));
531
RETVAL = est_err_msg(ecode);
544
db = est_mtdb_open(name, omode, &ecode);
545
XPUSHs(sv_2mortal(newSViv((IV)db)));
546
XPUSHs(sv_2mortal(newSViv((IV)ecode)));
556
rv = est_mtdb_close(db, &ecode);
557
XPUSHs(sv_2mortal(newSViv((IV)rv)));
558
XPUSHs(sv_2mortal(newSViv((IV)ecode)));
566
RETVAL = est_mtdb_error(db);
575
RETVAL = est_mtdb_fatal(db);
581
db_add_attr_index(db, name, type)
586
RETVAL = est_mtdb_add_attr_index(db, name, type);
596
RETVAL = est_mtdb_flush(db, max);
605
RETVAL = est_mtdb_sync(db);
611
db_optimize(db, options)
615
RETVAL = est_mtdb_optimize(db, options);
621
db_merge(db, name, options)
626
RETVAL = est_mtdb_merge(db, name, options);
632
db_put_doc(db, doc, options)
637
RETVAL = est_mtdb_put_doc(db, doc, options);
643
db_out_doc(db, id, options)
648
RETVAL = est_mtdb_out_doc(db, id, options);
658
RETVAL = est_mtdb_edit_doc(db, doc);
664
db_get_doc(db, id, options)
669
RETVAL = est_mtdb_get_doc(db, id, options);
675
db_get_doc_attr(db, id, name)
682
value = est_mtdb_get_doc_attr(db, id, name);
683
if(!value) XSRETURN_UNDEF;
684
XPUSHs(sv_2mortal(newSVpv(value, 0)));
690
db_uri_to_id(db, uri)
694
RETVAL = est_mtdb_uri_to_id(db, uri);
703
RETVAL = est_mtdb_name(db);
712
RETVAL = est_mtdb_doc_num(db);
721
RETVAL = est_mtdb_word_num(db);
730
RETVAL = est_mtdb_size(db);
744
hints = cbmapopenex(31);
745
res = est_mtdb_search(db, cond, &rnum, hints);
746
XPUSHs(sv_2mortal(newSViv((IV)res)));
747
XPUSHs(sv_2mortal(newSViv((IV)rnum)));
748
XPUSHs(sv_2mortal(newSViv((IV)hints)));
749
XPUSHs(sv_2mortal(newSViv((IV)est_cond_dup(cond))));
754
db_scan_doc(db, doc, cond)
759
RETVAL = est_mtdb_scan_doc(db, doc, cond);
765
db_set_cache_size(db, size, anum, tnum, rnum)
772
est_mtdb_set_cache_size(db, (size_t)size, anum, tnum, rnum);
776
db_add_pseudo_index(db, path)
780
RETVAL = est_mtdb_add_pseudo_index(db, path);
786
db_set_wildmax(db, num)
790
est_mtdb_set_wildmax(db, num);
794
db_set_informer(db, informer)
798
est_mtdb_set_informer(db, dbinform, informer);