/[Search-Estraier]/trunk/scripts/dbi-indexer.pl
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/dbi-indexer.pl

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

revision 131 by dpavlin, Mon May 8 21:05:32 2006 UTC revision 145 by dpavlin, Wed May 10 21:09:05 2006 UTC
# Line 1  Line 1 
1  #!/usr/bin/perl -w  #!/usr/bin/perl -w
2    
3  use strict;  use strict;
4  use Search::Estraier;  use Search::Estraier 0.06;
5  use DBI;  use DBI;
6  use Data::Dumper;  use Data::Dumper;
7  use Encode qw/from_to/;  use Encode qw/from_to/;
# Line 12  dbi-indexer.pl - example indexer of DBI Line 12  dbi-indexer.pl - example indexer of DBI
12    
13  =cut  =cut
14    
15  my $node_url = 'http://localhost:1978/node/dbi';  my $c = {
16  my $dbi = 'Pg:dbname=azop';          node_url => 'http://localhost:1978/node/dbi',
17  my $sql = qq{          dbi => 'Pg:dbname=azop',
18          select * from history_collection_view_cache          sql => qq{
19                    select * from history_collection_view_cache
20            },
21            db_encoding => 'iso-8859-2',
22            debug => 0,
23  };  };
 my $debug = 0;  
24    
25  # create and configure node  # create and configure node
26  my $node = new Search::Estraier::Node(  my $node = new Search::Estraier::Node(
27          url => $node_url,          url => $c->{node_url},
28          user => 'admin',          user => 'admin',
29          passwd => 'admin',          passwd => 'admin',
30          croak_on_error => 1,          croak_on_error => 1,
31          debug => $debug,          create => 1,
32            debug => $c->{debug},
33  );  );
34    
35  # create DBI connection  # create DBI connection
36  my $dbh = DBI->connect("DBI:$dbi","","") || die $DBI::errstr;  my $dbh = DBI->connect("DBI:$c->{dbi}","","") || die $DBI::errstr;
37    
38  my $sth = $dbh->prepare($sql) || die $dbh->errstr();  my $sth = $dbh->prepare($c->{sql}) || die $dbh->errstr();
39  $sth->execute() || die $sth->errstr();  $sth->execute() || die $sth->errstr();
40    
41  warn "# columns: ",join(",",@{ $sth->{NAME} }),"\n" if ($debug);  warn "# columns: ",join(",",@{ $sth->{NAME} }),"\n" if ($c->{debug});
42    
43  my $total = $sth->rows;  my $total = $sth->rows;
44  my $i = 1;  my $i = 1;
45    
46  while (my $row = $sth->fetchrow_hashref() ) {  while (my $row = $sth->fetchrow_hashref() ) {
47    
48          warn "# row: ",Dumper($row) if ($debug);          warn "# row: ",Dumper($row) if ($c->{debug});
49    
50          # create document          # create document
51          my $doc = new Search::Estraier::Document;          my $doc = new Search::Estraier::Document;
# Line 54  while (my $row = $sth->fetchrow_hashref( Line 58  while (my $row = $sth->fetchrow_hashref(
58    
59                  if ($val) {                  if ($val) {
60                          # change encoding?                          # change encoding?
61                          from_to($val, 'ISO-8859-2', 'UTF-8');                          from_to($val, ($c->{db_encoding} || 'ISO-8859-1'), 'UTF-8');
62    
63                          # add attributes (make column usable from attribute search)                          # add attributes (make column usable from attribute search)
64                          $doc->add_attr($col, $val);                          $doc->add_attr($col, $val);
# Line 71  while (my $row = $sth->fetchrow_hashref( Line 75  while (my $row = $sth->fetchrow_hashref(
75    
76          print " ", int(( $i++ / $total) * 100), "%\n";          print " ", int(( $i++ / $total) * 100), "%\n";
77    
78          warn "# doc draft: ",$doc->dump_draft, "\n" if ($debug);          warn "# doc draft: ",$doc->dump_draft, "\n" if ($c->{debug});
79    
80          die "error: ", $node->status,"\n" unless (eval { $node->put_doc($doc) });          die "error: ", $node->status,"\n" unless (eval { $node->put_doc($doc) });
81  }  }

Legend:
Removed from v.131  
changed lines
  Added in v.145

  ViewVC Help
Powered by ViewVC 1.1.26