/[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 145 - (hide annotations)
Wed May 10 21:09:05 2006 UTC (17 years, 11 months ago) by dpavlin
File MIME type: text/plain
File size: 1674 byte(s)
added db_encoding
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 dpavlin 145 db_encoding => 'iso-8859-2',
22 dpavlin 144 debug => 0,
23 dpavlin 131 };
24    
25     # create and configure node
26     my $node = new Search::Estraier::Node(
27 dpavlin 144 url => $c->{node_url},
28 dpavlin 131 user => 'admin',
29     passwd => 'admin',
30     croak_on_error => 1,
31 dpavlin 144 create => 1,
32     debug => $c->{debug},
33 dpavlin 131 );
34    
35     # create DBI connection
36 dpavlin 144 my $dbh = DBI->connect("DBI:$c->{dbi}","","") || die $DBI::errstr;
37 dpavlin 131
38 dpavlin 144 my $sth = $dbh->prepare($c->{sql}) || die $dbh->errstr();
39 dpavlin 131 $sth->execute() || die $sth->errstr();
40    
41 dpavlin 144 warn "# columns: ",join(",",@{ $sth->{NAME} }),"\n" if ($c->{debug});
42 dpavlin 131
43     my $total = $sth->rows;
44     my $i = 1;
45    
46     while (my $row = $sth->fetchrow_hashref() ) {
47    
48 dpavlin 144 warn "# row: ",Dumper($row) if ($c->{debug});
49 dpavlin 131
50     # create document
51     my $doc = new Search::Estraier::Document;
52    
53     $doc->add_attr('@uri', $row->{_id});
54    
55     printf "%4d ",$i;
56    
57     while (my ($col,$val) = each %{$row}) {
58    
59     if ($val) {
60     # change encoding?
61 dpavlin 145 from_to($val, ($c->{db_encoding} || 'ISO-8859-1'), 'UTF-8');
62 dpavlin 131
63     # add attributes (make column usable from attribute search)
64     $doc->add_attr($col, $val);
65    
66     # add body text to document (make it searchable using full-text index)
67     $doc->add_text($val);
68    
69     print "R";
70     } else {
71     print ".";
72     }
73    
74     }
75    
76     print " ", int(( $i++ / $total) * 100), "%\n";
77    
78 dpavlin 144 warn "# doc draft: ",$doc->dump_draft, "\n" if ($c->{debug});
79 dpavlin 131
80     die "error: ", $node->status,"\n" unless (eval { $node->put_doc($doc) });
81     }

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26