we need english stemmer because remote database is configured wrong
[Biblio-Z3950.git] / CROSBI.pm
index ca08906..62ae19f 100644 (file)
--- a/CROSBI.pm
+++ b/CROSBI.pm
@@ -8,6 +8,7 @@ use Data::Dump qw/dump/;
 use DBI;
 use utf8;
 
+use Scraper;
 use base 'Scraper';
 
 my $debug = $ENV{DEBUG} || 0;
@@ -47,6 +48,9 @@ sub usemap {{
 =cut
 
 my $dbname = 'bibliografija';
+my $pg_user = $ENV{PGUSER} || '';
+my $pg_passwd = $ENV{PGPASSWD} || '';
+my $pg_host = $ENV{PGHOST} || '';
 my @and;
 my @exec;
 
@@ -56,7 +60,7 @@ sub search {
        utf8::decode( $query );
        warn "QUERY",dump( $query );
 
-       die "need query" unless defined $query;
+       die "ERROR need query" unless defined $query;
 
        $query =~ s/^\s+//;
        $query =~ s/\s+$//;
@@ -96,7 +100,7 @@ inner join rad_ustanova using (id) -- sifra
 
                        my @or;
                        foreach my $f ( split(/,/,$fti) ) {
-                               push @or, "$f @@ to_tsquery(?)";
+                               push @or, "$f @@ to_tsquery('english',?)";
                                push @exec, $tsquery;
                        };
                        push @and, "( " . join(" or ", @or) . ")";
@@ -110,7 +114,7 @@ inner join rad_ustanova using (id) -- sifra
                parse_fti $query;
        } else { # no " AND " in query
                my $tsquery = join(' & ', split(/\s+/,$query) );
-               push @and, "( fti_au @@ to_tsquery(?) or fti_pr @@ to_tsquery(?) )";
+               push @and, "( fti_au @@ to_tsquery('english',?) or fti_pr @@ to_tsquery('english',?) )";
                push @exec, $tsquery,  $tsquery;
        }
 
@@ -119,7 +123,7 @@ inner join rad_ustanova using (id) -- sifra
 
 warn "XXX SQL = ",$sql, dump( @exec );
 
-       my $dbh = DBI->connect_cached("dbi:Pg:dbname=$dbname", '', '', {AutoCommit => 0});
+       my $dbh = DBI->connect_cached("dbi:Pg:dbname=$dbname;host=$pg_host", $pg_user, $pg_passwd, {AutoCommit => 0});
 
        my $sth = $dbh->prepare( $sql );
 
@@ -177,14 +181,14 @@ sub next_marc {
 
        $format ||= 'marc';
 
-       my $sth = $self->{_sth} || die "no _sth";
+       my $sth = $self->{_sth} || die "ERROR no _sth";
        my $row = $sth->fetchrow_hashref;
 
        warn "## row = ",dump($row) if $ENV{DEBUG};
 
        warn "ERROR: no row" unless $row;
 
-       my $id = $row->{id} || die "no id";
+       my $id = $row->{id} || die "ERROR no id";
 
        my $marc = MARC::Record->new;
        $marc->encoding('UTF-8');
@@ -404,39 +408,57 @@ sub next_marc {
                ) foreach @a;
        }
 
+       sub combine {
+               my $out = '';
+               my $last_delimiter = '';
+               while(@_) {
+                       my $value = shift @_;
+                       my $delimiter = shift @_;
+                       my ( $before,$after ) = ( '', '' );
+                       ( $before, $value, $after ) = @$value if ( ref $value eq 'ARRAY' );
+                       $out .= $last_delimiter . $value if $value;
+                       $last_delimiter = $delimiter || last;
+               }
+               warn "### [$out]";
+               return $out;
+       }
+                       
 
-       if ( $row->{casopis} ) {
+       if ( $self->{_table} =~ m/(casopis|preprint)/ ) {
 
        $marc->add_fields(773,'0',' ',
                t => $row->{casopis},
                x => $row->{issn},
-               g => "$row->{volumen} ($row->{godina}), $row->{broj} ;" . page_range(' str. ',$row->{stranica_prva}, $row->{stranica_zadnja}),
+#              g => "$row->{volumen} ($row->{godina}), $row->{broj} ;" . page_range(' str. ',$row->{stranica_prva}, $row->{stranica_zadnja}),
+               g => combine( $row->{volumen}, ' ', [ '(', $row->{godina}, ')' ], ', ', $row->{broj}, ' ;', page_range(' str. ',$row->{stranica_prva}, $row->{stranica_zadnja}) ),
        );
 
-       } elsif ( $row->{knjiga} ) {
+       } elsif ( $self->{_table} =~ m/rknjiga/ ) {
 
        # rknjiga-dbi2marc.pl
        $marc->add_fields(773,'0',' ',
                t => $row->{knjiga},
-               d => "$row->{grad} : $row->{nakladnik}, $row->{godina}",
+#              d => "$row->{grad} : $row->{nakladnik}, $row->{godina}",
+               d => combine( $row->{grad}, ' : ', $row->{nakladnik}, ', ', $row->{godina} ),
                k => $row->{serija},
                h => $row->{ukupno_stranica},
                n => $row->{uredink},
                z => $row->{isbn},
-               g => page_range(' str. ',$row->{stranica_prva}, $row->{stranica_zadnja}),
+               g => page_range('str. ',$row->{stranica_prva}, $row->{stranica_zadnja}),
        );
 
-       } elsif ( $row->{zbornik} ) {
+       } elsif ( $self->{_table} =~ m/zbornik/ ) {
 
        # zbornik-dbi2marc.pl
        $marc->add_fields(773,'0',' ',
                t => $row->{skup},
-               d => "$row->{grad} : $row->{nakladnik}, $row->{godina}",
+#              d => "$row->{grad} : $row->{nakladnik}, $row->{godina}",
+               d => combine( $row->{grad}, ' : ', $row->{nakladnik}, ', ', $row->{godina} ),
                k => $row->{serija},
                h => $row->{ukupno_stranica},
                n => $row->{uredink},
                z => $row->{isbn},
-               g => page_range(' str. ',$row->{stranica_prva}, $row->{stranica_zadnja}),
+               g => page_range('str. ',$row->{stranica_prva}, $row->{stranica_zadnja}),
        );
 
        } else {
@@ -469,7 +491,7 @@ sub next_marc {
        };
 
        my @f942 = (
-               c => $f942c->{ $self->{_table} } || die "no table $self->{_table} in ".dump($f942c),
+               c => $f942c->{ $self->{_table} } || die "ERROR no table $self->{_table} in ".dump($f942c),
        );
 
        if ( $row->{status_rada} ) {