parse AND queryies for field combinations from Koha
[Biblio-Z3950.git] / vuFind.pm
index d3e95e5..82c96f5 100644 (file)
--- a/vuFind.pm
+++ b/vuFind.pm
@@ -39,6 +39,15 @@ sub usemap {{
 #      12              => '',
 #      1007    => '',
        1016    => 'all',
+
+       RPN => {
+               And => '&bool[]=AND&',
+               Or  => '&bool[]=OR&',
+       },
+       prefix_term => sub {
+               my ( $prefix, $term ) = @_;
+               return 'type[]=' . $prefix . '&lookfor[]=' . $term;
+       }
 }};
 
 sub search {
@@ -47,7 +56,7 @@ sub search {
        die "need query" unless defined $query;
 
        # http://catalog.hathitrust.org/Search/Home?lookfor=croatia%20AND%20zagreb&type=title
-       my $url = 'http://catalog.hathitrust.org/Search/Home?lookfor=' . $query;
+       my $url = 'http://catalog.hathitrust.org/Search/Home?' . $query;
 
 diag "get $url";
 
@@ -64,13 +73,20 @@ diag "get $url";
 
 diag "got $hits results";
 
-       foreach my $link ( $self->mech->find_all_links( url_regex => qr{/Record/\d+} ) ) {
-               push @{ $self->{records} }, $link->url;
-       }
+       $self->populate_records;
 
        return $self->{hits} = $hits;
 }
 
+sub populate_records {
+       my ($self) = @_;
+
+       foreach my $link ( $self->mech->find_all_links( url_regex => qr{/Record/\d+} ) ) {
+               my $url = $link->url;
+               push @{ $self->{records} }, $url;
+               warn "## ++ $url\n";
+       }
+}
 
 sub next_marc {
        my ($self,$format) = @_;
@@ -79,6 +95,18 @@ sub next_marc {
 
        my $url = shift @{ $self->{records} };
 
+       if ( ! $url ) {
+               diag "fetch next page";
+               $self->save_content;
+               $self->mech->follow_link( text_regex => qr/Next/ );
+               $self->populate_records;
+               $url = shift @{ $self->{records} };
+               if ( ! $url ) {
+                       warn "ERROR no more results\n";
+                       return;
+               }
+       }
+
        my $id = $1 if $url =~ m{Record/(\d+)};
 
        $self->mech->get( $url . '.mrc' );
@@ -87,6 +115,8 @@ sub next_marc {
 
        $self->save_marc( "$id.marc", $marc );
 
+       $self->mech->back; # return to search results for next page
+
        return $id;
 
 }