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";
36 $cache = OpenSRF::Utils::Cache->new('global');
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.record.copy_count.staff",
125 __PACKAGE__->register_method(
126 method => "record_id_to_copy_count",
127 api_name => "open-ils.search.biblio.metarecord.copy_count",
130 __PACKAGE__->register_method(
131 method => "record_id_to_copy_count",
132 api_name => "open-ils.search.biblio.metarecord.copy_count.staff",
134 sub record_id_to_copy_count {
135 my( $self, $client, $org_id, $record_id, $format ) = @_;
137 return [] unless $record_id;
138 $format = undef if (!$format or $format eq 'all');
140 my $method = "open-ils.storage.biblio.record_entry.copy_count.atomic";
143 if($self->api_name =~ /metarecord/) {
144 $method = "open-ils.storage.metabib.metarecord.copy_count.atomic";
148 $method =~ s/atomic/staff\.atomic/og if($self->api_name =~ /staff/ );
150 my $count = $U->storagereq( $method,
151 org_unit => $org_id, $key => $record_id, format => $format );
153 return [ sort { $a->{depth} <=> $b->{depth} } @$count ];
159 __PACKAGE__->register_method(
160 method => "biblio_search_tcn",
161 api_name => "open-ils.search.biblio.tcn",
163 note => "Retrieve a record by TCN",
166 sub biblio_search_tcn {
168 my( $self, $client, $tcn ) = @_;
170 $tcn =~ s/.*?(\w+)\s*$/$1/o;
172 my $e = new_editor();
173 my $recs = $e->search_biblio_record_entry(
174 {deleted => 'f', tcn_value => $tcn}, {idlist =>1});
176 return { count => scalar(@$recs), ids => $recs };
180 # --------------------------------------------------------------------------------
182 __PACKAGE__->register_method(
183 method => "biblio_barcode_to_copy",
184 api_name => "open-ils.search.asset.copy.find_by_barcode",);
185 sub biblio_barcode_to_copy {
186 my( $self, $client, $barcode ) = @_;
187 my( $copy, $evt ) = $U->fetch_copy_by_barcode($barcode);
192 __PACKAGE__->register_method(
193 method => "biblio_id_to_copy",
194 api_name => "open-ils.search.asset.copy.batch.retrieve",);
195 sub biblio_id_to_copy {
196 my( $self, $client, $ids ) = @_;
197 $logger->info("Fetching copies @$ids");
198 return $U->storagereq(
199 "open-ils.storage.direct.asset.copy.batch.retrieve.atomic", @$ids );
203 __PACKAGE__->register_method(
204 method => "copy_retrieve",
205 api_name => "open-ils.search.asset.copy.retrieve",);
207 my( $self, $client, $cid ) = @_;
208 my( $copy, $evt ) = $U->fetch_copy($cid);
213 __PACKAGE__->register_method(
214 method => "volume_retrieve",
215 api_name => "open-ils.search.asset.call_number.retrieve");
216 sub volume_retrieve {
217 my( $self, $client, $vid ) = @_;
218 my $e = new_editor();
219 my $vol = $e->retrieve_asset_call_number($vid) or return $e->event;
223 __PACKAGE__->register_method(
224 method => "fleshed_copy_retrieve_batch",
225 api_name => "open-ils.search.asset.copy.fleshed.batch.retrieve");
227 sub fleshed_copy_retrieve_batch {
228 my( $self, $client, $ids ) = @_;
229 $logger->info("Fetching fleshed copies @$ids");
230 return $U->storagereq(
231 "open-ils.storage.fleshed.asset.copy.batch.retrieve.atomic", @$ids );
235 __PACKAGE__->register_method(
236 method => "fleshed_copy_retrieve",
237 api_name => "open-ils.search.asset.copy.fleshed.retrieve",);
239 sub fleshed_copy_retrieve {
240 my( $self, $client, $id ) = @_;
241 my( $c, $e) = $U->fetch_fleshed_copy($id);
248 __PACKAGE__->register_method(
249 method => "biblio_barcode_to_title",
250 api_name => "open-ils.search.biblio.find_by_barcode",
253 sub biblio_barcode_to_title {
254 my( $self, $client, $barcode ) = @_;
256 my $title = $apputils->simple_scalar_request(
258 "open-ils.storage.biblio.record_entry.retrieve_by_barcode", $barcode );
260 return { ids => [ $title->id ], count => 1 } if $title;
261 return { count => 0 };
265 __PACKAGE__->register_method(
266 method => "biblio_copy_to_mods",
267 api_name => "open-ils.search.biblio.copy.mods.retrieve",
270 # takes a copy object and returns it fleshed mods object
271 sub biblio_copy_to_mods {
272 my( $self, $client, $copy ) = @_;
274 my $volume = $U->storagereq(
275 "open-ils.storage.direct.asset.call_number.retrieve",
276 $copy->call_number() );
278 my $mods = _records_to_mods($volume->record());
279 $mods = shift @$mods;
280 $volume->copies([$copy]);
281 push @{$mods->call_numbers()}, $volume;
287 # ----------------------------------------------------------------------------
288 # These are the main OPAC search methods
289 # ----------------------------------------------------------------------------
291 __PACKAGE__->register_method(
292 method => 'the_quest_for_knowledge',
293 api_name => 'open-ils.search.biblio.multiclass',
295 Performs a multi class bilbli or metabib search
296 @param searchhash A search object layed out like so:
297 searches : { "$class" : "$value", ...}
298 org_unit : The org id to focus the search at
299 depth : The org depth
300 limit : The search limit
301 offset : The search offset
302 format : The MARC format
303 sort : What field to sort the results on [ author | title | pubdate ]
304 sort_dir : What direction do we sort? [ asc | desc ]
305 @return An object of the form
306 { "count" : $count, "ids" : [ [ $id, $relevancy, $total ], ...] }
310 __PACKAGE__->register_method(
311 method => 'the_quest_for_knowledge',
312 api_name => 'open-ils.search.biblio.multiclass.staff',
313 signature => q/@see open-ils.search.biblio.multiclass/);
314 __PACKAGE__->register_method(
315 method => 'the_quest_for_knowledge',
316 api_name => 'open-ils.search.metabib.multiclass',
317 signature => q/@see open-ils.search.biblio.multiclass/);
318 __PACKAGE__->register_method(
319 method => 'the_quest_for_knowledge',
320 api_name => 'open-ils.search.metabib.multiclass.staff',
321 signature => q/@see open-ils.search.biblio.multiclass/);
325 sub the_quest_for_knowledge {
326 my( $self, $conn, $searchhash ) = @_;
328 my $method = 'open-ils.storage.biblio.multiclass.search_fts';
334 my $o = $searchhash->{offset} || 0;
335 my $l = $searchhash->{limit} || 10;
336 $searchhash->{offset} = 0;
337 $searchhash->{limit} = 0;
339 my $ckey = $pfx . md5_hex($method . JSON->perl2JSON($searchhash));
341 $searchhash->{offset} = $o;
342 $searchhash->{limit} = $l;
345 if($self->api_name =~ /metabib/) {
347 $method =~ s/biblio/metabib/o;
350 # don't cache past max limit
351 my $result = ($o < $maxlimit) ? search_cache($ckey, $o, $l) : undef;
356 $method .= ".staff" if($self->api_name =~ /staff/);
357 $method .= ".atomic";
359 for (keys %$searchhash) {
360 delete $$searchhash{$_} unless defined $$searchhash{$_}; }
362 $searchhash->{limit} = $maxlimit;
363 $result = new_editor()->request( $method, %$searchhash );
367 $logger->debug("cache returned results: " . JSON->perl2JSON($result));
371 return {count => 0} unless ($result && $$result[0]);
373 for my $r (@$result) { push(@recs, $r) if ($r and $$r[0]); }
376 $logger->debug("putting search cache $ckey\n");
377 $cache->put_cache($ckey, \@recs, 900);
380 return { ids => \@recs,
381 count => ($ismeta) ? $result->[0]->[3] : $result->[0]->[2] };
386 #$cache_handle->put_cache( "_open-ils_seed_$username", $seed, 30 );
387 #my $current_seed = $cache_handle->get_cache("_open-ils_seed_$username");
388 #$cache_handle->delete_cache( "_open-ils_seed_$username" );
396 $logger->debug("fetching search cache $key\n");
398 my $data = $cache->get_cache($key);
399 return undef unless $data;
401 $logger->debug("search_cache found some data: o=$offset, l=$limit");
403 #$data = JSON->JSON2perl($data);
404 return undef unless $data and ref $data eq 'ARRAY';
405 return undef unless $$data[$offset] and $$data[$offset+($limit-1)];
407 $logger->debug("search_cache found data..$offset - " . ($offset + ($limit - 1)));
408 return [ @$data[$offset..($offset+$limit)] ];
416 __PACKAGE__->register_method(
417 method => "biblio_mrid_to_modsbatch_batch",
418 api_name => "open-ils.search.biblio.metarecord.mods_slim.batch.retrieve");
420 sub biblio_mrid_to_modsbatch_batch {
421 my( $self, $client, $mrids) = @_;
422 warn "Performing mrid_to_modsbatch_batch...";
424 my $method = $self->method_lookup("open-ils.search.biblio.metarecord.mods_slim.retrieve");
425 for my $id (@$mrids) {
426 next unless defined $id;
427 my ($m) = $method->run($id);
434 __PACKAGE__->register_method(
435 method => "biblio_mrid_to_modsbatch",
436 api_name => "open-ils.search.biblio.metarecord.mods_slim.retrieve",
437 notes => <<" NOTES");
438 Returns the mvr associated with a given metarecod. If none exists,
442 __PACKAGE__->register_method(
443 method => "biblio_mrid_to_modsbatch",
444 api_name => "open-ils.search.biblio.metarecord.mods_slim.retrieve.staff",
445 notes => <<" NOTES");
446 Returns the mvr associated with a given metarecod. If none exists,
450 sub biblio_mrid_to_modsbatch {
451 my( $self, $client, $mrid ) = @_;
453 warn "Grabbing mvr for $mrid\n";
455 my ($mr, $evt) = _grab_metarecord($mrid);
456 return $evt unless $mr;
458 if( my $m = $self->biblio_mrid_check_mvr($client, $mr)) {
462 return $self->biblio_mrid_make_modsbatch( $client, $mr );
465 # converts a metarecord to an mvr
468 my $perl = JSON->JSON2perl($mr->mods());
469 return Fieldmapper::metabib::virtual_record->new($perl);
472 # checks to see if a metarecord has mods, if so returns true;
474 __PACKAGE__->register_method(
475 method => "biblio_mrid_check_mvr",
476 api_name => "open-ils.search.biblio.metarecord.mods_slim.check",
477 notes => <<" NOTES");
478 Takes a metarecord ID or a metarecord object and returns true
479 if the metarecord already has an mvr associated with it.
482 sub biblio_mrid_check_mvr {
483 my( $self, $client, $mrid ) = @_;
487 if(ref($mrid)) { $mr = $mrid; }
488 else { ($mr, $evt) = _grab_metarecord($mrid); }
491 warn "Checking mvr for mr " . $mr->id . "\n";
493 return _mr_to_mvr($mr) if $mr->mods();
497 sub _grab_metarecord {
499 my $e = OpenILS::Utils::Editor->new;
500 my $mr = $e->retrieve_metabib_metarecord($mrid) or return ( undef, $e->event );
505 __PACKAGE__->register_method(
506 method => "biblio_mrid_make_modsbatch",
507 api_name => "open-ils.search.biblio.metarecord.mods_slim.create",
508 notes => <<" NOTES");
509 Takes either a metarecord ID or a metarecord object.
510 Forces the creations of an mvr for the given metarecord.
511 The created mvr is returned.
514 sub biblio_mrid_make_modsbatch {
515 my( $self, $client, $mrid ) = @_;
517 my $e = OpenILS::Utils::Editor->new;
524 $mr = $e->retrieve_metabib_metarecord($mrid)
528 my $masterid = $mr->master_record;
529 $logger->info("creating new mods batch for metarecord=$mrid, master record=$masterid");
531 my $ids = $e->request(
532 'open-ils.storage.ordered.metabib.metarecord.records.staff.atomic', $mrid);
533 return undef unless @$ids;
535 my $master = $e->retrieve_biblio_record_entry($masterid)
538 # start the mods batch
539 my $u = OpenILS::Utils::ModsParser->new();
540 $u->start_mods_batch( $master->marc );
542 # grab all of the sub-records and shove them into the batch
543 my @ids = grep { $_ ne $masterid } @$ids;
544 my $subrecs = $e->batch_retrieve_biblio_record_entry(\@ids);
547 $logger->debug("adding record ".$_->id." to mods batch for metarecord=$mrid");
548 $u->push_mods_batch( $_->marc ) if $_->marc;
552 # finish up and send to the client
553 my $mods = $u->finish_mods_batch();
554 $mods->doc_id($mrid);
555 $client->respond_complete($mods);
558 # now update the mods string in the db
559 my $string = JSON->perl2JSON($mods->decast);
562 $e = OpenILS::Utils::Editor->new(xact => 1);
563 $e->update_metabib_metarecord($mr)
564 or $logger->error("Error setting mods text on metarecord $mrid : " . Dumper($e->event));
573 # converts a mr id into a list of record ids
575 __PACKAGE__->register_method(
576 method => "biblio_mrid_to_record_ids",
577 api_name => "open-ils.search.biblio.metarecord_to_records",
580 __PACKAGE__->register_method(
581 method => "biblio_mrid_to_record_ids",
582 api_name => "open-ils.search.biblio.metarecord_to_records.staff",
585 sub biblio_mrid_to_record_ids {
586 my( $self, $client, $mrid, $args ) = @_;
588 my $format = $$args{format};
589 my $org = $$args{org};
590 my $depth = $$args{depth};
592 my $method = "open-ils.storage.ordered.metabib.metarecord.records.atomic";
593 $method =~ s/atomic/staff\.atomic/o if $self->api_name =~ /staff/o;
594 my $recs = $U->storagereq($method, $mrid, $format, $org, $depth);
596 return { count => scalar(@$recs), ids => $recs };
600 __PACKAGE__->register_method(
601 method => "biblio_record_to_marc_html",
602 api_name => "open-ils.search.biblio.record.html" );
604 my $parser = XML::LibXML->new();
605 my $xslt = XML::LibXSLT->new();
608 my $settings_client = OpenSRF::Utils::SettingsClient->new();
609 sub biblio_record_to_marc_html {
610 my( $self, $client, $recordid ) = @_;
613 my $dir = $settings_client->config_value( "dirs", "xsl" );
614 my $xsl = $settings_client->config_value(
615 "apps", "open-ils.search", "app_settings", "marc_html_xsl" );
617 $xsl = $parser->parse_file("$dir/$xsl");
618 $marc_sheet = $xslt->parse_stylesheet( $xsl );
622 my $record = $apputils->simple_scalar_request(
624 "open-ils.storage.direct.biblio.record_entry.retrieve",
627 my $xmldoc = $parser->parse_string($record->marc);
628 my $html = $marc_sheet->transform($xmldoc);
629 $html = $html->toString();
636 __PACKAGE__->register_method(
637 method => "retrieve_all_copy_locations",
638 api_name => "open-ils.search.config.copy_location.retrieve.all" );
640 my $shelving_locations;
641 sub retrieve_all_copy_locations {
642 my( $self, $client ) = @_;
643 if(!$shelving_locations) {
644 $shelving_locations = $apputils->simple_scalar_request(
646 "open-ils.storage.direct.asset.copy_location.retrieve.all.atomic");
648 return $shelving_locations;
654 __PACKAGE__->register_method(
655 method => "retrieve_all_copy_statuses",
656 api_name => "open-ils.search.config.copy_status.retrieve.all" );
659 sub retrieve_all_copy_statuses {
660 my( $self, $client ) = @_;
661 if(!$copy_statuses) {
662 $copy_statuses = $apputils->simple_scalar_request(
664 "open-ils.storage.direct.config.copy_status.retrieve.all.atomic" );
666 return $copy_statuses;
670 __PACKAGE__->register_method(
671 method => "copy_counts_per_org",
672 api_name => "open-ils.search.biblio.copy_counts.retrieve");
674 __PACKAGE__->register_method(
675 method => "copy_counts_per_org",
676 api_name => "open-ils.search.biblio.copy_counts.retrieve.staff");
678 sub copy_counts_per_org {
679 my( $self, $client, $record_id ) = @_;
681 warn "Retreiveing copy copy counts for record $record_id and method " . $self->api_name . "\n";
683 my $method = "open-ils.storage.biblio.record_entry.global_copy_count.atomic";
684 if($self->api_name =~ /staff/) { $method =~ s/atomic/staff\.atomic/; }
686 my $counts = $apputils->simple_scalar_request(
687 "open-ils.storage", $method, $record_id );
689 $counts = [ sort {$a->[0] <=> $b->[0]} @$counts ];
694 __PACKAGE__->register_method(
695 method => "copy_count_summary",
696 api_name => "open-ils.search.biblio.copy_counts.summary.retrieve",
697 notes => <<" NOTES");
698 returns an array of these:
699 [ org_id, callnumber_label, <status1_count>, <status2_cout>,...]
700 where statusx is a copy status name. the statuses are sorted
704 sub copy_count_summary {
705 my( $self, $client, $rid, $org, $depth ) = @_;
708 return $U->storagereq(
709 'open-ils.storage.biblio.record_entry.status_copy_count.atomic', $rid, $org, $depth );
715 __PACKAGE__->register_method(
716 method => "multiclass_search",
717 api_name => "open-ils.search.biblio.multiclass",
718 notes => <<" NOTES");
719 Performs a multiclass search
720 PARAMS( searchBlob, org_unit, format, limit )
721 where searchBlob is defined like this:
723 "title" : { "term" : "water" },
724 "author" : { "term" : "smith" },
729 __PACKAGE__->register_method(
730 method => "multiclass_search",
731 api_name => "open-ils.search.biblio.multiclass.staff",
732 notes => "see open-ils.search.biblio.multiclass" );
734 sub multiclass_search {
735 my( $self, $client, $searchBlob, $orgid, $format, $limit ) = @_;
737 $logger->debug("Performing multiclass search with org => $orgid, " .
738 "format => $format, limit => $limit, and search blob " . Dumper($searchBlob));
740 my $meth = 'open-ils.storage.metabib.post_filter.multiclass.search_fts.metarecord.atomic';
741 if($self->api_name =~ /staff/) { $meth =~ s/metarecord\.atomic/metarecord.staff.atomic/; }
744 my $records = $apputils->simplereq(
745 'open-ils.storage', $meth,
746 org_unit => $orgid, searches => $searchBlob, format => $format, limit => $limit );
751 if( ref($records) and $records->[0] and
752 defined($records->[0]->[3])) { $count = $records->[0]->[3];}
754 for my $r (@$records) { push( @$recs, $r ) if ($r and $r->[0]); }
756 # records has the form: [ mrid, rank, singleRecord / 0, hitCount ];
757 return { ids => $recs, count => $count };
763 __PACKAGE__->register_method(
764 method => "multiclass_search",
765 api_name => "open-ils.search.biblio.multiclass",
767 Performs a multiclass search
768 @param args A names hash of arguments:
769 org_unit : The org to focus the search on
770 depth : The search depth
773 offset : Search offset
774 searches : A named hash of searches which has the following format:
776 "title" : { "term" : "water" },
777 "author" : { "term" : "smith" },
780 @return { ids : <array of ids>, count : hitcount }
784 __PACKAGE__->register_method(
785 method => "multiclass_search",
786 api_name => "open-ils.search.biblio.multiclass.staff",
787 notes => q/@see open-ils.search.biblio.multiclass/ );
789 sub multiclass_search {
790 my( $self, $client, $args ) = @_;
792 $logger->debug("Performing multiclass search with args:\n" . Dumper($args));
793 my $meth = 'open-ils.storage.metabib.post_filter.multiclass.search_fts.metarecord.atomic';
794 if($self->api_name =~ /staff/) { $meth =~ s/metarecord\.atomic/metarecord.staff.atomic/; }
796 my $records = $apputils->simplereq( 'open-ils.storage', $meth, %$args );
801 if( ref($records) and $records->[0] and
802 defined($records->[0]->[3])) { $count = $records->[0]->[3];}
804 for my $r (@$records) { push( @$recs, $r ) if ($r and $r->[0]); }
806 return { ids => $recs, count => $count };
813 __PACKAGE__->register_method(
814 method => "marc_search",
815 api_name => "open-ils.search.biblio.marc.staff");
817 __PACKAGE__->register_method(
818 method => "marc_search",
819 api_name => "open-ils.search.biblio.marc",
820 notes => <<" NOTES");
822 open-ils.storage.biblio.full_rec.multi_search.atomic
823 { "searches": [{"term":"harry","restrict": [{"tag":245,"subfield":"a"}]}], "org_unit": 1,
824 "limit":5,"sort":"author","item_type":"g"}
828 my( $self, $conn, $args, $limit, $offset ) = @_;
830 my $method = 'open-ils.storage.biblio.full_rec.multi_search';
831 $method .= ".staff" if $self->api_name =~ /staff/;
832 $method .= ".atomic";
837 my $ckey = $pfx . md5_hex($method . JSON->perl2JSON($args));
838 my $recs = search_cache($ckey, $offset, $limit);
841 $recs = new_editor()->request($method, %$args);
842 $cache->put_cache($ckey, $recs, 900);
843 $recs = [ @$recs[$offset..($offset + ($limit - 1))] ];
847 $count = $recs->[0]->[2] if $recs->[0] and $recs->[0]->[2];
848 my @recs = map { $_->[0] } @$recs;
850 return { ids => \@recs, count => $count };
854 __PACKAGE__->register_method(
855 method => "biblio_search_isbn",
856 api_name => "open-ils.search.biblio.isbn",
859 sub biblio_search_isbn {
860 my( $self, $client, $isbn ) = @_;
861 $logger->debug("Searching ISBN $isbn");
862 my $e = new_editor();
863 my $recs = $e->request(
864 'open-ils.storage.id_list.biblio.record_entry.search.isbn.atomic', $isbn );
865 return { ids => $recs, count => scalar(@$recs) };
869 __PACKAGE__->register_method(
870 method => "biblio_search_issn",
871 api_name => "open-ils.search.biblio.issn",
874 sub biblio_search_issn {
875 my( $self, $client, $issn ) = @_;
876 $logger->debug("Searching ISSN $issn");
877 my $e = new_editor();
878 my $recs = $e->request(
879 'open-ils.storage.id_list.biblio.record_entry.search.issn.atomic', $issn );
880 return { ids => $recs, count => scalar(@$recs) };
886 __PACKAGE__->register_method(
887 method => "fetch_mods_by_copy",
888 api_name => "open-ils.search.biblio.mods_from_copy",
891 sub fetch_mods_by_copy {
892 my( $self, $client, $copyid ) = @_;
893 my ($record, $evt) = $apputils->fetch_record_by_copy( $copyid );
895 return OpenILS::Event->new('ITEM_NOT_CATALOGED') unless $record->marc;
896 return $apputils->record_to_mvr($record);
901 # -------------------------------------------------------------------------------------
903 __PACKAGE__->register_method(
904 method => "cn_browse",
905 api_name => "open-ils.search.callnumber.browse.target",
906 notes => "Starts a callnumber browse"
909 __PACKAGE__->register_method(
910 method => "cn_browse",
911 api_name => "open-ils.search.callnumber.browse.page_up",
912 notes => "Returns the previous page of callnumbers",
915 __PACKAGE__->register_method(
916 method => "cn_browse",
917 api_name => "open-ils.search.callnumber.browse.page_down",
918 notes => "Returns the next page of callnumbers",
922 # RETURNS array of arrays like so: label, owning_lib, record, id
924 my( $self, $client, @params ) = @_;
927 $method = 'open-ils.storage.asset.call_number.browse.target.atomic'
928 if( $self->api_name =~ /target/ );
929 $method = 'open-ils.storage.asset.call_number.browse.page_up.atomic'
930 if( $self->api_name =~ /page_up/ );
931 $method = 'open-ils.storage.asset.call_number.browse.page_down.atomic'
932 if( $self->api_name =~ /page_down/ );
934 return $apputils->simplereq( 'open-ils.storage', $method, @params );
936 # -------------------------------------------------------------------------------------
938 __PACKAGE__->register_method(
939 method => "fetch_cn",
940 api_name => "open-ils.search.callnumber.retrieve",
941 notes => "retrieves a callnumber based on ID",
945 my( $self, $client, $id ) = @_;
946 my( $cn, $evt ) = $apputils->fetch_callnumber( $id );
951 __PACKAGE__->register_method (
952 method => "fetch_copy_by_cn",
953 api_name => 'open-ils.search.copies_by_call_number.retrieve',
955 Returns an array of copy id's by callnumber id
956 @param cnid The callnumber id
957 @return An array of copy ids
961 sub fetch_copy_by_cn {
962 my( $self, $conn, $cnid ) = @_;
963 return $U->storagereq(
964 'open-ils.storage.id_list.asset.copy.search_where.atomic',
965 { call_number => $cnid, deleted => 'f' } );
968 __PACKAGE__->register_method (
969 method => 'fetch_cn_by_info',
970 api_name => 'open-ils.search.call_number.retrieve_by_info',
972 @param label The callnumber label
973 @param record The record the cn is attached to
974 @param org The owning library of the cn
975 @return The callnumber object
980 sub fetch_cn_by_info {
981 my( $self, $conn, $label, $record, $org ) = @_;
982 return $U->storagereq(
983 'open-ils.storage.direct.asset.call_number.search_where',
984 { label => $label, record => $record, owning_lib => $org, deleted => 'f' });
991 __PACKAGE__->register_method (
992 method => 'bib_extras',
993 api_name => 'open-ils.search.biblio.lit_form_map.retrieve.all');
994 __PACKAGE__->register_method (
995 method => 'bib_extras',
996 api_name => 'open-ils.search.biblio.item_form_map.retrieve.all');
997 __PACKAGE__->register_method (
998 method => 'bib_extras',
999 api_name => 'open-ils.search.biblio.item_type_map.retrieve.all');
1000 __PACKAGE__->register_method (
1001 method => 'bib_extras',
1002 api_name => 'open-ils.search.biblio.audience_map.retrieve.all');
1007 return $U->storagereq(
1008 'open-ils.storage.direct.config.lit_form_map.retrieve.all.atomic')
1009 if( $self->api_name =~ /lit_form/ );
1011 return $U->storagereq(
1012 'open-ils.storage.direct.config.item_form_map.retrieve.all.atomic')
1013 if( $self->api_name =~ /item_form_map/ );
1015 return $U->storagereq(
1016 'open-ils.storage.direct.config.item_type_map.retrieve.all.atomic')
1017 if( $self->api_name =~ /item_type_map/ );
1019 return $U->storagereq(
1020 'open-ils.storage.direct.config.audience_map.retrieve.all.atomic')
1021 if( $self->api_name =~ /audience/ );
1028 __PACKAGE__->register_method(
1029 method => 'fetch_slim_record',
1030 api_name => 'open-ils.search.biblio.record_entry.slim.retrieve',
1032 Returns a biblio.record_entry without the attached marcxml
1036 sub fetch_slim_record {
1037 my( $self, $conn, $ids ) = @_;
1039 my $editor = OpenILS::Utils::Editor->new;
1042 return $editor->event unless
1043 my $r = $editor->retrieve_biblio_record_entry($_);