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
#-------------------------------------------------------------------------------------------------
25
our @ISA = qw(Exporter);
28
XSLoader::load('Estraier', $VERSION);
44
return 0 unless $str =~ /^[0-9]+/;
46
foreach my $d (split(//, $str)){
47
last unless($d =~ /^[0-9]$/);
63
croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
67
$$self[0] = defined($draft) ? Estraier::doc_new_from_draft($draft) : Estraier::doc_new();
76
if(scalar(@_) != 0 || !defined($ptr)){
77
croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
89
return undef unless($$self[0]);
90
Estraier::doc_delete($$self[0]);
99
if(scalar(@_) != 0 || !defined($name)){
100
croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
103
$value = "\t(NULL)\t" if(!defined($value));
104
Estraier::doc_add_attr($$self[0], $name, $value);
112
if(scalar(@_) != 0 || !defined($text)){
113
croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
116
Estraier::doc_add_text($$self[0], $text);
121
sub add_hidden_text {
124
if(scalar(@_) != 0 || !defined($text)){
125
croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
128
Estraier::doc_add_hidden_text($$self[0], $text);
136
if(scalar(@_) != 0 || !defined($kwords) || ref($kwords) ne "HASH"){
137
croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
140
Estraier::doc_set_keywords($$self[0], $kwords);
148
if(scalar(@_) != 0 || !defined($score) || $score < 0){
149
croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
152
Estraier::doc_set_score($$self[0], $score);
160
croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
163
return Estraier::doc_id($$self[0]);
170
croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
173
return Estraier::doc_attr_names($$self[0]);
180
if(scalar(@_) != 0 || !defined($name)){
181
croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
184
return Estraier::doc_attr($$self[0], $name);
191
croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
194
return Estraier::doc_texts($$self[0]);
201
croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
204
return Estraier::doc_cat_texts($$self[0]);
211
croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
214
return Estraier::doc_keywords($$self[0]);
221
croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
224
return Estraier::doc_score($$self[0]);
231
croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
234
return Estraier::doc_dump_draft($$self[0]);
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);
250
return Estraier::doc_make_snippet($$self[0], $words, $wwidth, $hwidth, $awidth);
279
croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
283
$$self[0] = Estraier::cond_new();
284
bless($self, $class);
291
return undef unless($$self[0]);
292
Estraier::cond_delete($$self[0]);
300
if(scalar(@_) != 0 || !defined($phrase)){
301
croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
304
Estraier::cond_set_phrase($$self[0], $phrase);
312
if(scalar(@_) != 0 || !defined($expr)){
313
croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
316
Estraier::cond_add_attr($$self[0], $expr);
324
if(scalar(@_) != 0 || !defined($expr)){
325
croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
328
Estraier::cond_set_order($$self[0], $expr);
336
if(scalar(@_) != 0 || !defined($max) || $max < 0){
337
croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
340
Estraier::cond_set_max($$self[0], $max);
348
if(scalar(@_) != 0 || !defined($skip) || $skip < 0){
349
croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
352
Estraier::cond_set_skip($$self[0], $skip);
360
if(scalar(@_) != 0 || !defined($options)){
361
croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
364
Estraier::cond_set_options($$self[0], $options);
372
if(scalar(@_) != 0 || !defined($min)){
373
croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
376
Estraier::cond_set_auxiliary($$self[0], $min);
384
if(scalar(@_) != 0 || !defined($limit)){
385
croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
388
Estraier::cond_set_eclipse($$self[0], $limit);
396
if(scalar(@_) != 0 || !defined($name)){
397
croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
400
Estraier::cond_set_distinct($$self[0], $name);
417
if(scalar(@_) != 0 || !defined($resptr) || !defined($resnum) ||
418
!defined($hints) || !defined($cond)){
419
croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
422
my $self = [$resptr, $idxsptr, $resnum, $hints, $cond];
423
bless($self, $class);
430
return undef unless($$self[0]);
431
Estraier::res_delete($$self[0], defined($$self[1]) ? $$self[1] : 0, $$self[3], $$self[4]);
439
croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
449
if(scalar(@_) != 0 || !defined($index)){
450
croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
453
return -1 if($index < 0 || $index >= $$self[2]);
454
return Estraier::res_get_doc_id($$self[0], $index);
461
if(scalar(@_) != 0 || !defined($index)){
462
croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
465
return -1 if(!defined($$self[1]) || $index < 0 || $index >= $$self[2]);
466
return Estraier::res_get_dbidx($$self[1], $index);
473
croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
476
return Estraier::res_hint_words($$self[3]);
483
if(scalar(@_) != 0 || !defined($word)){
484
croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
487
return Estraier::res_hint($$self[3], $word);
494
if(scalar(@_) != 0 || !defined($index)){
495
croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
498
return -1 if($index < 0 || $index >= $$self[2]);
499
return Estraier::res_get_score($$self[4], $index);
506
if(scalar(@_) != 0 || !defined($id) || $id < 1){
507
croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
510
return Estraier::res_get_shadows($$self[4], $id);
520
return Estraier::db_version();
552
OPTNOPURGE => 1 << 0,
553
OPTNODBOPT => 1 << 1,
567
croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
570
my $self = [0, ERRNOERR, undef];
571
bless($self, $class);
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);
591
foreach my $elem (@$dbs){
592
return undef if(ref($elem) ne "Database" || !$$elem[0]);
593
push(@dbptrs, $$elem[0]);
595
my ($resptr, $idxsptr, $resnum, $hints, $tcond) =
596
Estraier::db_search_meta(\@dbptrs, $$cond[0]);
597
return new Result($resptr, $idxsptr, $resnum, $hints, $tcond);
604
if(scalar(@_) != 0 || !defined($ecode)){
605
croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
608
return Estraier::db_err_msg($ecode);
616
if(scalar(@_) != 0 || !defined($name) || !defined($omode)){
617
croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
618
return Estraier::FALSE;
622
return Estraier::FALSE;
624
($$self[0], $$self[1]) = Estraier::db_open($name, $omode);
625
return $$self[0] ? Estraier::TRUE : Estraier::FALSE;
632
croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
633
return Estraier::FALSE;
637
return Estraier::FALSE;
640
($ok, $$self[1]) = Estraier::db_close($$self[0]);
642
return $ok ? Estraier::TRUE : Estraier::FALSE;
655
croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
656
return Estraier::FALSE;
660
return Estraier::FALSE;
662
return Estraier::db_fatal($$self[0]);
670
if(scalar(@_) != 0 || !defined($name) || !defined($type)){
671
croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
672
return Estraier::FALSE;
676
return Estraier::FALSE;
678
if(!Estraier::db_add_attr_index($$self[0], $name, $type)){
679
$$self[1] = Estraier::db_error($$self[0]);
680
return Estraier::FALSE;
682
return Estraier::TRUE;
689
if(scalar(@_) != 0 || !defined($max)){
690
croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
691
return Estraier::FALSE;
695
return Estraier::FALSE;
697
if(!Estraier::db_flush($$self[0], $max)){
698
$$self[1] = Estraier::db_error($$self[0]);
699
return Estraier::FALSE;
701
return Estraier::TRUE;
708
croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
709
return Estraier::FALSE;
713
return Estraier::FALSE;
715
if(!Estraier::db_sync($$self[0])){
716
$$self[1] = Estraier::db_error($$self[0]);
717
return Estraier::FALSE;
719
return Estraier::TRUE;
726
if(scalar(@_) != 0 || !defined($options)){
727
croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
728
return Estraier::FALSE;
732
return Estraier::FALSE;
734
if(!Estraier::db_optimize($$self[0], $options)){
735
$$self[1] = Estraier::db_error($$self[0]);
736
return Estraier::FALSE;
738
return Estraier::TRUE;
746
if(scalar(@_) != 0 || !defined($name) || !defined($options)){
747
croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
748
return Estraier::FALSE;
752
return Estraier::FALSE;
754
if(!Estraier::db_merge($$self[0], $name, $options)){
755
$$self[1] = Estraier::db_error($$self[0]);
756
return Estraier::FALSE;
758
return Estraier::TRUE;
766
if(scalar(@_) != 0 || !defined($doc) || ref($doc) ne "Document" || !defined($options)){
767
croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
768
return Estraier::FALSE;
772
return Estraier::FALSE;
774
if(!Estraier::db_put_doc($$self[0], $$doc[0], $options)){
775
$$self[1] = Estraier::db_error($$self[0]);
776
return Estraier::FALSE;
778
return Estraier::TRUE;
786
if(scalar(@_) != 0 || !defined($id) || $id < 1 || !defined($options)){
787
croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
788
return Estraier::FALSE;
792
return Estraier::FALSE;
794
if(!Estraier::db_out_doc($$self[0], $id, $options)){
795
$$self[1] = Estraier::db_error($$self[0]);
796
return Estraier::FALSE;
798
return Estraier::TRUE;
805
if(scalar(@_) != 0 || !defined($doc) || ref($doc) ne "Document"){
806
croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
807
return Estraier::FALSE;
811
return Estraier::FALSE;
813
if(!Estraier::db_edit_doc($$self[0], $$doc[0])){
814
$$self[1] = Estraier::db_error($$self[0]);
815
return Estraier::FALSE;
817
return Estraier::TRUE;
825
if(scalar(@_) != 0 || !defined($id) || $id < 1 || !defined($options)){
826
croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
833
my $docptr = Estraier::db_get_doc($$self[0], $id, $options);
835
$$self[1] = Estraier::db_error($$self[0]);
838
return new_with_ptr Document($docptr);
846
if(scalar(@_) != 0 || !defined($id) || $id < 1 || !defined($name)){
847
croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
854
my $value = Estraier::db_get_doc_attr($$self[0], $id, $name);
856
$$self[1] = Estraier::db_error($$self[0]);
866
if(scalar(@_) != 0 || !defined($uri)){
867
croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
874
my $id = Estraier::db_uri_to_id($$self[0], $uri);
876
$$self[1] = Estraier::db_error($$self[0]);
886
croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
893
return Estraier::db_name($$self[0]);
900
croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
907
return Estraier::db_doc_num($$self[0]);
914
croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
921
return Estraier::db_word_num($$self[0]);
928
croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
935
return Estraier::db_size($$self[0]);
942
if(scalar(@_) != 0 || !defined($cond) || ref($cond) ne "Condition"){
943
croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
950
my ($resptr, $resnum, $hints, $tcond) = Estraier::db_search($$self[0], $$cond[0]);
951
return new Result($resptr, undef, $resnum, $hints, $tcond);
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);
968
return Estraier::db_scan_doc($$self[0], $$doc[0], $$cond[0]);
978
if(scalar(@_) != 0 || !defined($size) ||
979
!defined($anum) || !defined($tnum) || !defined($rnum)){
980
croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
987
Estraier::db_set_cache_size($$self[0], $size, $anum, $tnum, $rnum);
992
sub add_pseudo_index {
995
if(scalar(@_) != 0 || !defined($path)){
996
croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
1000
$$self[1] = ERRMISC;
1003
return Estraier::db_add_pseudo_index($$self[0], $path);
1010
if(scalar(@_) != 0 || !defined($num) || $num < 0){
1011
croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
1015
$$self[1] = ERRMISC;
1018
Estraier::db_set_wildmax($$self[0], $num);
1025
my $informer = shift;
1026
if(scalar(@_) != 0 || !defined($informer) || ref(\$informer) ne "SCALAR"){
1027
croak(__FILE__ . ": invalid parameter") if($Estraier::DEBUG);
1031
$$self[1] = ERRMISC;
1034
$$self[2] = $informer;
1035
Estraier::db_set_informer($$self[0], $informer);