| 1 | package SWISH::Prog::Xapian::InvIndex; | ||
| 2 | 2 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | 2 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 2 | ▶ | use base qw( SWISH::Prog::InvIndex ); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | use Carp; | ||
| 6 | use Search::Xapian ':db'; | ||
| 7 | __PACKAGE__->mk_ro_accessors(qw( xdb )); | ||
| 8 | |||
| 9 | our $VERSION = '0.09'; | ||
| 10 | |||
| 11 | =head1 NAME | ||
| 12 | |||
| 13 | SWISH::Prog::Xapian::InvIndex - Swish3 Xapian backend InvIndex | ||
| 14 | |||
| 15 | =head1 SYNOPSIS | ||
| 16 | |||
| 17 | # see SWISH::Prog::InvIndex | ||
| 18 | |||
| 19 | =cut | ||
| 20 | |||
| 21 | =head1 METHODS | ||
| 22 | |||
| 23 | Only new and overridden methods are documented here. See | ||
| 24 | the L<SWISH::Prog::InvIndex> documentation. | ||
| 25 | |||
| 26 | =head2 open | ||
| 27 | |||
| 28 | Open a WriteableDatabase and calls begin_transaction() on the | ||
| 29 | database handle. | ||
| 30 | |||
| 31 | =cut | ||
| 32 | |||
| 33 | sub open { | ||
| 34 | my $self = shift; | ||
| 35 | $self->{xdb} | ||
| 36 | = Search::Xapian::WritableDatabase->new( "$self", | ||
| 37 | $self->clobber ? DB_CREATE_OR_OVERWRITE : DB_CREATE_OR_OPEN ) | ||
| 38 | or croak "can't create Xapian WritableDatabase $self: $!"; | ||
| 39 | $self->{xdb}->begin_transaction(); | ||
| 40 | |||
| 41 | #warn "xdb open for $self->{xdb}"; | ||
| 42 | } | ||
| 43 | |||
| 44 | =head2 open_ro | ||
| 45 | |||
| 46 | Open a Database. | ||
| 47 | |||
| 48 | =cut | ||
| 49 | |||
| 50 | sub open_ro { | ||
| 51 | my $self = shift; | ||
| 52 | $self->{xdb} = Search::Xapian::Database->new("$self") | ||
| 53 | or croak "can't open Xapian Database $self: $!"; | ||
| 54 | |||
| 55 | #warn "xdb open_ro for $self->{xdb}"; | ||
| 56 | } | ||
| 57 | |||
| 58 | =head2 close | ||
| 59 | |||
| 60 | Calls commit_transaction() if the xdb() isa WriteableDatabase. | ||
| 61 | |||
| 62 | =cut | ||
| 63 | |||
| 64 | sub close { | ||
| 65 | my $self = shift; | ||
| 66 | $self->{xdb}->commit_transaction() | ||
| 67 | if $self->{xdb}->can('commit_transaction'); | ||
| 68 | $self->{xdb}->close() if $self->{xdb}->can('close'); | ||
| 69 | |||
| 70 | #warn "xdb close for $self->{xdb}"; | ||
| 71 | } | ||
| 72 | |||
| 73 | =head2 xdb | ||
| 74 | |||
| 75 | Returns the internal Search::Xapian::Database object. | ||
| 76 | |||
| 77 | =cut | ||
| 78 | |||
| 79 | 1; | ||
| 80 | |||
| 81 | __END__ | ||