~ubuntu-branches/ubuntu/trusty/hyperestraier/trusty-proposed

« back to all changes in this revision

Viewing changes to perlnative/src/Estraier.pm

  • Committer: Bazaar Package Importer
  • Author(s): Steve Langasek
  • Date: 2006-11-14 05:28:32 UTC
  • mfrom: (2.1.4 feisty)
  • Revision ID: james.westby@ubuntu.com-20061114052832-0lzqzcefn8mt4yqe
Tags: 1.4.9-1.1
* Non-maintainer upload.
* High-urgency upload for RC bugfix.
* Set HOME=$(CURDIR)/junkhome when building, otherwise the package build
  will incorrectly look for headers there -- and fail when the directory
  exists and is unreadable, as happens sometimes on sudo-using
  autobuilders!

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#-------------------------------------------------------------------------------------------------
 
2
# Perl binding of Hyper Estraier
 
3
#                                                       Copyright (C) 2004-2006 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
package Estraier;
 
18
 
 
19
use strict;
 
20
use warnings;
 
21
use Carp;
 
22
 
 
23
require Exporter;
 
24
require XSLoader;
 
25
our @ISA = qw(Exporter);
 
26
our $VERSION = '1.0';
 
27
our $DEBUG = 0;
 
28
XSLoader::load('Estraier', $VERSION);
 
29
 
 
30
use constant {
 
31
    TRUE => 1,
 
32
    FALSE => 0,
 
33
};
 
34
 
 
35
 
 
36
sub atoi {
 
37
    my $str = shift;
 
38
    $str =~ s/^ *//;
 
39
    my $sign = 1;
 
40
    if($str =~ /^-/){
 
41
        $sign = -1;
 
42
        $str =~ s/^-*//
 
43
    }
 
44
    return 0 unless $str =~ /^[0-9]+/;
 
45
    my $t = 0;
 
46
    foreach my $d (split(//, $str)){
 
47
        last unless($d =~ /^[0-9]$/);
 
48
        $t = $t * 10 + $d;
 
49
    }
 
50
    return $t * $sign;
 
51
}
 
52
 
 
53
 
 
54
 
 
55
package Document;
 
56
use Carp;
 
57
 
 
58
 
 
59
sub new {
 
60
    my $class = shift;
 
61
    my $draft = shift;
 
62
    if(scalar(@_) != 0){
 
63
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
64
        return undef;
 
65
    }
 
66
    my $self = [0];
 
67
    $$self[0] = defined($draft) ? Estraier::doc_new_from_draft($draft) : Estraier::doc_new();
 
68
    bless($self, $class);
 
69
    return $self;
 
70
}
 
71
 
 
72
 
 
73
sub new_with_ptr {
 
74
    my $class = shift;
 
75
    my $ptr = shift;
 
76
    if(scalar(@_) != 0 || !defined($ptr)){
 
77
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
78
        return undef;
 
79
    }
 
80
    my $self = [0];
 
81
    $$self[0] = $ptr;
 
82
    bless($self, $class);
 
83
    return $self;
 
84
}
 
85
 
 
86
 
 
87
sub DESTROY {
 
88
    my $self = shift;
 
89
    return undef unless($$self[0]);
 
90
    Estraier::doc_delete($$self[0]);
 
91
    return undef;
 
92
}
 
93
 
 
94
 
 
95
sub add_attr {
 
96
    my $self = shift;
 
97
    my $name = shift;
 
98
    my $value = shift;
 
99
    if(scalar(@_) != 0 || !defined($name)){
 
100
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
101
        return undef;
 
102
    }
 
103
    $value = "\t(NULL)\t" if(!defined($value));
 
104
    Estraier::doc_add_attr($$self[0], $name, $value);
 
105
    return undef;
 
106
}
 
107
 
 
108
 
 
109
sub add_text {
 
110
    my $self = shift;
 
111
    my $text = shift;
 
112
    if(scalar(@_) != 0 || !defined($text)){
 
113
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
114
        return undef;
 
115
    }
 
116
    Estraier::doc_add_text($$self[0], $text);
 
117
    return undef;
 
118
}
 
119
 
 
120
 
 
121
sub add_hidden_text {
 
122
    my $self = shift;
 
123
    my $text = shift;
 
124
    if(scalar(@_) != 0 || !defined($text)){
 
125
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
126
        return undef;
 
127
    }
 
128
    Estraier::doc_add_hidden_text($$self[0], $text);
 
129
    return undef;
 
130
}
 
131
 
 
132
 
 
133
sub set_keywords {
 
134
    my $self = shift;
 
135
    my $kwords = shift;
 
136
    if(scalar(@_) != 0 || !defined($kwords) || ref($kwords) ne "HASH"){
 
137
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
138
        return undef;
 
139
    }
 
140
    Estraier::doc_set_keywords($$self[0], $kwords);
 
141
    return undef;
 
142
}
 
143
 
 
144
 
 
145
sub set_score {
 
146
    my $self = shift;
 
147
    my $score = shift;
 
148
    if(scalar(@_) != 0 || !defined($score) || $score < 0){
 
149
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
150
        return undef;
 
151
    }
 
152
    Estraier::doc_set_score($$self[0], $score);
 
153
    return undef;
 
154
}
 
155
 
 
156
 
 
157
sub id {
 
158
    my $self = shift;
 
159
    if(scalar(@_) != 0){
 
160
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
161
        return undef;
 
162
    }
 
163
    return Estraier::doc_id($$self[0]);
 
164
}
 
165
 
 
166
 
 
167
sub attr_names {
 
168
    my $self = shift;
 
169
    if(scalar(@_) != 0){
 
170
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
171
        return undef;
 
172
    }
 
173
    return Estraier::doc_attr_names($$self[0]);
 
174
}
 
175
 
 
176
 
 
177
sub attr {
 
178
    my $self = shift;
 
179
    my $name = shift;
 
180
    if(scalar(@_) != 0 || !defined($name)){
 
181
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
182
        return undef;
 
183
    }
 
184
    return Estraier::doc_attr($$self[0], $name);
 
185
}
 
186
 
 
187
 
 
188
sub texts {
 
189
    my $self = shift;
 
190
    if(scalar(@_) != 0){
 
191
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
192
        return undef;
 
193
    }
 
194
    return Estraier::doc_texts($$self[0]);
 
195
}
 
196
 
 
197
 
 
198
sub cat_texts {
 
199
    my $self = shift;
 
200
    if(scalar(@_) != 0){
 
201
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
202
        return undef;
 
203
    }
 
204
    return Estraier::doc_cat_texts($$self[0]);
 
205
}
 
206
 
 
207
 
 
208
sub keywords {
 
209
    my $self = shift;
 
210
    if(scalar(@_) != 0){
 
211
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
212
        return undef;
 
213
    }
 
214
    return Estraier::doc_keywords($$self[0]);
 
215
}
 
216
 
 
217
 
 
218
sub score {
 
219
    my $self = shift;
 
220
    if(scalar(@_) != 0){
 
221
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
222
        return undef;
 
223
    }
 
224
    return Estraier::doc_score($$self[0]);
 
225
}
 
226
 
 
227
 
 
228
sub dump_draft {
 
229
    my $self = shift;
 
230
    if(scalar(@_) != 0){
 
231
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
232
        return undef;
 
233
    }
 
234
    return Estraier::doc_dump_draft($$self[0]);
 
235
}
 
236
 
 
237
 
 
238
sub make_snippet {
 
239
    my $self = shift;
 
240
    my $words = shift;
 
241
    my $wwidth = shift;
 
242
    my $hwidth = shift;
 
243
    my $awidth = shift;
 
244
    if(scalar(@_) != 0 || !defined($words) || ref($words) ne "ARRAY" ||
 
245
       !defined($wwidth) || $wwidth < 0 || !defined($hwidth) || $hwidth < 0 ||
 
246
       !defined($awidth) || $awidth < 0){
 
247
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
248
        return undef;
 
249
    }
 
250
    return Estraier::doc_make_snippet($$self[0], $words, $wwidth, $hwidth, $awidth);
 
251
}
 
252
 
 
253
 
 
254
 
 
255
package Condition;
 
256
use Carp;
 
257
 
 
258
 
 
259
use constant {
 
260
    SURE => 1 << 0,
 
261
    USUAL => 1 << 1,
 
262
    FAST => 1 << 2,
 
263
    AGITO => 1 << 3,
 
264
    NOIDF => 1 << 4,
 
265
    SIMPLE => 1 << 10,
 
266
    ROUGH => 1 << 11,
 
267
    UNION => 1 << 15,
 
268
    ISECT => 1 << 16,
 
269
    ECLSIMURL => 10.0,
 
270
    ECLSERV => 100.0,
 
271
    ECLDIR => 101.0,
 
272
    ECLFILE => 102.0,
 
273
};
 
274
 
 
275
 
 
276
sub new {
 
277
    my $class = shift;
 
278
    if(scalar(@_) != 0){
 
279
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
280
        return undef;
 
281
    }
 
282
    my $self = [0];
 
283
    $$self[0] = Estraier::cond_new();
 
284
    bless($self, $class);
 
285
    return $self;
 
286
}
 
287
 
 
288
 
 
289
sub DESTROY {
 
290
    my $self = shift;
 
291
    return undef unless($$self[0]);
 
292
    Estraier::cond_delete($$self[0]);
 
293
    return undef;
 
294
}
 
295
 
 
296
 
 
297
sub set_phrase {
 
298
    my $self = shift;
 
299
    my $phrase = shift;
 
300
    if(scalar(@_) != 0 || !defined($phrase)){
 
301
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
302
        return undef;
 
303
    }
 
304
    Estraier::cond_set_phrase($$self[0], $phrase);
 
305
    return undef;
 
306
}
 
307
 
 
308
 
 
309
sub add_attr {
 
310
    my $self = shift;
 
311
    my $expr = shift;
 
312
    if(scalar(@_) != 0 || !defined($expr)){
 
313
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
314
        return undef;
 
315
    }
 
316
    Estraier::cond_add_attr($$self[0], $expr);
 
317
    return undef;
 
318
}
 
319
 
 
320
 
 
321
sub set_order {
 
322
    my $self = shift;
 
323
    my $expr = shift;
 
324
    if(scalar(@_) != 0 || !defined($expr)){
 
325
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
326
        return undef;
 
327
    }
 
328
    Estraier::cond_set_order($$self[0], $expr);
 
329
    return undef;
 
330
}
 
331
 
 
332
 
 
333
sub set_max {
 
334
    my $self = shift;
 
335
    my $max = shift;
 
336
    if(scalar(@_) != 0 || !defined($max) || $max < 0){
 
337
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
338
        return undef;
 
339
    }
 
340
    Estraier::cond_set_max($$self[0], $max);
 
341
    return undef;
 
342
}
 
343
 
 
344
 
 
345
sub set_skip {
 
346
    my $self = shift;
 
347
    my $skip = shift;
 
348
    if(scalar(@_) != 0 || !defined($skip) || $skip < 0){
 
349
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
350
        return undef;
 
351
    }
 
352
    Estraier::cond_set_skip($$self[0], $skip);
 
353
    return undef;
 
354
}
 
355
 
 
356
 
 
357
sub set_options {
 
358
    my $self = shift;
 
359
    my $options = shift;
 
360
    if(scalar(@_) != 0 || !defined($options)){
 
361
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
362
        return undef;
 
363
    }
 
364
    Estraier::cond_set_options($$self[0], $options);
 
365
    return undef;
 
366
}
 
367
 
 
368
 
 
369
sub set_auxiliary {
 
370
    my $self = shift;
 
371
    my $min = shift;
 
372
    if(scalar(@_) != 0 || !defined($min)){
 
373
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
374
        return undef;
 
375
    }
 
376
    Estraier::cond_set_auxiliary($$self[0], $min);
 
377
    return undef;
 
378
}
 
379
 
 
380
 
 
381
sub set_eclipse {
 
382
    my $self = shift;
 
383
    my $limit = shift;
 
384
    if(scalar(@_) != 0 || !defined($limit)){
 
385
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
386
        return undef;
 
387
    }
 
388
    Estraier::cond_set_eclipse($$self[0], $limit);
 
389
    return undef;
 
390
}
 
391
 
 
392
 
 
393
sub set_distinct {
 
394
    my $self = shift;
 
395
    my $name = shift;
 
396
    if(scalar(@_) != 0 || !defined($name)){
 
397
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
398
        return undef;
 
399
    }
 
400
    Estraier::cond_set_distinct($$self[0], $name);
 
401
    return undef;
 
402
}
 
403
 
 
404
 
 
405
 
 
406
package Result;
 
407
use Carp;
 
408
 
 
409
 
 
410
sub new {
 
411
    my $class = shift;
 
412
    my $resptr = shift;
 
413
    my $idxsptr = shift;
 
414
    my $resnum = shift;
 
415
    my $hints = shift;
 
416
    my $cond = shift;
 
417
    if(scalar(@_) != 0 || !defined($resptr) || !defined($resnum) ||
 
418
       !defined($hints) || !defined($cond)){
 
419
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
420
        return undef;
 
421
    }
 
422
    my $self = [$resptr, $idxsptr, $resnum, $hints, $cond];
 
423
    bless($self, $class);
 
424
    return $self;
 
425
}
 
426
 
 
427
 
 
428
sub DESTROY {
 
429
    my $self = shift;
 
430
    return undef unless($$self[0]);
 
431
    Estraier::res_delete($$self[0], defined($$self[1]) ? $$self[1] : 0, $$self[3], $$self[4]);
 
432
    return undef;
 
433
}
 
434
 
 
435
 
 
436
sub doc_num {
 
437
    my $self = shift;
 
438
    if(scalar(@_) != 0){
 
439
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
440
        return -1;
 
441
    }
 
442
    return $$self[2];
 
443
}
 
444
 
 
445
 
 
446
sub get_doc_id {
 
447
    my $self = shift;
 
448
    my $index = shift;
 
449
    if(scalar(@_) != 0 || !defined($index)){
 
450
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
451
        return -1;
 
452
    }
 
453
    return -1 if($index < 0 || $index >= $$self[2]);
 
454
    return Estraier::res_get_doc_id($$self[0], $index);
 
455
}
 
456
 
 
457
 
 
458
sub get_dbidx {
 
459
    my $self = shift;
 
460
    my $index = shift;
 
461
    if(scalar(@_) != 0 || !defined($index)){
 
462
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
463
        return -1;
 
464
    }
 
465
    return -1 if(!defined($$self[1]) || $index < 0 || $index >= $$self[2]);
 
466
    return Estraier::res_get_dbidx($$self[1], $index);
 
467
}
 
468
 
 
469
 
 
470
sub hint_words {
 
471
    my $self = shift;
 
472
    if(scalar(@_) != 0){
 
473
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
474
        return undef;
 
475
    }
 
476
    return Estraier::res_hint_words($$self[3]);
 
477
}
 
478
 
 
479
 
 
480
sub hint {
 
481
    my $self = shift;
 
482
    my $word = shift;
 
483
    if(scalar(@_) != 0 || !defined($word)){
 
484
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
485
        return 0;
 
486
    }
 
487
    return Estraier::res_hint($$self[3], $word);
 
488
}
 
489
 
 
490
 
 
491
sub get_score {
 
492
    my $self = shift;
 
493
    my $index = shift;
 
494
    if(scalar(@_) != 0 || !defined($index)){
 
495
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
496
        return -1;
 
497
    }
 
498
    return -1 if($index < 0 || $index >= $$self[2]);
 
499
    return Estraier::res_get_score($$self[4], $index);
 
500
}
 
501
 
 
502
 
 
503
sub get_shadows {
 
504
    my $self = shift;
 
505
    my $id = shift;
 
506
    if(scalar(@_) != 0 || !defined($id) || $id < 1){
 
507
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
508
        return undef;
 
509
    }
 
510
    return Estraier::res_get_shadows($$self[4], $id);
 
511
}
 
512
 
 
513
 
 
514
 
 
515
package Database;
 
516
use Carp;
 
517
 
 
518
 
 
519
sub VERSION {
 
520
    return Estraier::db_version();
 
521
}
 
522
 
 
523
 
 
524
use constant {
 
525
    ERRNOERR => 0,
 
526
    ERRINVAL => 1,
 
527
    ERRACCES => 2,
 
528
    ERRLOCK => 3,
 
529
    ERRDB => 4,
 
530
    ERRIO => 5,
 
531
    ERRNOITEM => 6,
 
532
    ERRMISC => 9999,
 
533
    DBREADER => 1 << 0,
 
534
    DBWRITER => 1 << 1,
 
535
    DBCREAT => 1 << 2,
 
536
    DBTRUNC => 1 << 3,
 
537
    DBNOLCK => 1 << 4,
 
538
    DBLCKNB => 1 << 5,
 
539
    DBPERFNG => 1 << 10,
 
540
    DBCHRCAT => 1 << 11,
 
541
    DBSMALL => 1 << 20,
 
542
    DBLARGE => 1 << 21,
 
543
    DBHUGE => 1 << 22,
 
544
    DBHUGE2 => 1 << 23,
 
545
    DBHUGE3 => 1 << 24,
 
546
    DBSCVOID => 1 << 25,
 
547
    DBSCINT => 1 << 26,
 
548
    DBSCASIS => 1 << 27,
 
549
    IDXATTRSEQ => 0,
 
550
    IDXATTRSTR => 1,
 
551
    IDXATTRNUM => 2,
 
552
    OPTNOPURGE => 1 << 0,
 
553
    OPTNODBOPT => 1 << 1,
 
554
    MGCLEAN => 1 << 0,
 
555
    PDCLEAN => 1 << 0,
 
556
    PDWEIGHT => 1 << 1,
 
557
    ODCLEAN => 1 << 0,
 
558
    GDNOATTR => 1 << 0,
 
559
    GDNOTEXT => 1 << 1,
 
560
    GDNOKWD => 1 << 2,
 
561
};
 
562
 
 
563
 
 
564
sub new {
 
565
    my $class = shift;
 
566
    if(scalar(@_) != 0){
 
567
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
568
        return undef;
 
569
    }
 
570
    my $self = [0, ERRNOERR, undef];
 
571
    bless($self, $class);
 
572
    return $self;
 
573
}
 
574
 
 
575
 
 
576
sub DESTROY {
 
577
    my $self = shift;
 
578
    $self->close();
 
579
}
 
580
 
 
581
 
 
582
sub search_meta {
 
583
    my $dbs = shift;
 
584
    my $cond = shift;
 
585
    if(scalar(@_) != 0 || !defined($dbs) || ref($dbs) ne "ARRAY" ||
 
586
       !defined($cond) || ref($cond) ne "Condition"){
 
587
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
588
        return undef;
 
589
    }
 
590
    my @dbptrs;
 
591
    foreach my $elem (@$dbs){
 
592
        return undef if(ref($elem) ne "Database" || !$$elem[0]);
 
593
        push(@dbptrs, $$elem[0]);
 
594
    }
 
595
    my ($resptr, $idxsptr, $resnum, $hints, $tcond) =
 
596
        Estraier::db_search_meta(\@dbptrs, $$cond[0]);
 
597
    return new Result($resptr, $idxsptr, $resnum, $hints, $tcond);
 
598
}
 
599
 
 
600
 
 
601
sub err_msg {
 
602
    my $self = shift;
 
603
    my $ecode = shift;
 
604
    if(scalar(@_) != 0 || !defined($ecode)){
 
605
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
606
        return undef;
 
607
    }
 
608
    return Estraier::db_err_msg($ecode);
 
609
}
 
610
 
 
611
 
 
612
sub open {
 
613
    my $self = shift;
 
614
    my $name = shift;
 
615
    my $omode = shift;
 
616
    if(scalar(@_) != 0 || !defined($name) || !defined($omode)){
 
617
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
618
        return Estraier::FALSE;
 
619
    }
 
620
    if($$self[0]){
 
621
        $$self[1] = ERRMISC;
 
622
        return Estraier::FALSE;
 
623
    }
 
624
    ($$self[0], $$self[1]) = Estraier::db_open($name, $omode);
 
625
    return $$self[0] ? Estraier::TRUE : Estraier::FALSE;
 
626
}
 
627
 
 
628
 
 
629
sub close {
 
630
    my $self = shift;
 
631
    if(scalar(@_) != 0){
 
632
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
633
        return Estraier::FALSE;
 
634
    }
 
635
    unless($$self[0]){
 
636
        $$self[1] = ERRMISC;
 
637
        return Estraier::FALSE;
 
638
    }
 
639
    my $ok;
 
640
    ($ok, $$self[1]) = Estraier::db_close($$self[0]);
 
641
    $$self[0] = 0;
 
642
    return $ok ? Estraier::TRUE : Estraier::FALSE;
 
643
}
 
644
 
 
645
 
 
646
sub error {
 
647
    my $self = shift;
 
648
    return $$self[1];
 
649
}
 
650
 
 
651
 
 
652
sub fatal {
 
653
    my $self = shift;
 
654
    if(scalar(@_) != 0){
 
655
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
656
        return Estraier::FALSE;
 
657
    }
 
658
    unless($$self[0]){
 
659
        $$self[1] = ERRMISC;
 
660
        return Estraier::FALSE;
 
661
    }
 
662
    return Estraier::db_fatal($$self[0]);
 
663
}
 
664
 
 
665
 
 
666
sub add_attr_index {
 
667
    my $self = shift;
 
668
    my $name = shift;
 
669
    my $type = shift;
 
670
    if(scalar(@_) != 0 || !defined($name) || !defined($type)){
 
671
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
672
        return Estraier::FALSE;
 
673
    }
 
674
    unless($$self[0]){
 
675
        $$self[1] = ERRMISC;
 
676
        return Estraier::FALSE;
 
677
    }
 
678
    if(!Estraier::db_add_attr_index($$self[0], $name, $type)){
 
679
        $$self[1] = Estraier::db_error($$self[0]);
 
680
        return Estraier::FALSE;
 
681
    }
 
682
    return Estraier::TRUE;
 
683
}
 
684
 
 
685
 
 
686
sub flush {
 
687
    my $self = shift;
 
688
    my $max = shift;
 
689
    if(scalar(@_) != 0 || !defined($max)){
 
690
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
691
        return Estraier::FALSE;
 
692
    }
 
693
    unless($$self[0]){
 
694
        $$self[1] = ERRMISC;
 
695
        return Estraier::FALSE;
 
696
    }
 
697
    if(!Estraier::db_flush($$self[0], $max)){
 
698
        $$self[1] = Estraier::db_error($$self[0]);
 
699
        return Estraier::FALSE;
 
700
    }
 
701
    return Estraier::TRUE;
 
702
}
 
703
 
 
704
 
 
705
sub sync {
 
706
    my $self = shift;
 
707
    if(scalar(@_) != 0){
 
708
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
709
        return Estraier::FALSE;
 
710
    }
 
711
    unless($$self[0]){
 
712
        $$self[1] = ERRMISC;
 
713
        return Estraier::FALSE;
 
714
    }
 
715
    if(!Estraier::db_sync($$self[0])){
 
716
        $$self[1] = Estraier::db_error($$self[0]);
 
717
        return Estraier::FALSE;
 
718
    }
 
719
    return Estraier::TRUE;
 
720
}
 
721
 
 
722
 
 
723
sub optimize {
 
724
    my $self = shift;
 
725
    my $options = shift;
 
726
    if(scalar(@_) != 0 || !defined($options)){
 
727
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
728
        return Estraier::FALSE;
 
729
    }
 
730
    unless($$self[0]){
 
731
        $$self[1] = ERRMISC;
 
732
        return Estraier::FALSE;
 
733
    }
 
734
    if(!Estraier::db_optimize($$self[0], $options)){
 
735
        $$self[1] = Estraier::db_error($$self[0]);
 
736
        return Estraier::FALSE;
 
737
    }
 
738
    return Estraier::TRUE;
 
739
}
 
740
 
 
741
 
 
742
sub merge {
 
743
    my $self = shift;
 
744
    my $name = shift;
 
745
    my $options = shift;
 
746
    if(scalar(@_) != 0 || !defined($name) || !defined($options)){
 
747
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
748
        return Estraier::FALSE;
 
749
    }
 
750
    unless($$self[0]){
 
751
        $$self[1] = ERRMISC;
 
752
        return Estraier::FALSE;
 
753
    }
 
754
    if(!Estraier::db_merge($$self[0], $name, $options)){
 
755
        $$self[1] = Estraier::db_error($$self[0]);
 
756
        return Estraier::FALSE;
 
757
    }
 
758
    return Estraier::TRUE;
 
759
}
 
760
 
 
761
 
 
762
sub put_doc {
 
763
    my $self = shift;
 
764
    my $doc = shift;
 
765
    my $options = shift;
 
766
    if(scalar(@_) != 0 || !defined($doc) || ref($doc) ne "Document" || !defined($options)){
 
767
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
768
        return Estraier::FALSE;
 
769
    }
 
770
    unless($$self[0]){
 
771
        $$self[1] = ERRMISC;
 
772
        return Estraier::FALSE;
 
773
    }
 
774
    if(!Estraier::db_put_doc($$self[0], $$doc[0], $options)){
 
775
        $$self[1] = Estraier::db_error($$self[0]);
 
776
        return Estraier::FALSE;
 
777
    }
 
778
    return Estraier::TRUE;
 
779
}
 
780
 
 
781
 
 
782
sub out_doc {
 
783
    my $self = shift;
 
784
    my $id = shift;
 
785
    my $options = shift;
 
786
    if(scalar(@_) != 0 || !defined($id) || $id < 1 || !defined($options)){
 
787
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
788
        return Estraier::FALSE;
 
789
    }
 
790
    unless($$self[0]){
 
791
        $$self[1] = ERRMISC;
 
792
        return Estraier::FALSE;
 
793
    }
 
794
    if(!Estraier::db_out_doc($$self[0], $id, $options)){
 
795
        $$self[1] = Estraier::db_error($$self[0]);
 
796
        return Estraier::FALSE;
 
797
    }
 
798
    return Estraier::TRUE;
 
799
}
 
800
 
 
801
 
 
802
sub edit_doc {
 
803
    my $self = shift;
 
804
    my $doc = shift;
 
805
    if(scalar(@_) != 0 || !defined($doc) || ref($doc) ne "Document"){
 
806
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
807
        return Estraier::FALSE;
 
808
    }
 
809
    unless($$self[0]){
 
810
        $$self[1] = ERRMISC;
 
811
        return Estraier::FALSE;
 
812
    }
 
813
    if(!Estraier::db_edit_doc($$self[0], $$doc[0])){
 
814
        $$self[1] = Estraier::db_error($$self[0]);
 
815
        return Estraier::FALSE;
 
816
    }
 
817
    return Estraier::TRUE;
 
818
}
 
819
 
 
820
 
 
821
sub get_doc {
 
822
    my $self = shift;
 
823
    my $id = shift;
 
824
    my $options = shift;
 
825
    if(scalar(@_) != 0 || !defined($id) || $id < 1 || !defined($options)){
 
826
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
827
        return undef;
 
828
    }
 
829
    unless($$self[0]){
 
830
        $$self[1] = ERRMISC;
 
831
        return undef;
 
832
    }
 
833
    my $docptr = Estraier::db_get_doc($$self[0], $id, $options);
 
834
    if(!$docptr){
 
835
        $$self[1] = Estraier::db_error($$self[0]);
 
836
        return undef;
 
837
    }
 
838
    return new_with_ptr Document($docptr);
 
839
}
 
840
 
 
841
 
 
842
sub get_doc_attr {
 
843
    my $self = shift;
 
844
    my $id = shift;
 
845
    my $name = shift;
 
846
    if(scalar(@_) != 0 || !defined($id) || $id < 1 || !defined($name)){
 
847
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
848
        return undef;
 
849
    }
 
850
    unless($$self[0]){
 
851
        $$self[1] = ERRMISC;
 
852
        return undef;
 
853
    }
 
854
    my $value = Estraier::db_get_doc_attr($$self[0], $id, $name);
 
855
    if(!$value){
 
856
        $$self[1] = Estraier::db_error($$self[0]);
 
857
        return undef;
 
858
    }
 
859
    return $value;
 
860
}
 
861
 
 
862
 
 
863
sub uri_to_id {
 
864
    my $self = shift;
 
865
    my $uri = shift;
 
866
    if(scalar(@_) != 0 || !defined($uri)){
 
867
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
868
        return -1;
 
869
    }
 
870
    unless($$self[0]){
 
871
        $$self[1] = ERRMISC;
 
872
        return -1;
 
873
    }
 
874
    my $id = Estraier::db_uri_to_id($$self[0], $uri);
 
875
    if($id < 1){
 
876
        $$self[1] = Estraier::db_error($$self[0]);
 
877
        return -1;
 
878
    }
 
879
    return $id;
 
880
}
 
881
 
 
882
 
 
883
sub name {
 
884
    my $self = shift;
 
885
    if(scalar(@_) != 0){
 
886
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
887
        return undef;
 
888
    }
 
889
    unless($$self[0]){
 
890
        $$self[1] = ERRMISC;
 
891
        return undef;
 
892
    }
 
893
    return Estraier::db_name($$self[0]);
 
894
}
 
895
 
 
896
 
 
897
sub doc_num {
 
898
    my $self = shift;
 
899
    if(scalar(@_) != 0){
 
900
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
901
        return -1;
 
902
    }
 
903
    unless($$self[0]){
 
904
        $$self[1] = ERRMISC;
 
905
        return -1;
 
906
    }
 
907
    return Estraier::db_doc_num($$self[0]);
 
908
}
 
909
 
 
910
 
 
911
sub word_num {
 
912
    my $self = shift;
 
913
    if(scalar(@_) != 0){
 
914
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
915
        return -1;
 
916
    }
 
917
    unless($$self[0]){
 
918
        $$self[1] = ERRMISC;
 
919
        return -1;
 
920
    }
 
921
    return Estraier::db_word_num($$self[0]);
 
922
}
 
923
 
 
924
 
 
925
sub size {
 
926
    my $self = shift;
 
927
    if(scalar(@_) != 0){
 
928
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
929
        return -1;
 
930
    }
 
931
    unless($$self[0]){
 
932
        $$self[1] = ERRMISC;
 
933
        return -1;
 
934
    }
 
935
    return Estraier::db_size($$self[0]);
 
936
}
 
937
 
 
938
 
 
939
sub search {
 
940
    my $self = shift;
 
941
    my $cond = shift;
 
942
    if(scalar(@_) != 0 || !defined($cond) || ref($cond) ne "Condition"){
 
943
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
944
        return undef;
 
945
    }
 
946
    unless($$self[0]){
 
947
        $$self[1] = ERRMISC;
 
948
        return undef;
 
949
    }
 
950
    my ($resptr, $resnum, $hints, $tcond) = Estraier::db_search($$self[0], $$cond[0]);
 
951
    return new Result($resptr, undef, $resnum, $hints, $tcond);
 
952
}
 
953
 
 
954
 
 
955
sub scan_doc {
 
956
    my $self = shift;
 
957
    my $doc = shift;
 
958
    my $cond = shift;
 
959
    if(scalar(@_) != 0 || !defined($doc) || ref($doc) ne "Document" ||
 
960
       !defined($cond) || ref($cond) ne "Condition"){
 
961
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
962
        return undef;
 
963
    }
 
964
    unless($$self[0]){
 
965
        $$self[1] = ERRMISC;
 
966
        return undef;
 
967
    }
 
968
    return Estraier::db_scan_doc($$self[0], $$doc[0], $$cond[0]);
 
969
}
 
970
 
 
971
 
 
972
sub set_cache_size {
 
973
    my $self = shift;
 
974
    my $size = shift;
 
975
    my $anum = shift;
 
976
    my $tnum = shift;
 
977
    my $rnum = shift;
 
978
    if(scalar(@_) != 0 || !defined($size) ||
 
979
       !defined($anum) || !defined($tnum) || !defined($rnum)){
 
980
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
981
        return undef;
 
982
    }
 
983
    unless($$self[0]){
 
984
        $$self[1] = ERRMISC;
 
985
        return undef;
 
986
    }
 
987
    Estraier::db_set_cache_size($$self[0], $size, $anum, $tnum, $rnum);
 
988
    return undef;
 
989
}
 
990
 
 
991
 
 
992
sub add_pseudo_index {
 
993
    my $self = shift;
 
994
    my $path = shift;
 
995
    if(scalar(@_) != 0 || !defined($path)){
 
996
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
997
        return undef;
 
998
    }
 
999
    unless($$self[0]){
 
1000
        $$self[1] = ERRMISC;
 
1001
        return undef;
 
1002
    }
 
1003
    return Estraier::db_add_pseudo_index($$self[0], $path);
 
1004
}
 
1005
 
 
1006
 
 
1007
sub set_wildmax {
 
1008
    my $self = shift;
 
1009
    my $num = shift;
 
1010
    if(scalar(@_) != 0 || !defined($num) || $num < 0){
 
1011
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
1012
        return undef;
 
1013
    }
 
1014
    unless($$self[0]){
 
1015
        $$self[1] = ERRMISC;
 
1016
        return undef;
 
1017
    }
 
1018
    Estraier::db_set_wildmax($$self[0], $num);
 
1019
    return undef;
 
1020
}
 
1021
 
 
1022
 
 
1023
sub set_informer {
 
1024
    my $self = shift;
 
1025
    my $informer = shift;
 
1026
    if(scalar(@_) != 0 || !defined($informer) || ref(\$informer) ne "SCALAR"){
 
1027
        croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
 
1028
        return undef;
 
1029
    }
 
1030
    unless($$self[0]){
 
1031
        $$self[1] = ERRMISC;
 
1032
        return undef;
 
1033
    }
 
1034
    $$self[2] = $informer;
 
1035
    Estraier::db_set_informer($$self[0], $informer);
 
1036
    return undef;
 
1037
}
 
1038
 
 
1039
 
 
1040
 
 
1041
Estraier::TRUE;
 
1042
 
 
1043
 
 
1044
# END OF FILE