use MARC::Record;
use Data::Dump qw/dump/;
use DBI;
+use utf8;
use base 'Scraper';
# @attr 1=1016 any
sub usemap {{
- 4 => '',
- 7 => '',
- 8 => '',
- 1003 => '',
-# 16 => '',
- 21 => '',
- 12 => '',
-# 1007 => '',
- 1016 => '',
+ 4 => 'fti_pr:',
+ 7 => 'fti_pr:',
+ 8 => 'fti_pr:',
+ 1003 => 'fti_au:',
+ 16 => 'fti_pr:',
+ 21 => 'fti_pr:',
+ 12 => 'fti_pr:',
+ 1007 => 'pti_pr:',
+ 1016 => 'fti_au,fti_pr:',
}};
=for sql
my $dbname = 'bibliografija';
-my $dbh = DBI->connect("dbi:Pg:dbname=$dbname", '', '', {AutoCommit => 0});
-
sub search {
my ( $self, $query ) = @_;
+ utf8::decode( $query );
+ warn "QUERY",dump( $query );
+
die "need query" unless defined $query;
- my $tsquery = join(' & ', split(/\s+/,$query) );
+ my $table = lc $self->{database};
+ $table =~ s/^crosbi-//g;
my $sql = qq{
select *
-from casopis
+from $table
inner join rad_ustanova using (id)
left outer join rad_napomena using (id)
left outer join rad_projekt using (id)
left outer join rad_godina using (id)
left outer join rad_podrucje using (id)
left outer join url using (id)
-where rad_ustanova.sifra = ? and (
- fti_au @@ to_tsquery(?)
- or fti_pr @@ to_tsquery(?)
-)
-
};
- my $sth = $dbh->prepare( $sql );
+ my @and = ( qq{ rad_ustanova.sifra = ? } );
+ my @exec = ( 130 ); # FIXME ustanova
-warn "XXX SQL = ",$sql;
+ foreach my $and ( split(/ AND /, $query) ) {
-#-- and naslov like ?
+ if ( $and =~ s/^(fti_.+):// ) {
+ my $tsquery = join(' & ', split(/\s+/,$and) );
- $sth->execute(
- 130, # FIXME ustanova
- $tsquery,
- $tsquery,
-# , '%' . $query . '%'
- );
+ my @or;
+ foreach my $f ( split(/,/,$1) ) {
+ push @or, "$f @@ to_tsquery(?)";
+ push @exec, $tsquery;
+ };
+ push @and, "( " . join(" or ", @or) . ")";
+ } else {
+ warn "INVALID QUERY [$query]";
+ }
+ }
+ $sql .= "where " . join(" and ", @and);
+
+warn "XXX SQL = ",$sql, dump( @exec );
+
+ my $dbh = DBI->connect_cached("dbi:Pg:dbname=$dbname", '', '', {AutoCommit => 0});
+
+ my $sth = $dbh->prepare( $sql );
+
+ $sth->execute( @exec );
- $self->{_sth} = $sth;
my $hits = $sth->rows;
- warn "# [$tsquery] $hits hits\n";
+ $self->{_sth} = $sth;
+
+ warn "# [$query] $hits hits\n";
return $self->{hits} = $hits;
}
my $id = $row->{id} || die "no id";
my $marc = MARC::Record->new;
- $marc->encoding('utf-8');
+ $marc->encoding('UTF-8');
my $leader = $marc->leader;
## LDR 06 - a - language material
## LDR 07 - a - monographic component part
- $leader =~ s/^(....).../$1naa/;
+ $leader =~ s/^(....)...(.+)/$1naa$2/;
## LDR 17 - Encoding level ; 7 - minimal level, u - unknown
## LDR 18 - i = isbd ; u = unknown
- $leader =~ s/^(.{17})/$1uu/;
+ $leader =~ s/^(.{17})..(.+)/$1uu$2/;
$marc->leader( $leader );
warn "# leader [$leader]";
'a' => $row->{title}
);
+ sub page_range {
+ my ( $prefix, $from, $to ) = @_;
+ my $out;
+ if ( $from ) {
+ $out = $prefix . $from;
+ $out .= '-' . $to if $to;
+ }
+ return $out;
+ }
+
$marc->add_fields(300,' ',' ',
- a => join(' ', $row->{stranica_prva}, $row->{stranica_zadnja}),
+ a => page_range('',$row->{stranica_prva},$row->{stranica_zadnja}),
f => 'str.'
);
) foreach @a;
}
-
$marc->add_fields(773,'0',' ',
t => $row->{casopis},
x => $row->{issn},
- g => "$row->{volumen}, ($row->{godina}), str. $row->{stranica_prva}-$row->{stranica_zadnja}",
+ g => "$row->{volumen} ($row->{godina}), $row->{broj} ;" . page_range(' str. ',$row->{stranica_prva}, $row->{stranica_zadnja}),
);
if ( my $file = $row->{datoteka} ) {
);
}
- $marc->add_fields(942,' ',' ',
- c => 'CLA',
- $row->{status_rada} ? (
+ my @f942 = (
+ c => 'CLA'
+ );
+ if ( $row->{status_rada} ) {
+ push @f942, (
f => 1,
g => $row->{status_rada}
- ) : (),
- $row->{kategorija} =~ m/Znanstveni/ ? (
- t => '1.01'
- ) : $row->{kategorija} =~ m/Strucni/ ? (
- t => '1.04'
- ) : (),
+ );
+ }
+ push @f942, t => '1.01' if $row->{kategorija} =~ m/Znanstveni/;
+ push @f942, t => '1.04' if $row->{kategorija} =~ m/Strucni/;
+
+ $marc->add_fields(942,' ',' ',
+ @f942,
u => '1',
z => join(' - ', $row->{kategorija}, $row->{vrsta_rada}),
);