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 |
|
|
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 ---- |
104 |
return strftime($t_fmt,localtime()); |
return strftime($t_fmt,localtime()); |
105 |
} |
} |
106 |
|
|
|
my $hest_db; |
|
107 |
my $hest_node; |
my $hest_node; |
108 |
|
|
|
sub signal { |
|
|
my($sig) = @_; |
|
|
if ($hest_db) { |
|
|
print "\nCaught a SIG$sig--syncing database and shutting down\n"; |
|
|
$hest_db->sync(); |
|
|
$hest_db->close(); |
|
|
} |
|
|
exit(0); |
|
|
} |
|
|
|
|
|
$SIG{'INT'} = \&signal; |
|
|
$SIG{'QUIT'} = \&signal; |
|
|
|
|
109 |
sub hest_update { |
sub hest_update { |
110 |
|
|
111 |
my ($host_id, $share_id, $num) = @_; |
my ($host_id, $share_id, $num) = @_; |
112 |
|
|
113 |
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"; |
114 |
|
|
115 |
unless (defined($use_hest)) { |
unless (defined($index_node_url)) { |
116 |
print STDERR "HyperEstraier support not enabled in configuration\n"; |
print STDERR "HyperEstraier support not enabled in configuration\n"; |
117 |
$use_hest = 0; |
$index_node_url = 0; |
118 |
return; |
return; |
119 |
} |
} |
120 |
|
|
121 |
return unless($use_hest); |
print curr_time," updating Hyper Estraier:"; |
|
|
|
|
print curr_time," updating HyperEstraier:"; |
|
122 |
|
|
123 |
my $t = time(); |
my $t = time(); |
124 |
|
|
125 |
my $offset = 0; |
my $offset = 0; |
126 |
my $added = 0; |
my $added = 0; |
127 |
|
|
128 |
print " opening index $use_hest"; |
print " opening index $index_node_url"; |
129 |
if ($index_path) { |
if ($index_node_url) { |
130 |
$hest_db = HyperEstraier::Database->new(); |
$hest_node ||= Search::Estraier::Node->new( |
131 |
$hest_db->open($TopDir . $index_path, $HyperEstraier::Database::DBWRITER | $HyperEstraier::Database::DBCREAT); |
url => $index_node_url, |
132 |
print " directly"; |
user => 'admin', |
133 |
} elsif ($index_node_url) { |
passwd => 'admin', |
134 |
$hest_node ||= HyperEstraier::Node->new($index_node_url); |
croak_on_error => 1, |
135 |
$hest_node->set_auth('admin', 'admin'); |
); |
136 |
print " via node URL"; |
print " via node URL"; |
137 |
} else { |
} else { |
138 |
die "don't know how to use HyperEstraier Index $use_hest"; |
die "don't know how to use Hyper Estraier Index $index_node_url"; |
139 |
} |
} |
|
print " increment is " . EST_CHUNK . " files:"; |
|
140 |
|
|
141 |
my $results = 0; |
my $results = 0; |
142 |
|
|
183 |
|
|
184 |
if ($results == 0) { |
if ($results == 0) { |
185 |
print " - no new files\n"; |
print " - no new files\n"; |
186 |
last; |
return; |
187 |
|
} else { |
188 |
|
print " - $results files: "; |
189 |
} |
} |
190 |
|
|
191 |
sub fmt_date { |
sub fmt_date { |
201 |
my $uri = 'file:///' . $fid; |
my $uri = 'file:///' . $fid; |
202 |
|
|
203 |
unless ($skip_check) { |
unless ($skip_check) { |
204 |
my $id = ($hest_db || $hest_node)->uri_to_id($uri); |
my $id = $hest_node->uri_to_id($uri); |
205 |
next unless ($id == -1); |
next if ($id && $id == -1); |
206 |
} |
} |
207 |
|
|
208 |
# create a document object |
# create a document object |
209 |
my $doc = HyperEstraier::Document->new; |
my $doc = Search::Estraier::Document->new; |
210 |
|
|
211 |
# add attributes to the document object |
# add attributes to the document object |
212 |
$doc->add_attr('@uri', $uri); |
$doc->add_attr('@uri', $uri); |
213 |
|
|
214 |
foreach my $c (@{ $sth->{NAME} }) { |
foreach my $c (@{ $sth->{NAME} }) { |
215 |
|
print STDERR "attr $c = $row->{$c}\n" if ($debug > 2); |
216 |
$doc->add_attr($c, $row->{$c}) if (defined($row->{$c})); |
$doc->add_attr($c, $row->{$c}) if (defined($row->{$c})); |
217 |
} |
} |
218 |
|
|
227 |
print STDERR $doc->dump_draft,"\n" if ($debug > 1); |
print STDERR $doc->dump_draft,"\n" if ($debug > 1); |
228 |
|
|
229 |
# register the document object to the database |
# register the document object to the database |
230 |
if ($hest_db) { |
if ($hest_node) { |
|
$hest_db->put_doc($doc, $HyperEstraier::Database::PDCLEAN); |
|
|
} elsif ($hest_node) { |
|
231 |
$hest_node->put_doc($doc); |
$hest_node->put_doc($doc); |
232 |
} else { |
} else { |
233 |
die "not supported"; |
die "not supported"; |
236 |
} |
} |
237 |
|
|
238 |
print " $added"; |
print " $added"; |
|
$hest_db->sync() if ($index_path); |
|
239 |
|
|
240 |
$offset += EST_CHUNK; |
$offset += EST_CHUNK; |
241 |
|
|
242 |
} while ($results == EST_CHUNK); |
} while ($results == EST_CHUNK); |
243 |
|
|
|
if ($index_path) { |
|
|
print ", close"; |
|
|
$hest_db->close(); |
|
|
} |
|
|
|
|
244 |
my $dur = (time() - $t) || 1; |
my $dur = (time() - $t) || 1; |
245 |
printf(" [%.2f/s dur: %s]\n", |
printf(" [%.2f/s dur: %s]\n", |
246 |
( $added / $dur ), |
( $added / $dur ), |
252 |
|
|
253 |
|
|
254 |
## update index ## |
## update index ## |
255 |
if (($opt{i} || $opt{j} || ($index_path && ! -e $TopDir . $index_path)) && !$opt{c}) { |
if ( ( $opt{i} || $opt{j} ) && !$opt{c} ) { |
256 |
# update all |
# update all |
257 |
print "force update of HyperEstraier index "; |
print "force update of Hyper Estraier index "; |
|
print "importing existing data" unless (-e $TopDir . $index_path); |
|
258 |
print "by -i flag" if ($opt{i}); |
print "by -i flag" if ($opt{i}); |
259 |
print "by -j flag" if ($opt{j}); |
print "by -j flag" if ($opt{j}); |
260 |
print "\n"; |
print "\n"; |