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 => "_" },
48 __PACKAGE__->register_method(
49 method => "cat_biblio_search_tcn",
50 api_name => "open-ils.search.cat.biblio.tcn",
52 note => "Searches biblio information by search class",
55 sub cat_biblio_search_tcn {
57 my( $self, $client, $tcn ) = @_;
59 my $session = OpenSRF::AppSession->create( "open-ils.storage" );
60 my $request = $session->request(
61 "open-ils.storage.biblio.record_entry.search.tcn_value", $tcn );
62 my $response = $request->recv();
65 unless ($response) { return undef; }
67 if($response->isa("OpenSRF::EX")) {
68 warn $response->stringify();
69 throw $response ($response->stringify);
73 my $record_entry = $response->content;
74 $record_entry = $record_entry->[0];
77 $request = $session->request(
78 "open-ils.storage.biblio.record_marc.retrieve", $record_entry->id() );
79 $response = $request->recv();
81 unless ($response) { return undef; }
83 if($response->isa("OpenSRF::EX")) {
84 warn $response->stringify();
85 throw $response ($response->stringify);
88 my $marcxml = $response->content;
90 my $u = OpenILS::Application::Cat::Utils->new();
91 $u->start_mods_batch( $marcxml->marc );
92 my $mods = $u->finish_mods_batch();
93 $mods->{doc_id} = $marcxml->id();
104 __PACKAGE__->register_method(
105 method => "cat_biblio_search_class",
106 api_name => "open-ils.search.cat.biblio.class",
108 note => "Searches biblio information by search class",
111 sub cat_biblio_search_class {
112 my( $self, $client, $class, $sort, $string ) = @_;
114 # sort = title, author, pubdate
116 warn "Starting search " . time() . "\n";
120 warn "Searching $class, $sort, $string\n";
122 warn "Looking up method: " . time() . "\n";
124 my $method = $self->method_lookup("open-ils.search.biblio.marc");
126 throw OpenSRF::EX::PANIC
127 ("Can't lookup method 'open-ils.search.biblio.marc'");
130 warn "Running: " . time() . "\n";
132 my ($records) = $method->run( $cat_search_hash->{$class}, $string );
136 for my $i (@$records) {
140 warn "Found Id's: @ids\n";
141 warn "Search For Id's complete, fixing: " . time() . "\n";
146 my $session = OpenSRF::AppSession->create("open-ils.storage");
147 my $request = $session->request(
148 "open-ils.storage.biblio.record_marc.batch.retrieve", @ids );
151 my $last_content = undef;
153 while( my $response = $request->recv() ) {
155 warn "Received record from storage " . time() . "\n";
157 if( $last_content ) {
158 my $u = OpenILS::Application::Cat::Utils->new();
159 $u->start_mods_batch( $last_content->marc );
160 my $mods = $u->finish_mods_batch();
161 $mods->{doc_id} = $last_content->id();
162 warn "Processed mods " . time() . "\n";
163 #$client->respond( $mods );
164 $last_content = undef;
165 push @results, $mods;
168 next unless $response;
170 if($response->isa("OpenSRF::EX")) {
171 throw $response ($response->stringify);
174 $last_content = $response->content;
178 if( $last_content ) {
179 my $u = OpenILS::Application::Cat::Utils->new();
180 $u->start_mods_batch( $last_content->marc );
181 my $mods = $u->finish_mods_batch();
182 $mods->{doc_id} = $last_content->id();
183 warn "Processed mods " . time() . "\n";
184 #$client->respond( $mods );
185 push @results, $mods;
189 $client->respond( \@results );
193 $session->disconnect();
202 __PACKAGE__->register_method(
203 method => "biblio_search_marc",
204 api_name => "open-ils.search.biblio.marc",
206 note => "Searches biblio information by marc tag",
209 sub biblio_search_marc {
211 my( $self, $client, $search_hash, $string ) = @_;
213 my $session = OpenSRF::AppSession->create("open-ils.storage");
214 my $request = $session->request(
215 "open-ils.storage.metabib.full_rec.search_fts.index_vector", $search_hash, $string );
217 my $response = $request->recv();
218 if($response and $response->isa("OpenSRF::EX")) {
219 throw $response ($response->stringify);
222 my $data = $response->content;
226 $session->disconnect();