added experimental HyperEstraier index creation.
authordpavlin <dpavlin@8392b6e1-25fa-0310-8288-cc32f8e212ea>
Sun, 28 Aug 2005 08:40:06 +0000 (08:40 +0000)
committerdpavlin <dpavlin@8392b6e1-25fa-0310-8288-cc32f8e212ea>
Sun, 28 Aug 2005 08:40:06 +0000 (08:40 +0000)
git-svn-id: svn+ssh://llin/home/dpavlin/private/svn/BackupPC/trunk@81 8392b6e1-25fa-0310-8288-cc32f8e212ea

Makefile
bin/BackupPC_updatedb

index 2afc93c..b478d1f 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -29,6 +29,10 @@ install-etc:
 update:
        sudo -u backuppc /data/backuppc/bin/BackupPC_updatedb
 
+index: test
+       test -d /tmp/casket && sudo rm -Rf /tmp/casket || true
+       sudo -u backuppc /data/backuppc/bin/BackupPC_updatedb -i -v 2 2>debug
+
 xls:
        sudo -u backuppc /data/backuppc/bin/BackupPC_xls_report && cp -vf /tmp/report.xls ~/public_html/
 
index ae14d63..13a91c4 100755 (executable)
@@ -45,19 +45,112 @@ my $dbh = DBI->connect($dsn, $user, "", { RaiseError => 1, AutoCommit => 0 });
 
 my %opt;
 
-if ( !getopts("cdm:v:", \%opt ) ) {
+if ( !getopts("cdm:v:i", \%opt ) ) {
        print STDERR <<EOF;
-usage: $0 [-c|-d] [-m num] [-v|-v level]
+usage: $0 [-c|-d] [-m num] [-v|-v level] [-i]
 
 Options:
        -c      create database on first use
        -d      delete database before import
        -m num  import just num increments for one host
        -v num  set verbosity (debug) level (default $debug)
+       -i      update HyperEstraier full text index
 EOF
        exit 1;
 }
 
+if ($opt{v}) {
+       print "Debug level at $opt{v}\n";
+       $debug = $opt{v};
+}
+
+## update index ##
+if ($opt{i}) {
+
+       my $index_dir = '/var/tmp/casket';
+
+       print "updating HyperEstraier index $index_dir...";
+
+       use HyperEstraier;
+       my $db = HyperEstraier::Database->new();
+       $db->open($index_dir, $HyperEstraier::Database::DBWRITER | $HyperEstraier::Database::DBCREAT);
+
+       my $sth = $dbh->prepare(qq{
+               SELECT
+                       files.id                        AS fid,
+                       hosts.name                      AS hname,
+                       shares.name                     AS sname,
+                       shares.share                    AS sharename,
+                       files.backupNum                 AS backupNum,
+                       files.name                      AS filename,
+                       files.path                      AS filepath,
+                       files.date                      AS date,
+                       files.type                      AS filetype,
+                       files.size                      AS size,
+                       files.shareid                   AS shareid
+               FROM files 
+                       INNER JOIN shares       ON files.shareID=shares.ID
+                       INNER JOIN hosts        ON hosts.ID = shares.hostID
+                       INNER JOIN backups      ON backups.num = files.backupNum and backups.hostID = hosts.ID AND backups.shareID = shares.ID
+       });
+
+       $sth->execute();
+
+       my $dot = int($sth->rows / 15);
+
+       print $sth->rows, " files ($dot/#) ";
+
+       sub fmt_date {
+               my $t = shift || return;
+               my $iso = BackupPC::Lib::timeStamp($t);
+               $iso =~ s/\s/T/;
+               return $iso;
+       }
+
+       my $i = 0;
+       my $max = int($sth->rows / $dot);
+
+       while (my $row = $sth->fetchrow_hashref()) {
+
+               # create a document object 
+               my $doc = HyperEstraier::Document->new;
+
+               # add attributes to the document object 
+               $doc->add_attr('@uri', 'file:///' . $row->{'fid'});
+
+               foreach my $c (qw/fid hname sname sharename backupNum filename filepath shareid/) {
+                       $doc->add_attr($c, $row->{$c}) if ($row->{$c});
+               }
+
+               $doc->add_attr('date', fmt_date($row->{'date'}));
+
+               # add the body text to the document object 
+               my $path = $row->{'filepath'};
+               $doc->add_text($path);
+               $path =~ s/(.)/$1 /g;
+               $doc->add_hidden_text($path);
+
+               print STDERR $doc->dump_draft,"\n" if ($debug > 1);
+
+               # register the document object to the database
+               $db->put_doc($doc, $HyperEstraier::Database::PDCLEAN);
+
+               $i++;
+               if ($i % $dot == 0) {
+                       print "$max ";
+                       $max--;
+               }
+
+       }
+
+       print "sync";
+       $db->sync();
+       print " close\n";
+       $db->close();
+
+       exit;
+}
+
 ###################################create tables############################3
 
 if ($opt{c}) {
@@ -160,11 +253,6 @@ if ($opt{d}) {
        $dbh->commit;
 }
 
-if ($opt{v}) {
-       print "Debug level at $opt{v}\n";
-       $debug = $opt{v};
-}
-
 #################################INSERT VALUES#############################
 
 # get hosts