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 $tcn =~ s/.*?(\w+)\s*$/$1/o;
60 warn "Searching TCN $tcn\n";
62 my $session = OpenSRF::AppSession->create( "open-ils.storage" );
63 my $request = $session->request(
64 "open-ils.storage.biblio.record_entry.search.tcn_value", $tcn );
65 my $response = $request->recv();
68 unless ($response) { return undef; }
70 if($response->isa("OpenSRF::EX")) {
71 warn $response->stringify();
72 throw $response ($response->stringify);
76 my $record_entry = $response->content;
77 $record_entry = $record_entry->[0];
80 $request = $session->request(
81 "open-ils.storage.biblio.record_marc.retrieve", $record_entry->id() );
82 $response = $request->recv();
84 unless ($response) { return undef; }
86 if($response->isa("OpenSRF::EX")) {
87 warn $response->stringify();
88 throw $response ($response->stringify);
91 my $marcxml = $response->content;
93 my $u = OpenILS::Application::Cat::Utils->new();
94 $u->start_mods_batch( $marcxml->marc );
95 my $mods = $u->finish_mods_batch();
96 $mods->{doc_id} = $marcxml->id();
100 $session->disconnect;
107 __PACKAGE__->register_method(
108 method => "cat_biblio_search_class",
109 api_name => "open-ils.search.cat.biblio.class",
111 note => "Searches biblio information by search class",
114 sub cat_biblio_search_class {
115 my( $self, $client, $class, $sort, $string ) = @_;
117 # sort = title, author, pubdate
119 warn "Starting search " . time() . "\n";
123 warn "Searching $class, $sort, $string\n";
125 warn "Looking up method: " . time() . "\n";
127 my $method = $self->method_lookup("open-ils.search.biblio.marc");
129 throw OpenSRF::EX::PANIC
130 ("Can't lookup method 'open-ils.search.biblio.marc'");
133 warn "Running: " . time() . "\n";
135 my ($records) = $method->run( $cat_search_hash->{$class}, $string );
139 for my $i (@$records) {
143 warn "Found Id's: @ids\n";
144 warn "Search For Id's complete, fixing: " . time() . "\n";
149 my $session = OpenSRF::AppSession->create("open-ils.storage");
150 my $request = $session->request(
151 "open-ils.storage.biblio.record_marc.batch.retrieve", @ids );
154 my $last_content = undef;
156 while( my $response = $request->recv() ) {
158 warn "Received record from storage " . time() . "\n";
160 if( $last_content ) {
161 my $u = OpenILS::Application::Cat::Utils->new();
162 $u->start_mods_batch( $last_content->marc );
163 my $mods = $u->finish_mods_batch();
164 $mods->{doc_id} = $last_content->id();
165 warn "Processed mods " . time() . "\n";
166 #$client->respond( $mods );
167 $last_content = undef;
168 push @results, $mods;
171 next unless $response;
173 if($response->isa("OpenSRF::EX")) {
174 throw $response ($response->stringify);
177 $last_content = $response->content;
181 if( $last_content ) {
182 my $u = OpenILS::Application::Cat::Utils->new();
183 $u->start_mods_batch( $last_content->marc );
184 my $mods = $u->finish_mods_batch();
185 $mods->{doc_id} = $last_content->id();
186 warn "Processed mods " . time() . "\n";
187 #$client->respond( $mods );
188 push @results, $mods;
192 $client->respond( \@results );
196 $session->disconnect();
205 __PACKAGE__->register_method(
206 method => "biblio_search_marc",
207 api_name => "open-ils.search.biblio.marc",
209 note => "Searches biblio information by marc tag",
212 sub biblio_search_marc {
214 my( $self, $client, $search_hash, $string ) = @_;
216 my $session = OpenSRF::AppSession->create("open-ils.storage");
217 my $request = $session->request(
218 "open-ils.storage.metabib.full_rec.search_fts.index_vector", $search_hash, $string );
220 my $response = $request->recv();
221 if($response and $response->isa("OpenSRF::EX")) {
222 throw $response ($response->stringify);
225 my $data = $response->content;
229 $session->disconnect();