17 |
#$verbose = 1; |
#$verbose = 1; |
18 |
my $debug = 0; |
my $debug = 0; |
19 |
my $force = 0; |
my $force = 0; |
20 |
|
my $all = 0; |
21 |
|
|
22 |
my $result = GetOptions( |
my $result = GetOptions( |
23 |
"collection=s" => \$collection, |
"collection=s" => \$collection, |
26 |
"debug!" => \$debug, |
"debug!" => \$debug, |
27 |
"exclude=s" => \$exclude, |
"exclude=s" => \$exclude, |
28 |
"force!" => \$force, |
"force!" => \$force, |
29 |
|
"all!" => \$all, |
30 |
); |
); |
31 |
|
|
32 |
my ($node_url,$dir) = @ARGV; |
my ($node_url,$dir) = @ARGV; |
41 |
--verbose |
--verbose |
42 |
--force |
--force |
43 |
--debug |
--debug |
44 |
|
--all save placeholders for all files |
45 |
_END_OF_USAGE_ |
_END_OF_USAGE_ |
46 |
|
|
47 |
if (! -e $dir) { |
if (! -e $dir) { |
73 |
select(STDERR); $|=1; |
select(STDERR); $|=1; |
74 |
select(STDOUT); $|=1; |
select(STDOUT); $|=1; |
75 |
|
|
76 |
my $db = new Search::Estraier::Node; |
my $db = new Search::Estraier::Node( |
77 |
$db->set_url($node_url); |
url => $node_url, |
78 |
$db->set_auth('admin', 'admin'); |
user => 'admin', |
79 |
|
passwd => 'admin', |
80 |
|
croak_on_error => 1, |
81 |
|
); |
82 |
|
|
83 |
find({ wanted => \&file, |
find({ wanted => \&file, |
84 |
follow => 1, |
follow => 1, |
136 |
# boost title |
# boost title |
137 |
$doc->add_hidden_text($title); |
$doc->add_hidden_text($title); |
138 |
|
|
139 |
# print $doc->dump_draft if ($verbose); |
print $doc->dump_draft if ($debug); |
140 |
|
|
141 |
# register the document object to the database |
# register the document object to the database |
142 |
$db->put_doc($doc); |
$db->put_doc($doc); |
194 |
my $path = $_; |
my $path = $_; |
195 |
my $contents; |
my $contents; |
196 |
|
|
197 |
return if (! $force && -l $path || $path =~ m#/.svn# || $path =~ m/(~|.bak)$/); |
return if (! $force && -l $path || $path =~ m#/.svn# || $path =~ m/(~|.bak|.gif)$/); |
198 |
|
|
199 |
my $mtime = (stat($path))[9] || -1; |
my $mtime = (stat($path))[9] || -1; |
200 |
my $mtime_db = $db->get_doc_attr_by_uri("file:///$path", '@mtime') || -2; |
my $mtime_db = eval { $db->get_doc_attr_by_uri("file:///$path", '@mtime') }; |
201 |
|
$mtime_db ||= -2; |
202 |
|
|
203 |
if ($mtime == $mtime_db) { |
if ($mtime == $mtime_db) { |
204 |
print STDERR "# same: $path $mtime\n" if ($verbose); |
print STDERR "# same: $path $mtime\n" if ($verbose); |
235 |
} else { |
} else { |
236 |
|
|
237 |
# return if (! -f $path || ! m/\.(html*|php|pl|txt|info|log|text)$/i); |
# return if (! -f $path || ! m/\.(html*|php|pl|txt|info|log|text)$/i); |
238 |
if (-f $path && $type =~ m/html/ || |
if (-f $path && |
239 |
($path !~ m/\.(php|pl|txt|info|log|text)$/io) |
$type !~ m/html/ && |
240 |
|
$path !~ m/\.(php|pl|txt|info|log|text)$/io |
241 |
) { |
) { |
242 |
dump_contents($db, '', $mtime, $path, -s $path); |
dump_contents($db, '', $mtime, $path, -s $path) if ($all); |
243 |
return; |
return; |
244 |
} |
} |
245 |
|
|
246 |
# skip index files |
# skip index files |
247 |
return if (m/index_[a-z]\.html*/i || m/index_symbol\.html*/i); |
return if ($path =~ m/index_(?:[a-z]+|symbol)\.html*/i); |
248 |
|
|
249 |
open(F,"$path") || die "can't open file: $path"; |
open(F,"$path") || die "can't open file: $path"; |
250 |
print STDERR "$path ($type)" if ($verbose); |
print STDERR "$path ($type)" if ($verbose); |