root/libswish3/trunk/perl/dbi_test.pl

Revision 1913, 2.2 kB (checked in by karpet, 1 year ago)

for all the world to see

Line 
1 use lib qw( /usr/local/lib/swish-e/perl );
2
3 package My::DBI;
4 use base qw( SWISH::Prog::DBI );
5
6 use Encode;
7 use Search::Tools::Transliterate;
8
9 sub title_filter
10 {
11     my $self = shift;
12     my $row  = shift;
13
14     return $row->{Movie_Title};
15
16 }
17
18 sub row_filter
19 {
20     my $self = shift;
21     my $row  = shift;
22
23     for (keys %$row)
24     {
25
26         # until we store as proper UTF8 we need this
27         if (!Encode::is_utf8($row->{$_}))
28         {
29             $row->{$_} =
30               Search::Tools::Transliterate->convert(
31                 Encode::encode_utf8(Encode::decode('MacRoman', $row->{$_}, 1)));
32
33         }
34     }
35
36 }
37
38 1;
39
40 package My::DBI::Doc;
41 use base qw( SWISH::Prog::DBI::Doc );
42
43 my $url_base = 'http://al.com/play/';
44
45 sub url_filter
46 {
47     my $doc     = shift;
48     my $db_data = $doc->row;
49
50     $doc->url($url_base . $db_data->{ID});
51 }
52
53 sub content_filter
54 {
55     my $doc = shift;
56     my $c   = $doc->content;
57
58     # get rid of the timer marks in the Caption field
59     $c =~ s,\[\d\d:\d\d:\d\d\.\d\d\],,g;
60
61     #warn $c;
62
63     $doc->content($c);
64 }
65
66 1;
67
68 package main;
69 use Carp;
70 use Data::Dumper;
71
72 my $dbi_indexer = My::DBI->new(
73                     db => [
74                            "DBI:mysql:database=movies;host=localhost;port=3306",
75                            'aluser', 'alpass',
76                            {
77                             RaiseError  => 1,
78                             HandleError => sub { confess(shift) },
79                            }
80                           ],
81                     name  => 'movielist.index',
82                     #fh    => 0,    # print to stdout
83                     #quiet => 1,     # don't print counter (with fh=>0)
84                     #debug => 1,    # print config etc.
85 );
86
87 $dbi_indexer->create(
88     tables => {
89         'movielist' => {
90             columns => {
91                         Movie_Title => 1,
92                         Application => 1,
93                         Description => 1,
94                         Question    => 1,
95                         Caption     => 1,
96                         ID          => 1,
97                        },
98             title => 'Movie_Title',
99             desc  => {
100                 Description => 1,
101                 Caption     => 1,
102
103                 #Question    => 1
104                     }
105         }
106     }
107 );
108
109 exit;
110
Note: See TracBrowser for help on using the browser.