]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Search/Z3950.pm
circ husk and z39 basic search module
[working/Evergreen.git] / Open-ILS / src / perlmods / OpenILS / Application / Search / Z3950.pm
1 #!/usr/bin/perl
2 package OpenILS::Application::Search::Z3950;
3 use strict; use warnings;
4 use base qw/OpenSRF::Application/;
5
6
7 use Net::Z3950;
8 use MARC::Record;
9 use MARC::File::XML;
10
11 use OpenILS::Utils::ModsParser;
12
13 my $output = "USMARC"; # only support output for now
14
15
16
17 __PACKAGE__->register_method(
18         method  => "z39_search_by_string",
19         api_name        => "open-ils.search.z3950.raw_string",
20         argc            => 1, 
21         note            => "z3950 search by raw query string",
22 );
23
24
25 sub z39_search_by_string {
26
27         my( $self, $client, $server, 
28                         $port, $db, $search, $user, $pw ) = @_;
29
30         throw OpenSRF::EX::InvalidArg unless( 
31                         $server and $port and $db and $search);
32
33         $user ||= "";
34         $pw     ||= "";
35
36         my $conn = new Net::Z3950::Connection(
37                 $server, $port, 
38                 databaseName                            => $db, 
39                 user                                                    => $user,
40                 password                                                => $pw,
41                 preferredRecordSyntax   => $output, 
42         );
43
44
45         my $rs = $conn->search( $search );
46
47         my $records = [];
48         my $hash = {};
49
50         $hash->{count} =  $rs->size();
51         warn "Z3950 Search recovered " . $hash->{count} . " records\n";
52
53         for( my $x = 0; $x != $hash->{count}; $x++ ) {
54                 my $rec = $rs->record($x+1);
55                 my $marc = MARC::Record->new_from_usmarc($rec->rawdata());
56
57                 my $u = OpenILS::Utils::ModsParser->new();
58                 $u->start_mods_batch($marc->as_xml());
59                 my $mods = $u->finish_mods_batch();
60
61                 push @$records, $mods;
62         }
63
64         $hash->{records} = $records;
65         return $hash;
66
67 }
68
69
70 1;