WAIT
view release on metacpan or search on metacpan
lib/WAIT/Table.pm view on Meta::CPAN
sub create_inverted_index {
my $self = shift;
my %parm = @_;
croak "No attribute specified" unless $parm{attribute};
croak "No pipeline specified" unless $parm{pipeline};
$parm{predicate} ||= $parm{pipeline}->[-1];
croak "Cannot create index for table aready populated"
if $self->{nextk} > 1;
require WAIT::InvertedIndex;
# backward compatibility stuff
my %opt = %parm;
for (qw(attribute pipeline predicate)) {
delete $opt{$_};
}
my $name = join '_', ($parm{attribute}, @{$parm{pipeline}});
my $idx = new WAIT::InvertedIndex(file => $self->{file}.'/'.$name,
filter => [@{$parm{pipeline}}], # clone
name => $name,
attr => $parm{attribute},
%opt, # backward compatibility stuff
);
# We will have to use $parm{predicate} here
push @{$self->{inverted}->{$parm{attribute}}}, $idx;
}
sub dir {
$_[0]->{file};
}
=head2 C<$tb-E<gt>layout>
Returns the reference to the associated parser object.
=cut
sub layout { $_[0]->{layout} }
=head2 C<$tb-E<gt>fields>
Returns the array of attribute names.
=cut
sub fields { keys %{$_[0]->{inverted}}}
=head2 C<$tb-E<gt>drop>
Must be called via C<WAIT::Database::drop_table>
=cut
sub drop {
my $self = shift;
if ((caller)[0] eq 'WAIT::Database') { # database knows about this
$self->close; # just make sure
my $file = $self->{file};
for (values %{$self->{indexes}}) {
$_->drop;
}
unlink "$file/records";
# $self->unlock;
! (!-e $file or rmdir $file);
} else {
croak ref($self)."::drop called directly";
}
}
sub mrequire ($) {
my $module = shift;
$module =~ s{::}{/}g;
$module .= '.pm';
require $module;
}
sub open {
my $self = shift;
my $file = $self->{file} . '/records';
mrequire ref($self); # that's tricky eh?
if (defined $self->{'layout'}) {
mrequire ref($self->{'layout'});
}
if (defined $self->{'access'}) {
mrequire ref($self->{'access'});
}
if (exists $self->{indexes}) {
require WAIT::Index;
for (values %{$self->{indexes}}) {
$_->{mode} = $self->{mode};
}
}
if (exists $self->{inverted}) {
my ($att, $idx);
for $att (keys %{$self->{inverted}}) {
for $idx (@{$self->{inverted}->{$att}}) {
$idx->{mode} = $self->{mode};
}
}
require WAIT::InvertedIndex;
}
unless (defined $self->{dbh}) {
if ($USE_RECNO) {
$self->{dbh} = tie(@{$self->{db}}, 'DB_File', $file,
$self->{mode}, 0664, $DB_RECNO);
} else {
$self->{dbh} =
tie(%{$self->{db}}, 'DB_File', $file,
$self->{mode}, 0664, $DB_BTREE);
}
}
# Locking
( run in 0.842 second using v1.01-cache-2.11-cpan-4ef0a570458 )