]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Search.pm
just keeping up to date
[Evergreen.git] / Open-ILS / src / perlmods / OpenILS / Application / Search.pm
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;
7
8 use OpenSRF::EX qw(:try);
9
10 sub _child_init {
11
12         try {
13                 OpenSRF::Application->method_lookup( "blah" );
14
15         } catch Error with { 
16                 warn "Child Init Failed: " . shift() . "\n";
17         };
18
19 }
20
21 my $cat_search_hash =  {
22
23         author => [ 
24                 { tag => "100", subfield => "a"} ,
25                 { tag => "700", subfield => "a"}, 
26         ],
27
28         title => [ 
29                 { tag => "245", subfield => "a"},
30                 { tag => "242", subfield => "a"}, 
31                 { tag => "240", subfield => "a"},
32                 { tag => "210", subfield => "a"},
33         ],
34
35         subject => [ 
36                 { tag => "650", subfield => "_" }, 
37         ],
38
39         tcn     => [
40                 { tag => "035", subfield => "_" },
41         ],
42
43 };
44
45
46
47
48
49 __PACKAGE__->register_method(
50         method  => "cat_biblio_search_class",
51         api_name        => "open-ils.search.cat.biblio.class",
52         argc            => 3, 
53         note            => "Searches biblio information by search class",
54 );
55
56 sub cat_biblio_search_class {
57         my( $self, $client, $class, $sort, $string ) = @_;
58
59         # sort = title, author, pubdate
60
61         warn "Starting search " . time() . "\n";
62         
63         my $search_hash;
64
65         warn "Searching $class, $sort, $string\n";
66         
67         warn "Looking up method: "  . time() . "\n";
68
69         my $method = $self->method_lookup("open-ils.search.biblio.marc");
70         if(!$method) {
71                 throw OpenSRF::EX::PANIC 
72                         ("Can't lookup method 'open-ils.search.biblio.marc'");
73         }
74
75         use Data::Dumper;
76
77         warn "Running: "  . time() . "\n";
78
79         my ($records) = $method->run( $cat_search_hash->{$class}, $string );
80
81         my @ids;
82
83         for my $i (@$records) {
84                 push @ids, $i->[0];
85         }
86
87         warn "Found Id's: @ids\n";
88         warn "Search For Id's complete, fixing: "  . time() . "\n";
89
90         my @results = ();
91
92         my @marcxml_objs;
93         my $session = OpenSRF::AppSession->create("open-ils.storage");
94         my $request = $session->request(
95                         "open-ils.storage.biblio.record_marc.batch.retrieve",  @ids );
96
97
98         my $last_content = undef;
99
100         while( my $response = $request->recv() ) {
101
102                 warn "Received record from storage " . time() . "\n";
103
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;
113                 }
114
115                 if($response and $response->isa("OpenSRF::EX")) {
116                         throw $response ($response->stringify);
117                 }
118
119                 $last_content = $response->content;
120
121         }
122
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;
131         }
132
133
134         $client->respond( \@results );
135         
136         $request->finish();
137         $session->finish();
138         $session->disconnect();
139         $session->kill_me();
140         
141         return undef;
142
143 }
144
145
146
147 __PACKAGE__->register_method(
148         method  => "biblio_search_marc",
149         api_name        => "open-ils.search.biblio.marc",
150         argc            => 1, 
151         note            => "Searches biblio information by marc tag",
152 );
153
154 sub biblio_search_marc {
155
156         my( $self, $client, $search_hash, $string ) = @_;
157
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 );
161
162         my $response = $request->recv();
163         if($response and $response->isa("OpenSRF::EX")) {
164                 throw $response ($response->stringify);
165         }
166
167         my $data = $response->content;
168
169         $request->finish();
170         $session->finish();
171         $session->disconnect();
172         $session->kill_me();
173
174         return $data;
175
176 }
177
178
179
180
181 1;