NAME
Metadata::DB::File::Indexer
DESCRIPTION
The indexer object is a main interface to creating and managing metadata tables about many files. This object does not manage child instances of Metadata::DB::File, code that elsewhere.
SYNOPSIS
# start a database handle
my $dbh;
my $i = Metadata::DB::File::Indexer->new({ DBH => $dbh });
$i->table_all_reset; # clear everything
# You are left to figure out on your own what files to index
my @files;
$i->files_to_index(\@files);
# you should determine what metadata will be stored for each
# by overriding Metadata::DB::File::Indexer::_abs_path_to_metadata()
no warnings 'redefine';
*Metadata::DB::File::Indexer::_abs_path_to_metadata = \&mysub;
sub mysub {
my $abs_path = shift;
my $meta = {}; #whatever you want
return $meta;
}
$i->run;
REINDEXING ALL
If you want to reindex an entire archive you should
1) reset/clear the tables
$i->table_all_reset;
2) determine the files you want to index, abs paths
my @files;
$i->files_to_index_set(\@files);
3) define a method to turn one of the paths to metadata
&Metadata::DB::File::Indexer::_abs_path_to_metadata =
sub { my $abs_path = shift; my hash = {} ; return $hash; }
REINDEXING A PORTION
What if you only want to reindex a section? Maybe you indexed /home/myself/mp3s but you just want to reindex a subpath...
1) reset that portion
$i->tree_clear('/home/myself/mp3s');
2) determine the files you will index, used File::Find::Rule etc
my @files
3) determine how to convert into a metadata hash
&Metadata::DB::File::Indexer::_abs_path_to_metadata =
sub { my $abs_path = shift; my hash = {} ; return $hash; }
3) set and run
$i->files_to_index_set(\@files);
$i->run;
METHODS
new()
required arg is hashref with key DBH to open database handle
my $i = Metadata::DB::File::Indexer({ DBH => $dbh });
table_all_reset()
you'll have to call for the first time
files_indexed_count()
returns number
files_to_index()
files_to_index_set()
arg is array ref with abs paths to files on disk
files_to_index_count()
returns count of files indexed
run()
takes no args runs the indexing procedure
WHAT IF I WANT TO CHANGE THE NAME OF THE TABLE
What if you want to store in another table?
Data is stored in two tables, the metadata table, and the files table. to rename these..
(To read more: Metadata::DB::Base and Metadat::DB::File::Base )
table_metadata_name_set()
arg is string
table_files_name_set()
arg is string
CAVEAT
Before you index, make sure the entries are cleared.. you can do this:
$i->tree_clear('/lowest/common/denominator/base');
$i->run;
If you know will reindex the entire achive tree(everything you want to be in the db), then you can simple reset the metadata and files table:
$i->table_all_reset;
$i->run;
SEE ALSO
Metadata::DB Metadata::DB::Base Metadata::DB::Search Metadata::DB::Analizer Metadata::DB::File Metadata::DB::File::Base
AUTHOR
Leo Charre leocharre at cpan dot org