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 = _grab_metarecord($mrid);
407 return undef 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 ) = @_;
437 if(ref($mrid)) { $mr = $mrid; }
438 else { $mr = _grab_metarecord($mrid); }
440 warn "Checking mvr for mr " . $mr->id . "\n";
442 return _mr_to_mvr($mr) if $mr->mods();
446 sub _grab_metarecord {
449 warn "Grabbing MR $mrid\n";
451 my $mr = OpenILS::Application::AppUtils->simple_scalar_request(
453 "open-ils.storage.direct.metabib.metarecord.retrieve", $mrid );
456 throw OpenSRF::EX::ERROR
457 ("No metarecord exists with the given id: $mrid");
464 __PACKAGE__->register_method(
465 method => "biblio_mrid_make_modsbatch",
466 api_name => "open-ils.search.biblio.metarecord.mods_slim.create",
467 notes => <<" NOTES");
468 Takes either a metarecord ID or a metarecord object.
469 Forces the creations of an mvr for the given metarecord.
470 The created mvr is returned.
473 sub biblio_mrid_make_modsbatch {
474 my( $self, $client, $mrid ) = @_;
476 my $e = OpenILS::Utils::Editor->new;
483 $mr = $e->retrieve_metabib_metarecord($mrid)
487 my $masterid = $mr->master_record;
488 $logger->info("creating new mods batch for metarecord=$mrid, master record=$masterid");
490 my $ids = $e->request(
491 'open-ils.storage.ordered.metabib.metarecord.records.staff.atomic', $mrid);
492 return undef unless @$ids;
494 my $master = $e->retrieve_biblio_record_entry($masterid)
497 # start the mods batch
498 my $u = OpenILS::Utils::ModsParser->new();
499 $u->start_mods_batch( $master->marc );
501 # grab all of the sub-records and shove them into the batch
502 my @ids = grep { $_ ne $masterid } @$ids;
503 my $subrecs = $e->batch_retrieve_biblio_record_entry(\@ids);
506 $logger->debug("adding record ".$_->id." to mods batch for metarecord=$mrid");
507 $u->push_mods_batch( $_->marc ) if $_->marc;
511 # finish up and send to the client
512 my $mods = $u->finish_mods_batch();
513 $mods->doc_id($mrid);
514 $client->respond_complete($mods);
517 # now update the mods string in the db
518 my $string = JSON->perl2JSON($mods->decast);
521 $e = OpenILS::Utils::Editor->new(xact => 1);
522 $e->update_metabib_metarecord($mr)
523 or $logger->error("Error setting mods text on metarecord $mrid : " . Dumper($e->event));
534 sub _biblio_mrid_make_modsbatch {
536 my( $self, $client, $mrid ) = @_;
539 if(ref($mrid)) { $mr = $mrid; }
540 else { $mr = _grab_metarecord($mrid); }
543 warn "Forcing mvr creation for mr " . $mr->id . "\n";
544 my $master_id = $mr->master_record;
546 my $session = OpenSRF::AppSession->create("open-ils.storage");
548 # grab the records attached to this metarecod
549 warn "Creating mods batch for metarecord $mrid\n";
550 my $meth = "open-ils.search.biblio.metarecord_to_records.staff";
551 $meth = $self->method_lookup($meth);
552 my ($id_hash) = $meth->run($mrid);
553 my @ids = @{$id_hash->{ids}};
554 if(@ids < 1) { return undef; }
556 warn "Master ID is $master_id\n";
557 # grab the master record to start the mods batch
559 $meth = "open-ils.storage.direct.biblio.record_entry.retrieve";
561 my $record = $session->request(
562 "open-ils.storage.direct.biblio.record_entry.retrieve", $master_id );
563 $record = $record->gather(1);
565 #my $record = OpenILS::Application::AppUtils->simple_scalar_request( "open-ils.storage",
568 warn "No record returned with id $master_id";
569 throw OpenSRF::EX::ERROR
572 my $u = OpenILS::Utils::ModsParser->new();
573 $u->start_mods_batch( $record->marc );
574 my $main_doc_id = $record->id();
576 @ids = grep { $_ ne $master_id } @ids;
578 # now we have to collect all of the marc objects and push them into a mods batch
579 my $request = $session->request(
580 "open-ils.storage.direct.biblio.record_entry.batch.retrieve", @ids );
582 while( my $response = $request->recv() ) {
584 next unless $response;
585 if(UNIVERSAL::isa( $response,"OpenSRF::EX")) {
586 throw $response ($response->stringify);
589 my $content = $response->content;
592 $u->push_mods_batch( $content->marc );
596 my $mods = $u->finish_mods_batch();
597 $mods->doc_id($mrid);
600 $client->respond_complete($mods);
602 my $mods_string = JSON->perl2JSON($mods->decast);
604 $mr->mods($mods_string);
606 my $req = $session->request(
607 "open-ils.storage.direct.metabib.metarecord.update", $mr );
612 $session->disconnect();
620 # converts a mr id into a list of record ids
622 __PACKAGE__->register_method(
623 method => "biblio_mrid_to_record_ids",
624 api_name => "open-ils.search.biblio.metarecord_to_records",
627 __PACKAGE__->register_method(
628 method => "biblio_mrid_to_record_ids",
629 api_name => "open-ils.search.biblio.metarecord_to_records.staff",
632 sub biblio_mrid_to_record_ids {
633 my( $self, $client, $mrid, $args ) = @_;
635 my $format = $$args{format};
636 my $org = $$args{org};
637 my $depth = $$args{depth};
639 my $method = "open-ils.storage.ordered.metabib.metarecord.records.atomic";
640 $method =~ s/atomic/staff\.atomic/o if $self->api_name =~ /staff/o;
641 my $recs = $U->storagereq($method, $mrid, $format, $org, $depth);
643 return { count => scalar(@$recs), ids => $recs };
647 __PACKAGE__->register_method(
648 method => "biblio_record_to_marc_html",
649 api_name => "open-ils.search.biblio.record.html" );
651 my $parser = XML::LibXML->new();
652 my $xslt = XML::LibXSLT->new();
655 my $settings_client = OpenSRF::Utils::SettingsClient->new();
656 sub biblio_record_to_marc_html {
657 my( $self, $client, $recordid ) = @_;
660 my $dir = $settings_client->config_value( "dirs", "xsl" );
661 my $xsl = $settings_client->config_value(
662 "apps", "open-ils.search", "app_settings", "marc_html_xsl" );
664 $xsl = $parser->parse_file("$dir/$xsl");
665 $marc_sheet = $xslt->parse_stylesheet( $xsl );
669 my $record = $apputils->simple_scalar_request(
671 "open-ils.storage.direct.biblio.record_entry.retrieve",
674 my $xmldoc = $parser->parse_string($record->marc);
675 my $html = $marc_sheet->transform($xmldoc);
676 $html = $html->toString();
683 __PACKAGE__->register_method(
684 method => "retrieve_all_copy_locations",
685 api_name => "open-ils.search.config.copy_location.retrieve.all" );
687 my $shelving_locations;
688 sub retrieve_all_copy_locations {
689 my( $self, $client ) = @_;
690 if(!$shelving_locations) {
691 $shelving_locations = $apputils->simple_scalar_request(
693 "open-ils.storage.direct.asset.copy_location.retrieve.all.atomic");
695 return $shelving_locations;
701 __PACKAGE__->register_method(
702 method => "retrieve_all_copy_statuses",
703 api_name => "open-ils.search.config.copy_status.retrieve.all" );
706 sub retrieve_all_copy_statuses {
707 my( $self, $client ) = @_;
708 if(!$copy_statuses) {
709 $copy_statuses = $apputils->simple_scalar_request(
711 "open-ils.storage.direct.config.copy_status.retrieve.all.atomic" );
713 return $copy_statuses;
717 __PACKAGE__->register_method(
718 method => "copy_counts_per_org",
719 api_name => "open-ils.search.biblio.copy_counts.retrieve");
721 __PACKAGE__->register_method(
722 method => "copy_counts_per_org",
723 api_name => "open-ils.search.biblio.copy_counts.retrieve.staff");
725 sub copy_counts_per_org {
726 my( $self, $client, $record_id ) = @_;
728 warn "Retreiveing copy copy counts for record $record_id and method " . $self->api_name . "\n";
730 my $method = "open-ils.storage.biblio.record_entry.global_copy_count.atomic";
731 if($self->api_name =~ /staff/) { $method =~ s/atomic/staff\.atomic/; }
733 my $counts = $apputils->simple_scalar_request(
734 "open-ils.storage", $method, $record_id );
736 $counts = [ sort {$a->[0] <=> $b->[0]} @$counts ];
741 __PACKAGE__->register_method(
742 method => "copy_count_summary",
743 api_name => "open-ils.search.biblio.copy_counts.summary.retrieve",
744 notes => <<" NOTES");
745 returns an array of these:
746 [ org_id, callnumber_label, <status1_count>, <status2_cout>,...]
747 where statusx is a copy status name. the statuses are sorted
751 sub copy_count_summary {
752 my( $self, $client, $rid ) = @_;
753 return $U->storagereq(
754 'open-ils.storage.biblio.record_entry.status_copy_count.atomic', $rid );
760 __PACKAGE__->register_method(
761 method => "multiclass_search",
762 api_name => "open-ils.search.biblio.multiclass",
763 notes => <<" NOTES");
764 Performs a multiclass search
765 PARAMS( searchBlob, org_unit, format, limit )
766 where searchBlob is defined like this:
768 "title" : { "term" : "water" },
769 "author" : { "term" : "smith" },
774 __PACKAGE__->register_method(
775 method => "multiclass_search",
776 api_name => "open-ils.search.biblio.multiclass.staff",
777 notes => "see open-ils.search.biblio.multiclass" );
779 sub multiclass_search {
780 my( $self, $client, $searchBlob, $orgid, $format, $limit ) = @_;
782 $logger->debug("Performing multiclass search with org => $orgid, " .
783 "format => $format, limit => $limit, and search blob " . Dumper($searchBlob));
785 my $meth = 'open-ils.storage.metabib.post_filter.multiclass.search_fts.metarecord.atomic';
786 if($self->api_name =~ /staff/) { $meth =~ s/metarecord\.atomic/metarecord.staff.atomic/; }
789 my $records = $apputils->simplereq(
790 'open-ils.storage', $meth,
791 org_unit => $orgid, searches => $searchBlob, format => $format, limit => $limit );
796 if( ref($records) and $records->[0] and
797 defined($records->[0]->[3])) { $count = $records->[0]->[3];}
799 for my $r (@$records) { push( @$recs, $r ) if ($r and $r->[0]); }
801 # records has the form: [ mrid, rank, singleRecord / 0, hitCount ];
802 return { ids => $recs, count => $count };
808 __PACKAGE__->register_method(
809 method => "multiclass_search",
810 api_name => "open-ils.search.biblio.multiclass",
812 Performs a multiclass search
813 @param args A names hash of arguments:
814 org_unit : The org to focus the search on
815 depth : The search depth
818 offset : Search offset
819 searches : A named hash of searches which has the following format:
821 "title" : { "term" : "water" },
822 "author" : { "term" : "smith" },
825 @return { ids : <array of ids>, count : hitcount }
829 __PACKAGE__->register_method(
830 method => "multiclass_search",
831 api_name => "open-ils.search.biblio.multiclass.staff",
832 notes => q/@see open-ils.search.biblio.multiclass/ );
834 sub multiclass_search {
835 my( $self, $client, $args ) = @_;
837 $logger->debug("Performing multiclass search with args:\n" . Dumper($args));
838 my $meth = 'open-ils.storage.metabib.post_filter.multiclass.search_fts.metarecord.atomic';
839 if($self->api_name =~ /staff/) { $meth =~ s/metarecord\.atomic/metarecord.staff.atomic/; }
841 my $records = $apputils->simplereq( 'open-ils.storage', $meth, %$args );
846 if( ref($records) and $records->[0] and
847 defined($records->[0]->[3])) { $count = $records->[0]->[3];}
849 for my $r (@$records) { push( @$recs, $r ) if ($r and $r->[0]); }
851 return { ids => $recs, count => $count };
858 __PACKAGE__->register_method(
859 method => "marc_search",
860 api_name => "open-ils.search.biblio.marc",
861 notes => <<" NOTES");
863 open-ils.storage.biblio.full_rec.multi_search.atomic
864 { "searches": [{"term":"harry","restrict": [{"tag":245,"subfield":"a"}]}], "org_unit": 1,
865 "limit":5,"sort":"author","item_type":"g"}
869 my( $self, $conn, $args ) = @_;
870 my $records = $U->storagereq(
871 'open-ils.storage.biblio.full_rec.multi_search.atomic', %$args );
875 $count = $records->[0]->[2] if( ref($records) and
876 $records->[0] and defined($records->[0]->[2]));
878 return { ids => $records, count => $count };
883 __PACKAGE__->register_method(
884 method => "biblio_search_isbn",
885 api_name => "open-ils.search.biblio.isbn",
888 sub biblio_search_isbn {
889 my( $self, $client, $isbn ) = @_;
890 $logger->debug("Searching ISBN $isbn");
891 my $e = OpenILS::Utils::Editor->new;
892 my $recs = $e->request(
893 'open-ils.storage.id_list.biblio.record_entry.search.isbn.atomic', $isbn );
894 return { ids => $recs, count => scalar(@$recs) };
898 __PACKAGE__->register_method(
899 method => "biblio_search_issn",
900 api_name => "open-ils.search.biblio.issn",
903 sub biblio_search_issn {
904 my( $self, $client, $issn ) = @_;
905 $logger->debug("Searching ISSN $issn");
906 my $e = OpenILS::Utils::Editor->new;
907 my $recs = $e->request(
908 'open-ils.storage.id_list.biblio.record_entry.search.issn.atomic', $issn );
909 return { ids => $recs, count => scalar(@$recs) };
915 __PACKAGE__->register_method(
916 method => "fetch_mods_by_copy",
917 api_name => "open-ils.search.biblio.mods_from_copy",
920 sub fetch_mods_by_copy {
921 my( $self, $client, $copyid ) = @_;
922 my ($record, $evt) = $apputils->fetch_record_by_copy( $copyid );
924 return OpenILS::Event->new('ITEM_NOT_CATALOGED') unless $record->marc;
925 return $apputils->record_to_mvr($record);
932 # -------------------------------------------------------------------------------------
934 __PACKAGE__->register_method(
935 method => "cn_browse",
936 api_name => "open-ils.search.callnumber.browse.target",
937 notes => "Starts a callnumber browse"
940 __PACKAGE__->register_method(
941 method => "cn_browse",
942 api_name => "open-ils.search.callnumber.browse.page_up",
943 notes => "Returns the previous page of callnumbers",
946 __PACKAGE__->register_method(
947 method => "cn_browse",
948 api_name => "open-ils.search.callnumber.browse.page_down",
949 notes => "Returns the next page of callnumbers",
953 # RETURNS array of arrays like so: label, owning_lib, record, id
955 my( $self, $client, @params ) = @_;
958 $method = 'open-ils.storage.asset.call_number.browse.target.atomic'
959 if( $self->api_name =~ /target/ );
960 $method = 'open-ils.storage.asset.call_number.browse.page_up.atomic'
961 if( $self->api_name =~ /page_up/ );
962 $method = 'open-ils.storage.asset.call_number.browse.page_down.atomic'
963 if( $self->api_name =~ /page_down/ );
965 return $apputils->simplereq( 'open-ils.storage', $method, @params );
967 # -------------------------------------------------------------------------------------
969 __PACKAGE__->register_method(
970 method => "fetch_cn",
971 api_name => "open-ils.search.callnumber.retrieve",
972 notes => "retrieves a callnumber based on ID",
976 my( $self, $client, $id ) = @_;
977 my( $cn, $evt ) = $apputils->fetch_callnumber( $id );
982 __PACKAGE__->register_method (
983 method => "fetch_copy_by_cn",
984 api_name => 'open-ils.search.copies_by_call_number.retrieve',
986 Returns an array of copy id's by callnumber id
987 @param cnid The callnumber id
988 @return An array of copy ids
992 sub fetch_copy_by_cn {
993 my( $self, $conn, $cnid ) = @_;
994 return $U->storagereq(
995 'open-ils.storage.id_list.asset.copy.search_where.atomic',
996 { call_number => $cnid, deleted => 'f' } );
999 __PACKAGE__->register_method (
1000 method => 'fetch_cn_by_info',
1001 api_name => 'open-ils.search.call_number.retrieve_by_info',
1003 @param label The callnumber label
1004 @param record The record the cn is attached to
1005 @param org The owning library of the cn
1006 @return The callnumber object
1011 sub fetch_cn_by_info {
1012 my( $self, $conn, $label, $record, $org ) = @_;
1013 return $U->storagereq(
1014 'open-ils.storage.direct.asset.call_number.search_where',
1015 { label => $label, record => $record, owning_lib => $org, deleted => 'f' });
1022 __PACKAGE__->register_method (
1023 method => 'bib_extras',
1024 api_name => 'open-ils.search.biblio.lit_form_map.retrieve.all');
1025 __PACKAGE__->register_method (
1026 method => 'bib_extras',
1027 api_name => 'open-ils.search.biblio.item_form_map.retrieve.all');
1028 __PACKAGE__->register_method (
1029 method => 'bib_extras',
1030 api_name => 'open-ils.search.biblio.item_type_map.retrieve.all');
1031 __PACKAGE__->register_method (
1032 method => 'bib_extras',
1033 api_name => 'open-ils.search.biblio.audience_map.retrieve.all');
1038 return $U->storagereq(
1039 'open-ils.storage.direct.config.lit_form_map.retrieve.all.atomic')
1040 if( $self->api_name =~ /lit_form/ );
1042 return $U->storagereq(
1043 'open-ils.storage.direct.config.item_form_map.retrieve.all.atomic')
1044 if( $self->api_name =~ /item_form_map/ );
1046 return $U->storagereq(
1047 'open-ils.storage.direct.config.item_type_map.retrieve.all.atomic')
1048 if( $self->api_name =~ /item_type_map/ );
1050 return $U->storagereq(
1051 'open-ils.storage.direct.config.audience_map.retrieve.all.atomic')
1052 if( $self->api_name =~ /audience/ );
1059 __PACKAGE__->register_method(
1060 method => 'fetch_slim_record',
1061 api_name => 'open-ils.search.biblio.record_entry.slim.retrieve',
1063 Returns a biblio.record_entry without the attached marcxml
1067 sub fetch_slim_record {
1068 my( $self, $conn, $ids ) = @_;
1070 my $editor = OpenILS::Utils::Editor->new;
1073 return $editor->event unless
1074 my $r = $editor->retrieve_biblio_record_entry($_);