7 use Data::Dump qw/dump/;
17 # Bib-1 @and @and @and @and @and @and @and @or
23 # @attr 1=21 subject-holding
24 # @attr 1=12 control-no
25 # @attr 1=1007 standard-id
28 # LCC - Klasifikacija Kongresne knjižnice
29 # LCN - Signatura Kongresne knjižnice
30 # DDC - Deweyjeva klasifikacija
35 # SRS - Nakladnička cjelina
38 # WTI - Riječi u polju naslova
39 # WAU - Riječi u polju autora
40 # WPE - Riječi u polju individualnog autora
41 # WCO - Riječi u polju korporativnog autora
42 # WME - Riječi u polju sastanka
43 # WUT - Riječi u polju jedinstvenog naslova
44 # WPL - Riječi u polju mjesta izdavanja
45 # WPU - Riječi u polju nakladnika
46 # WSU - Riječi u polju predmetnica
47 # WSM - Riječi u predmetnicama MeSH-a
48 # WST - Riječi u polju status
49 # WGA - Riječi u geografskim odrednicama
50 # WYR - Godina izdavanja
65 my ( $self, $query ) = @_;
67 die "need query" unless defined $query;
69 $session_id ||= int rand(1000000000);
70 # FIXME allocate session just once
71 my $url = 'http://161.53.240.197:8991/F?RN=' . $session_id;
72 # fake JavaScript code on page which creates random session
76 my $mech = $self->{mech} || die "no mech?";
79 diag "advanced search";
81 $mech->follow_link( url_regex => qr/find-c/ );
83 my $database = $self->{database};
85 if ( $mech->content =~ m{Requested library is unavailable at the moment} ) {
86 warn "ERROR: default database not available, try to swith to $database\n";
88 $mech->follow_link( url_regex => qr/local_base=$database/i );
89 diag "re-try advanced search";
90 $mech->follow_link( url_regex => qr/find-c/ );
93 diag "submit search [$query] on ", $self->{database};
99 'local_base' => $self->{database},
104 if ( $mech->content =~ m{ukupno\s+(\d+).*do\s+(\d+)}s ) {
106 $hits = $2 if $2 && $2 < $1; # correct for max. results
108 diag "get't find results in ", $mech->content;
112 diag "got $hits results, get first one";
114 $mech->follow_link( url_regex => qr/set_entry=000001/ );
116 diag "in MARC format";
118 $mech->follow_link( url_regex => qr/format=001/ );
120 return $self->{hits} = $hits;
124 our ( $hash, $marc );
127 my ($self,$format) = @_;
131 my $mech = $self->{mech} || die "no mech?";
133 #warn "## ", $mech->content;
135 if ( $mech->content =~ m{Zapis\s+(\d+)}s ) {
141 $marc = MARC::Record->new;
144 my $html = $mech->content;
148 $v =~ s/\Q \E/ /gs;
158 warn "$f not numeric!";
162 if ( $v !~ s/^\|// ) { # no subfields
163 $marc->add_fields( $f, $v );
164 warn "## ++ ", dump( $f, $v );
168 my ($i1,$i2) = (' ',' ');
169 ($i1,$i2) = ($2,$3) if $f =~ s/^(...)(.)?(.)?/$1/;
170 my @sf = split(/\|/, $v);
171 @sf = map { s/^(\w)\s+//; { $1 => $_ } } @sf;
172 #warn "## sf = ", dump(@sf);
173 $marc->add_fields( $f, $i1, $i2, @sf );
174 warn "## ++ ", dump( $f, $i1, $i2, @sf );
177 $html =~ s|<tr>\s*<td class=td1 id=bold[^>]*>(.+?)</td>\s*<td class=td1>(.+?)</td>|field($1,$2)|ges;
178 diag "# hash ",dump($hash);
179 diag "# marc ", $marc->as_formatted;
181 my $id = $hash->{SYS} || die "no SYS";
183 $self->save_marc( $id, $marc->as_usmarc );
185 if ( $nr < $self->{hits} ) {
187 diag "follow link to next record $nr";
188 $mech->follow_link( url_regex => qr/set_entry=0*$nr/ );
191 return $marc->as_usmarc;
193 die "can't fetch COMARC format from ", $mech->content;