1 package OpenILS::Application::Search;
2 use base qw/OpenSRF::Application/;
3 use strict; use warnings;
4 use OpenILS::Utils::Fieldmapper;
5 use Time::HiRes qw(time);
6 use OpenILS::Application::Cat::Utils;
8 use OpenSRF::EX qw(:try);
13 OpenSRF::Application->method_lookup( "blah" );
16 warn "Child Init Failed: " . shift() . "\n";
21 my $cat_search_hash = {
24 { tag => "100", subfield => "a"} ,
25 { tag => "700", subfield => "a"},
29 { tag => "245", subfield => "a"},
30 { tag => "242", subfield => "a"},
31 { tag => "240", subfield => "a"},
32 { tag => "210", subfield => "a"},
36 { tag => "650", subfield => "_" },
40 { tag => "035", subfield => "_" },
49 __PACKAGE__->register_method(
50 method => "cat_biblio_search_class",
51 api_name => "open-ils.search.cat.biblio.class",
53 note => "Searches biblio information by search class",
56 sub cat_biblio_search_class {
57 my( $self, $client, $class, $sort, $string ) = @_;
59 # sort = title, author, pubdate
61 warn "Starting search " . time() . "\n";
65 warn "Searching $class, $sort, $string\n";
67 warn "Looking up method: " . time() . "\n";
69 my $method = $self->method_lookup("open-ils.search.biblio.marc");
71 throw OpenSRF::EX::PANIC
72 ("Can't lookup method 'open-ils.search.biblio.marc'");
77 warn "Running: " . time() . "\n";
79 my ($records) = $method->run( $cat_search_hash->{$class}, $string );
83 for my $i (@$records) {
87 warn "Found Id's: @ids\n";
88 warn "Search For Id's complete, fixing: " . time() . "\n";
93 my $session = OpenSRF::AppSession->create("open-ils.storage");
94 my $request = $session->request(
95 "open-ils.storage.biblio.record_marc.batch.retrieve", @ids );
98 my $last_content = undef;
100 while( my $response = $request->recv() ) {
102 warn "Received record from storage " . time() . "\n";
104 if( $last_content ) {
105 my $u = OpenILS::Application::Cat::Utils->new();
106 $u->start_mods_batch( $last_content->marc );
107 my $mods = $u->finish_mods_batch();
108 $mods->{doc_id} = $last_content->id();
109 warn "Processed mods " . time() . "\n";
110 #$client->respond( $mods );
111 $last_content = undef;
112 push @results, $mods;
115 if($response and $response->isa("OpenSRF::EX")) {
116 throw $response ($response->stringify);
119 $last_content = $response->content;
123 if( $last_content ) {
124 my $u = OpenILS::Application::Cat::Utils->new();
125 $u->start_mods_batch( $last_content->marc );
126 my $mods = $u->finish_mods_batch();
127 $mods->{doc_id} = $last_content->id();
128 warn "Processed mods " . time() . "\n";
129 #$client->respond( $mods );
130 push @results, $mods;
134 $client->respond( \@results );
138 $session->disconnect();
147 __PACKAGE__->register_method(
148 method => "biblio_search_marc",
149 api_name => "open-ils.search.biblio.marc",
151 note => "Searches biblio information by marc tag",
154 sub biblio_search_marc {
156 my( $self, $client, $search_hash, $string ) = @_;
158 my $session = OpenSRF::AppSession->create("open-ils.storage");
159 my $request = $session->request(
160 "open-ils.storage.metabib.full_rec.search.fts", $search_hash, $string );
162 my $response = $request->recv();
163 if($response and $response->isa("OpenSRF::EX")) {
164 throw $response ($response->stringify);
167 my $data = $response->content;
171 $session->disconnect();