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::CStoreEditor 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_";
38 $cache = OpenSRF::Utils::Cache->new('global');
39 my $sclient = OpenSRF::Utils::SettingsClient->new();
40 $cache_timeout = $sclient->config_value(
41 "apps", "open-ils.search", "app_settings", "cache_timeout" ) || 300;
42 $logger->info("Search cache timeout is $cache_timeout");
47 # ---------------------------------------------------------------------------
48 # takes a list of record id's and turns the docs into friendly
49 # mods structures. Creates one MODS structure for each doc id.
50 # ---------------------------------------------------------------------------
51 sub _records_to_mods {
57 my $session = OpenSRF::AppSession->create("open-ils.storage");
58 my $request = $session->request(
59 "open-ils.storage.direct.biblio.record_entry.batch.retrieve", @ids );
61 while( my $resp = $request->recv ) {
62 my $content = $resp->content;
63 my $u = OpenILS::Utils::ModsParser->new();
64 $u->start_mods_batch( $content->marc );
65 my $mods = $u->finish_mods_batch();
66 $mods->doc_id($content->id());
67 $mods->tcn($content->tcn_value);
71 $session->disconnect();
75 __PACKAGE__->register_method(
76 method => "record_id_to_mods",
77 api_name => "open-ils.search.biblio.record.mods.retrieve",
79 note => "Provide ID, we provide the mods"
82 # converts a record into a mods object with copy counts attached
83 sub record_id_to_mods {
85 my( $self, $client, $org_id, $id ) = @_;
87 my $mods_list = _records_to_mods( $id );
88 my $mods_obj = $mods_list->[0];
89 my $cmethod = $self->method_lookup(
90 "open-ils.search.biblio.record.copy_count");
91 my ($count) = $cmethod->run($org_id, $id);
92 $mods_obj->copy_count($count);
99 __PACKAGE__->register_method(
100 method => "record_id_to_mods_slim",
101 api_name => "open-ils.search.biblio.record.mods_slim.retrieve",
103 note => "Provide ID, we provide the mods"
106 # converts a record into a mods object with NO copy counts attached
107 sub record_id_to_mods_slim {
108 my( $self, $client, $id ) = @_;
109 return undef unless defined $id;
111 if(ref($id) and ref($id) == 'ARRAY') {
112 return _records_to_mods( @$id );
114 my $mods_list = _records_to_mods( $id );
115 my $mods_obj = $mods_list->[0];
120 # Returns the number of copies attached to a record based on org location
121 __PACKAGE__->register_method(
122 method => "record_id_to_copy_count",
123 api_name => "open-ils.search.biblio.record.copy_count",
126 __PACKAGE__->register_method(
127 method => "record_id_to_copy_count",
128 api_name => "open-ils.search.biblio.record.copy_count.staff",
131 __PACKAGE__->register_method(
132 method => "record_id_to_copy_count",
133 api_name => "open-ils.search.biblio.metarecord.copy_count",
136 __PACKAGE__->register_method(
137 method => "record_id_to_copy_count",
138 api_name => "open-ils.search.biblio.metarecord.copy_count.staff",
140 sub record_id_to_copy_count {
141 my( $self, $client, $org_id, $record_id, $format ) = @_;
143 return [] unless $record_id;
144 $format = undef if (!$format or $format eq 'all');
146 my $method = "open-ils.storage.biblio.record_entry.copy_count.atomic";
149 if($self->api_name =~ /metarecord/) {
150 $method = "open-ils.storage.metabib.metarecord.copy_count.atomic";
154 $method =~ s/atomic/staff\.atomic/og if($self->api_name =~ /staff/ );
156 my $count = $U->storagereq( $method,
157 org_unit => $org_id, $key => $record_id, format => $format );
159 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;
178 my $e = new_editor();
179 my $recs = $e->search_biblio_record_entry(
180 {deleted => 'f', tcn_value => $tcn}, {idlist =>1});
182 return { count => scalar(@$recs), ids => $recs };
186 # --------------------------------------------------------------------------------
188 __PACKAGE__->register_method(
189 method => "biblio_barcode_to_copy",
190 api_name => "open-ils.search.asset.copy.find_by_barcode",);
191 sub biblio_barcode_to_copy {
192 my( $self, $client, $barcode ) = @_;
193 my( $copy, $evt ) = $U->fetch_copy_by_barcode($barcode);
198 __PACKAGE__->register_method(
199 method => "biblio_id_to_copy",
200 api_name => "open-ils.search.asset.copy.batch.retrieve",);
201 sub biblio_id_to_copy {
202 my( $self, $client, $ids ) = @_;
203 $logger->info("Fetching copies @$ids");
204 return $U->storagereq(
205 "open-ils.storage.direct.asset.copy.batch.retrieve.atomic", @$ids );
209 __PACKAGE__->register_method(
210 method => "copy_retrieve",
211 api_name => "open-ils.search.asset.copy.retrieve",);
213 my( $self, $client, $cid ) = @_;
214 my( $copy, $evt ) = $U->fetch_copy($cid);
219 __PACKAGE__->register_method(
220 method => "volume_retrieve",
221 api_name => "open-ils.search.asset.call_number.retrieve");
222 sub volume_retrieve {
223 my( $self, $client, $vid ) = @_;
224 my $e = new_editor();
225 my $vol = $e->retrieve_asset_call_number($vid) or return $e->event;
229 __PACKAGE__->register_method(
230 method => "fleshed_copy_retrieve_batch",
231 api_name => "open-ils.search.asset.copy.fleshed.batch.retrieve");
233 sub fleshed_copy_retrieve_batch {
234 my( $self, $client, $ids ) = @_;
235 $logger->info("Fetching fleshed copies @$ids");
236 return $U->storagereq(
237 "open-ils.storage.fleshed.asset.copy.batch.retrieve.atomic", @$ids );
241 __PACKAGE__->register_method(
242 method => "fleshed_copy_retrieve",
243 api_name => "open-ils.search.asset.copy.fleshed.retrieve",);
245 sub fleshed_copy_retrieve {
246 my( $self, $client, $id ) = @_;
247 my( $c, $e) = $U->fetch_fleshed_copy($id);
254 __PACKAGE__->register_method(
255 method => "biblio_barcode_to_title",
256 api_name => "open-ils.search.biblio.find_by_barcode",
259 sub biblio_barcode_to_title {
260 my( $self, $client, $barcode ) = @_;
262 my $title = $apputils->simple_scalar_request(
264 "open-ils.storage.biblio.record_entry.retrieve_by_barcode", $barcode );
266 return { ids => [ $title->id ], count => 1 } if $title;
267 return { count => 0 };
271 __PACKAGE__->register_method(
272 method => "biblio_copy_to_mods",
273 api_name => "open-ils.search.biblio.copy.mods.retrieve",
276 # takes a copy object and returns it fleshed mods object
277 sub biblio_copy_to_mods {
278 my( $self, $client, $copy ) = @_;
280 my $volume = $U->storagereq(
281 "open-ils.storage.direct.asset.call_number.retrieve",
282 $copy->call_number() );
284 my $mods = _records_to_mods($volume->record());
285 $mods = shift @$mods;
286 $volume->copies([$copy]);
287 push @{$mods->call_numbers()}, $volume;
293 # ----------------------------------------------------------------------------
294 # These are the main OPAC search methods
295 # ----------------------------------------------------------------------------
297 __PACKAGE__->register_method(
298 method => 'the_quest_for_knowledge',
299 api_name => 'open-ils.search.biblio.multiclass',
301 Performs a multi class bilbli or metabib search
302 @param searchhash A search object layed out like so:
303 searches : { "$class" : "$value", ...}
304 org_unit : The org id to focus the search at
305 depth : The org depth
306 limit : The search limit
307 offset : The search offset
308 format : The MARC format
309 sort : What field to sort the results on [ author | title | pubdate ]
310 sort_dir : What direction do we sort? [ asc | desc ]
311 @return An object of the form
312 { "count" : $count, "ids" : [ [ $id, $relevancy, $total ], ...] }
316 __PACKAGE__->register_method(
317 method => 'the_quest_for_knowledge',
318 api_name => 'open-ils.search.biblio.multiclass.staff',
319 signature => q/@see open-ils.search.biblio.multiclass/);
320 __PACKAGE__->register_method(
321 method => 'the_quest_for_knowledge',
322 api_name => 'open-ils.search.metabib.multiclass',
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.staff',
327 signature => q/@see open-ils.search.biblio.multiclass/);
331 sub the_quest_for_knowledge {
332 my( $self, $conn, $searchhash ) = @_;
334 return { count => 0 } unless $searchhash and
335 ref $searchhash->{searches} eq 'HASH';
337 my $method = 'open-ils.storage.biblio.multiclass.search_fts';
342 my $offset = $searchhash->{offset} || 0;
343 my $limit = $searchhash->{limit} || 10;
344 my $end = $offset + $limit - 1;
347 $searchhash->{offset} = 0;
348 $searchhash->{limit} = $maxlimit;
351 push( @search, ($_ => $$searchhash{$_})) for (sort keys %$searchhash);
352 my $ckey = $pfx . md5_hex($method . JSON->perl2JSON(\@search));
354 $searchhash->{limit} -= $offset;
356 if($self->api_name =~ /metabib/) {
358 $method =~ s/biblio/metabib/o;
361 # don't cache past max limit
362 my $result = ($end < $searchhash->{limit}) ?
363 search_cache($ckey, $offset, $limit) : undef;
368 $method .= ".staff" if($self->api_name =~ /staff/);
369 $method .= ".atomic";
371 for (keys %$searchhash) {
372 delete $$searchhash{$_} unless defined $$searchhash{$_}; }
374 #$searchhash->{limit} = $maxlimit;
380 $result = $U->storagereq( $method, %$searchhash );
385 my $errstr = "Multiclass search failed. Args = " .
386 JSON->perl2JSON($searchhash) . "\nError = $err";
388 $logger->error($errstr);
392 throw $err ($errstr) if $err;
399 return {count => 0} unless ($result && $$result[0]);
401 for my $r (@$result) { push(@recs, $r) if ($r and $$r[0]); }
404 if( $docache and ($end < $maxlimit) ) {
405 # If we didn't get this data from the cache, put it into the cache
406 # then return the correct offset of records
407 $logger->debug("putting search cache $ckey\n");
408 put_cache($ckey, \@recs);
411 for ($offset..$end) {
412 last if $_ > scalar(@recs);
413 push(@t, $recs[$_]) if $recs[$_];
417 #$logger->debug("cache done .. returning $offset..$end : " . JSON->perl2JSON(\@recs));
420 return { ids => \@recs,
421 count => ($ismeta) ? $result->[0]->[3] : $result->[0]->[2] };
434 my $end = $offset + $limit - 1;
436 $logger->debug("searching cache for $key : $start..$end\n");
438 return undef unless $cache;
439 my $data = $cache->get_cache($key);
441 #return undef unless $data and ref $data eq 'ARRAY' and $$data[$start] and $$data[$end];
442 return undef unless $data and ref $data eq 'ARRAY' and $$data[$start] and $$data[$end];
444 #$logger->debug("search_cache found data " . JSON->perl2JSON($data));
445 $logger->debug("search_cache found data for indices $start..$end");
447 my $result = [ (@$data[$start..$end]) ];
449 $logger->debug("cache returning results: [".
450 JSON->perl2JSON($$result[0]) . '...' .
451 JSON->perl2JSON($$result[$limit-1]) .']' );
458 my( $key, $data ) = @_;
459 return undef unless $cache;
460 $logger->debug("search_cache putting ".
461 scalar(@$data)." items at key $key with timeout $cache_timeout");
462 $cache->put_cache($key, $data, $cache_timeout);
470 __PACKAGE__->register_method(
471 method => "biblio_mrid_to_modsbatch_batch",
472 api_name => "open-ils.search.biblio.metarecord.mods_slim.batch.retrieve");
474 sub biblio_mrid_to_modsbatch_batch {
475 my( $self, $client, $mrids) = @_;
476 warn "Performing mrid_to_modsbatch_batch...";
478 my $method = $self->method_lookup("open-ils.search.biblio.metarecord.mods_slim.retrieve");
479 for my $id (@$mrids) {
480 next unless defined $id;
481 my ($m) = $method->run($id);
488 __PACKAGE__->register_method(
489 method => "biblio_mrid_to_modsbatch",
490 api_name => "open-ils.search.biblio.metarecord.mods_slim.retrieve",
491 notes => <<" NOTES");
492 Returns the mvr associated with a given metarecod. If none exists,
496 __PACKAGE__->register_method(
497 method => "biblio_mrid_to_modsbatch",
498 api_name => "open-ils.search.biblio.metarecord.mods_slim.retrieve.staff",
499 notes => <<" NOTES");
500 Returns the mvr associated with a given metarecod. If none exists,
504 sub biblio_mrid_to_modsbatch {
505 my( $self, $client, $mrid ) = @_;
507 warn "Grabbing mvr for $mrid\n";
509 my ($mr, $evt) = _grab_metarecord($mrid);
510 return $evt unless $mr;
512 if( my $m = $self->biblio_mrid_check_mvr($client, $mr)) {
516 return $self->biblio_mrid_make_modsbatch( $client, $mr );
519 # converts a metarecord to an mvr
522 my $perl = JSON->JSON2perl($mr->mods());
523 return Fieldmapper::metabib::virtual_record->new($perl);
526 # checks to see if a metarecord has mods, if so returns true;
528 __PACKAGE__->register_method(
529 method => "biblio_mrid_check_mvr",
530 api_name => "open-ils.search.biblio.metarecord.mods_slim.check",
531 notes => <<" NOTES");
532 Takes a metarecord ID or a metarecord object and returns true
533 if the metarecord already has an mvr associated with it.
536 sub biblio_mrid_check_mvr {
537 my( $self, $client, $mrid ) = @_;
541 if(ref($mrid)) { $mr = $mrid; }
542 else { ($mr, $evt) = _grab_metarecord($mrid); }
545 warn "Checking mvr for mr " . $mr->id . "\n";
547 return _mr_to_mvr($mr) if $mr->mods();
551 sub _grab_metarecord {
553 #my $e = OpenILS::Utils::Editor->new;
554 my $e = new_editor();
555 my $mr = $e->retrieve_metabib_metarecord($mrid) or return ( undef, $e->event );
560 __PACKAGE__->register_method(
561 method => "biblio_mrid_make_modsbatch",
562 api_name => "open-ils.search.biblio.metarecord.mods_slim.create",
563 notes => <<" NOTES");
564 Takes either a metarecord ID or a metarecord object.
565 Forces the creations of an mvr for the given metarecord.
566 The created mvr is returned.
569 sub biblio_mrid_make_modsbatch {
570 my( $self, $client, $mrid ) = @_;
572 #my $e = OpenILS::Utils::Editor->new;
573 my $e = new_editor();
580 $mr = $e->retrieve_metabib_metarecord($mrid)
584 my $masterid = $mr->master_record;
585 $logger->info("creating new mods batch for metarecord=$mrid, master record=$masterid");
587 my $ids = $U->storagereq(
588 'open-ils.storage.ordered.metabib.metarecord.records.staff.atomic', $mrid);
589 return undef unless @$ids;
591 my $master = $e->retrieve_biblio_record_entry($masterid)
594 # start the mods batch
595 my $u = OpenILS::Utils::ModsParser->new();
596 $u->start_mods_batch( $master->marc );
598 # grab all of the sub-records and shove them into the batch
599 my @ids = grep { $_ ne $masterid } @$ids;
600 my $subrecs = $e->batch_retrieve_biblio_record_entry(\@ids);
603 $logger->debug("adding record ".$_->id." to mods batch for metarecord=$mrid");
604 $u->push_mods_batch( $_->marc ) if $_->marc;
608 # finish up and send to the client
609 my $mods = $u->finish_mods_batch();
610 $mods->doc_id($mrid);
611 $client->respond_complete($mods);
614 # now update the mods string in the db
615 my $string = JSON->perl2JSON($mods->decast);
618 #$e = OpenILS::Utils::Editor->new(xact => 1);
619 $e = new_editor(xact => 1);
620 $e->update_metabib_metarecord($mr)
621 or $logger->error("Error setting mods text on metarecord $mrid : " . Dumper($e->event));
630 # converts a mr id into a list of record ids
632 __PACKAGE__->register_method(
633 method => "biblio_mrid_to_record_ids",
634 api_name => "open-ils.search.biblio.metarecord_to_records",
637 __PACKAGE__->register_method(
638 method => "biblio_mrid_to_record_ids",
639 api_name => "open-ils.search.biblio.metarecord_to_records.staff",
642 sub biblio_mrid_to_record_ids {
643 my( $self, $client, $mrid, $args ) = @_;
645 my $format = $$args{format};
646 my $org = $$args{org};
647 my $depth = $$args{depth};
649 my $method = "open-ils.storage.ordered.metabib.metarecord.records.atomic";
650 $method =~ s/atomic/staff\.atomic/o if $self->api_name =~ /staff/o;
651 my $recs = $U->storagereq($method, $mrid, $format, $org, $depth);
653 return { count => scalar(@$recs), ids => $recs };
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 return $copy_statuses if $copy_statuses;
719 return $copy_statuses =
720 new_editor()->retrieve_all_config_copy_status();
724 __PACKAGE__->register_method(
725 method => "copy_counts_per_org",
726 api_name => "open-ils.search.biblio.copy_counts.retrieve");
728 __PACKAGE__->register_method(
729 method => "copy_counts_per_org",
730 api_name => "open-ils.search.biblio.copy_counts.retrieve.staff");
732 sub copy_counts_per_org {
733 my( $self, $client, $record_id ) = @_;
735 warn "Retreiveing copy copy counts for record $record_id and method " . $self->api_name . "\n";
737 my $method = "open-ils.storage.biblio.record_entry.global_copy_count.atomic";
738 if($self->api_name =~ /staff/) { $method =~ s/atomic/staff\.atomic/; }
740 my $counts = $apputils->simple_scalar_request(
741 "open-ils.storage", $method, $record_id );
743 $counts = [ sort {$a->[0] <=> $b->[0]} @$counts ];
748 __PACKAGE__->register_method(
749 method => "copy_count_summary",
750 api_name => "open-ils.search.biblio.copy_counts.summary.retrieve",
751 notes => <<" NOTES");
752 returns an array of these:
753 [ org_id, callnumber_label, <status1_count>, <status2_cout>,...]
754 where statusx is a copy status name. the statuses are sorted
758 sub copy_count_summary {
759 my( $self, $client, $rid, $org, $depth ) = @_;
762 return $U->storagereq(
763 'open-ils.storage.biblio.record_entry.status_copy_count.atomic', $rid, $org, $depth );
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 };
817 __PACKAGE__->register_method(
818 method => "multiclass_search",
819 api_name => "open-ils.search.biblio.multiclass",
821 Performs a multiclass search
822 @param args A names hash of arguments:
823 org_unit : The org to focus the search on
824 depth : The search depth
827 offset : Search offset
828 searches : A named hash of searches which has the following format:
830 "title" : { "term" : "water" },
831 "author" : { "term" : "smith" },
834 @return { ids : <array of ids>, count : hitcount }
838 __PACKAGE__->register_method(
839 method => "multiclass_search",
840 api_name => "open-ils.search.biblio.multiclass.staff",
841 notes => q/@see open-ils.search.biblio.multiclass/ );
843 sub multiclass_search {
844 my( $self, $client, $args ) = @_;
846 $logger->debug("Performing multiclass search with args:\n" . Dumper($args));
847 my $meth = 'open-ils.storage.metabib.post_filter.multiclass.search_fts.metarecord.atomic';
848 if($self->api_name =~ /staff/) { $meth =~ s/metarecord\.atomic/metarecord.staff.atomic/; }
850 my $records = $apputils->simplereq( 'open-ils.storage', $meth, %$args );
855 if( ref($records) and $records->[0] and
856 defined($records->[0]->[3])) { $count = $records->[0]->[3];}
858 for my $r (@$records) { push( @$recs, $r ) if ($r and $r->[0]); }
860 return { ids => $recs, count => $count };
867 __PACKAGE__->register_method(
868 method => "marc_search",
869 api_name => "open-ils.search.biblio.marc.staff");
871 __PACKAGE__->register_method(
872 method => "marc_search",
873 api_name => "open-ils.search.biblio.marc",
874 notes => <<" NOTES");
876 open-ils.storage.biblio.full_rec.multi_search.atomic
877 { "searches": [{"term":"harry","restrict": [{"tag":245,"subfield":"a"}]}], "org_unit": 1,
878 "limit":5,"sort":"author","item_type":"g"}
882 my( $self, $conn, $args, $limit, $offset ) = @_;
884 my $method = 'open-ils.storage.biblio.full_rec.multi_search';
885 $method .= ".staff" if $self->api_name =~ /staff/;
886 $method .= ".atomic";
892 push( @search, ($_ => $$args{$_}) ) for (sort keys %$args);
893 my $ckey = $pfx . md5_hex($method . JSON->perl2JSON(\@search));
895 my $recs = search_cache($ckey, $offset, $limit);
898 $recs = $U->storagereq($method, %$args);
899 put_cache($ckey, $recs);
900 $recs = [ @$recs[$offset..($offset + ($limit - 1))] ];
904 $count = $recs->[0]->[2] if $recs->[0] and $recs->[0]->[2];
905 my @recs = map { $_->[0] } @$recs;
907 return { ids => \@recs, count => $count };
911 __PACKAGE__->register_method(
912 method => "biblio_search_isbn",
913 api_name => "open-ils.search.biblio.isbn",
916 sub biblio_search_isbn {
917 my( $self, $client, $isbn ) = @_;
918 $logger->debug("Searching ISBN $isbn");
919 my $e = new_editor();
920 my $recs = $U->storagereq(
921 'open-ils.storage.id_list.biblio.record_entry.search.isbn.atomic', $isbn );
922 return { ids => $recs, count => scalar(@$recs) };
926 __PACKAGE__->register_method(
927 method => "biblio_search_issn",
928 api_name => "open-ils.search.biblio.issn",
931 sub biblio_search_issn {
932 my( $self, $client, $issn ) = @_;
933 $logger->debug("Searching ISSN $issn");
934 my $e = new_editor();
935 my $recs = $U->storagereq(
936 'open-ils.storage.id_list.biblio.record_entry.search.issn.atomic', $issn );
937 return { ids => $recs, count => scalar(@$recs) };
943 __PACKAGE__->register_method(
944 method => "fetch_mods_by_copy",
945 api_name => "open-ils.search.biblio.mods_from_copy",
948 sub fetch_mods_by_copy {
949 my( $self, $client, $copyid ) = @_;
950 my ($record, $evt) = $apputils->fetch_record_by_copy( $copyid );
952 return OpenILS::Event->new('ITEM_NOT_CATALOGED') unless $record->marc;
953 return $apputils->record_to_mvr($record);
958 # -------------------------------------------------------------------------------------
960 __PACKAGE__->register_method(
961 method => "cn_browse",
962 api_name => "open-ils.search.callnumber.browse.target",
963 notes => "Starts a callnumber browse"
966 __PACKAGE__->register_method(
967 method => "cn_browse",
968 api_name => "open-ils.search.callnumber.browse.page_up",
969 notes => "Returns the previous page of callnumbers",
972 __PACKAGE__->register_method(
973 method => "cn_browse",
974 api_name => "open-ils.search.callnumber.browse.page_down",
975 notes => "Returns the next page of callnumbers",
979 # RETURNS array of arrays like so: label, owning_lib, record, id
981 my( $self, $client, @params ) = @_;
984 $method = 'open-ils.storage.asset.call_number.browse.target.atomic'
985 if( $self->api_name =~ /target/ );
986 $method = 'open-ils.storage.asset.call_number.browse.page_up.atomic'
987 if( $self->api_name =~ /page_up/ );
988 $method = 'open-ils.storage.asset.call_number.browse.page_down.atomic'
989 if( $self->api_name =~ /page_down/ );
991 return $apputils->simplereq( 'open-ils.storage', $method, @params );
993 # -------------------------------------------------------------------------------------
995 __PACKAGE__->register_method(
996 method => "fetch_cn",
997 api_name => "open-ils.search.callnumber.retrieve",
998 notes => "retrieves a callnumber based on ID",
1002 my( $self, $client, $id ) = @_;
1003 my( $cn, $evt ) = $apputils->fetch_callnumber( $id );
1004 return $evt if $evt;
1008 __PACKAGE__->register_method (
1009 method => "fetch_copy_by_cn",
1010 api_name => 'open-ils.search.copies_by_call_number.retrieve',
1012 Returns an array of copy id's by callnumber id
1013 @param cnid The callnumber id
1014 @return An array of copy ids
1018 sub fetch_copy_by_cn {
1019 my( $self, $conn, $cnid ) = @_;
1020 return $U->storagereq(
1021 'open-ils.storage.id_list.asset.copy.search_where.atomic',
1022 { call_number => $cnid, deleted => 'f' } );
1025 __PACKAGE__->register_method (
1026 method => 'fetch_cn_by_info',
1027 api_name => 'open-ils.search.call_number.retrieve_by_info',
1029 @param label The callnumber label
1030 @param record The record the cn is attached to
1031 @param org The owning library of the cn
1032 @return The callnumber object
1037 sub fetch_cn_by_info {
1038 my( $self, $conn, $label, $record, $org ) = @_;
1039 return $U->storagereq(
1040 'open-ils.storage.direct.asset.call_number.search_where',
1041 { label => $label, record => $record, owning_lib => $org, deleted => 'f' });
1048 __PACKAGE__->register_method (
1049 method => 'bib_extras',
1050 api_name => 'open-ils.search.biblio.lit_form_map.retrieve.all');
1051 __PACKAGE__->register_method (
1052 method => 'bib_extras',
1053 api_name => 'open-ils.search.biblio.item_form_map.retrieve.all');
1054 __PACKAGE__->register_method (
1055 method => 'bib_extras',
1056 api_name => 'open-ils.search.biblio.item_type_map.retrieve.all');
1057 __PACKAGE__->register_method (
1058 method => 'bib_extras',
1059 api_name => 'open-ils.search.biblio.audience_map.retrieve.all');
1064 my $e = new_editor();
1066 return $e->retrieve_all_config_lit_form_map()
1067 if( $self->api_name =~ /lit_form/ );
1069 return $e->retrieve_all_config_item_form_map()
1070 if( $self->api_name =~ /item_form_map/ );
1072 return $e->retrieve_all_config_item_type_map()
1073 if( $self->api_name =~ /item_type_map/ );
1075 return $e->retrieve_all_config_audience_map()
1076 if( $self->api_name =~ /audience_map/ );
1083 __PACKAGE__->register_method(
1084 method => 'fetch_slim_record',
1085 api_name => 'open-ils.search.biblio.record_entry.slim.retrieve',
1087 Returns a biblio.record_entry without the attached marcxml
1091 sub fetch_slim_record {
1092 my( $self, $conn, $ids ) = @_;
1094 #my $editor = OpenILS::Utils::Editor->new;
1095 my $editor = new_editor();
1098 return $editor->event unless
1099 my $r = $editor->retrieve_biblio_record_entry($_);
1108 __PACKAGE__->register_method(
1109 method => 'rec_to_mr_rec_descriptors',
1110 api_name => 'open-ils.search.metabib.record_to_descriptors',
1112 specialized method...
1113 Given a biblio record id or a metarecord id,
1114 this returns a list of metabib.record_descriptor
1115 objects that live within the same metarecord
1116 @param args Object of args including:
1120 sub rec_to_mr_rec_descriptors {
1121 my( $self, $conn, $args ) = @_;
1123 my $rec = $$args{record};
1124 my $mrec = $$args{metarecord};
1125 my $item_forms = $$args{item_forms};
1126 my $item_types = $$args{item_types};
1127 my $item_lang = $$args{item_lang};
1129 my $e = new_editor();
1133 my $map = $e->search_metabib_metarecord_source_map({source => $rec});
1134 return $e->event unless @$map;
1135 $mrec = $$map[0]->metarecord;
1138 $recs = $e->search_metabib_metarecord_source_map({metarecord => $mrec});
1139 return $e->event unless @$recs;
1141 my @recs = map { $_->source } @$recs;
1142 my $search = { record => \@recs };
1143 $search->{item_form} = $item_forms if $item_forms and @$item_forms;
1144 $search->{item_type} = $item_types if $item_types and @$item_types;
1145 $search->{item_lang} = $item_lang if $item_lang;
1147 my $desc = $e->search_metabib_record_descriptor($search);
1149 return { metarecord => $mrec, descriptors => $desc };
1155 __PACKAGE__->register_method(
1156 method => 'copies_created_on',
1160 sub copies_created_on {
1161 my( $self, $conn, $auth, $org, $date ) = @_;
1162 my $e = new_editor(authtoken=>$auth);
1163 return $e->event unless $e->checkauth;