/[Search-Estraier]/trunk/scripts/est-spider
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/scripts/est-spider

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

revision 90 by dpavlin, Thu Jan 26 01:53:29 2006 UTC revision 178 by dpavlin, Tue Aug 15 16:38:06 2006 UTC
# Line 7  use Search::Estraier; Line 7  use Search::Estraier;
7  use Text::Iconv;  use Text::Iconv;
8  #use File::MMagic;  #use File::MMagic;
9  use File::MMagic::XS qw/:compat/;  use File::MMagic::XS qw/:compat/;
10    use Time::HiRes qw/time/;
11    
12  my $collection;         # name which will be inserted  my $collection;         # name which will be inserted
13  my $path_add;           # add additional info in path  my $path_add;           # add additional info in path
# Line 16  my $exclude; Line 17  my $exclude;
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,
# Line 24  my $result = GetOptions( Line 26  my $result = GetOptions(
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;
# Line 38  options: Line 41  options:
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) {
# Line 49  if (! -e $dir) { Line 53  if (! -e $dir) {
53  #$basedir =~ s,/[^/]+$,/,;  #$basedir =~ s,/[^/]+$,/,;
54  #require "$basedir/filter.pm";  #require "$basedir/filter.pm";
55    
56    my $docs = 0;
57    my $start_t = time();
58    
59  my $filter;  my $filter;
60  foreach my $f (qw/pdftotext pstotext/) {  foreach my $f (qw/pdftotext pstotext/) {
61          my $w = which($f);          my $w = which($f);
# Line 66  my $iconv = new Text::Iconv('iso-8859-2' Line 73  my $iconv = new Text::Iconv('iso-8859-2'
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,
# Line 76  find({ wanted => \&file, Line 86  find({ wanted => \&file,
86          no_chdir => 1,          no_chdir => 1,
87  }, $dir);  }, $dir);
88    
89    my $dur = (time() - $start_t) || 1;
90    printf STDERR "%d documents in %.2fs [%.2f docs/s]\n", $docs, $dur, ($docs / $dur);
91    
92    $db->master(
93            action => 'sync'
94    );
95    
96    
97  exit;  exit;
98    
# Line 124  sub dump_contents { Line 141  sub dump_contents {
141          # boost title          # boost title
142          $doc->add_hidden_text($title);          $doc->add_hidden_text($title);
143    
144  #       print $doc->dump_draft if ($verbose);          print $doc->dump_draft if ($debug);
145    
146          # register the document object to the database          # register the document object to the database
147          $db->put_doc($doc);          $db->put_doc($doc);
148    
149            $docs++;
150    
151  }  }
152    
153  sub filter_to_pages {  sub filter_to_pages {
# Line 180  sub file { Line 199  sub file {
199          my $path = $_;          my $path = $_;
200          my $contents;          my $contents;
201    
202          return if (! $force && -l $path || $path =~ m#/.svn# || $path =~ m/(~|.bak)$/);          return if (! $force && -l $path || $path =~ m#/.svn# || $path =~ m/(~|.bak|.gif)$/);
203            return if (! $all && -d $path);
204    
205          my $mtime = (stat($path))[9] || -1;          my $mtime = (stat($path))[9] || -1;
206          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') };
207            $mtime_db ||= -2;
208    
209          if ($mtime == $mtime_db) {          if ($mtime == $mtime_db) {
210                  print STDERR "# same: $path $mtime\n" if ($verbose);                  print STDERR "# same: $path $mtime\n" if ($verbose);
# Line 220  sub file { Line 241  sub file {
241          } else {          } else {
242    
243  #               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);
244                  if (-f $path && $type =~ m/html/ ||                  if (-f $path &&
245                          ($path !~ m/\.(php|pl|txt|info|log|text)$/io)                          $type !~ m/html/ &&
246                            $path !~ m/\.(php|pl|txt|info|log|text)$/io
247                  ) {                  ) {
248                          dump_contents($db, '', $mtime, $path, -s $path);                          dump_contents($db, '', $mtime, $path, -s $path) if ($all);
249                          return;                          return;
250                  }                  }
251    
252                  # skip index files                  # skip index files
253                  return if (m/index_[a-z]\.html*/i || m/index_symbol\.html*/i);                  return if ($path =~ m/index_(?:[a-z]+|symbol)\.html*/i);
254    
255                  open(F,"$path") || die "can't open file: $path";                  open(F,"$path") || die "can't open file: $path";
256                  print STDERR "$path ($type)" if ($verbose);                  print STDERR "$path ($type)" if ($verbose);

Legend:
Removed from v.90  
changed lines
  Added in v.178

  ViewVC Help
Powered by ViewVC 1.1.26