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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 144 - (show 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 #!/usr/bin/perl -w
2
3 use strict;
4 use Search::Estraier 0.06;
5 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 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 };
23
24 # create and configure node
25 my $node = new Search::Estraier::Node(
26 url => $c->{node_url},
27 user => 'admin',
28 passwd => 'admin',
29 croak_on_error => 1,
30 create => 1,
31 debug => $c->{debug},
32 );
33
34 # create DBI connection
35 my $dbh = DBI->connect("DBI:$c->{dbi}","","") || die $DBI::errstr;
36
37 my $sth = $dbh->prepare($c->{sql}) || die $dbh->errstr();
38 $sth->execute() || die $sth->errstr();
39
40 warn "# columns: ",join(",",@{ $sth->{NAME} }),"\n" if ($c->{debug});
41
42 my $total = $sth->rows;
43 my $i = 1;
44
45 while (my $row = $sth->fetchrow_hashref() ) {
46
47 warn "# row: ",Dumper($row) if ($c->{debug});
48
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 warn "# doc draft: ",$doc->dump_draft, "\n" if ($c->{debug});
78
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