--- lib/Search/TokyoDystopia.pm 2008/08/17 23:53:11 10 +++ lib/Search/TokyoDystopia.pm 2008/09/09 13:17:16 34 @@ -6,7 +6,7 @@ require Exporter; require XSLoader; use base qw(Exporter); -our $VERSION = '0.00'; +our $VERSION = '0.01'; our $debug = 0; XSLoader::load('Search::TokyoDystopia', $VERSION); @@ -29,35 +29,117 @@ IDBOTRUNC IDBONOLCK IDBOLCKNB +tcidbclose +tcidbput +tcidbout +tcidbget +tcidbsearch +tcidbsearch2 +IDBSSUBSTR +IDBSPREFIX +IDBSSUFFIX +IDBSFULL +IDBSTOKEN +IDBSTOKPRE +IDBSTOKSUF +tcidbiterinit +tcidbiternext +tcidbsync +tcidboptimize +tcidbvanish +tcidbcopy +tcidbpath +tcidbrnum +tcidbfsiz + +tdversion +tcqdberrmsg +tcqdbnew +tcqdbdel +tcqdbnew +tcqdbecode +tcqdbtune +QDBTLARGE +QDBTDEFLATE +QDBTTCBS +tcqdbsetcache +tcqdbsetfwmmax +tcqdbopen +QDBOREADER +QDBOWRITER +QDBOCREAT +QDBOTRUNC +QDBONOLCK +QDBOLCKNB +tcqdbclose +tcqdbput +tcqdbout +tcqdbget +tcqdbsearch +tcqdbsearch2 +QDBSSUBSTR +QDBSPREFIX +QDBSSUFFIX +QDBSFULL +QDBSTOKEN +QDBSTOKPRE +QDBSTOKSUF +tcqdbiterinit +tcqdbiternext +tcqdbsync +tcqdboptimize +tcqdbvanish +tcqdbcopy +tcqdbpath +tcqdbtnum +tcqdbfsiz + ); =head1 NAME Search::TokyoDystopia - XS bindings for Tokyo Dystopia -=head1 EXPORTS +=head1 Core API If you don't prevent it, it will export all kind of stuff into your namespace to cut down on typing. +void +tcqdbget(qdb, id) + void * qdb + int id +PREINIT: + char *vbuf; +PPCODE: + vbuf = tcqdbget(qdb, id); + if(vbuf){ + XPUSHs(sv_2mortal(newSVpvn(vbuf, strlen(vbuf)))); + tcfree(vbuf); + } else { + XPUSHs((SV *)&PL_sv_undef); + } + XSRETURN(1); + + =head2 tcidberrmsg - my $message = Search::TokyoDystopia::tcidberrmsg( $ecode ); + my $message = tcidberrmsg( $ecode ); =head2 tcidbnew - my $idb = Search::TokyoDystopia::tcidbnew; + my $idb = tcidbnew; =head2 tcidbdel - Search::TokyoDystopia::tcidbdel( $idb ); + tcidbdel( $idb ); =head2 tcidbecode - my $ecode = Search::TokyoDystopia::tcidbecode( $idb ); + my $ecode = tcidbecode( $idb ); =head2 tcidbtune - my $success = Search::TokyoDystopia::tcidbtune( $idb, $ernum, $etnum, $iusiz, IDBTLARGE || IDBTDEFLATE ); + my $success = tcidbtune( $idb, $ernum, $etnum, $iusiz, IDBTLARGE | IDBTDEFLATE ); =cut @@ -69,15 +151,15 @@ =head2 tcidbsetcache - my $success = Search::TokyoDystopia::tcidbsetcache( $idb, $icsiz, $lcnum ); + my $success = tcidbsetcache( $idb, $icsiz, $lcnum ); =head2 tcidbsetfwmmax - my $success = Search::TokyoDystopia::tcidbsetfwmmax( $idb, $fwnum ); + my $success = tcidbsetfwmmax( $idb, $fwnum ); =head2 tcidbopen - Search::TokyoDystopia::tcidbopen( $idb, 'casket', IDBOTRUNC ), 1, 'tcidbopen' ); + my $success = tcidbopen( $idb, 'casket', IDBOWRITER | IDBOCREAT ); =cut @@ -90,6 +172,191 @@ IDBOLCKNB => 1 << 5, }; +=head2 tcidbclose + + my $success = tcidbclose( $idb ); + +=head2 tcidbput + + my $success = tcidbput( $idb, $id, $text ); + +=head2 tcidbout + + my $success = tcidbout( $idb, $id ); + +=head2 tcidbget + + my $text = tcidbget( $idb, $id ); + +=head2 tcidbsearch + + my $ids = tcidbsearch( $idb, $word, IDBSSUBSTR ); + +=cut + +use constant { + IDBSSUBSTR => 0, # substring matching + IDBSPREFIX => 1, # prefix matching + IDBSSUFFIX => 2, # suffix matching + IDBSFULL => 3, # full matching + IDBSTOKEN => 4, # token matching + IDBSTOKPRE => 5, # token prefix matching + IDBSTOKSUF => 6, # token suffix matching +}; + +=head2 tcidbsearch2 + + my $ids = tcidbsearch2( $idb, $expr ); + +=head2 tcidbiterinit + + my $success = tcidbiterinit( $idb ); + +=head2 tcidbiternext + + my $id = tcidbiternext( $idb ); + +=head2 tcidbsync + + my $success = tcidbsync( $idb ); + +=head2 tcidboptimize + + my $success = tcidboptimize( $idb ); + +=head2 tcidbvanish + + my $success = tcidbvanish( $idb ); + +=head2 tcidbcopy + + my $success = tcidbcopy( $idb, '/path/of/copy' ); + +=head2 tcidbpath + + my $path = tcidbpath( $idb ); + +=head2 tcidbrnum + + my $number_of_records = tcidbrnum( $idb ); + +=head2 tcidbfsiz + + my $file_size = tcidbfsiz( $idb ); + +=cut + +=head1 Q-gram API + +=head2 tcqdberrmsg + + my $message = tcqdberrmsg( $ecode ); + +=head2 tcqdbnew + + my $qdb = tcqdbnew; + +=head2 tcqdbdel + + tcqdbdel( $qdb ); + +=head2 tcqdbecode + + my $ecode = tcqdbecode( $qdb ); + +=head2 tcqdbtune + + my $success = tcqdbtune( $qdb, $etnum, QDBTLARGE | QDBTDEFLATE ); + +=cut + +use constant { + QDBTLARGE => 1 << 0, + QDBTDEFLATE => 1 << 1, + QDBTTCBS => 1 << 2, +}; + +=head2 tcqdbsetcache + + my $success = tcqdbsetcache( $qdb, $icsiz, $lcnum ); + +=head2 tcqdbsetfwmmax + + my $success = tcqdbsetfwmmax( $qdb, $fwnum ); + +=head2 tcqdbopen + + my $success = tcqdbopen( $qdb, 'casket', QDBOWRITER | QDBOCREAT ); + +=cut + +use constant { + QDBOREADER => 1 << 0, + QDBOWRITER => 1 << 1, + QDBOCREAT => 1 << 2, + QDBOTRUNC => 1 << 3, + QDBONOLCK => 1 << 4, + QDBOLCKNB => 1 << 5, +}; + +=head2 tcqdbclose + + my $success = tcqdbclose( $qdb ); + +=head2 tcqdbput + + my $success = tcqdbput( $qdb, $id, $text ); + +=head2 tcqdbout + + my $success = tcqdbout( $qdb, $id ); + +=head2 tcqdbsearch + + my $ids = tcqdbsearch( $qdb, $word, QDBSSUBSTR ); + +=cut + +use constant { + QDBSSUBSTR => 0, # substring matching + QDBSPREFIX => 1, # prefix matching + QDBSUFFIX => 2, # suffix matching + QDBFULL => 3, # full matching + QDBTOKEN => 4, # token matching + QDBTOKPRE => 5, # token prefix matching + QDBTOKSUF => 6, # token suffix matching +}; + +=head2 tcqdbsync + + my $success = tcqdbsync( $qdb ); + +=head2 tcqdboptimize + + my $success = tcqdboptimize( $qdb ); + +=head2 tcqdbvanish + + my $success = tcqdbvanish( $qdb ); + +=head2 tcqdbcopy + + my $success = tcqdbcopy( $qdb, '/path/of/copy' ); + +=head2 tcqdbpath + + my $path = tcqdbpath( $qdb ); + +=head2 tcqdbtnum + + my $number_of_records = tcqdbtnum( $qdb ); + +=head2 tcqdbfsiz + + my $file_size = tcqdbtsiz( $qdb ); + +=cut + =head1 KNOWN BUGS Low-level functions often just die when called on invalid (or deleted) database