/[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

Annotation of /trunk/scripts/dbi-indexer.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 144 - (hide annotations)
Wed May 10 20:31:02 2006 UTC (17 years, 11 months ago) by dpavlin
File MIME type: text/plain
File size: 1621 byte(s)
create node if needed, moved config into hash
1 dpavlin 131 #!/usr/bin/perl -w
2    
3     use strict;
4 dpavlin 144 use Search::Estraier 0.06;
5 dpavlin 131 use DBI;
6     use Data::Dumper;
7     use Encode qw/from_to/;
8    
9     =head1 NAME
10    
11     dbi-indexer.pl - example indexer of DBI sources for Search::Estraier
12    
13     =cut
14    
15 dpavlin 144 my $c = {
16     node_url => 'http://localhost:1978/node/dbi',
17     dbi => 'Pg:dbname=azop',
18     sql => qq{
19     select * from history_collection_view_cache
20     },
21     debug => 0,
22 dpavlin 131 };
23    
24     # create and configure node
25     my $node = new Search::Estraier::Node(
26 dpavlin 144 url => $c->{node_url},
27 dpavlin 131 user => 'admin',
28     passwd => 'admin',
29     croak_on_error => 1,
30 dpavlin 144 create => 1,
31     debug => $c->{debug},
32 dpavlin 131 );
33    
34     # create DBI connection
35 dpavlin 144 my $dbh = DBI->connect("DBI:$c->{dbi}","","") || die $DBI::errstr;
36 dpavlin 131
37 dpavlin 144 my $sth = $dbh->prepare($c->{sql}) || die $dbh->errstr();
38 dpavlin 131 $sth->execute() || die $sth->errstr();
39    
40 dpavlin 144 warn "# columns: ",join(",",@{ $sth->{NAME} }),"\n" if ($c->{debug});
41 dpavlin 131
42     my $total = $sth->rows;
43     my $i = 1;
44    
45     while (my $row = $sth->fetchrow_hashref() ) {
46    
47 dpavlin 144 warn "# row: ",Dumper($row) if ($c->{debug});
48 dpavlin 131
49     # create document
50     my $doc = new Search::Estraier::Document;
51    
52     $doc->add_attr('@uri', $row->{_id});
53    
54     printf "%4d ",$i;
55    
56     while (my ($col,$val) = each %{$row}) {
57    
58     if ($val) {
59     # change encoding?
60     from_to($val, 'ISO-8859-2', 'UTF-8');
61    
62     # add attributes (make column usable from attribute search)
63     $doc->add_attr($col, $val);
64    
65     # add body text to document (make it searchable using full-text index)
66     $doc->add_text($val);
67    
68     print "R";
69     } else {
70     print ".";
71     }
72    
73     }
74    
75     print " ", int(( $i++ / $total) * 100), "%\n";
76    
77 dpavlin 144 warn "# doc draft: ",$doc->dump_draft, "\n" if ($c->{debug});
78 dpavlin 131
79     die "error: ", $node->status,"\n" unless (eval { $node->put_doc($doc) });
80     }

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26