1 package OpenILS::Application::Search::Biblio;
2 use base qw/OpenSRF::Application/;
3 use strict; use warnings;
8 use OpenILS::Utils::Fieldmapper;
9 use OpenILS::Utils::ModsParser;
10 use OpenSRF::Utils::SettingsClient;
11 use OpenILS::Utils::Editor;
13 use OpenSRF::Utils::Logger qw/:logger/;
18 use Time::HiRes qw(time);
19 use OpenSRF::EX qw(:try);
20 use Digest::MD5 qw(md5_hex);
26 $Data::Dumper::Indent = 0;
28 use OpenILS::Application::AppUtils;
29 my $apputils = "OpenILS::Application::AppUtils";
33 # useful for MARC based searches
34 my $cat_search_hash = {
35 isbn => [ { tag => '020', subfield => 'a' }, ],
36 issn => [ { tag => '022', subfield => 'a' }, ],
42 # ---------------------------------------------------------------------------
43 # takes a list of record id's and turns the docs into friendly
44 # mods structures. Creates one MODS structure for each doc id.
45 # ---------------------------------------------------------------------------
46 sub _records_to_mods {
52 my $session = OpenSRF::AppSession->create("open-ils.storage");
53 my $request = $session->request(
54 "open-ils.storage.direct.biblio.record_entry.batch.retrieve", @ids );
56 while( my $resp = $request->recv ) {
57 my $content = $resp->content;
58 my $u = OpenILS::Utils::ModsParser->new();
59 $u->start_mods_batch( $content->marc );
60 my $mods = $u->finish_mods_batch();
61 $mods->doc_id($content->id());
62 $mods->tcn($content->tcn_value);
66 $session->disconnect();
70 __PACKAGE__->register_method(
71 method => "record_id_to_mods",
72 api_name => "open-ils.search.biblio.record.mods.retrieve",
74 note => "Provide ID, we provide the mods"
77 # converts a record into a mods object with copy counts attached
78 sub record_id_to_mods {
80 my( $self, $client, $org_id, $id ) = @_;
82 my $mods_list = _records_to_mods( $id );
83 my $mods_obj = $mods_list->[0];
84 my $cmethod = $self->method_lookup(
85 "open-ils.search.biblio.record.copy_count");
86 my ($count) = $cmethod->run($org_id, $id);
87 $mods_obj->copy_count($count);
94 __PACKAGE__->register_method(
95 method => "record_id_to_mods_slim",
96 api_name => "open-ils.search.biblio.record.mods_slim.retrieve",
98 note => "Provide ID, we provide the mods"
101 # converts a record into a mods object with NO copy counts attached
102 sub record_id_to_mods_slim {
103 my( $self, $client, $id ) = @_;
104 return undef unless defined $id;
106 if(ref($id) and ref($id) == 'ARRAY') {
107 return _records_to_mods( @$id );
109 my $mods_list = _records_to_mods( $id );
110 my $mods_obj = $mods_list->[0];
115 # Returns the number of copies attached to a record based on org location
116 __PACKAGE__->register_method(
117 method => "record_id_to_copy_count",
118 api_name => "open-ils.search.biblio.record.copy_count",
121 __PACKAGE__->register_method(
122 method => "record_id_to_copy_count",
123 api_name => "open-ils.search.biblio.metarecord.copy_count",
126 __PACKAGE__->register_method(
127 method => "record_id_to_copy_count",
128 api_name => "open-ils.search.biblio.metarecord.copy_count.staff",
130 sub record_id_to_copy_count {
131 my( $self, $client, $org_id, $record_id, $format ) = @_;
133 $format = undef if (!$format or $format eq 'all');
135 my $method = "open-ils.storage.biblio.record_entry.copy_count.atomic";
137 if($self->api_name =~ /metarecord/) {
138 $method = "open-ils.storage.metabib.metarecord.copy_count.atomic";
142 if($self->api_name =~ /staff/ ) {
143 $method =~ s/atomic/staff\.atomic/og;
144 warn "Doing staff search $method\n";
148 my $session = OpenSRF::AppSession->create("open-ils.storage");
149 warn "copy_count retrieve $record_id\n";
150 return undef unless(defined $record_id);
152 my $request = $session->request(
153 $method, org_unit => $org_id => $key => $record_id, format => $format );
156 my $count = $request->gather(1);
157 $session->disconnect();
158 return [ sort { $a->{depth} <=> $b->{depth} } @$count ];
165 __PACKAGE__->register_method(
166 method => "biblio_search_tcn",
167 api_name => "open-ils.search.biblio.tcn",
169 note => "Retrieve a record by TCN",
172 sub biblio_search_tcn {
174 my( $self, $client, $tcn ) = @_;
176 $tcn =~ s/.*?(\w+)\s*$/$1/o;
177 warn "Searching TCN $tcn\n";
179 my $session = OpenSRF::AppSession->create( "open-ils.storage" );
180 my $request = $session->request(
181 "open-ils.storage.direct.biblio.record_entry.search_where.atomic",
182 { tcn_value => $tcn, deleted => 'f' } );
183 #"open-ils.storage.direct.biblio.record_entry.search.tcn_value.atomic", $tcn );
184 my $record_entry = $request->gather(1);
187 for my $record (@$record_entry) {
188 push @ids, $record->id;
191 $session->disconnect();
194 return { count => $size, ids => \@ids };
198 # --------------------------------------------------------------------------------
200 __PACKAGE__->register_method(
201 method => "biblio_barcode_to_copy",
202 api_name => "open-ils.search.asset.copy.find_by_barcode",);
203 sub biblio_barcode_to_copy {
204 my( $self, $client, $barcode ) = @_;
205 my( $copy, $evt ) = $U->fetch_copy_by_barcode($barcode);
210 __PACKAGE__->register_method(
211 method => "biblio_id_to_copy",
212 api_name => "open-ils.search.asset.copy.batch.retrieve",);
213 sub biblio_id_to_copy {
214 my( $self, $client, $ids ) = @_;
215 $logger->info("Fetching copies @$ids");
216 return $U->storagereq(
217 "open-ils.storage.direct.asset.copy.batch.retrieve.atomic", @$ids );
221 __PACKAGE__->register_method(
222 method => "copy_retrieve",
223 api_name => "open-ils.search.asset.copy.retrieve",);
225 my( $self, $client, $cid ) = @_;
226 my( $copy, $evt ) = $U->fetch_copy($cid);
232 __PACKAGE__->register_method(
233 method => "fleshed_copy_retrieve_batch",
234 api_name => "open-ils.search.asset.copy.fleshed.batch.retrieve");
236 sub fleshed_copy_retrieve_batch {
237 my( $self, $client, $ids ) = @_;
238 $logger->info("Fetching fleshed copies @$ids");
239 return $U->storagereq(
240 "open-ils.storage.fleshed.asset.copy.batch.retrieve.atomic", @$ids );
244 __PACKAGE__->register_method(
245 method => "fleshed_copy_retrieve",
246 api_name => "open-ils.search.asset.copy.fleshed.retrieve",);
248 sub fleshed_copy_retrieve {
249 my( $self, $client, $id ) = @_;
250 my( $c, $e) = $U->fetch_fleshed_copy($id);
257 __PACKAGE__->register_method(
258 method => "biblio_barcode_to_title",
259 api_name => "open-ils.search.biblio.find_by_barcode",
262 sub biblio_barcode_to_title {
263 my( $self, $client, $barcode ) = @_;
265 my $title = $apputils->simple_scalar_request(
267 "open-ils.storage.biblio.record_entry.retrieve_by_barcode", $barcode );
269 return { ids => [ $title->id ], count => 1 } if $title;
270 return { count => 0 };
274 __PACKAGE__->register_method(
275 method => "biblio_copy_to_mods",
276 api_name => "open-ils.search.biblio.copy.mods.retrieve",
279 # takes a copy object and returns it fleshed mods object
280 sub biblio_copy_to_mods {
281 my( $self, $client, $copy ) = @_;
283 my $volume = $U->storagereq(
284 "open-ils.storage.direct.asset.call_number.retrieve",
285 $copy->call_number() );
287 my $mods = _records_to_mods($volume->record());
288 $mods = shift @$mods;
289 $volume->copies([$copy]);
290 push @{$mods->call_numbers()}, $volume;
296 # ----------------------------------------------------------------------------
297 # These are the main OPAC search methods
298 # ----------------------------------------------------------------------------
300 __PACKAGE__->register_method(
301 method => 'the_quest_for_knowledge',
302 api_name => 'open-ils.search.biblio.multiclass',
304 Performs a multi class bilbli or metabib search
305 @param searchhash A search object layed out like so:
306 searches : { "$class" : "$value", ...}
307 org_unit : The org id to focus the search at
308 depth : The org depth
309 limit : The search limit
310 offset : The search offset
311 format : The MARC format
312 sort : What field to sort the results on [ author | title | pubdate ]
313 sort_dir : What direction do we sort? [ asc | desc ]
314 @return An object of the form
315 { "count" : $count, "ids" : [ [ $id, $relevancy, $total ], ...] }
319 __PACKAGE__->register_method(
320 method => 'the_quest_for_knowledge',
321 api_name => 'open-ils.search.record.multiclass.staff',
322 signature => q/@see open-ils.search.biblio.multiclass/);
323 __PACKAGE__->register_method(
324 method => 'the_quest_for_knowledge',
325 api_name => 'open-ils.search.metabib.multiclass',
326 signature => q/@see open-ils.search.biblio.multiclass/);
327 __PACKAGE__->register_method(
328 method => 'the_quest_for_knowledge',
329 api_name => 'open-ils.search.metabib.multiclass.staff',
330 signature => q/@see open-ils.search.biblio.multiclass/);
333 sub the_quest_for_knowledge {
334 my( $self, $conn, $searchhash ) = @_;
336 my $method = 'open-ils.storage.biblio.multiclass.search_fts';
340 if($self->api_name =~ /metabib/) {
342 $method =~ s/biblio/metabib/o;
345 $method .= ".staff" if($self->api_name =~ /staff/);
346 $method .= ".atomic";
348 for (keys %$searchhash) {
349 delete $$searchhash{$_} unless defined $$searchhash{$_}; }
351 my $result = $U->storagereq( $method, %$searchhash );
353 return {count => 0} unless ($result && $$result[0]);
355 for my $r (@$result) { push(@recs, $r) if ($r and $$r[0]); }
356 return { ids => \@recs,
357 count => ($ismeta) ? $result->[0]->[3] : $result->[0]->[2] };
367 __PACKAGE__->register_method(
368 method => "biblio_mrid_to_modsbatch_batch",
369 api_name => "open-ils.search.biblio.metarecord.mods_slim.batch.retrieve");
371 sub biblio_mrid_to_modsbatch_batch {
372 my( $self, $client, $mrids) = @_;
373 warn "Performing mrid_to_modsbatch_batch...";
375 my $method = $self->method_lookup("open-ils.search.biblio.metarecord.mods_slim.retrieve");
376 for my $id (@$mrids) {
377 next unless defined $id;
378 my ($m) = $method->run($id);
385 __PACKAGE__->register_method(
386 method => "biblio_mrid_to_modsbatch",
387 api_name => "open-ils.search.biblio.metarecord.mods_slim.retrieve",
388 notes => <<" NOTES");
389 Returns the mvr associated with a given metarecod. If none exists,
393 __PACKAGE__->register_method(
394 method => "biblio_mrid_to_modsbatch",
395 api_name => "open-ils.search.biblio.metarecord.mods_slim.retrieve.staff",
396 notes => <<" NOTES");
397 Returns the mvr associated with a given metarecod. If none exists,
401 sub biblio_mrid_to_modsbatch {
402 my( $self, $client, $mrid ) = @_;
404 warn "Grabbing mvr for $mrid\n";
406 my ($mr, $evt) = _grab_metarecord($mrid);
407 return $evt unless $mr;
409 if( my $m = $self->biblio_mrid_check_mvr($client, $mr)) {
413 return $self->biblio_mrid_make_modsbatch( $client, $mr );
416 # converts a metarecord to an mvr
419 my $perl = JSON->JSON2perl($mr->mods());
420 return Fieldmapper::metabib::virtual_record->new($perl);
423 # checks to see if a metarecord has mods, if so returns true;
425 __PACKAGE__->register_method(
426 method => "biblio_mrid_check_mvr",
427 api_name => "open-ils.search.biblio.metarecord.mods_slim.check",
428 notes => <<" NOTES");
429 Takes a metarecord ID or a metarecord object and returns true
430 if the metarecord already has an mvr associated with it.
433 sub biblio_mrid_check_mvr {
434 my( $self, $client, $mrid ) = @_;
438 if(ref($mrid)) { $mr = $mrid; }
439 else { ($mr, $evt) = _grab_metarecord($mrid); }
442 warn "Checking mvr for mr " . $mr->id . "\n";
444 return _mr_to_mvr($mr) if $mr->mods();
448 sub _grab_metarecord {
450 my $e = OpenILS::Utils::Editor->new;
451 my $mr = $e->retrieve_metabib_metarecord($mrid) or return ( undef, $e->event );
456 __PACKAGE__->register_method(
457 method => "biblio_mrid_make_modsbatch",
458 api_name => "open-ils.search.biblio.metarecord.mods_slim.create",
459 notes => <<" NOTES");
460 Takes either a metarecord ID or a metarecord object.
461 Forces the creations of an mvr for the given metarecord.
462 The created mvr is returned.
465 sub biblio_mrid_make_modsbatch {
466 my( $self, $client, $mrid ) = @_;
468 my $e = OpenILS::Utils::Editor->new;
475 $mr = $e->retrieve_metabib_metarecord($mrid)
479 my $masterid = $mr->master_record;
480 $logger->info("creating new mods batch for metarecord=$mrid, master record=$masterid");
482 my $ids = $e->request(
483 'open-ils.storage.ordered.metabib.metarecord.records.staff.atomic', $mrid);
484 return undef unless @$ids;
486 my $master = $e->retrieve_biblio_record_entry($masterid)
489 # start the mods batch
490 my $u = OpenILS::Utils::ModsParser->new();
491 $u->start_mods_batch( $master->marc );
493 # grab all of the sub-records and shove them into the batch
494 my @ids = grep { $_ ne $masterid } @$ids;
495 my $subrecs = $e->batch_retrieve_biblio_record_entry(\@ids);
498 $logger->debug("adding record ".$_->id." to mods batch for metarecord=$mrid");
499 $u->push_mods_batch( $_->marc ) if $_->marc;
503 # finish up and send to the client
504 my $mods = $u->finish_mods_batch();
505 $mods->doc_id($mrid);
506 $client->respond_complete($mods);
509 # now update the mods string in the db
510 my $string = JSON->perl2JSON($mods->decast);
513 $e = OpenILS::Utils::Editor->new(xact => 1);
514 $e->update_metabib_metarecord($mr)
515 or $logger->error("Error setting mods text on metarecord $mrid : " . Dumper($e->event));
526 sub _biblio_mrid_make_modsbatch {
528 my( $self, $client, $mrid ) = @_;
531 if(ref($mrid)) { $mr = $mrid; }
532 else { $mr = _grab_metarecord($mrid); }
535 warn "Forcing mvr creation for mr " . $mr->id . "\n";
536 my $master_id = $mr->master_record;
538 my $session = OpenSRF::AppSession->create("open-ils.storage");
540 # grab the records attached to this metarecod
541 warn "Creating mods batch for metarecord $mrid\n";
542 my $meth = "open-ils.search.biblio.metarecord_to_records.staff";
543 $meth = $self->method_lookup($meth);
544 my ($id_hash) = $meth->run($mrid);
545 my @ids = @{$id_hash->{ids}};
546 if(@ids < 1) { return undef; }
548 warn "Master ID is $master_id\n";
549 # grab the master record to start the mods batch
551 $meth = "open-ils.storage.direct.biblio.record_entry.retrieve";
553 my $record = $session->request(
554 "open-ils.storage.direct.biblio.record_entry.retrieve", $master_id );
555 $record = $record->gather(1);
557 #my $record = OpenILS::Application::AppUtils->simple_scalar_request( "open-ils.storage",
560 warn "No record returned with id $master_id";
561 throw OpenSRF::EX::ERROR
564 my $u = OpenILS::Utils::ModsParser->new();
565 $u->start_mods_batch( $record->marc );
566 my $main_doc_id = $record->id();
568 @ids = grep { $_ ne $master_id } @ids;
570 # now we have to collect all of the marc objects and push them into a mods batch
571 my $request = $session->request(
572 "open-ils.storage.direct.biblio.record_entry.batch.retrieve", @ids );
574 while( my $response = $request->recv() ) {
576 next unless $response;
577 if(UNIVERSAL::isa( $response,"OpenSRF::EX")) {
578 throw $response ($response->stringify);
581 my $content = $response->content;
584 $u->push_mods_batch( $content->marc );
588 my $mods = $u->finish_mods_batch();
589 $mods->doc_id($mrid);
592 $client->respond_complete($mods);
594 my $mods_string = JSON->perl2JSON($mods->decast);
596 $mr->mods($mods_string);
598 my $req = $session->request(
599 "open-ils.storage.direct.metabib.metarecord.update", $mr );
604 $session->disconnect();
612 # converts a mr id into a list of record ids
614 __PACKAGE__->register_method(
615 method => "biblio_mrid_to_record_ids",
616 api_name => "open-ils.search.biblio.metarecord_to_records",
619 __PACKAGE__->register_method(
620 method => "biblio_mrid_to_record_ids",
621 api_name => "open-ils.search.biblio.metarecord_to_records.staff",
624 sub biblio_mrid_to_record_ids {
625 my( $self, $client, $mrid, $args ) = @_;
627 my $format = $$args{format};
628 my $org = $$args{org};
629 my $depth = $$args{depth};
631 my $method = "open-ils.storage.ordered.metabib.metarecord.records.atomic";
632 $method =~ s/atomic/staff\.atomic/o if $self->api_name =~ /staff/o;
633 my $recs = $U->storagereq($method, $mrid, $format, $org, $depth);
635 return { count => scalar(@$recs), ids => $recs };
639 __PACKAGE__->register_method(
640 method => "biblio_record_to_marc_html",
641 api_name => "open-ils.search.biblio.record.html" );
643 my $parser = XML::LibXML->new();
644 my $xslt = XML::LibXSLT->new();
647 my $settings_client = OpenSRF::Utils::SettingsClient->new();
648 sub biblio_record_to_marc_html {
649 my( $self, $client, $recordid ) = @_;
652 my $dir = $settings_client->config_value( "dirs", "xsl" );
653 my $xsl = $settings_client->config_value(
654 "apps", "open-ils.search", "app_settings", "marc_html_xsl" );
656 $xsl = $parser->parse_file("$dir/$xsl");
657 $marc_sheet = $xslt->parse_stylesheet( $xsl );
661 my $record = $apputils->simple_scalar_request(
663 "open-ils.storage.direct.biblio.record_entry.retrieve",
666 my $xmldoc = $parser->parse_string($record->marc);
667 my $html = $marc_sheet->transform($xmldoc);
668 $html = $html->toString();
675 __PACKAGE__->register_method(
676 method => "retrieve_all_copy_locations",
677 api_name => "open-ils.search.config.copy_location.retrieve.all" );
679 my $shelving_locations;
680 sub retrieve_all_copy_locations {
681 my( $self, $client ) = @_;
682 if(!$shelving_locations) {
683 $shelving_locations = $apputils->simple_scalar_request(
685 "open-ils.storage.direct.asset.copy_location.retrieve.all.atomic");
687 return $shelving_locations;
693 __PACKAGE__->register_method(
694 method => "retrieve_all_copy_statuses",
695 api_name => "open-ils.search.config.copy_status.retrieve.all" );
698 sub retrieve_all_copy_statuses {
699 my( $self, $client ) = @_;
700 if(!$copy_statuses) {
701 $copy_statuses = $apputils->simple_scalar_request(
703 "open-ils.storage.direct.config.copy_status.retrieve.all.atomic" );
705 return $copy_statuses;
709 __PACKAGE__->register_method(
710 method => "copy_counts_per_org",
711 api_name => "open-ils.search.biblio.copy_counts.retrieve");
713 __PACKAGE__->register_method(
714 method => "copy_counts_per_org",
715 api_name => "open-ils.search.biblio.copy_counts.retrieve.staff");
717 sub copy_counts_per_org {
718 my( $self, $client, $record_id ) = @_;
720 warn "Retreiveing copy copy counts for record $record_id and method " . $self->api_name . "\n";
722 my $method = "open-ils.storage.biblio.record_entry.global_copy_count.atomic";
723 if($self->api_name =~ /staff/) { $method =~ s/atomic/staff\.atomic/; }
725 my $counts = $apputils->simple_scalar_request(
726 "open-ils.storage", $method, $record_id );
728 $counts = [ sort {$a->[0] <=> $b->[0]} @$counts ];
733 __PACKAGE__->register_method(
734 method => "copy_count_summary",
735 api_name => "open-ils.search.biblio.copy_counts.summary.retrieve",
736 notes => <<" NOTES");
737 returns an array of these:
738 [ org_id, callnumber_label, <status1_count>, <status2_cout>,...]
739 where statusx is a copy status name. the statuses are sorted
743 sub copy_count_summary {
744 my( $self, $client, $rid ) = @_;
745 return $U->storagereq(
746 'open-ils.storage.biblio.record_entry.status_copy_count.atomic', $rid );
752 __PACKAGE__->register_method(
753 method => "multiclass_search",
754 api_name => "open-ils.search.biblio.multiclass",
755 notes => <<" NOTES");
756 Performs a multiclass search
757 PARAMS( searchBlob, org_unit, format, limit )
758 where searchBlob is defined like this:
760 "title" : { "term" : "water" },
761 "author" : { "term" : "smith" },
766 __PACKAGE__->register_method(
767 method => "multiclass_search",
768 api_name => "open-ils.search.biblio.multiclass.staff",
769 notes => "see open-ils.search.biblio.multiclass" );
771 sub multiclass_search {
772 my( $self, $client, $searchBlob, $orgid, $format, $limit ) = @_;
774 $logger->debug("Performing multiclass search with org => $orgid, " .
775 "format => $format, limit => $limit, and search blob " . Dumper($searchBlob));
777 my $meth = 'open-ils.storage.metabib.post_filter.multiclass.search_fts.metarecord.atomic';
778 if($self->api_name =~ /staff/) { $meth =~ s/metarecord\.atomic/metarecord.staff.atomic/; }
781 my $records = $apputils->simplereq(
782 'open-ils.storage', $meth,
783 org_unit => $orgid, searches => $searchBlob, format => $format, limit => $limit );
788 if( ref($records) and $records->[0] and
789 defined($records->[0]->[3])) { $count = $records->[0]->[3];}
791 for my $r (@$records) { push( @$recs, $r ) if ($r and $r->[0]); }
793 # records has the form: [ mrid, rank, singleRecord / 0, hitCount ];
794 return { ids => $recs, count => $count };
800 __PACKAGE__->register_method(
801 method => "multiclass_search",
802 api_name => "open-ils.search.biblio.multiclass",
804 Performs a multiclass search
805 @param args A names hash of arguments:
806 org_unit : The org to focus the search on
807 depth : The search depth
810 offset : Search offset
811 searches : A named hash of searches which has the following format:
813 "title" : { "term" : "water" },
814 "author" : { "term" : "smith" },
817 @return { ids : <array of ids>, count : hitcount }
821 __PACKAGE__->register_method(
822 method => "multiclass_search",
823 api_name => "open-ils.search.biblio.multiclass.staff",
824 notes => q/@see open-ils.search.biblio.multiclass/ );
826 sub multiclass_search {
827 my( $self, $client, $args ) = @_;
829 $logger->debug("Performing multiclass search with args:\n" . Dumper($args));
830 my $meth = 'open-ils.storage.metabib.post_filter.multiclass.search_fts.metarecord.atomic';
831 if($self->api_name =~ /staff/) { $meth =~ s/metarecord\.atomic/metarecord.staff.atomic/; }
833 my $records = $apputils->simplereq( 'open-ils.storage', $meth, %$args );
838 if( ref($records) and $records->[0] and
839 defined($records->[0]->[3])) { $count = $records->[0]->[3];}
841 for my $r (@$records) { push( @$recs, $r ) if ($r and $r->[0]); }
843 return { ids => $recs, count => $count };
850 __PACKAGE__->register_method(
851 method => "marc_search",
852 api_name => "open-ils.search.biblio.marc",
853 notes => <<" NOTES");
855 open-ils.storage.biblio.full_rec.multi_search.atomic
856 { "searches": [{"term":"harry","restrict": [{"tag":245,"subfield":"a"}]}], "org_unit": 1,
857 "limit":5,"sort":"author","item_type":"g"}
861 my( $self, $conn, $args ) = @_;
862 my $records = $U->storagereq(
863 'open-ils.storage.biblio.full_rec.multi_search.atomic', %$args );
867 $count = $records->[0]->[2] if( ref($records) and
868 $records->[0] and defined($records->[0]->[2]));
870 return { ids => $records, count => $count };
875 __PACKAGE__->register_method(
876 method => "biblio_search_isbn",
877 api_name => "open-ils.search.biblio.isbn",
880 sub biblio_search_isbn {
881 my( $self, $client, $isbn ) = @_;
882 $logger->debug("Searching ISBN $isbn");
883 my $e = OpenILS::Utils::Editor->new;
884 my $recs = $e->request(
885 'open-ils.storage.id_list.biblio.record_entry.search.isbn.atomic', $isbn );
886 return { ids => $recs, count => scalar(@$recs) };
890 __PACKAGE__->register_method(
891 method => "biblio_search_issn",
892 api_name => "open-ils.search.biblio.issn",
895 sub biblio_search_issn {
896 my( $self, $client, $issn ) = @_;
897 $logger->debug("Searching ISSN $issn");
898 my $e = OpenILS::Utils::Editor->new;
899 my $recs = $e->request(
900 'open-ils.storage.id_list.biblio.record_entry.search.issn.atomic', $issn );
901 return { ids => $recs, count => scalar(@$recs) };
907 __PACKAGE__->register_method(
908 method => "fetch_mods_by_copy",
909 api_name => "open-ils.search.biblio.mods_from_copy",
912 sub fetch_mods_by_copy {
913 my( $self, $client, $copyid ) = @_;
914 my ($record, $evt) = $apputils->fetch_record_by_copy( $copyid );
916 return OpenILS::Event->new('ITEM_NOT_CATALOGED') unless $record->marc;
917 return $apputils->record_to_mvr($record);
924 # -------------------------------------------------------------------------------------
926 __PACKAGE__->register_method(
927 method => "cn_browse",
928 api_name => "open-ils.search.callnumber.browse.target",
929 notes => "Starts a callnumber browse"
932 __PACKAGE__->register_method(
933 method => "cn_browse",
934 api_name => "open-ils.search.callnumber.browse.page_up",
935 notes => "Returns the previous page of callnumbers",
938 __PACKAGE__->register_method(
939 method => "cn_browse",
940 api_name => "open-ils.search.callnumber.browse.page_down",
941 notes => "Returns the next page of callnumbers",
945 # RETURNS array of arrays like so: label, owning_lib, record, id
947 my( $self, $client, @params ) = @_;
950 $method = 'open-ils.storage.asset.call_number.browse.target.atomic'
951 if( $self->api_name =~ /target/ );
952 $method = 'open-ils.storage.asset.call_number.browse.page_up.atomic'
953 if( $self->api_name =~ /page_up/ );
954 $method = 'open-ils.storage.asset.call_number.browse.page_down.atomic'
955 if( $self->api_name =~ /page_down/ );
957 return $apputils->simplereq( 'open-ils.storage', $method, @params );
959 # -------------------------------------------------------------------------------------
961 __PACKAGE__->register_method(
962 method => "fetch_cn",
963 api_name => "open-ils.search.callnumber.retrieve",
964 notes => "retrieves a callnumber based on ID",
968 my( $self, $client, $id ) = @_;
969 my( $cn, $evt ) = $apputils->fetch_callnumber( $id );
974 __PACKAGE__->register_method (
975 method => "fetch_copy_by_cn",
976 api_name => 'open-ils.search.copies_by_call_number.retrieve',
978 Returns an array of copy id's by callnumber id
979 @param cnid The callnumber id
980 @return An array of copy ids
984 sub fetch_copy_by_cn {
985 my( $self, $conn, $cnid ) = @_;
986 return $U->storagereq(
987 'open-ils.storage.id_list.asset.copy.search_where.atomic',
988 { call_number => $cnid, deleted => 'f' } );
991 __PACKAGE__->register_method (
992 method => 'fetch_cn_by_info',
993 api_name => 'open-ils.search.call_number.retrieve_by_info',
995 @param label The callnumber label
996 @param record The record the cn is attached to
997 @param org The owning library of the cn
998 @return The callnumber object
1003 sub fetch_cn_by_info {
1004 my( $self, $conn, $label, $record, $org ) = @_;
1005 return $U->storagereq(
1006 'open-ils.storage.direct.asset.call_number.search_where',
1007 { label => $label, record => $record, owning_lib => $org, deleted => 'f' });
1014 __PACKAGE__->register_method (
1015 method => 'bib_extras',
1016 api_name => 'open-ils.search.biblio.lit_form_map.retrieve.all');
1017 __PACKAGE__->register_method (
1018 method => 'bib_extras',
1019 api_name => 'open-ils.search.biblio.item_form_map.retrieve.all');
1020 __PACKAGE__->register_method (
1021 method => 'bib_extras',
1022 api_name => 'open-ils.search.biblio.item_type_map.retrieve.all');
1023 __PACKAGE__->register_method (
1024 method => 'bib_extras',
1025 api_name => 'open-ils.search.biblio.audience_map.retrieve.all');
1030 return $U->storagereq(
1031 'open-ils.storage.direct.config.lit_form_map.retrieve.all.atomic')
1032 if( $self->api_name =~ /lit_form/ );
1034 return $U->storagereq(
1035 'open-ils.storage.direct.config.item_form_map.retrieve.all.atomic')
1036 if( $self->api_name =~ /item_form_map/ );
1038 return $U->storagereq(
1039 'open-ils.storage.direct.config.item_type_map.retrieve.all.atomic')
1040 if( $self->api_name =~ /item_type_map/ );
1042 return $U->storagereq(
1043 'open-ils.storage.direct.config.audience_map.retrieve.all.atomic')
1044 if( $self->api_name =~ /audience/ );
1051 __PACKAGE__->register_method(
1052 method => 'fetch_slim_record',
1053 api_name => 'open-ils.search.biblio.record_entry.slim.retrieve',
1055 Returns a biblio.record_entry without the attached marcxml
1059 sub fetch_slim_record {
1060 my( $self, $conn, $ids ) = @_;
1062 my $editor = OpenILS::Utils::Editor->new;
1065 return $editor->event unless
1066 my $r = $editor->retrieve_biblio_record_entry($_);