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 # XXX add last 3 circs and total circ count
233 __PACKAGE__->register_method(
234 method => "fleshed_copy_retrieve_batch",
235 api_name => "open-ils.search.asset.copy.fleshed.batch.retrieve");
237 sub fleshed_copy_retrieve_batch {
238 my( $self, $client, $ids ) = @_;
239 $logger->info("Fetching fleshed copies @$ids");
240 return $U->storagereq(
241 "open-ils.storage.fleshed.asset.copy.batch.retrieve.atomic", @$ids );
245 __PACKAGE__->register_method(
246 method => "fleshed_copy_retrieve",
247 api_name => "open-ils.search.asset.copy.fleshed.retrieve",);
249 sub fleshed_copy_retrieve {
250 my( $self, $client, $id ) = @_;
251 my( $c, $e) = $U->fetch_fleshed_copy($id);
258 __PACKAGE__->register_method(
259 method => "biblio_barcode_to_title",
260 api_name => "open-ils.search.biblio.find_by_barcode",
263 sub biblio_barcode_to_title {
264 my( $self, $client, $barcode ) = @_;
266 my $title = $apputils->simple_scalar_request(
268 "open-ils.storage.biblio.record_entry.retrieve_by_barcode", $barcode );
270 return { ids => [ $title->id ], count => 1 } if $title;
271 return { count => 0 };
275 __PACKAGE__->register_method(
276 method => "biblio_copy_to_mods",
277 api_name => "open-ils.search.biblio.copy.mods.retrieve",
280 # takes a copy object and returns it fleshed mods object
281 sub biblio_copy_to_mods {
282 my( $self, $client, $copy ) = @_;
284 my $volume = $U->storagereq(
285 "open-ils.storage.direct.asset.call_number.retrieve",
286 $copy->call_number() );
288 my $mods = _records_to_mods($volume->record());
289 $mods = shift @$mods;
290 $volume->copies([$copy]);
291 push @{$mods->call_numbers()}, $volume;
297 # ----------------------------------------------------------------------------
298 # These are the main OPAC search methods
299 # ----------------------------------------------------------------------------
301 __PACKAGE__->register_method(
302 method => 'the_quest_for_knowledge',
303 api_name => 'open-ils.search.biblio.multiclass',
305 Performs a multi class bilbli or metabib search
306 @param searchhash A search object layed out like so:
307 searches : { "$class" : "$value", ...}
308 org_unit : The org id to focus the search at
309 depth : The org depth
310 limit : The search limit
311 offset : The search offset
312 format : The MARC format
313 sort : What field to sort the results on [ author | title | pubdate ]
314 sort_dir : What direction do we sort? [ asc | desc ]
315 @return An object of the form
316 { "count" : $count, "ids" : [ [ $id, $relevancy, $total ], ...] }
320 __PACKAGE__->register_method(
321 method => 'the_quest_for_knowledge',
322 api_name => 'open-ils.search.record.multiclass.staff',
323 signature => q/@see open-ils.search.biblio.multiclass/);
324 __PACKAGE__->register_method(
325 method => 'the_quest_for_knowledge',
326 api_name => 'open-ils.search.metabib.multiclass',
327 signature => q/@see open-ils.search.biblio.multiclass/);
328 __PACKAGE__->register_method(
329 method => 'the_quest_for_knowledge',
330 api_name => 'open-ils.search.metabib.multiclass.staff',
331 signature => q/@see open-ils.search.biblio.multiclass/);
334 sub the_quest_for_knowledge {
335 my( $self, $conn, $searchhash ) = @_;
337 my $method = 'open-ils.storage.biblio.multiclass.search_fts';
341 if($self->api_name =~ /metabib/) {
343 $method =~ s/biblio/metabib/o;
346 $method .= ".staff" if($self->api_name =~ /staff/);
347 $method .= ".atomic";
349 for (keys %$searchhash) {
350 delete $$searchhash{$_} unless defined $$searchhash{$_}; }
352 my $result = $U->storagereq( $method, %$searchhash );
354 return {count => 0} unless ($result && $$result[0]);
356 for my $r (@$result) { push(@recs, $r) if ($r and $$r[0]); }
357 return { ids => \@recs,
358 count => ($ismeta) ? $result->[0]->[3] : $result->[0]->[2] };
365 # XXX XXX old class search...
366 =head old search method
367 __PACKAGE__->register_method(
368 method => "record_search_class",
369 api_name => "open-ils.search.biblio.record.class.search",
371 Performs a class search for biblio records (not metarecords)
372 @param class The search class to use
373 @param args A hash of named parameters including:
374 term : The search string,
375 org_unit : The org id to focus the search at
376 depth : The org depth
377 limit : The search limit
378 offset : The search offset
379 format : The MARC format
380 sort : What field to sort the results on [ author | title | pubdate ]
381 sort_dir : What direction do we sort? [ asc | desc ]
382 The only required argument is the term.
386 __PACKAGE__->register_method(
387 method => "record_search_class",
388 api_name => "open-ils.search.biblio.record.class.search.staff",
389 signature => q/@see open-ils.search.biblio.record.class.search/);
390 __PACKAGE__->register_method(
391 method => "record_search_class",
392 api_name => "open-ils.search.biblio.metabib.class.search",
393 signature => q/@see open-ils.search.biblio.record.class.search/);
394 __PACKAGE__->register_method(
395 method => "record_search_class",
396 api_name => "open-ils.search.biblio.metabib.class.search.staff",
397 signature => q/@see open-ils.search.biblio.record.class.search/);
399 sub record_search_class {
400 my( $self, $client, $class, $args ) = @_;
402 my $type = ($self->api_name =~ /metabib/) ? 1 : 0;
403 my $method = "open-ils.storage.metabib.$class.post_filter.search_fts.metarecord.atomic";
404 $method = "open-ils.storage.biblio.$class.search_fts.record.atomic" unless $type;
406 if(!$$args{'sort'}) {
407 delete $$args{'sort'};
408 delete $$args{'sort_dir'};
410 $$args{limit} = 200 if (!$$args{limit} || $$args{limit} > 1000);
411 $$args{offset} ||= 0;
413 $logger->info("Class search with args: ".Dumper($args));
415 $method =~ s/\.atomic/.staff.atomic/o if $self->api_name =~ /staff/o;
416 my $result = $U->storagereq( $method, %$args );
418 if($result and $result->[0]) {
420 for my $r (@$result) { push(@$recs, $r) if ($r and $r->[0]); }
421 return { ids => $recs,
422 count => ($type) ? $result->[0]->[3] : $result->[0]->[2] };
424 return { count => 0 };
431 __PACKAGE__->register_method(
432 method => "biblio_mrid_to_modsbatch_batch",
433 api_name => "open-ils.search.biblio.metarecord.mods_slim.batch.retrieve");
435 sub biblio_mrid_to_modsbatch_batch {
436 my( $self, $client, $mrids) = @_;
437 warn "Performing mrid_to_modsbatch_batch...";
439 my $method = $self->method_lookup("open-ils.search.biblio.metarecord.mods_slim.retrieve");
440 for my $id (@$mrids) {
441 next unless defined $id;
442 my ($m) = $method->run($id);
449 __PACKAGE__->register_method(
450 method => "biblio_mrid_to_modsbatch",
451 api_name => "open-ils.search.biblio.metarecord.mods_slim.retrieve",
452 notes => <<" NOTES");
453 Returns the mvr associated with a given metarecod. If none exists,
457 __PACKAGE__->register_method(
458 method => "biblio_mrid_to_modsbatch",
459 api_name => "open-ils.search.biblio.metarecord.mods_slim.retrieve.staff",
460 notes => <<" NOTES");
461 Returns the mvr associated with a given metarecod. If none exists,
465 sub biblio_mrid_to_modsbatch {
466 my( $self, $client, $mrid ) = @_;
468 warn "Grabbing mvr for $mrid\n";
470 my $mr = _grab_metarecord($mrid);
471 return undef unless $mr;
473 if( my $m = $self->biblio_mrid_check_mvr($client, $mr)) {
477 return $self->biblio_mrid_make_modsbatch( $client, $mr );
480 # converts a metarecord to an mvr
483 my $perl = JSON->JSON2perl($mr->mods());
484 return Fieldmapper::metabib::virtual_record->new($perl);
487 # checks to see if a metarecord has mods, if so returns true;
489 __PACKAGE__->register_method(
490 method => "biblio_mrid_check_mvr",
491 api_name => "open-ils.search.biblio.metarecord.mods_slim.check",
492 notes => <<" NOTES");
493 Takes a metarecord ID or a metarecord object and returns true
494 if the metarecord already has an mvr associated with it.
497 sub biblio_mrid_check_mvr {
498 my( $self, $client, $mrid ) = @_;
501 if(ref($mrid)) { $mr = $mrid; }
502 else { $mr = _grab_metarecord($mrid); }
504 warn "Checking mvr for mr " . $mr->id . "\n";
506 return _mr_to_mvr($mr) if $mr->mods();
510 sub _grab_metarecord {
513 warn "Grabbing MR $mrid\n";
515 my $mr = OpenILS::Application::AppUtils->simple_scalar_request(
517 "open-ils.storage.direct.metabib.metarecord.retrieve", $mrid );
520 throw OpenSRF::EX::ERROR
521 ("No metarecord exists with the given id: $mrid");
527 __PACKAGE__->register_method(
528 method => "biblio_mrid_make_modsbatch",
529 api_name => "open-ils.search.biblio.metarecord.mods_slim.create",
530 notes => <<" NOTES");
531 Takes either a metarecord ID or a metarecord object.
532 Forces the creations of an mvr for the given metarecord.
533 The created mvr is returned.
536 sub biblio_mrid_make_modsbatch {
538 my( $self, $client, $mrid ) = @_;
541 if(ref($mrid)) { $mr = $mrid; }
542 else { $mr = _grab_metarecord($mrid); }
545 warn "Forcing mvr creation for mr " . $mr->id . "\n";
546 my $master_id = $mr->master_record;
548 my $session = OpenSRF::AppSession->create("open-ils.storage");
550 # grab the records attached to this metarecod
551 warn "Creating mods batch for metarecord $mrid\n";
552 my $meth = "open-ils.search.biblio.metarecord_to_records.staff";
553 $meth = $self->method_lookup($meth);
554 my ($id_hash) = $meth->run($mrid);
555 my @ids = @{$id_hash->{ids}};
556 if(@ids < 1) { return undef; }
558 warn "Master ID is $master_id\n";
559 # grab the master record to start the mods batch
561 $meth = "open-ils.storage.direct.biblio.record_entry.retrieve";
563 my $record = $session->request(
564 "open-ils.storage.direct.biblio.record_entry.retrieve", $master_id );
565 $record = $record->gather(1);
567 #my $record = OpenILS::Application::AppUtils->simple_scalar_request( "open-ils.storage",
570 warn "No record returned with id $master_id";
571 throw OpenSRF::EX::ERROR
574 my $u = OpenILS::Utils::ModsParser->new();
575 $u->start_mods_batch( $record->marc );
576 my $main_doc_id = $record->id();
578 @ids = grep { $_ ne $master_id } @ids;
580 # now we have to collect all of the marc objects and push them into a mods batch
581 my $request = $session->request(
582 "open-ils.storage.direct.biblio.record_entry.batch.retrieve", @ids );
584 while( my $response = $request->recv() ) {
586 next unless $response;
587 if(UNIVERSAL::isa( $response,"OpenSRF::EX")) {
588 throw $response ($response->stringify);
591 my $content = $response->content;
594 $u->push_mods_batch( $content->marc );
598 my $mods = $u->finish_mods_batch();
599 $mods->doc_id($mrid);
602 $client->respond_complete($mods);
604 my $mods_string = JSON->perl2JSON($mods->decast);
606 $mr->mods($mods_string);
608 my $req = $session->request(
609 "open-ils.storage.direct.metabib.metarecord.update", $mr );
614 $session->disconnect();
621 # converts a mr id into a list of record ids
623 __PACKAGE__->register_method(
624 method => "biblio_mrid_to_record_ids",
625 api_name => "open-ils.search.biblio.metarecord_to_records",
628 __PACKAGE__->register_method(
629 method => "biblio_mrid_to_record_ids",
630 api_name => "open-ils.search.biblio.metarecord_to_records.staff",
633 sub biblio_mrid_to_record_ids {
634 my( $self, $client, $mrid, $args ) = @_;
636 my $format = $$args{format};
637 my $org = $$args{org};
638 my $depth = $$args{depth};
640 my $method = "open-ils.storage.ordered.metabib.metarecord.records.atomic";
641 $method =~ s/atomic/staff\.atomic/o if $self->api_name =~ /staff/o;
642 my $recs = $U->storagereq($method, $mrid, $format, $org, $depth);
644 return { count => scalar(@$recs), ids => $recs };
648 __PACKAGE__->register_method(
649 method => "biblio_record_to_marc_html",
650 api_name => "open-ils.search.biblio.record.html" );
652 my $parser = XML::LibXML->new();
653 my $xslt = XML::LibXSLT->new();
656 my $settings_client = OpenSRF::Utils::SettingsClient->new();
657 sub biblio_record_to_marc_html {
658 my( $self, $client, $recordid ) = @_;
661 my $dir = $settings_client->config_value( "dirs", "xsl" );
662 my $xsl = $settings_client->config_value(
663 "apps", "open-ils.search", "app_settings", "marc_html_xsl" );
665 $xsl = $parser->parse_file("$dir/$xsl");
666 $marc_sheet = $xslt->parse_stylesheet( $xsl );
670 my $record = $apputils->simple_scalar_request(
672 "open-ils.storage.direct.biblio.record_entry.retrieve",
675 my $xmldoc = $parser->parse_string($record->marc);
676 my $html = $marc_sheet->transform($xmldoc);
677 $html = $html->toString();
684 __PACKAGE__->register_method(
685 method => "retrieve_all_copy_locations",
686 api_name => "open-ils.search.config.copy_location.retrieve.all" );
688 my $shelving_locations;
689 sub retrieve_all_copy_locations {
690 my( $self, $client ) = @_;
691 if(!$shelving_locations) {
692 $shelving_locations = $apputils->simple_scalar_request(
694 "open-ils.storage.direct.asset.copy_location.retrieve.all.atomic");
696 return $shelving_locations;
702 __PACKAGE__->register_method(
703 method => "retrieve_all_copy_statuses",
704 api_name => "open-ils.search.config.copy_status.retrieve.all" );
707 sub retrieve_all_copy_statuses {
708 my( $self, $client ) = @_;
709 if(!$copy_statuses) {
710 $copy_statuses = $apputils->simple_scalar_request(
712 "open-ils.storage.direct.config.copy_status.retrieve.all.atomic" );
714 return $copy_statuses;
718 __PACKAGE__->register_method(
719 method => "copy_counts_per_org",
720 api_name => "open-ils.search.biblio.copy_counts.retrieve");
722 __PACKAGE__->register_method(
723 method => "copy_counts_per_org",
724 api_name => "open-ils.search.biblio.copy_counts.retrieve.staff");
726 sub copy_counts_per_org {
727 my( $self, $client, $record_id ) = @_;
729 warn "Retreiveing copy copy counts for record $record_id and method " . $self->api_name . "\n";
731 my $method = "open-ils.storage.biblio.record_entry.global_copy_count.atomic";
732 if($self->api_name =~ /staff/) { $method =~ s/atomic/staff\.atomic/; }
734 my $counts = $apputils->simple_scalar_request(
735 "open-ils.storage", $method, $record_id );
737 $counts = [ sort {$a->[0] <=> $b->[0]} @$counts ];
742 __PACKAGE__->register_method(
743 method => "copy_count_summary",
744 api_name => "open-ils.search.biblio.copy_counts.summary.retrieve",
745 notes => <<" NOTES");
746 returns an array of these:
747 [ org_id, callnumber_label, <status1_count>, <status2_cout>,...]
748 where statusx is a copy status name. the statuses are sorted
752 sub copy_count_summary {
753 my( $self, $client, $rid ) = @_;
754 return $U->storagereq(
755 'open-ils.storage.biblio.record_entry.status_copy_count.atomic', $rid );
761 __PACKAGE__->register_method(
762 method => "multiclass_search",
763 api_name => "open-ils.search.biblio.multiclass",
764 notes => <<" NOTES");
765 Performs a multiclass search
766 PARAMS( searchBlob, org_unit, format, limit )
767 where searchBlob is defined like this:
769 "title" : { "term" : "water" },
770 "author" : { "term" : "smith" },
775 __PACKAGE__->register_method(
776 method => "multiclass_search",
777 api_name => "open-ils.search.biblio.multiclass.staff",
778 notes => "see open-ils.search.biblio.multiclass" );
780 sub multiclass_search {
781 my( $self, $client, $searchBlob, $orgid, $format, $limit ) = @_;
783 $logger->debug("Performing multiclass search with org => $orgid, " .
784 "format => $format, limit => $limit, and search blob " . Dumper($searchBlob));
786 my $meth = 'open-ils.storage.metabib.post_filter.multiclass.search_fts.metarecord.atomic';
787 if($self->api_name =~ /staff/) { $meth =~ s/metarecord\.atomic/metarecord.staff.atomic/; }
790 my $records = $apputils->simplereq(
791 'open-ils.storage', $meth,
792 org_unit => $orgid, searches => $searchBlob, format => $format, limit => $limit );
797 if( ref($records) and $records->[0] and
798 defined($records->[0]->[3])) { $count = $records->[0]->[3];}
800 for my $r (@$records) { push( @$recs, $r ) if ($r and $r->[0]); }
802 # records has the form: [ mrid, rank, singleRecord / 0, hitCount ];
803 return { ids => $recs, count => $count };
809 __PACKAGE__->register_method(
810 method => "multiclass_search",
811 api_name => "open-ils.search.biblio.multiclass",
813 Performs a multiclass search
814 @param args A names hash of arguments:
815 org_unit : The org to focus the search on
816 depth : The search depth
819 offset : Search offset
820 searches : A named hash of searches which has the following format:
822 "title" : { "term" : "water" },
823 "author" : { "term" : "smith" },
826 @return { ids : <array of ids>, count : hitcount }
830 __PACKAGE__->register_method(
831 method => "multiclass_search",
832 api_name => "open-ils.search.biblio.multiclass.staff",
833 notes => q/@see open-ils.search.biblio.multiclass/ );
835 sub multiclass_search {
836 my( $self, $client, $args ) = @_;
838 $logger->debug("Performing multiclass search with args:\n" . Dumper($args));
839 my $meth = 'open-ils.storage.metabib.post_filter.multiclass.search_fts.metarecord.atomic';
840 if($self->api_name =~ /staff/) { $meth =~ s/metarecord\.atomic/metarecord.staff.atomic/; }
842 my $records = $apputils->simplereq( 'open-ils.storage', $meth, %$args );
847 if( ref($records) and $records->[0] and
848 defined($records->[0]->[3])) { $count = $records->[0]->[3];}
850 for my $r (@$records) { push( @$recs, $r ) if ($r and $r->[0]); }
852 return { ids => $recs, count => $count };
859 __PACKAGE__->register_method(
860 method => "marc_search",
861 api_name => "open-ils.search.biblio.marc",
862 notes => <<" NOTES");
864 open-ils.storage.biblio.full_rec.multi_search.atomic
865 { "searches": [{"term":"harry","restrict": [{"tag":245,"subfield":"a"}]}], "org_unit": 1,
866 "limit":5,"sort":"author","item_type":"g"}
870 my( $self, $conn, $args ) = @_;
871 my $records = $U->storagereq(
872 'open-ils.storage.biblio.full_rec.multi_search.atomic', %$args );
876 $count = $records->[0]->[2] if( ref($records) and
877 $records->[0] and defined($records->[0]->[2]));
879 return { ids => $records, count => $count };
884 __PACKAGE__->register_method(
885 method => "biblio_search_isbn",
886 api_name => "open-ils.search.biblio.isbn",
889 sub biblio_search_isbn {
890 my( $self, $client, $isbn ) = @_;
892 $logger->debug("Searching ISBN $isbn");
894 my $method = $self->method_lookup("open-ils.search.biblio.marc");
896 my ($records) = $method->run(
898 restrict => $cat_search_hash->{isbn} } ], 1);
904 __PACKAGE__->register_method(
905 method => "biblio_search_issn",
906 api_name => "open-ils.search.biblio.issn",
909 sub biblio_search_issn {
910 my( $self, $client, $issn ) = @_;
912 $logger->debug("Searching ISSN $issn");
914 my $method = $self->method_lookup("open-ils.search.biblio.marc");
916 my ($records) = $method->run(
918 restrict => $cat_search_hash->{issn} } ], 1);
926 __PACKAGE__->register_method(
927 method => "fetch_mods_by_copy",
928 api_name => "open-ils.search.biblio.mods_from_copy",
931 sub fetch_mods_by_copy {
932 my( $self, $client, $copyid ) = @_;
933 my ($record, $evt) = $apputils->fetch_record_by_copy( $copyid );
935 return OpenILS::Event->new('ITEM_NOT_CATALOGED') unless $record->marc;
936 return $apputils->record_to_mvr($record);
943 # -------------------------------------------------------------------------------------
945 __PACKAGE__->register_method(
946 method => "cn_browse",
947 api_name => "open-ils.search.callnumber.browse.target",
948 notes => "Starts a callnumber browse"
951 __PACKAGE__->register_method(
952 method => "cn_browse",
953 api_name => "open-ils.search.callnumber.browse.page_up",
954 notes => "Returns the previous page of callnumbers",
957 __PACKAGE__->register_method(
958 method => "cn_browse",
959 api_name => "open-ils.search.callnumber.browse.page_down",
960 notes => "Returns the next page of callnumbers",
964 # RETURNS array of arrays like so: label, owning_lib, record, id
966 my( $self, $client, @params ) = @_;
969 $method = 'open-ils.storage.asset.call_number.browse.target.atomic'
970 if( $self->api_name =~ /target/ );
971 $method = 'open-ils.storage.asset.call_number.browse.page_up.atomic'
972 if( $self->api_name =~ /page_up/ );
973 $method = 'open-ils.storage.asset.call_number.browse.page_down.atomic'
974 if( $self->api_name =~ /page_down/ );
976 return $apputils->simplereq( 'open-ils.storage', $method, @params );
978 # -------------------------------------------------------------------------------------
980 __PACKAGE__->register_method(
981 method => "fetch_cn",
982 api_name => "open-ils.search.callnumber.retrieve",
983 notes => "retrieves a callnumber based on ID",
987 my( $self, $client, $id ) = @_;
988 my( $cn, $evt ) = $apputils->fetch_callnumber( $id );
993 __PACKAGE__->register_method (
994 method => "fetch_copy_by_cn",
995 api_name => 'open-ils.search.copies_by_call_number.retrieve',
997 Returns an array of copy id's by callnumber id
998 @param cnid The callnumber id
999 @return An array of copy ids
1003 sub fetch_copy_by_cn {
1004 my( $self, $conn, $cnid ) = @_;
1005 return $U->storagereq(
1006 'open-ils.storage.id_list.asset.copy.search_where.atomic',
1007 { call_number => $cnid, deleted => 'f' } );
1010 __PACKAGE__->register_method (
1011 method => 'fetch_cn_by_info',
1012 api_name => 'open-ils.search.call_number.retrieve_by_info',
1014 @param label The callnumber label
1015 @param record The record the cn is attached to
1016 @param org The owning library of the cn
1017 @return The callnumber object
1022 sub fetch_cn_by_info {
1023 my( $self, $conn, $label, $record, $org ) = @_;
1024 return $U->storagereq(
1025 'open-ils.storage.direct.asset.call_number.search_where',
1026 { label => $label, record => $record, owning_lib => $org, deleted => 'f' });
1033 __PACKAGE__->register_method (
1034 method => 'bib_extras',
1035 api_name => 'open-ils.search.biblio.lit_form_map.retrieve.all');
1036 __PACKAGE__->register_method (
1037 method => 'bib_extras',
1038 api_name => 'open-ils.search.biblio.item_form_map.retrieve.all');
1039 __PACKAGE__->register_method (
1040 method => 'bib_extras',
1041 api_name => 'open-ils.search.biblio.item_type_map.retrieve.all');
1042 __PACKAGE__->register_method (
1043 method => 'bib_extras',
1044 api_name => 'open-ils.search.biblio.audience_map.retrieve.all');
1049 return $U->storagereq(
1050 'open-ils.storage.direct.config.lit_form_map.retrieve.all.atomic')
1051 if( $self->api_name =~ /lit_form/ );
1053 return $U->storagereq(
1054 'open-ils.storage.direct.config.item_form_map.retrieve.all.atomic')
1055 if( $self->api_name =~ /item_form_map/ );
1057 return $U->storagereq(
1058 'open-ils.storage.direct.config.item_type_map.retrieve.all.atomic')
1059 if( $self->api_name =~ /item_type_map/ );
1061 return $U->storagereq(
1062 'open-ils.storage.direct.config.audience_map.retrieve.all.atomic')
1063 if( $self->api_name =~ /audience/ );
1070 __PACKAGE__->register_method(
1071 method => 'fetch_slim_record',
1072 api_name => 'open-ils.search.biblio.record_entry.slim.retrieve',
1074 Returns a biblio.record_entry without the attached marcxml
1078 sub fetch_slim_record {
1079 my( $self, $conn, $ids ) = @_;
1081 my $editor = OpenILS::Utils::Editor->new;
1084 return $editor->event unless
1085 my $r = $editor->retrieve_biblio_record_entry($_);