1 package OpenILS::Application::Search::Biblio;
2 use base qw/OpenSRF::Application/;
3 use strict; use warnings;
7 use OpenILS::Utils::Fieldmapper;
8 use OpenILS::Utils::ModsParser;
9 use OpenSRF::Utils::SettingsClient;
10 use OpenILS::Utils::Editor q/:funcs/;
11 use OpenSRF::Utils::Cache;
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";
32 my $pfx = "open-ils.search_";
37 $cache = OpenSRF::Utils::Cache->new('global');
38 my $sclient = OpenSRF::Utils::SettingsClient->new();
39 $cache_timeout = $sclient->config_value(
40 "apps", "open-ils.search", "app_settings", "cache_timeout" ) || 300;
41 $logger->info("Search cache timeout is $cache_timeout");
46 # ---------------------------------------------------------------------------
47 # takes a list of record id's and turns the docs into friendly
48 # mods structures. Creates one MODS structure for each doc id.
49 # ---------------------------------------------------------------------------
50 sub _records_to_mods {
56 my $session = OpenSRF::AppSession->create("open-ils.storage");
57 my $request = $session->request(
58 "open-ils.storage.direct.biblio.record_entry.batch.retrieve", @ids );
60 while( my $resp = $request->recv ) {
61 my $content = $resp->content;
62 my $u = OpenILS::Utils::ModsParser->new();
63 $u->start_mods_batch( $content->marc );
64 my $mods = $u->finish_mods_batch();
65 $mods->doc_id($content->id());
66 $mods->tcn($content->tcn_value);
70 $session->disconnect();
74 __PACKAGE__->register_method(
75 method => "record_id_to_mods",
76 api_name => "open-ils.search.biblio.record.mods.retrieve",
78 note => "Provide ID, we provide the mods"
81 # converts a record into a mods object with copy counts attached
82 sub record_id_to_mods {
84 my( $self, $client, $org_id, $id ) = @_;
86 my $mods_list = _records_to_mods( $id );
87 my $mods_obj = $mods_list->[0];
88 my $cmethod = $self->method_lookup(
89 "open-ils.search.biblio.record.copy_count");
90 my ($count) = $cmethod->run($org_id, $id);
91 $mods_obj->copy_count($count);
98 __PACKAGE__->register_method(
99 method => "record_id_to_mods_slim",
100 api_name => "open-ils.search.biblio.record.mods_slim.retrieve",
102 note => "Provide ID, we provide the mods"
105 # converts a record into a mods object with NO copy counts attached
106 sub record_id_to_mods_slim {
107 my( $self, $client, $id ) = @_;
108 return undef unless defined $id;
110 if(ref($id) and ref($id) == 'ARRAY') {
111 return _records_to_mods( @$id );
113 my $mods_list = _records_to_mods( $id );
114 my $mods_obj = $mods_list->[0];
119 # Returns the number of copies attached to a record based on org location
120 __PACKAGE__->register_method(
121 method => "record_id_to_copy_count",
122 api_name => "open-ils.search.biblio.record.copy_count",
125 __PACKAGE__->register_method(
126 method => "record_id_to_copy_count",
127 api_name => "open-ils.search.biblio.record.copy_count.staff",
130 __PACKAGE__->register_method(
131 method => "record_id_to_copy_count",
132 api_name => "open-ils.search.biblio.metarecord.copy_count",
135 __PACKAGE__->register_method(
136 method => "record_id_to_copy_count",
137 api_name => "open-ils.search.biblio.metarecord.copy_count.staff",
139 sub record_id_to_copy_count {
140 my( $self, $client, $org_id, $record_id, $format ) = @_;
142 return [] unless $record_id;
143 $format = undef if (!$format or $format eq 'all');
145 my $method = "open-ils.storage.biblio.record_entry.copy_count.atomic";
148 if($self->api_name =~ /metarecord/) {
149 $method = "open-ils.storage.metabib.metarecord.copy_count.atomic";
153 $method =~ s/atomic/staff\.atomic/og if($self->api_name =~ /staff/ );
155 my $count = $U->storagereq( $method,
156 org_unit => $org_id, $key => $record_id, format => $format );
158 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;
177 my $e = new_editor();
178 my $recs = $e->search_biblio_record_entry(
179 {deleted => 'f', tcn_value => $tcn}, {idlist =>1});
181 return { count => scalar(@$recs), ids => $recs };
185 # --------------------------------------------------------------------------------
187 __PACKAGE__->register_method(
188 method => "biblio_barcode_to_copy",
189 api_name => "open-ils.search.asset.copy.find_by_barcode",);
190 sub biblio_barcode_to_copy {
191 my( $self, $client, $barcode ) = @_;
192 my( $copy, $evt ) = $U->fetch_copy_by_barcode($barcode);
197 __PACKAGE__->register_method(
198 method => "biblio_id_to_copy",
199 api_name => "open-ils.search.asset.copy.batch.retrieve",);
200 sub biblio_id_to_copy {
201 my( $self, $client, $ids ) = @_;
202 $logger->info("Fetching copies @$ids");
203 return $U->storagereq(
204 "open-ils.storage.direct.asset.copy.batch.retrieve.atomic", @$ids );
208 __PACKAGE__->register_method(
209 method => "copy_retrieve",
210 api_name => "open-ils.search.asset.copy.retrieve",);
212 my( $self, $client, $cid ) = @_;
213 my( $copy, $evt ) = $U->fetch_copy($cid);
218 __PACKAGE__->register_method(
219 method => "volume_retrieve",
220 api_name => "open-ils.search.asset.call_number.retrieve");
221 sub volume_retrieve {
222 my( $self, $client, $vid ) = @_;
223 my $e = new_editor();
224 my $vol = $e->retrieve_asset_call_number($vid) or return $e->event;
228 __PACKAGE__->register_method(
229 method => "fleshed_copy_retrieve_batch",
230 api_name => "open-ils.search.asset.copy.fleshed.batch.retrieve");
232 sub fleshed_copy_retrieve_batch {
233 my( $self, $client, $ids ) = @_;
234 $logger->info("Fetching fleshed copies @$ids");
235 return $U->storagereq(
236 "open-ils.storage.fleshed.asset.copy.batch.retrieve.atomic", @$ids );
240 __PACKAGE__->register_method(
241 method => "fleshed_copy_retrieve",
242 api_name => "open-ils.search.asset.copy.fleshed.retrieve",);
244 sub fleshed_copy_retrieve {
245 my( $self, $client, $id ) = @_;
246 my( $c, $e) = $U->fetch_fleshed_copy($id);
253 __PACKAGE__->register_method(
254 method => "biblio_barcode_to_title",
255 api_name => "open-ils.search.biblio.find_by_barcode",
258 sub biblio_barcode_to_title {
259 my( $self, $client, $barcode ) = @_;
261 my $title = $apputils->simple_scalar_request(
263 "open-ils.storage.biblio.record_entry.retrieve_by_barcode", $barcode );
265 return { ids => [ $title->id ], count => 1 } if $title;
266 return { count => 0 };
270 __PACKAGE__->register_method(
271 method => "biblio_copy_to_mods",
272 api_name => "open-ils.search.biblio.copy.mods.retrieve",
275 # takes a copy object and returns it fleshed mods object
276 sub biblio_copy_to_mods {
277 my( $self, $client, $copy ) = @_;
279 my $volume = $U->storagereq(
280 "open-ils.storage.direct.asset.call_number.retrieve",
281 $copy->call_number() );
283 my $mods = _records_to_mods($volume->record());
284 $mods = shift @$mods;
285 $volume->copies([$copy]);
286 push @{$mods->call_numbers()}, $volume;
292 # ----------------------------------------------------------------------------
293 # These are the main OPAC search methods
294 # ----------------------------------------------------------------------------
296 __PACKAGE__->register_method(
297 method => 'the_quest_for_knowledge',
298 api_name => 'open-ils.search.biblio.multiclass',
300 Performs a multi class bilbli or metabib search
301 @param searchhash A search object layed out like so:
302 searches : { "$class" : "$value", ...}
303 org_unit : The org id to focus the search at
304 depth : The org depth
305 limit : The search limit
306 offset : The search offset
307 format : The MARC format
308 sort : What field to sort the results on [ author | title | pubdate ]
309 sort_dir : What direction do we sort? [ asc | desc ]
310 @return An object of the form
311 { "count" : $count, "ids" : [ [ $id, $relevancy, $total ], ...] }
315 __PACKAGE__->register_method(
316 method => 'the_quest_for_knowledge',
317 api_name => 'open-ils.search.biblio.multiclass.staff',
318 signature => q/@see open-ils.search.biblio.multiclass/);
319 __PACKAGE__->register_method(
320 method => 'the_quest_for_knowledge',
321 api_name => 'open-ils.search.metabib.multiclass',
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.staff',
326 signature => q/@see open-ils.search.biblio.multiclass/);
330 sub the_quest_for_knowledge {
331 my( $self, $conn, $searchhash ) = @_;
333 my $method = 'open-ils.storage.biblio.multiclass.search_fts';
339 my $o = $searchhash->{offset} || 0;
340 my $l = $searchhash->{limit} || 10;
341 $searchhash->{offset} = 0;
342 $searchhash->{limit} = 0;
344 my $ckey = $pfx . md5_hex($method . JSON->perl2JSON($searchhash));
346 $searchhash->{offset} = $o;
347 $searchhash->{limit} = $l;
350 if($self->api_name =~ /metabib/) {
352 $method =~ s/biblio/metabib/o;
355 # don't cache past max limit
356 my $result = ($o < $maxlimit) ? search_cache($ckey, $o, $l) : undef;
361 $method .= ".staff" if($self->api_name =~ /staff/);
362 $method .= ".atomic";
364 for (keys %$searchhash) {
365 delete $$searchhash{$_} unless defined $$searchhash{$_}; }
367 $searchhash->{limit} = $maxlimit;
368 $result = new_editor()->request( $method, %$searchhash );
372 $logger->debug("cache returned results: " . JSON->perl2JSON($result));
376 return {count => 0} unless ($result && $$result[0]);
378 for my $r (@$result) { push(@recs, $r) if ($r and $$r[0]); }
381 $logger->debug("putting search cache $ckey\n");
382 $cache->put_cache($ckey, \@recs, $cache_timeout);
385 return { ids => \@recs,
386 count => ($ismeta) ? $result->[0]->[3] : $result->[0]->[2] };
397 $logger->debug("fetching search cache $key\n");
399 my $data = $cache->get_cache($key);
400 return undef unless $data;
402 $logger->debug("search_cache found some data: o=$offset, l=$limit");
404 #$data = JSON->JSON2perl($data);
405 return undef unless $data and ref $data eq 'ARRAY';
406 return undef unless $$data[$offset] and $$data[$offset+($limit-1)];
408 $logger->debug("search_cache found data..$offset - " . ($offset + ($limit - 1)));
409 return [ @$data[$offset..($offset+$limit)] ];
417 __PACKAGE__->register_method(
418 method => "biblio_mrid_to_modsbatch_batch",
419 api_name => "open-ils.search.biblio.metarecord.mods_slim.batch.retrieve");
421 sub biblio_mrid_to_modsbatch_batch {
422 my( $self, $client, $mrids) = @_;
423 warn "Performing mrid_to_modsbatch_batch...";
425 my $method = $self->method_lookup("open-ils.search.biblio.metarecord.mods_slim.retrieve");
426 for my $id (@$mrids) {
427 next unless defined $id;
428 my ($m) = $method->run($id);
435 __PACKAGE__->register_method(
436 method => "biblio_mrid_to_modsbatch",
437 api_name => "open-ils.search.biblio.metarecord.mods_slim.retrieve",
438 notes => <<" NOTES");
439 Returns the mvr associated with a given metarecod. If none exists,
443 __PACKAGE__->register_method(
444 method => "biblio_mrid_to_modsbatch",
445 api_name => "open-ils.search.biblio.metarecord.mods_slim.retrieve.staff",
446 notes => <<" NOTES");
447 Returns the mvr associated with a given metarecod. If none exists,
451 sub biblio_mrid_to_modsbatch {
452 my( $self, $client, $mrid ) = @_;
454 warn "Grabbing mvr for $mrid\n";
456 my ($mr, $evt) = _grab_metarecord($mrid);
457 return $evt unless $mr;
459 if( my $m = $self->biblio_mrid_check_mvr($client, $mr)) {
463 return $self->biblio_mrid_make_modsbatch( $client, $mr );
466 # converts a metarecord to an mvr
469 my $perl = JSON->JSON2perl($mr->mods());
470 return Fieldmapper::metabib::virtual_record->new($perl);
473 # checks to see if a metarecord has mods, if so returns true;
475 __PACKAGE__->register_method(
476 method => "biblio_mrid_check_mvr",
477 api_name => "open-ils.search.biblio.metarecord.mods_slim.check",
478 notes => <<" NOTES");
479 Takes a metarecord ID or a metarecord object and returns true
480 if the metarecord already has an mvr associated with it.
483 sub biblio_mrid_check_mvr {
484 my( $self, $client, $mrid ) = @_;
488 if(ref($mrid)) { $mr = $mrid; }
489 else { ($mr, $evt) = _grab_metarecord($mrid); }
492 warn "Checking mvr for mr " . $mr->id . "\n";
494 return _mr_to_mvr($mr) if $mr->mods();
498 sub _grab_metarecord {
500 my $e = OpenILS::Utils::Editor->new;
501 my $mr = $e->retrieve_metabib_metarecord($mrid) or return ( undef, $e->event );
504 # my $mr = $U->simplereq(
506 # 'open-ils.cstore.direct.metabib.metarecord.retrieve',
513 __PACKAGE__->register_method(
514 method => "biblio_mrid_make_modsbatch",
515 api_name => "open-ils.search.biblio.metarecord.mods_slim.create",
516 notes => <<" NOTES");
517 Takes either a metarecord ID or a metarecord object.
518 Forces the creations of an mvr for the given metarecord.
519 The created mvr is returned.
522 sub biblio_mrid_make_modsbatch {
523 my( $self, $client, $mrid ) = @_;
525 my $e = OpenILS::Utils::Editor->new;
532 $mr = $e->retrieve_metabib_metarecord($mrid)
536 my $masterid = $mr->master_record;
537 $logger->info("creating new mods batch for metarecord=$mrid, master record=$masterid");
539 my $ids = $e->request(
540 'open-ils.storage.ordered.metabib.metarecord.records.staff.atomic', $mrid);
541 return undef unless @$ids;
543 my $master = $e->retrieve_biblio_record_entry($masterid)
546 # start the mods batch
547 my $u = OpenILS::Utils::ModsParser->new();
548 $u->start_mods_batch( $master->marc );
550 # grab all of the sub-records and shove them into the batch
551 my @ids = grep { $_ ne $masterid } @$ids;
552 my $subrecs = $e->batch_retrieve_biblio_record_entry(\@ids);
555 $logger->debug("adding record ".$_->id." to mods batch for metarecord=$mrid");
556 $u->push_mods_batch( $_->marc ) if $_->marc;
560 # finish up and send to the client
561 my $mods = $u->finish_mods_batch();
562 $mods->doc_id($mrid);
563 $client->respond_complete($mods);
566 # now update the mods string in the db
567 my $string = JSON->perl2JSON($mods->decast);
570 $e = OpenILS::Utils::Editor->new(xact => 1);
571 $e->update_metabib_metarecord($mr)
572 or $logger->error("Error setting mods text on metarecord $mrid : " . Dumper($e->event));
581 # converts a mr id into a list of record ids
583 __PACKAGE__->register_method(
584 method => "biblio_mrid_to_record_ids",
585 api_name => "open-ils.search.biblio.metarecord_to_records",
588 __PACKAGE__->register_method(
589 method => "biblio_mrid_to_record_ids",
590 api_name => "open-ils.search.biblio.metarecord_to_records.staff",
593 sub biblio_mrid_to_record_ids {
594 my( $self, $client, $mrid, $args ) = @_;
596 my $format = $$args{format};
597 my $org = $$args{org};
598 my $depth = $$args{depth};
600 my $method = "open-ils.storage.ordered.metabib.metarecord.records.atomic";
601 $method =~ s/atomic/staff\.atomic/o if $self->api_name =~ /staff/o;
602 my $recs = $U->storagereq($method, $mrid, $format, $org, $depth);
604 return { count => scalar(@$recs), ids => $recs };
608 __PACKAGE__->register_method(
609 method => "biblio_record_to_marc_html",
610 api_name => "open-ils.search.biblio.record.html" );
612 my $parser = XML::LibXML->new();
613 my $xslt = XML::LibXSLT->new();
616 my $settings_client = OpenSRF::Utils::SettingsClient->new();
617 sub biblio_record_to_marc_html {
618 my( $self, $client, $recordid ) = @_;
621 my $dir = $settings_client->config_value( "dirs", "xsl" );
622 my $xsl = $settings_client->config_value(
623 "apps", "open-ils.search", "app_settings", "marc_html_xsl" );
625 $xsl = $parser->parse_file("$dir/$xsl");
626 $marc_sheet = $xslt->parse_stylesheet( $xsl );
630 my $record = $apputils->simple_scalar_request(
632 "open-ils.storage.direct.biblio.record_entry.retrieve",
635 my $xmldoc = $parser->parse_string($record->marc);
636 my $html = $marc_sheet->transform($xmldoc);
637 $html = $html->toString();
644 __PACKAGE__->register_method(
645 method => "retrieve_all_copy_locations",
646 api_name => "open-ils.search.config.copy_location.retrieve.all" );
648 my $shelving_locations;
649 sub retrieve_all_copy_locations {
650 my( $self, $client ) = @_;
651 if(!$shelving_locations) {
652 $shelving_locations = $apputils->simple_scalar_request(
654 "open-ils.storage.direct.asset.copy_location.retrieve.all.atomic");
656 return $shelving_locations;
662 __PACKAGE__->register_method(
663 method => "retrieve_all_copy_statuses",
664 api_name => "open-ils.search.config.copy_status.retrieve.all" );
667 sub retrieve_all_copy_statuses {
668 my( $self, $client ) = @_;
669 if(!$copy_statuses) {
670 $copy_statuses = $apputils->simple_scalar_request(
672 "open-ils.storage.direct.config.copy_status.retrieve.all.atomic" );
674 return $copy_statuses;
678 __PACKAGE__->register_method(
679 method => "copy_counts_per_org",
680 api_name => "open-ils.search.biblio.copy_counts.retrieve");
682 __PACKAGE__->register_method(
683 method => "copy_counts_per_org",
684 api_name => "open-ils.search.biblio.copy_counts.retrieve.staff");
686 sub copy_counts_per_org {
687 my( $self, $client, $record_id ) = @_;
689 warn "Retreiveing copy copy counts for record $record_id and method " . $self->api_name . "\n";
691 my $method = "open-ils.storage.biblio.record_entry.global_copy_count.atomic";
692 if($self->api_name =~ /staff/) { $method =~ s/atomic/staff\.atomic/; }
694 my $counts = $apputils->simple_scalar_request(
695 "open-ils.storage", $method, $record_id );
697 $counts = [ sort {$a->[0] <=> $b->[0]} @$counts ];
702 __PACKAGE__->register_method(
703 method => "copy_count_summary",
704 api_name => "open-ils.search.biblio.copy_counts.summary.retrieve",
705 notes => <<" NOTES");
706 returns an array of these:
707 [ org_id, callnumber_label, <status1_count>, <status2_cout>,...]
708 where statusx is a copy status name. the statuses are sorted
712 sub copy_count_summary {
713 my( $self, $client, $rid, $org, $depth ) = @_;
716 return $U->storagereq(
717 'open-ils.storage.biblio.record_entry.status_copy_count.atomic', $rid, $org, $depth );
723 __PACKAGE__->register_method(
724 method => "multiclass_search",
725 api_name => "open-ils.search.biblio.multiclass",
726 notes => <<" NOTES");
727 Performs a multiclass search
728 PARAMS( searchBlob, org_unit, format, limit )
729 where searchBlob is defined like this:
731 "title" : { "term" : "water" },
732 "author" : { "term" : "smith" },
737 __PACKAGE__->register_method(
738 method => "multiclass_search",
739 api_name => "open-ils.search.biblio.multiclass.staff",
740 notes => "see open-ils.search.biblio.multiclass" );
742 sub multiclass_search {
743 my( $self, $client, $searchBlob, $orgid, $format, $limit ) = @_;
745 $logger->debug("Performing multiclass search with org => $orgid, " .
746 "format => $format, limit => $limit, and search blob " . Dumper($searchBlob));
748 my $meth = 'open-ils.storage.metabib.post_filter.multiclass.search_fts.metarecord.atomic';
749 if($self->api_name =~ /staff/) { $meth =~ s/metarecord\.atomic/metarecord.staff.atomic/; }
752 my $records = $apputils->simplereq(
753 'open-ils.storage', $meth,
754 org_unit => $orgid, searches => $searchBlob, format => $format, limit => $limit );
759 if( ref($records) and $records->[0] and
760 defined($records->[0]->[3])) { $count = $records->[0]->[3];}
762 for my $r (@$records) { push( @$recs, $r ) if ($r and $r->[0]); }
764 # records has the form: [ mrid, rank, singleRecord / 0, hitCount ];
765 return { ids => $recs, count => $count };
771 __PACKAGE__->register_method(
772 method => "multiclass_search",
773 api_name => "open-ils.search.biblio.multiclass",
775 Performs a multiclass search
776 @param args A names hash of arguments:
777 org_unit : The org to focus the search on
778 depth : The search depth
781 offset : Search offset
782 searches : A named hash of searches which has the following format:
784 "title" : { "term" : "water" },
785 "author" : { "term" : "smith" },
788 @return { ids : <array of ids>, count : hitcount }
792 __PACKAGE__->register_method(
793 method => "multiclass_search",
794 api_name => "open-ils.search.biblio.multiclass.staff",
795 notes => q/@see open-ils.search.biblio.multiclass/ );
797 sub multiclass_search {
798 my( $self, $client, $args ) = @_;
800 $logger->debug("Performing multiclass search with args:\n" . Dumper($args));
801 my $meth = 'open-ils.storage.metabib.post_filter.multiclass.search_fts.metarecord.atomic';
802 if($self->api_name =~ /staff/) { $meth =~ s/metarecord\.atomic/metarecord.staff.atomic/; }
804 my $records = $apputils->simplereq( 'open-ils.storage', $meth, %$args );
809 if( ref($records) and $records->[0] and
810 defined($records->[0]->[3])) { $count = $records->[0]->[3];}
812 for my $r (@$records) { push( @$recs, $r ) if ($r and $r->[0]); }
814 return { ids => $recs, count => $count };
821 __PACKAGE__->register_method(
822 method => "marc_search",
823 api_name => "open-ils.search.biblio.marc.staff");
825 __PACKAGE__->register_method(
826 method => "marc_search",
827 api_name => "open-ils.search.biblio.marc",
828 notes => <<" NOTES");
830 open-ils.storage.biblio.full_rec.multi_search.atomic
831 { "searches": [{"term":"harry","restrict": [{"tag":245,"subfield":"a"}]}], "org_unit": 1,
832 "limit":5,"sort":"author","item_type":"g"}
836 my( $self, $conn, $args, $limit, $offset ) = @_;
838 my $method = 'open-ils.storage.biblio.full_rec.multi_search';
839 $method .= ".staff" if $self->api_name =~ /staff/;
840 $method .= ".atomic";
845 my $ckey = $pfx . md5_hex($method . JSON->perl2JSON($args));
846 my $recs = search_cache($ckey, $offset, $limit);
849 $recs = new_editor()->request($method, %$args);
850 $cache->put_cache($ckey, $recs, $cache_timeout);
851 $recs = [ @$recs[$offset..($offset + ($limit - 1))] ];
855 $count = $recs->[0]->[2] if $recs->[0] and $recs->[0]->[2];
856 my @recs = map { $_->[0] } @$recs;
858 return { ids => \@recs, count => $count };
862 __PACKAGE__->register_method(
863 method => "biblio_search_isbn",
864 api_name => "open-ils.search.biblio.isbn",
867 sub biblio_search_isbn {
868 my( $self, $client, $isbn ) = @_;
869 $logger->debug("Searching ISBN $isbn");
870 my $e = new_editor();
871 my $recs = $e->request(
872 'open-ils.storage.id_list.biblio.record_entry.search.isbn.atomic', $isbn );
873 return { ids => $recs, count => scalar(@$recs) };
877 __PACKAGE__->register_method(
878 method => "biblio_search_issn",
879 api_name => "open-ils.search.biblio.issn",
882 sub biblio_search_issn {
883 my( $self, $client, $issn ) = @_;
884 $logger->debug("Searching ISSN $issn");
885 my $e = new_editor();
886 my $recs = $e->request(
887 'open-ils.storage.id_list.biblio.record_entry.search.issn.atomic', $issn );
888 return { ids => $recs, count => scalar(@$recs) };
894 __PACKAGE__->register_method(
895 method => "fetch_mods_by_copy",
896 api_name => "open-ils.search.biblio.mods_from_copy",
899 sub fetch_mods_by_copy {
900 my( $self, $client, $copyid ) = @_;
901 my ($record, $evt) = $apputils->fetch_record_by_copy( $copyid );
903 return OpenILS::Event->new('ITEM_NOT_CATALOGED') unless $record->marc;
904 return $apputils->record_to_mvr($record);
909 # -------------------------------------------------------------------------------------
911 __PACKAGE__->register_method(
912 method => "cn_browse",
913 api_name => "open-ils.search.callnumber.browse.target",
914 notes => "Starts a callnumber browse"
917 __PACKAGE__->register_method(
918 method => "cn_browse",
919 api_name => "open-ils.search.callnumber.browse.page_up",
920 notes => "Returns the previous page of callnumbers",
923 __PACKAGE__->register_method(
924 method => "cn_browse",
925 api_name => "open-ils.search.callnumber.browse.page_down",
926 notes => "Returns the next page of callnumbers",
930 # RETURNS array of arrays like so: label, owning_lib, record, id
932 my( $self, $client, @params ) = @_;
935 $method = 'open-ils.storage.asset.call_number.browse.target.atomic'
936 if( $self->api_name =~ /target/ );
937 $method = 'open-ils.storage.asset.call_number.browse.page_up.atomic'
938 if( $self->api_name =~ /page_up/ );
939 $method = 'open-ils.storage.asset.call_number.browse.page_down.atomic'
940 if( $self->api_name =~ /page_down/ );
942 return $apputils->simplereq( 'open-ils.storage', $method, @params );
944 # -------------------------------------------------------------------------------------
946 __PACKAGE__->register_method(
947 method => "fetch_cn",
948 api_name => "open-ils.search.callnumber.retrieve",
949 notes => "retrieves a callnumber based on ID",
953 my( $self, $client, $id ) = @_;
954 my( $cn, $evt ) = $apputils->fetch_callnumber( $id );
959 __PACKAGE__->register_method (
960 method => "fetch_copy_by_cn",
961 api_name => 'open-ils.search.copies_by_call_number.retrieve',
963 Returns an array of copy id's by callnumber id
964 @param cnid The callnumber id
965 @return An array of copy ids
969 sub fetch_copy_by_cn {
970 my( $self, $conn, $cnid ) = @_;
971 return $U->storagereq(
972 'open-ils.storage.id_list.asset.copy.search_where.atomic',
973 { call_number => $cnid, deleted => 'f' } );
976 __PACKAGE__->register_method (
977 method => 'fetch_cn_by_info',
978 api_name => 'open-ils.search.call_number.retrieve_by_info',
980 @param label The callnumber label
981 @param record The record the cn is attached to
982 @param org The owning library of the cn
983 @return The callnumber object
988 sub fetch_cn_by_info {
989 my( $self, $conn, $label, $record, $org ) = @_;
990 return $U->storagereq(
991 'open-ils.storage.direct.asset.call_number.search_where',
992 { label => $label, record => $record, owning_lib => $org, deleted => 'f' });
999 __PACKAGE__->register_method (
1000 method => 'bib_extras',
1001 api_name => 'open-ils.search.biblio.lit_form_map.retrieve.all');
1002 __PACKAGE__->register_method (
1003 method => 'bib_extras',
1004 api_name => 'open-ils.search.biblio.item_form_map.retrieve.all');
1005 __PACKAGE__->register_method (
1006 method => 'bib_extras',
1007 api_name => 'open-ils.search.biblio.item_type_map.retrieve.all');
1008 __PACKAGE__->register_method (
1009 method => 'bib_extras',
1010 api_name => 'open-ils.search.biblio.audience_map.retrieve.all');
1015 return $U->storagereq(
1016 'open-ils.storage.direct.config.lit_form_map.retrieve.all.atomic')
1017 if( $self->api_name =~ /lit_form/ );
1019 return $U->storagereq(
1020 'open-ils.storage.direct.config.item_form_map.retrieve.all.atomic')
1021 if( $self->api_name =~ /item_form_map/ );
1023 return $U->storagereq(
1024 'open-ils.storage.direct.config.item_type_map.retrieve.all.atomic')
1025 if( $self->api_name =~ /item_type_map/ );
1027 return $U->storagereq(
1028 'open-ils.storage.direct.config.audience_map.retrieve.all.atomic')
1029 if( $self->api_name =~ /audience/ );
1036 __PACKAGE__->register_method(
1037 method => 'fetch_slim_record',
1038 api_name => 'open-ils.search.biblio.record_entry.slim.retrieve',
1040 Returns a biblio.record_entry without the attached marcxml
1044 sub fetch_slim_record {
1045 my( $self, $conn, $ids ) = @_;
1047 my $editor = OpenILS::Utils::Editor->new;
1050 return $editor->event unless
1051 my $r = $editor->retrieve_biblio_record_entry($_);
1060 __PACKAGE__->register_method(
1061 method => 'rec_to_mr_rec_descriptors',
1062 api_name => 'open-ils.search.metabib.record_to_descriptors',
1064 specialized method...
1065 Given a biblio record id or a metarecord id,
1066 this returns a list of metabib.record_descriptor
1067 objects that live within the same metarecord
1068 @param args Object of args including:
1072 sub rec_to_mr_rec_descriptors {
1073 my( $self, $conn, $args ) = @_;
1075 my $rec = $$args{record};
1076 my $mrec = $$args{metarecord};
1077 my $item_forms = $$args{item_forms};
1078 my $item_types = $$args{item_types};
1079 my $item_lang = $$args{item_lang};
1081 my $e = new_editor();
1085 my $map = $e->search_metabib_metarecord_source_map({source => $rec});
1086 return $e->event unless @$map;
1087 $mrec = $$map[0]->metarecord;
1090 $recs = $e->search_metabib_metarecord_source_map({metarecord => $mrec});
1091 return $e->event unless @$recs;
1093 my @recs = map { $_->source } @$recs;
1094 my $search = { record => \@recs };
1095 $search->{item_form} = $item_forms if $item_forms and @$item_forms;
1096 $search->{item_type} = $item_types if $item_types and @$item_types;
1097 $search->{item_lang} = $item_lang if $item_lang;
1099 my $desc = $e->search_metabib_record_descriptor($search);
1101 return { metarecord => $mrec, descriptors => $desc };