/[BackupPC]/trunk/bin/BackupPC_updatedb
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/bin/BackupPC_updatedb

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 250 by dpavlin, Sun Dec 11 14:27:45 2005 UTC revision 303 by dpavlin, Sat Jan 28 16:45:46 2006 UTC
# Line 52  my $beenThere = {}; Line 52  my $beenThere = {};
52  my $dsn = $Conf{SearchDSN} || die "Need SearchDSN in config.pl\n";  my $dsn = $Conf{SearchDSN} || die "Need SearchDSN in config.pl\n";
53  my $user = $Conf{SearchUser} || '';  my $user = $Conf{SearchUser} || '';
54    
55  my $use_hest = $Conf{HyperEstraierIndex};  my $index_node_url = $Conf{HyperEstraierIndex};
 my ($index_path, $index_node_url) = BackupPC::SearchLib::getHyperEstraier_url($use_hest);  
56    
57  my $dbh = DBI->connect($dsn, $user, "", { RaiseError => 1, AutoCommit => 0 });  my $dbh = DBI->connect($dsn, $user, "", { RaiseError => 1, AutoCommit => 0 });
58    
# Line 87  if ($opt{v}) { Line 86  if ($opt{v}) {
86          $debug = $opt{v};          $debug = $opt{v};
87  } elsif ($opt{f}) {  } elsif ($opt{f}) {
88          print "WARNING: disabling full-text index update. You need to re-run $0 -j !\n";          print "WARNING: disabling full-text index update. You need to re-run $0 -j !\n";
89          ($use_hest, $index_path, $index_node_url) = (undef, undef, undef);          $index_node_url = undef;
90  }  }
91    
92  #---- subs ----  #---- subs ----
# Line 127  sub hest_update { Line 126  sub hest_update {
126    
127          my $skip_check = $opt{j} && print STDERR "Skipping check for existing files -- this should be used only with initital import\n";          my $skip_check = $opt{j} && print STDERR "Skipping check for existing files -- this should be used only with initital import\n";
128    
129          unless (defined($use_hest)) {          unless (defined($index_node_url)) {
130                  print STDERR "HyperEstraier support not enabled in configuration\n";                  print STDERR "HyperEstraier support not enabled in configuration\n";
131                  $use_hest = 0;                  $index_node_url = 0;
132                  return;                  return;
133          }          }
134    
135          return unless($use_hest);          print curr_time," updating Hyper Estraier:";
   
         print curr_time," updating HyperEstraier:";  
136    
137          my $t = time();          my $t = time();
138    
139          my $offset = 0;          my $offset = 0;
140          my $added = 0;          my $added = 0;
141    
142          print " opening index $use_hest";          print " opening index $index_node_url";
143          if ($index_path) {          if ($index_node_url) {
144                  $hest_db = HyperEstraier::Database->new();                  $hest_node ||= Search::Estraier::Node->new($index_node_url);
                 $hest_db->open($TopDir . $index_path, $HyperEstraier::Database::DBWRITER | $HyperEstraier::Database::DBCREAT);  
                 print " directly";  
         } elsif ($index_node_url) {  
                 $hest_node ||= HyperEstraier::Node->new($index_node_url);  
145                  $hest_node->set_auth('admin', 'admin');                  $hest_node->set_auth('admin', 'admin');
146                  print " via node URL";                  print " via node URL";
147          } else {          } else {
148                  die "don't know how to use HyperEstraier Index $use_hest";                  die "don't know how to use Hyper Estraier Index $index_node_url";
149          }          }
         print " increment is " . EST_CHUNK . " files:";  
150    
151          my $results = 0;          my $results = 0;
152    
# Line 202  sub hest_update { Line 194  sub hest_update {
194                  if ($results == 0) {                  if ($results == 0) {
195                          print " - no new files\n";                          print " - no new files\n";
196                          last;                          last;
197                    } else {
198                            print " - $results files: ";
199                  }                  }
200    
201                  sub fmt_date {                  sub fmt_date {
# Line 222  sub hest_update { Line 216  sub hest_update {
216                          }                          }
217    
218                          # create a document object                          # create a document object
219                          my $doc = HyperEstraier::Document->new;                          my $doc = Search::Estraier::Document->new;
220    
221                          # add attributes to the document object                          # add attributes to the document object
222                          $doc->add_attr('@uri', $uri);                          $doc->add_attr('@uri', $uri);
# Line 242  sub hest_update { Line 236  sub hest_update {
236                          print STDERR $doc->dump_draft,"\n" if ($debug > 1);                          print STDERR $doc->dump_draft,"\n" if ($debug > 1);
237    
238                          # register the document object to the database                          # register the document object to the database
239                          if ($hest_db) {                          if ($hest_node) {
                                 $hest_db->put_doc($doc, $HyperEstraier::Database::PDCLEAN);  
                         } elsif ($hest_node) {  
240                                  $hest_node->put_doc($doc);                                  $hest_node->put_doc($doc);
241                          } else {                          } else {
242                                  die "not supported";                                  die "not supported";
# Line 253  sub hest_update { Line 245  sub hest_update {
245                  }                  }
246    
247                  print " $added";                  print " $added";
                 $hest_db->sync() if ($index_path);  
248    
249                  $offset += EST_CHUNK;                  $offset += EST_CHUNK;
250    
251          } while ($results == EST_CHUNK);          } while ($results == EST_CHUNK);
252    
         if ($index_path) {  
                 print ", close";  
                 $hest_db->close();  
         }  
   
253          my $dur = (time() - $t) || 1;          my $dur = (time() - $t) || 1;
254          printf(" [%.2f/s dur: %s]\n",          printf(" [%.2f/s dur: %s]\n",
255                  ( $added / $dur ),                  ( $added / $dur ),
# Line 275  sub hest_update { Line 261  sub hest_update {
261    
262    
263  ## update index ##  ## update index ##
264  if (($opt{i} || $opt{j} || ($index_path && ! -e $TopDir . $index_path)) && !$opt{c}) {  if ( ( $opt{i} || $opt{j} ) && !$opt{c} ) {
265          # update all          # update all
266          print "force update of HyperEstraier index ";          print "force update of Hyper Estraier index ";
         print "importing existing data" unless (-e $TopDir . $index_path);  
267          print "by -i flag" if ($opt{i});          print "by -i flag" if ($opt{i});
268          print "by -j flag" if ($opt{j});          print "by -j flag" if ($opt{j});
269          print "\n";          print "\n";

Legend:
Removed from v.250  
changed lines
  Added in v.303

  ViewVC Help
Powered by ViewVC 1.1.26