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;
12 use OpenSRF::Utils::Logger qw/:logger/;
17 use Time::HiRes qw(time);
18 use OpenSRF::EX qw(:try);
19 use Digest::MD5 qw(md5_hex);
25 $Data::Dumper::Indent = 0;
27 use OpenILS::Application::AppUtils;
28 my $apputils = "OpenILS::Application::AppUtils";
32 # useful for MARC based searches
33 my $cat_search_hash = {
34 isbn => [ { tag => '020', subfield => 'a' }, ],
35 issn => [ { tag => '022', subfield => 'a' }, ],
41 # ---------------------------------------------------------------------------
42 # takes a list of record id's and turns the docs into friendly
43 # mods structures. Creates one MODS structure for each doc id.
44 # ---------------------------------------------------------------------------
45 sub _records_to_mods {
51 my $session = OpenSRF::AppSession->create("open-ils.storage");
52 my $request = $session->request(
53 "open-ils.storage.direct.biblio.record_entry.batch.retrieve", @ids );
55 while( my $resp = $request->recv ) {
56 my $content = $resp->content;
57 my $u = OpenILS::Utils::ModsParser->new();
58 $u->start_mods_batch( $content->marc );
59 my $mods = $u->finish_mods_batch();
60 $mods->doc_id($content->id());
61 $mods->tcn($content->tcn_value);
65 $session->disconnect();
69 __PACKAGE__->register_method(
70 method => "record_id_to_mods",
71 api_name => "open-ils.search.biblio.record.mods.retrieve",
73 note => "Provide ID, we provide the mods"
76 # converts a record into a mods object with copy counts attached
77 sub record_id_to_mods {
79 my( $self, $client, $org_id, $id ) = @_;
81 my $mods_list = _records_to_mods( $id );
82 my $mods_obj = $mods_list->[0];
83 my $cmethod = $self->method_lookup(
84 "open-ils.search.biblio.record.copy_count");
85 my ($count) = $cmethod->run($org_id, $id);
86 $mods_obj->copy_count($count);
93 __PACKAGE__->register_method(
94 method => "record_id_to_mods_slim",
95 api_name => "open-ils.search.biblio.record.mods_slim.retrieve",
97 note => "Provide ID, we provide the mods"
100 # converts a record into a mods object with NO copy counts attached
101 sub record_id_to_mods_slim {
102 my( $self, $client, $id ) = @_;
103 return undef unless defined $id;
105 if(ref($id) and ref($id) == 'ARRAY') {
106 return _records_to_mods( @$id );
108 my $mods_list = _records_to_mods( $id );
109 my $mods_obj = $mods_list->[0];
114 # Returns the number of copies attached to a record based on org location
115 __PACKAGE__->register_method(
116 method => "record_id_to_copy_count",
117 api_name => "open-ils.search.biblio.record.copy_count",
120 __PACKAGE__->register_method(
121 method => "record_id_to_copy_count",
122 api_name => "open-ils.search.biblio.metarecord.copy_count",
125 __PACKAGE__->register_method(
126 method => "record_id_to_copy_count",
127 api_name => "open-ils.search.biblio.metarecord.copy_count.staff",
129 sub record_id_to_copy_count {
130 my( $self, $client, $org_id, $record_id, $format ) = @_;
132 $format = undef if ($format eq 'all');
134 my $method = "open-ils.storage.biblio.record_entry.copy_count.atomic";
136 if($self->api_name =~ /metarecord/) {
137 $method = "open-ils.storage.metabib.metarecord.copy_count.atomic";
141 if($self->api_name =~ /staff/ ) {
142 $method =~ s/atomic/staff\.atomic/og;
143 warn "Doing staff search $method\n";
147 my $session = OpenSRF::AppSession->create("open-ils.storage");
148 warn "copy_count retrieve $record_id\n";
149 return undef unless(defined $record_id);
151 my $request = $session->request(
152 $method, org_unit => $org_id => $key => $record_id, format => $format );
155 my $count = $request->gather(1);
156 $session->disconnect();
157 return [ sort { $a->{depth} <=> $b->{depth} } @$count ];
164 __PACKAGE__->register_method(
165 method => "biblio_search_tcn",
166 api_name => "open-ils.search.biblio.tcn",
168 note => "Retrieve a record by TCN",
171 sub biblio_search_tcn {
173 my( $self, $client, $tcn ) = @_;
175 $tcn =~ s/.*?(\w+)\s*$/$1/o;
176 warn "Searching TCN $tcn\n";
178 my $session = OpenSRF::AppSession->create( "open-ils.storage" );
179 my $request = $session->request(
180 "open-ils.storage.direct.biblio.record_entry.search_where.atomic",
181 { tcn_value => $tcn, deleted => 'f' } );
182 #"open-ils.storage.direct.biblio.record_entry.search.tcn_value.atomic", $tcn );
183 my $record_entry = $request->gather(1);
186 for my $record (@$record_entry) {
187 push @ids, $record->id;
190 $session->disconnect();
193 return { count => $size, ids => \@ids };
197 # --------------------------------------------------------------------------------
199 __PACKAGE__->register_method(
200 method => "biblio_barcode_to_copy",
201 api_name => "open-ils.search.asset.copy.find_by_barcode",);
202 sub biblio_barcode_to_copy {
203 my( $self, $client, $barcode ) = @_;
204 my( $copy, $evt ) = $U->fetch_copy_by_barcode($barcode);
209 __PACKAGE__->register_method(
210 method => "biblio_id_to_copy",
211 api_name => "open-ils.search.asset.copy.batch.retrieve",);
212 sub biblio_id_to_copy {
213 my( $self, $client, $ids ) = @_;
214 $logger->info("Fetching copies @$ids");
215 return $U->storagereq(
216 "open-ils.storage.direct.asset.copy.batch.retrieve.atomic", @$ids );
220 __PACKAGE__->register_method(
221 method => "copy_retrieve",
222 api_name => "open-ils.search.asset.copy.retrieve",);
224 my( $self, $client, $cid ) = @_;
225 my( $copy, $evt ) = $U->fetch_copy($cid);
231 __PACKAGE__->register_method(
232 method => "fleshed_copy_retrieve_batch",
233 api_name => "open-ils.search.asset.copy.fleshed.batch.retrieve",);
235 sub fleshed_copy_retrieve_batch {
236 my( $self, $client, $ids ) = @_;
237 $logger->info("Fetching fleshed copies @$ids");
238 return $U->storagereq(
239 "open-ils.storage.fleshed.asset.copy.batch.retrieve.atomic", @$ids );
243 __PACKAGE__->register_method(
244 method => "fleshed_copy_retrieve",
245 api_name => "open-ils.search.asset.copy.fleshed.retrieve",);
247 sub fleshed_copy_retrieve {
248 my( $self, $client, $id ) = @_;
249 my( $c, $e) = $U->fetch_fleshed_copy($id);
256 __PACKAGE__->register_method(
257 method => "biblio_barcode_to_title",
258 api_name => "open-ils.search.biblio.find_by_barcode",
261 sub biblio_barcode_to_title {
262 my( $self, $client, $barcode ) = @_;
264 my $title = $apputils->simple_scalar_request(
266 "open-ils.storage.biblio.record_entry.retrieve_by_barcode", $barcode );
268 return { ids => [ $title->id ], count => 1 } if $title;
269 return { count => 0 };
273 __PACKAGE__->register_method(
274 method => "biblio_copy_to_mods",
275 api_name => "open-ils.search.biblio.copy.mods.retrieve",
278 # takes a copy object and returns it fleshed mods object
279 sub biblio_copy_to_mods {
280 my( $self, $client, $copy ) = @_;
282 my $volume = $U->storagereq(
283 "open-ils.storage.direct.asset.call_number.retrieve",
284 $copy->call_number() );
286 my $mods = _records_to_mods($volume->record());
287 $mods = shift @$mods;
288 $volume->copies([$copy]);
289 push @{$mods->call_numbers()}, $volume;
295 # ----------------------------------------------------------------------------
296 # These are the main OPAC search methods
297 # ----------------------------------------------------------------------------
299 __PACKAGE__->register_method(
300 method => 'the_quest_for_knowledge',
301 api_name => 'open-ils.search.biblio.multiclass',
303 Performs a multi class bilbli or metabib search
304 @param searchhash A search object layed out like so:
305 searches : { "$class" : "$value", ...}
306 org_unit : The org id to focus the search at
307 depth : The org depth
308 limit : The search limit
309 offset : The search offset
310 format : The MARC format
311 sort : What field to sort the results on [ author | title | pubdate ]
312 sort_dir : What direction do we sort? [ asc | desc ]
313 @return An object of the form
314 { "count" : $count, "ids" : [ [ $id, $relevancy, $total ], ...] }
318 __PACKAGE__->register_method(
319 method => 'the_quest_for_knowledge',
320 api_name => 'open-ils.search.record.multiclass.staff',
321 signature => q/@see open-ils.search.biblio.multiclass/);
322 __PACKAGE__->register_method(
323 method => 'the_quest_for_knowledge',
324 api_name => 'open-ils.search.metabib.multiclass',
325 signature => q/@see open-ils.search.biblio.multiclass/);
326 __PACKAGE__->register_method(
327 method => 'the_quest_for_knowledge',
328 api_name => 'open-ils.search.metabib.multiclass.staff',
329 signature => q/@see open-ils.search.biblio.multiclass/);
332 sub the_quest_for_knowledge {
333 my( $self, $conn, $searchhash ) = @_;
335 my $method = 'open-ils.storage.biblio.multiclass.search_fts';
339 if($self->api_name =~ /metabib/) {
341 $method =~ s/biblio/metabib/o;
344 $method .= ".staff" if($self->api_name =~ /staff/);
345 $method .= ".atomic";
347 for (keys %$searchhash) {
348 delete $$searchhash{$_} unless defined $$searchhash{$_}; }
350 my $result = $U->storagereq( $method, %$searchhash );
352 return {count => 0} unless ($result && $$result[0]);
354 for my $r (@$result) { push(@recs, $r) if ($r and $$r[0]); }
355 return { ids => \@recs,
356 count => ($ismeta) ? $result->[0]->[3] : $result->[0]->[2] };
363 # XXX XXX old class search...
364 =head old search method
365 __PACKAGE__->register_method(
366 method => "record_search_class",
367 api_name => "open-ils.search.biblio.record.class.search",
369 Performs a class search for biblio records (not metarecords)
370 @param class The search class to use
371 @param args A hash of named parameters including:
372 term : The search string,
373 org_unit : The org id to focus the search at
374 depth : The org depth
375 limit : The search limit
376 offset : The search offset
377 format : The MARC format
378 sort : What field to sort the results on [ author | title | pubdate ]
379 sort_dir : What direction do we sort? [ asc | desc ]
380 The only required argument is the term.
384 __PACKAGE__->register_method(
385 method => "record_search_class",
386 api_name => "open-ils.search.biblio.record.class.search.staff",
387 signature => q/@see open-ils.search.biblio.record.class.search/);
388 __PACKAGE__->register_method(
389 method => "record_search_class",
390 api_name => "open-ils.search.biblio.metabib.class.search",
391 signature => q/@see open-ils.search.biblio.record.class.search/);
392 __PACKAGE__->register_method(
393 method => "record_search_class",
394 api_name => "open-ils.search.biblio.metabib.class.search.staff",
395 signature => q/@see open-ils.search.biblio.record.class.search/);
397 sub record_search_class {
398 my( $self, $client, $class, $args ) = @_;
400 my $type = ($self->api_name =~ /metabib/) ? 1 : 0;
401 my $method = "open-ils.storage.metabib.$class.post_filter.search_fts.metarecord.atomic";
402 $method = "open-ils.storage.biblio.$class.search_fts.record.atomic" unless $type;
404 if(!$$args{'sort'}) {
405 delete $$args{'sort'};
406 delete $$args{'sort_dir'};
408 $$args{limit} = 200 if (!$$args{limit} || $$args{limit} > 1000);
409 $$args{offset} ||= 0;
411 $logger->info("Class search with args: ".Dumper($args));
413 $method =~ s/\.atomic/.staff.atomic/o if $self->api_name =~ /staff/o;
414 my $result = $U->storagereq( $method, %$args );
416 if($result and $result->[0]) {
418 for my $r (@$result) { push(@$recs, $r) if ($r and $r->[0]); }
419 return { ids => $recs,
420 count => ($type) ? $result->[0]->[3] : $result->[0]->[2] };
422 return { count => 0 };
429 __PACKAGE__->register_method(
430 method => "biblio_mrid_to_modsbatch_batch",
431 api_name => "open-ils.search.biblio.metarecord.mods_slim.batch.retrieve");
433 sub biblio_mrid_to_modsbatch_batch {
434 my( $self, $client, $mrids) = @_;
435 warn "Performing mrid_to_modsbatch_batch...";
437 my $method = $self->method_lookup("open-ils.search.biblio.metarecord.mods_slim.retrieve");
438 for my $id (@$mrids) {
439 next unless defined $id;
440 my ($m) = $method->run($id);
447 __PACKAGE__->register_method(
448 method => "biblio_mrid_to_modsbatch",
449 api_name => "open-ils.search.biblio.metarecord.mods_slim.retrieve",
450 notes => <<" NOTES");
451 Returns the mvr associated with a given metarecod. If none exists,
455 __PACKAGE__->register_method(
456 method => "biblio_mrid_to_modsbatch",
457 api_name => "open-ils.search.biblio.metarecord.mods_slim.retrieve.staff",
458 notes => <<" NOTES");
459 Returns the mvr associated with a given metarecod. If none exists,
463 sub biblio_mrid_to_modsbatch {
464 my( $self, $client, $mrid ) = @_;
466 warn "Grabbing mvr for $mrid\n";
468 my $mr = _grab_metarecord($mrid);
469 return undef unless $mr;
471 if( my $m = $self->biblio_mrid_check_mvr($client, $mr)) {
475 return $self->biblio_mrid_make_modsbatch( $client, $mr );
478 # converts a metarecord to an mvr
481 my $perl = JSON->JSON2perl($mr->mods());
482 return Fieldmapper::metabib::virtual_record->new($perl);
485 # checks to see if a metarecord has mods, if so returns true;
487 __PACKAGE__->register_method(
488 method => "biblio_mrid_check_mvr",
489 api_name => "open-ils.search.biblio.metarecord.mods_slim.check",
490 notes => <<" NOTES");
491 Takes a metarecord ID or a metarecord object and returns true
492 if the metarecord already has an mvr associated with it.
495 sub biblio_mrid_check_mvr {
496 my( $self, $client, $mrid ) = @_;
499 if(ref($mrid)) { $mr = $mrid; }
500 else { $mr = _grab_metarecord($mrid); }
502 warn "Checking mvr for mr " . $mr->id . "\n";
504 return _mr_to_mvr($mr) if $mr->mods();
508 sub _grab_metarecord {
511 warn "Grabbing MR $mrid\n";
513 my $mr = OpenILS::Application::AppUtils->simple_scalar_request(
515 "open-ils.storage.direct.metabib.metarecord.retrieve", $mrid );
518 throw OpenSRF::EX::ERROR
519 ("No metarecord exists with the given id: $mrid");
525 __PACKAGE__->register_method(
526 method => "biblio_mrid_make_modsbatch",
527 api_name => "open-ils.search.biblio.metarecord.mods_slim.create",
528 notes => <<" NOTES");
529 Takes either a metarecord ID or a metarecord object.
530 Forces the creations of an mvr for the given metarecord.
531 The created mvr is returned.
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();
619 # converts a mr id into a list of record ids
621 __PACKAGE__->register_method(
622 method => "biblio_mrid_to_record_ids",
623 api_name => "open-ils.search.biblio.metarecord_to_records",
626 __PACKAGE__->register_method(
627 method => "biblio_mrid_to_record_ids",
628 api_name => "open-ils.search.biblio.metarecord_to_records.staff",
631 sub biblio_mrid_to_record_ids {
632 my( $self, $client, $mrid, $format ) = @_;
634 throw OpenSRF::EX::InvalidArg
635 ("search.biblio.metarecord_to_record_ids requires mr id")
636 unless defined( $mrid );
638 warn "Searching for record for MR $mrid and format $format\n";
640 my $method = "open-ils.storage.ordered.metabib.metarecord.records.atomic";
641 if($self and $self->api_name =~ /staff/) { $method =~ s/atomic/staff\.atomic/; }
642 warn "Performing record retrieval with method $method\n";
645 my $mrmaps = OpenILS::Application::AppUtils->simple_scalar_request(
646 "open-ils.storage", $method, $mrid, $format );
652 return { count => $size, ids => $mrmaps };
657 __PACKAGE__->register_method(
658 method => "biblio_record_to_marc_html",
659 api_name => "open-ils.search.biblio.record.html" );
661 my $parser = XML::LibXML->new();
662 my $xslt = XML::LibXSLT->new();
665 my $settings_client = OpenSRF::Utils::SettingsClient->new();
666 sub biblio_record_to_marc_html {
667 my( $self, $client, $recordid ) = @_;
670 my $dir = $settings_client->config_value( "dirs", "xsl" );
671 my $xsl = $settings_client->config_value(
672 "apps", "open-ils.search", "app_settings", "marc_html_xsl" );
674 $xsl = $parser->parse_file("$dir/$xsl");
675 $marc_sheet = $xslt->parse_stylesheet( $xsl );
679 my $record = $apputils->simple_scalar_request(
681 "open-ils.storage.direct.biblio.record_entry.retrieve",
684 my $xmldoc = $parser->parse_string($record->marc);
685 my $html = $marc_sheet->transform($xmldoc);
686 $html = $html->toString();
693 __PACKAGE__->register_method(
694 method => "retrieve_all_copy_locations",
695 api_name => "open-ils.search.config.copy_location.retrieve.all" );
697 my $shelving_locations;
698 sub retrieve_all_copy_locations {
699 my( $self, $client ) = @_;
700 if(!$shelving_locations) {
701 $shelving_locations = $apputils->simple_scalar_request(
703 "open-ils.storage.direct.asset.copy_location.retrieve.all.atomic");
705 return $shelving_locations;
711 __PACKAGE__->register_method(
712 method => "retrieve_all_copy_statuses",
713 api_name => "open-ils.search.config.copy_status.retrieve.all" );
716 sub retrieve_all_copy_statuses {
717 my( $self, $client ) = @_;
718 if(!$copy_statuses) {
719 $copy_statuses = $apputils->simple_scalar_request(
721 "open-ils.storage.direct.config.copy_status.retrieve.all.atomic" );
723 return $copy_statuses;
727 __PACKAGE__->register_method(
728 method => "copy_counts_per_org",
729 api_name => "open-ils.search.biblio.copy_counts.retrieve");
731 __PACKAGE__->register_method(
732 method => "copy_counts_per_org",
733 api_name => "open-ils.search.biblio.copy_counts.retrieve.staff");
735 sub copy_counts_per_org {
736 my( $self, $client, $record_id ) = @_;
738 warn "Retreiveing copy copy counts for record $record_id and method " . $self->api_name . "\n";
740 my $method = "open-ils.storage.biblio.record_entry.global_copy_count.atomic";
741 if($self->api_name =~ /staff/) { $method =~ s/atomic/staff\.atomic/; }
743 my $counts = $apputils->simple_scalar_request(
744 "open-ils.storage", $method, $record_id );
746 $counts = [ sort {$a->[0] <=> $b->[0]} @$counts ];
751 __PACKAGE__->register_method(
752 method => "copy_count_summary",
753 api_name => "open-ils.search.biblio.copy_counts.summary.retrieve",
754 notes => <<" NOTES");
755 returns an array of these:
756 [ org_id, callnumber_label, <status1_count>, <status2_cout>,...]
757 where statusx is a copy status name. the statuses are sorted
761 sub copy_count_summary {
762 my( $self, $client, $rid ) = @_;
763 my $method = "open-ils.storage.biblio.record_entry.status_copy_count.atomic";
764 return $apputils->simple_scalar_request( "open-ils.storage", $method, $rid );
769 __PACKAGE__->register_method(
770 method => "multiclass_search",
771 api_name => "open-ils.search.biblio.multiclass",
772 notes => <<" NOTES");
773 Performs a multiclass search
774 PARAMS( searchBlob, org_unit, format, limit )
775 where searchBlob is defined like this:
777 "title" : { "term" : "water" },
778 "author" : { "term" : "smith" },
783 __PACKAGE__->register_method(
784 method => "multiclass_search",
785 api_name => "open-ils.search.biblio.multiclass.staff",
786 notes => "see open-ils.search.biblio.multiclass" );
788 sub multiclass_search {
789 my( $self, $client, $searchBlob, $orgid, $format, $limit ) = @_;
791 $logger->debug("Performing multiclass search with org => $orgid, " .
792 "format => $format, limit => $limit, and search blob " . Dumper($searchBlob));
794 my $meth = 'open-ils.storage.metabib.post_filter.multiclass.search_fts.metarecord.atomic';
795 if($self->api_name =~ /staff/) { $meth =~ s/metarecord\.atomic/metarecord.staff.atomic/; }
798 my $records = $apputils->simplereq(
799 'open-ils.storage', $meth,
800 org_unit => $orgid, searches => $searchBlob, format => $format, limit => $limit );
805 if( ref($records) and $records->[0] and
806 defined($records->[0]->[3])) { $count = $records->[0]->[3];}
808 for my $r (@$records) { push( @$recs, $r ) if ($r and $r->[0]); }
810 # records has the form: [ mrid, rank, singleRecord / 0, hitCount ];
811 return { ids => $recs, count => $count };
818 __PACKAGE__->register_method(
819 method => "multiclass_search",
820 api_name => "open-ils.search.biblio.multiclass",
822 Performs a multiclass search
823 @param args A names hash of arguments:
824 org_unit : The org to focus the search on
825 depth : The search depth
828 offset : Search offset
829 searches : A named hash of searches which has the following format:
831 "title" : { "term" : "water" },
832 "author" : { "term" : "smith" },
835 @return { ids : <array of ids>, count : hitcount }
839 __PACKAGE__->register_method(
840 method => "multiclass_search",
841 api_name => "open-ils.search.biblio.multiclass.staff",
842 notes => q/@see open-ils.search.biblio.multiclass/ );
844 sub multiclass_search {
845 my( $self, $client, $args ) = @_;
847 $logger->debug("Performing multiclass search with args:\n" . Dumper($args));
848 my $meth = 'open-ils.storage.metabib.post_filter.multiclass.search_fts.metarecord.atomic';
849 if($self->api_name =~ /staff/) { $meth =~ s/metarecord\.atomic/metarecord.staff.atomic/; }
851 my $records = $apputils->simplereq( 'open-ils.storage', $meth, %$args );
856 if( ref($records) and $records->[0] and
857 defined($records->[0]->[3])) { $count = $records->[0]->[3];}
859 for my $r (@$records) { push( @$recs, $r ) if ($r and $r->[0]); }
861 return { ids => $recs, count => $count };
869 # request open-ils.storage
870 # open-ils.storage.biblio.full_rec.multi_search.atomic "searches",
871 # [{"term":"harry","restrict": [{"tag":245,"subfield":"a"}]}], "org_unit", 1,
872 # "limit",5,"sort","author","item_type","g"
875 __PACKAGE__->register_method(
876 method => "marc_search",
877 api_name => "open-ils.search.biblio.marc",
878 notes => <<" NOTES");
879 Performs a multiclass search
880 PARAMS( searchBlob, org_unit, format )
881 where searchBlob is defined like this:
884 "term":"shakespeare",
885 "restrict":[{"tag":"245","subfield":"a"}]
889 "restrict":[{"tag":"100","subfield":"a"}]
896 my( $self, $client, $searchBlob, $orgid, $format ) = @_;
898 $logger->debug("Performing MARC search with org => $orgid, " .
899 "format => $format and search blob " . Dumper($searchBlob) );
901 my $records = $apputils->simplereq(
903 'open-ils.storage.metabib.full_rec.multi_search.atomic',
904 searches => $searchBlob, org_unit => $orgid, format => $format );
909 if( ref($records) and $records->[0] and
910 defined($records->[0]->[3])) { $count = $records->[0]->[3];}
912 for my $r (@$records) { push( @$recs, $r ) if ($r and $r->[0]); }
914 # records has the form: [ mrid, rank, singleRecord / 0, hitCount ];
915 return { ids => $recs, count => $count };
921 __PACKAGE__->register_method(
922 method => "biblio_search_isbn",
923 api_name => "open-ils.search.biblio.isbn",
926 sub biblio_search_isbn {
927 my( $self, $client, $isbn ) = @_;
929 $logger->debug("Searching ISBN $isbn");
931 my $method = $self->method_lookup("open-ils.search.biblio.marc");
933 my ($records) = $method->run(
935 restrict => $cat_search_hash->{isbn} } ], 1);
941 __PACKAGE__->register_method(
942 method => "biblio_search_issn",
943 api_name => "open-ils.search.biblio.issn",
946 sub biblio_search_issn {
947 my( $self, $client, $issn ) = @_;
949 $logger->debug("Searching ISSN $issn");
951 my $method = $self->method_lookup("open-ils.search.biblio.marc");
953 my ($records) = $method->run(
955 restrict => $cat_search_hash->{issn} } ], 1);
963 __PACKAGE__->register_method(
964 method => "fetch_mods_by_copy",
965 api_name => "open-ils.search.biblio.mods_from_copy",
968 sub fetch_mods_by_copy {
969 my( $self, $client, $copyid ) = @_;
970 my ($record, $evt) = $apputils->fetch_record_by_copy( $copyid );
972 return OpenILS::Event->new('ITEM_NOT_CATALOGED') unless $record->marc;
973 return $apputils->record_to_mvr($record);
980 # -------------------------------------------------------------------------------------
982 __PACKAGE__->register_method(
983 method => "cn_browse",
984 api_name => "open-ils.search.callnumber.browse.target",
985 notes => "Starts a callnumber browse"
988 __PACKAGE__->register_method(
989 method => "cn_browse",
990 api_name => "open-ils.search.callnumber.browse.page_up",
991 notes => "Returns the previous page of callnumbers",
994 __PACKAGE__->register_method(
995 method => "cn_browse",
996 api_name => "open-ils.search.callnumber.browse.page_down",
997 notes => "Returns the next page of callnumbers",
1001 # RETURNS array of arrays like so: label, owning_lib, record, id
1003 my( $self, $client, @params ) = @_;
1006 $method = 'open-ils.storage.asset.call_number.browse.target.atomic'
1007 if( $self->api_name =~ /target/ );
1008 $method = 'open-ils.storage.asset.call_number.browse.page_up.atomic'
1009 if( $self->api_name =~ /page_up/ );
1010 $method = 'open-ils.storage.asset.call_number.browse.page_down.atomic'
1011 if( $self->api_name =~ /page_down/ );
1013 return $apputils->simplereq( 'open-ils.storage', $method, @params );
1015 # -------------------------------------------------------------------------------------
1017 __PACKAGE__->register_method(
1018 method => "fetch_cn",
1019 api_name => "open-ils.search.callnumber.retrieve",
1020 notes => "retrieves a callnumber based on ID",
1024 my( $self, $client, $id ) = @_;
1025 my( $cn, $evt ) = $apputils->fetch_callnumber( $id );
1026 return $evt if $evt;
1030 __PACKAGE__->register_method (
1031 method => "fetch_copy_by_cn",
1032 api_name => 'open-ils.search.copies_by_call_number.retrieve',
1034 Returns an array of copy id's by callnumber id
1035 @param cnid The callnumber id
1036 @return An array of copy ids
1040 sub fetch_copy_by_cn {
1041 my( $self, $conn, $cnid ) = @_;
1042 return $U->storagereq(
1043 'open-ils.storage.id_list.asset.copy.search_where.atomic',
1044 { call_number => $cnid, deleted => 'f' } );
1047 __PACKAGE__->register_method (
1048 method => 'fetch_cn_by_info',
1049 api_name => 'open-ils.search.call_number.retrieve_by_info',
1051 @param label The callnumber label
1052 @param record The record the cn is attached to
1053 @param org The owning library of the cn
1054 @return The callnumber object
1058 sub fetch_cn_by_info {
1059 my( $self, $conn, $label, $record, $org ) = @_;
1060 return $U->storagereq(
1061 'open-ils.storage.direct.asset.call_number.search_where',
1062 { label => $label, record => $record, owning_lib => $org, deleted => 'f' });