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 OpenILS::Utils::CStoreEditor q/:funcs/;
12 use OpenSRF::Utils::Cache;
14 use OpenSRF::Utils::Logger qw/:logger/;
19 use Time::HiRes qw(time);
20 use OpenSRF::EX qw(:try);
21 use Digest::MD5 qw(md5_hex);
27 $Data::Dumper::Indent = 0;
29 use OpenILS::Application::AppUtils;
30 my $apputils = "OpenILS::Application::AppUtils";
33 my $pfx = "open-ils.search_";
39 $cache = OpenSRF::Utils::Cache->new('global');
40 my $sclient = OpenSRF::Utils::SettingsClient->new();
41 $cache_timeout = $sclient->config_value(
42 "apps", "open-ils.search", "app_settings", "cache_timeout" ) || 300;
43 $logger->info("Search cache timeout is $cache_timeout");
48 # ---------------------------------------------------------------------------
49 # takes a list of record id's and turns the docs into friendly
50 # mods structures. Creates one MODS structure for each doc id.
51 # ---------------------------------------------------------------------------
52 sub _records_to_mods {
58 my $session = OpenSRF::AppSession->create("open-ils.storage");
59 my $request = $session->request(
60 "open-ils.storage.direct.biblio.record_entry.batch.retrieve", @ids );
62 while( my $resp = $request->recv ) {
63 my $content = $resp->content;
64 my $u = OpenILS::Utils::ModsParser->new();
65 $u->start_mods_batch( $content->marc );
66 my $mods = $u->finish_mods_batch();
67 $mods->doc_id($content->id());
68 $mods->tcn($content->tcn_value);
72 $session->disconnect();
76 __PACKAGE__->register_method(
77 method => "record_id_to_mods",
78 api_name => "open-ils.search.biblio.record.mods.retrieve",
80 note => "Provide ID, we provide the mods"
83 # converts a record into a mods object with copy counts attached
84 sub record_id_to_mods {
86 my( $self, $client, $org_id, $id ) = @_;
88 my $mods_list = _records_to_mods( $id );
89 my $mods_obj = $mods_list->[0];
90 my $cmethod = $self->method_lookup(
91 "open-ils.search.biblio.record.copy_count");
92 my ($count) = $cmethod->run($org_id, $id);
93 $mods_obj->copy_count($count);
100 __PACKAGE__->register_method(
101 method => "record_id_to_mods_slim",
102 api_name => "open-ils.search.biblio.record.mods_slim.retrieve",
104 note => "Provide ID, we provide the mods"
107 # converts a record into a mods object with NO copy counts attached
108 sub record_id_to_mods_slim {
109 my( $self, $client, $id ) = @_;
110 return undef unless defined $id;
112 if(ref($id) and ref($id) == 'ARRAY') {
113 return _records_to_mods( @$id );
115 my $mods_list = _records_to_mods( $id );
116 my $mods_obj = $mods_list->[0];
121 # Returns the number of copies attached to a record based on org location
122 __PACKAGE__->register_method(
123 method => "record_id_to_copy_count",
124 api_name => "open-ils.search.biblio.record.copy_count",
127 __PACKAGE__->register_method(
128 method => "record_id_to_copy_count",
129 api_name => "open-ils.search.biblio.record.copy_count.staff",
132 __PACKAGE__->register_method(
133 method => "record_id_to_copy_count",
134 api_name => "open-ils.search.biblio.metarecord.copy_count",
137 __PACKAGE__->register_method(
138 method => "record_id_to_copy_count",
139 api_name => "open-ils.search.biblio.metarecord.copy_count.staff",
141 sub record_id_to_copy_count {
142 my( $self, $client, $org_id, $record_id, $format ) = @_;
144 return [] unless $record_id;
145 $format = undef if (!$format or $format eq 'all');
147 my $method = "open-ils.storage.biblio.record_entry.copy_count.atomic";
150 if($self->api_name =~ /metarecord/) {
151 $method = "open-ils.storage.metabib.metarecord.copy_count.atomic";
155 $method =~ s/atomic/staff\.atomic/og if($self->api_name =~ /staff/ );
157 my $count = $U->storagereq( $method,
158 org_unit => $org_id, $key => $record_id, format => $format );
160 return [ sort { $a->{depth} <=> $b->{depth} } @$count ];
166 __PACKAGE__->register_method(
167 method => "biblio_search_tcn",
168 api_name => "open-ils.search.biblio.tcn",
170 note => "Retrieve a record by TCN",
173 sub biblio_search_tcn {
175 my( $self, $client, $tcn ) = @_;
177 $tcn =~ s/.*?(\w+)\s*$/$1/o;
179 my $e = new_editor();
180 my $recs = $e->search_biblio_record_entry(
181 {deleted => 'f', tcn_value => $tcn}, {idlist =>1});
183 return { count => scalar(@$recs), ids => $recs };
187 # --------------------------------------------------------------------------------
189 __PACKAGE__->register_method(
190 method => "biblio_barcode_to_copy",
191 api_name => "open-ils.search.asset.copy.find_by_barcode",);
192 sub biblio_barcode_to_copy {
193 my( $self, $client, $barcode ) = @_;
194 my( $copy, $evt ) = $U->fetch_copy_by_barcode($barcode);
199 __PACKAGE__->register_method(
200 method => "biblio_id_to_copy",
201 api_name => "open-ils.search.asset.copy.batch.retrieve",);
202 sub biblio_id_to_copy {
203 my( $self, $client, $ids ) = @_;
204 $logger->info("Fetching copies @$ids");
205 return $U->storagereq(
206 "open-ils.storage.direct.asset.copy.batch.retrieve.atomic", @$ids );
210 __PACKAGE__->register_method(
211 method => "copy_retrieve",
212 api_name => "open-ils.search.asset.copy.retrieve",);
214 my( $self, $client, $cid ) = @_;
215 my( $copy, $evt ) = $U->fetch_copy($cid);
220 __PACKAGE__->register_method(
221 method => "volume_retrieve",
222 api_name => "open-ils.search.asset.call_number.retrieve");
223 sub volume_retrieve {
224 my( $self, $client, $vid ) = @_;
225 my $e = new_editor();
226 my $vol = $e->retrieve_asset_call_number($vid) or return $e->event;
230 __PACKAGE__->register_method(
231 method => "fleshed_copy_retrieve_batch",
232 api_name => "open-ils.search.asset.copy.fleshed.batch.retrieve");
234 sub fleshed_copy_retrieve_batch {
235 my( $self, $client, $ids ) = @_;
236 $logger->info("Fetching fleshed copies @$ids");
237 return $U->storagereq(
238 "open-ils.storage.fleshed.asset.copy.batch.retrieve.atomic", @$ids );
242 __PACKAGE__->register_method(
243 method => "fleshed_copy_retrieve",
244 api_name => "open-ils.search.asset.copy.fleshed.retrieve",);
246 sub fleshed_copy_retrieve {
247 my( $self, $client, $id ) = @_;
248 my( $c, $e) = $U->fetch_fleshed_copy($id);
255 __PACKAGE__->register_method(
256 method => "biblio_barcode_to_title",
257 api_name => "open-ils.search.biblio.find_by_barcode",
260 sub biblio_barcode_to_title {
261 my( $self, $client, $barcode ) = @_;
263 my $title = $apputils->simple_scalar_request(
265 "open-ils.storage.biblio.record_entry.retrieve_by_barcode", $barcode );
267 return { ids => [ $title->id ], count => 1 } if $title;
268 return { count => 0 };
272 __PACKAGE__->register_method(
273 method => "biblio_copy_to_mods",
274 api_name => "open-ils.search.biblio.copy.mods.retrieve",
277 # takes a copy object and returns it fleshed mods object
278 sub biblio_copy_to_mods {
279 my( $self, $client, $copy ) = @_;
281 my $volume = $U->storagereq(
282 "open-ils.storage.direct.asset.call_number.retrieve",
283 $copy->call_number() );
285 my $mods = _records_to_mods($volume->record());
286 $mods = shift @$mods;
287 $volume->copies([$copy]);
288 push @{$mods->call_numbers()}, $volume;
294 # ----------------------------------------------------------------------------
295 # These are the main OPAC search methods
296 # ----------------------------------------------------------------------------
298 __PACKAGE__->register_method(
299 method => 'the_quest_for_knowledge',
300 api_name => 'open-ils.search.biblio.multiclass',
302 Performs a multi class bilbli or metabib search
303 @param searchhash A search object layed out like so:
304 searches : { "$class" : "$value", ...}
305 org_unit : The org id to focus the search at
306 depth : The org depth
307 limit : The search limit
308 offset : The search offset
309 format : The MARC format
310 sort : What field to sort the results on [ author | title | pubdate ]
311 sort_dir : What direction do we sort? [ asc | desc ]
312 @return An object of the form
313 { "count" : $count, "ids" : [ [ $id, $relevancy, $total ], ...] }
317 __PACKAGE__->register_method(
318 method => 'the_quest_for_knowledge',
319 api_name => 'open-ils.search.biblio.multiclass.staff',
320 signature => q/@see open-ils.search.biblio.multiclass/);
321 __PACKAGE__->register_method(
322 method => 'the_quest_for_knowledge',
323 api_name => 'open-ils.search.metabib.multiclass',
324 signature => q/@see open-ils.search.biblio.multiclass/);
325 __PACKAGE__->register_method(
326 method => 'the_quest_for_knowledge',
327 api_name => 'open-ils.search.metabib.multiclass.staff',
328 signature => q/@see open-ils.search.biblio.multiclass/);
332 sub the_quest_for_knowledge {
333 my( $self, $conn, $searchhash ) = @_;
335 return { count => 0 } unless $searchhash and
336 ref $searchhash->{searches} eq 'HASH';
338 my $method = 'open-ils.storage.biblio.multiclass.search_fts';
344 my $offset = $searchhash->{offset} || 0;
345 my $limit = $searchhash->{limit} || 10;
346 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->{offset} = $offset;
355 #$searchhash->{limit} = $limit;
357 if($self->api_name =~ /metabib/) {
359 $method =~ s/biblio/metabib/o;
362 # don't cache past max limit
363 my $result = ($end < $maxlimit) ? 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 push(@t, $recs[$_]) for ($offset..$end);
414 $logger->debug("cache done .. returning $offset..$end : " . JSON->perl2JSON(\@recs));
417 return { ids => \@recs,
418 count => ($ismeta) ? $result->[0]->[3] : $result->[0]->[2] };
429 $logger->debug("searching cache for $key\n");
432 my $end = $offset + $limit - 1;
434 return undef unless $cache;
435 my $data = $cache->get_cache($key);
437 return undef unless $data and ref $data eq 'ARRAY' and $$data[$start] and $$data[$end];
439 #$logger->debug("search_cache found data " . JSON->perl2JSON($data));
440 $logger->debug("search_cache found data for indices $start..$end");
442 my $result = [ (@$data[$start..$end]) ];
444 $logger->debug("cache returning results: [".
445 JSON->perl2JSON($$result[0]) . '...' .
446 JSON->perl2JSON($$result[$limit-1]) .']' );
453 my( $key, $data ) = @_;
454 return undef unless $cache;
455 $logger->debug("search_cache putting ".
456 scalar(@$data)." items at key $key with timeout $cache_timeout");
457 $cache->put_cache($key, $data, $cache_timeout);
465 __PACKAGE__->register_method(
466 method => "biblio_mrid_to_modsbatch_batch",
467 api_name => "open-ils.search.biblio.metarecord.mods_slim.batch.retrieve");
469 sub biblio_mrid_to_modsbatch_batch {
470 my( $self, $client, $mrids) = @_;
471 warn "Performing mrid_to_modsbatch_batch...";
473 my $method = $self->method_lookup("open-ils.search.biblio.metarecord.mods_slim.retrieve");
474 for my $id (@$mrids) {
475 next unless defined $id;
476 my ($m) = $method->run($id);
483 __PACKAGE__->register_method(
484 method => "biblio_mrid_to_modsbatch",
485 api_name => "open-ils.search.biblio.metarecord.mods_slim.retrieve",
486 notes => <<" NOTES");
487 Returns the mvr associated with a given metarecod. If none exists,
491 __PACKAGE__->register_method(
492 method => "biblio_mrid_to_modsbatch",
493 api_name => "open-ils.search.biblio.metarecord.mods_slim.retrieve.staff",
494 notes => <<" NOTES");
495 Returns the mvr associated with a given metarecod. If none exists,
499 sub biblio_mrid_to_modsbatch {
500 my( $self, $client, $mrid ) = @_;
502 warn "Grabbing mvr for $mrid\n";
504 my ($mr, $evt) = _grab_metarecord($mrid);
505 return $evt unless $mr;
507 if( my $m = $self->biblio_mrid_check_mvr($client, $mr)) {
511 return $self->biblio_mrid_make_modsbatch( $client, $mr );
514 # converts a metarecord to an mvr
517 my $perl = JSON->JSON2perl($mr->mods());
518 return Fieldmapper::metabib::virtual_record->new($perl);
521 # checks to see if a metarecord has mods, if so returns true;
523 __PACKAGE__->register_method(
524 method => "biblio_mrid_check_mvr",
525 api_name => "open-ils.search.biblio.metarecord.mods_slim.check",
526 notes => <<" NOTES");
527 Takes a metarecord ID or a metarecord object and returns true
528 if the metarecord already has an mvr associated with it.
531 sub biblio_mrid_check_mvr {
532 my( $self, $client, $mrid ) = @_;
536 if(ref($mrid)) { $mr = $mrid; }
537 else { ($mr, $evt) = _grab_metarecord($mrid); }
540 warn "Checking mvr for mr " . $mr->id . "\n";
542 return _mr_to_mvr($mr) if $mr->mods();
546 sub _grab_metarecord {
548 #my $e = OpenILS::Utils::Editor->new;
549 my $e = new_editor();
550 my $mr = $e->retrieve_metabib_metarecord($mrid) or return ( undef, $e->event );
555 __PACKAGE__->register_method(
556 method => "biblio_mrid_make_modsbatch",
557 api_name => "open-ils.search.biblio.metarecord.mods_slim.create",
558 notes => <<" NOTES");
559 Takes either a metarecord ID or a metarecord object.
560 Forces the creations of an mvr for the given metarecord.
561 The created mvr is returned.
564 sub biblio_mrid_make_modsbatch {
565 my( $self, $client, $mrid ) = @_;
567 #my $e = OpenILS::Utils::Editor->new;
568 my $e = new_editor();
575 $mr = $e->retrieve_metabib_metarecord($mrid)
579 my $masterid = $mr->master_record;
580 $logger->info("creating new mods batch for metarecord=$mrid, master record=$masterid");
582 my $ids = $U->storagereq(
583 'open-ils.storage.ordered.metabib.metarecord.records.staff.atomic', $mrid);
584 return undef unless @$ids;
586 my $master = $e->retrieve_biblio_record_entry($masterid)
589 # start the mods batch
590 my $u = OpenILS::Utils::ModsParser->new();
591 $u->start_mods_batch( $master->marc );
593 # grab all of the sub-records and shove them into the batch
594 my @ids = grep { $_ ne $masterid } @$ids;
595 my $subrecs = $e->batch_retrieve_biblio_record_entry(\@ids);
598 $logger->debug("adding record ".$_->id." to mods batch for metarecord=$mrid");
599 $u->push_mods_batch( $_->marc ) if $_->marc;
603 # finish up and send to the client
604 my $mods = $u->finish_mods_batch();
605 $mods->doc_id($mrid);
606 $client->respond_complete($mods);
609 # now update the mods string in the db
610 my $string = JSON->perl2JSON($mods->decast);
613 #$e = OpenILS::Utils::Editor->new(xact => 1);
614 $e = new_editor(xact => 1);
615 $e->update_metabib_metarecord($mr)
616 or $logger->error("Error setting mods text on metarecord $mrid : " . Dumper($e->event));
625 # converts a mr id into a list of record ids
627 __PACKAGE__->register_method(
628 method => "biblio_mrid_to_record_ids",
629 api_name => "open-ils.search.biblio.metarecord_to_records",
632 __PACKAGE__->register_method(
633 method => "biblio_mrid_to_record_ids",
634 api_name => "open-ils.search.biblio.metarecord_to_records.staff",
637 sub biblio_mrid_to_record_ids {
638 my( $self, $client, $mrid, $args ) = @_;
640 my $format = $$args{format};
641 my $org = $$args{org};
642 my $depth = $$args{depth};
644 my $method = "open-ils.storage.ordered.metabib.metarecord.records.atomic";
645 $method =~ s/atomic/staff\.atomic/o if $self->api_name =~ /staff/o;
646 my $recs = $U->storagereq($method, $mrid, $format, $org, $depth);
648 return { count => scalar(@$recs), ids => $recs };
652 __PACKAGE__->register_method(
653 method => "biblio_record_to_marc_html",
654 api_name => "open-ils.search.biblio.record.html" );
656 my $parser = XML::LibXML->new();
657 my $xslt = XML::LibXSLT->new();
660 my $settings_client = OpenSRF::Utils::SettingsClient->new();
661 sub biblio_record_to_marc_html {
662 my( $self, $client, $recordid ) = @_;
665 my $dir = $settings_client->config_value( "dirs", "xsl" );
666 my $xsl = $settings_client->config_value(
667 "apps", "open-ils.search", "app_settings", "marc_html_xsl" );
669 $xsl = $parser->parse_file("$dir/$xsl");
670 $marc_sheet = $xslt->parse_stylesheet( $xsl );
674 my $record = $apputils->simple_scalar_request(
676 "open-ils.storage.direct.biblio.record_entry.retrieve",
679 my $xmldoc = $parser->parse_string($record->marc);
680 my $html = $marc_sheet->transform($xmldoc);
681 $html = $html->toString();
688 __PACKAGE__->register_method(
689 method => "retrieve_all_copy_locations",
690 api_name => "open-ils.search.config.copy_location.retrieve.all" );
692 my $shelving_locations;
693 sub retrieve_all_copy_locations {
694 my( $self, $client ) = @_;
695 if(!$shelving_locations) {
696 $shelving_locations = $apputils->simple_scalar_request(
698 "open-ils.storage.direct.asset.copy_location.retrieve.all.atomic");
700 return $shelving_locations;
706 __PACKAGE__->register_method(
707 method => "retrieve_all_copy_statuses",
708 api_name => "open-ils.search.config.copy_status.retrieve.all" );
711 sub retrieve_all_copy_statuses {
712 my( $self, $client ) = @_;
713 if(!$copy_statuses) {
714 $copy_statuses = $apputils->simple_scalar_request(
716 "open-ils.storage.direct.config.copy_status.retrieve.all.atomic" );
718 return $copy_statuses;
722 __PACKAGE__->register_method(
723 method => "copy_counts_per_org",
724 api_name => "open-ils.search.biblio.copy_counts.retrieve");
726 __PACKAGE__->register_method(
727 method => "copy_counts_per_org",
728 api_name => "open-ils.search.biblio.copy_counts.retrieve.staff");
730 sub copy_counts_per_org {
731 my( $self, $client, $record_id ) = @_;
733 warn "Retreiveing copy copy counts for record $record_id and method " . $self->api_name . "\n";
735 my $method = "open-ils.storage.biblio.record_entry.global_copy_count.atomic";
736 if($self->api_name =~ /staff/) { $method =~ s/atomic/staff\.atomic/; }
738 my $counts = $apputils->simple_scalar_request(
739 "open-ils.storage", $method, $record_id );
741 $counts = [ sort {$a->[0] <=> $b->[0]} @$counts ];
746 __PACKAGE__->register_method(
747 method => "copy_count_summary",
748 api_name => "open-ils.search.biblio.copy_counts.summary.retrieve",
749 notes => <<" NOTES");
750 returns an array of these:
751 [ org_id, callnumber_label, <status1_count>, <status2_cout>,...]
752 where statusx is a copy status name. the statuses are sorted
756 sub copy_count_summary {
757 my( $self, $client, $rid, $org, $depth ) = @_;
760 return $U->storagereq(
761 'open-ils.storage.biblio.record_entry.status_copy_count.atomic', $rid, $org, $depth );
767 __PACKAGE__->register_method(
768 method => "multiclass_search",
769 api_name => "open-ils.search.biblio.multiclass",
770 notes => <<" NOTES");
771 Performs a multiclass search
772 PARAMS( searchBlob, org_unit, format, limit )
773 where searchBlob is defined like this:
775 "title" : { "term" : "water" },
776 "author" : { "term" : "smith" },
781 __PACKAGE__->register_method(
782 method => "multiclass_search",
783 api_name => "open-ils.search.biblio.multiclass.staff",
784 notes => "see open-ils.search.biblio.multiclass" );
786 sub multiclass_search {
787 my( $self, $client, $searchBlob, $orgid, $format, $limit ) = @_;
789 $logger->debug("Performing multiclass search with org => $orgid, " .
790 "format => $format, limit => $limit, and search blob " . Dumper($searchBlob));
792 my $meth = 'open-ils.storage.metabib.post_filter.multiclass.search_fts.metarecord.atomic';
793 if($self->api_name =~ /staff/) { $meth =~ s/metarecord\.atomic/metarecord.staff.atomic/; }
796 my $records = $apputils->simplereq(
797 'open-ils.storage', $meth,
798 org_unit => $orgid, searches => $searchBlob, format => $format, limit => $limit );
803 if( ref($records) and $records->[0] and
804 defined($records->[0]->[3])) { $count = $records->[0]->[3];}
806 for my $r (@$records) { push( @$recs, $r ) if ($r and $r->[0]); }
808 # records has the form: [ mrid, rank, singleRecord / 0, hitCount ];
809 return { ids => $recs, count => $count };
815 __PACKAGE__->register_method(
816 method => "multiclass_search",
817 api_name => "open-ils.search.biblio.multiclass",
819 Performs a multiclass search
820 @param args A names hash of arguments:
821 org_unit : The org to focus the search on
822 depth : The search depth
825 offset : Search offset
826 searches : A named hash of searches which has the following format:
828 "title" : { "term" : "water" },
829 "author" : { "term" : "smith" },
832 @return { ids : <array of ids>, count : hitcount }
836 __PACKAGE__->register_method(
837 method => "multiclass_search",
838 api_name => "open-ils.search.biblio.multiclass.staff",
839 notes => q/@see open-ils.search.biblio.multiclass/ );
841 sub multiclass_search {
842 my( $self, $client, $args ) = @_;
844 $logger->debug("Performing multiclass search with args:\n" . Dumper($args));
845 my $meth = 'open-ils.storage.metabib.post_filter.multiclass.search_fts.metarecord.atomic';
846 if($self->api_name =~ /staff/) { $meth =~ s/metarecord\.atomic/metarecord.staff.atomic/; }
848 my $records = $apputils->simplereq( 'open-ils.storage', $meth, %$args );
853 if( ref($records) and $records->[0] and
854 defined($records->[0]->[3])) { $count = $records->[0]->[3];}
856 for my $r (@$records) { push( @$recs, $r ) if ($r and $r->[0]); }
858 return { ids => $recs, count => $count };
865 __PACKAGE__->register_method(
866 method => "marc_search",
867 api_name => "open-ils.search.biblio.marc.staff");
869 __PACKAGE__->register_method(
870 method => "marc_search",
871 api_name => "open-ils.search.biblio.marc",
872 notes => <<" NOTES");
874 open-ils.storage.biblio.full_rec.multi_search.atomic
875 { "searches": [{"term":"harry","restrict": [{"tag":245,"subfield":"a"}]}], "org_unit": 1,
876 "limit":5,"sort":"author","item_type":"g"}
880 my( $self, $conn, $args, $limit, $offset ) = @_;
882 my $method = 'open-ils.storage.biblio.full_rec.multi_search';
883 $method .= ".staff" if $self->api_name =~ /staff/;
884 $method .= ".atomic";
890 push( @search, ($_ => $$args{$_}) ) for (sort keys %$args);
891 my $ckey = $pfx . md5_hex($method . JSON->perl2JSON(\@search));
893 my $recs = search_cache($ckey, $offset, $limit);
896 $recs = new_editor()->request($method, %$args);
897 put_cache($ckey, $recs);
898 $recs = [ @$recs[$offset..($offset + ($limit - 1))] ];
902 $count = $recs->[0]->[2] if $recs->[0] and $recs->[0]->[2];
903 my @recs = map { $_->[0] } @$recs;
905 return { ids => \@recs, count => $count };
909 __PACKAGE__->register_method(
910 method => "biblio_search_isbn",
911 api_name => "open-ils.search.biblio.isbn",
914 sub biblio_search_isbn {
915 my( $self, $client, $isbn ) = @_;
916 $logger->debug("Searching ISBN $isbn");
917 my $e = new_editor();
918 my $recs = $U->storagereq(
919 'open-ils.storage.id_list.biblio.record_entry.search.isbn.atomic', $isbn );
920 return { ids => $recs, count => scalar(@$recs) };
924 __PACKAGE__->register_method(
925 method => "biblio_search_issn",
926 api_name => "open-ils.search.biblio.issn",
929 sub biblio_search_issn {
930 my( $self, $client, $issn ) = @_;
931 $logger->debug("Searching ISSN $issn");
932 my $e = new_editor();
933 my $recs = $U->storagereq(
934 'open-ils.storage.id_list.biblio.record_entry.search.issn.atomic', $issn );
935 return { ids => $recs, count => scalar(@$recs) };
941 __PACKAGE__->register_method(
942 method => "fetch_mods_by_copy",
943 api_name => "open-ils.search.biblio.mods_from_copy",
946 sub fetch_mods_by_copy {
947 my( $self, $client, $copyid ) = @_;
948 my ($record, $evt) = $apputils->fetch_record_by_copy( $copyid );
950 return OpenILS::Event->new('ITEM_NOT_CATALOGED') unless $record->marc;
951 return $apputils->record_to_mvr($record);
956 # -------------------------------------------------------------------------------------
958 __PACKAGE__->register_method(
959 method => "cn_browse",
960 api_name => "open-ils.search.callnumber.browse.target",
961 notes => "Starts a callnumber browse"
964 __PACKAGE__->register_method(
965 method => "cn_browse",
966 api_name => "open-ils.search.callnumber.browse.page_up",
967 notes => "Returns the previous page of callnumbers",
970 __PACKAGE__->register_method(
971 method => "cn_browse",
972 api_name => "open-ils.search.callnumber.browse.page_down",
973 notes => "Returns the next page of callnumbers",
977 # RETURNS array of arrays like so: label, owning_lib, record, id
979 my( $self, $client, @params ) = @_;
982 $method = 'open-ils.storage.asset.call_number.browse.target.atomic'
983 if( $self->api_name =~ /target/ );
984 $method = 'open-ils.storage.asset.call_number.browse.page_up.atomic'
985 if( $self->api_name =~ /page_up/ );
986 $method = 'open-ils.storage.asset.call_number.browse.page_down.atomic'
987 if( $self->api_name =~ /page_down/ );
989 return $apputils->simplereq( 'open-ils.storage', $method, @params );
991 # -------------------------------------------------------------------------------------
993 __PACKAGE__->register_method(
994 method => "fetch_cn",
995 api_name => "open-ils.search.callnumber.retrieve",
996 notes => "retrieves a callnumber based on ID",
1000 my( $self, $client, $id ) = @_;
1001 my( $cn, $evt ) = $apputils->fetch_callnumber( $id );
1002 return $evt if $evt;
1006 __PACKAGE__->register_method (
1007 method => "fetch_copy_by_cn",
1008 api_name => 'open-ils.search.copies_by_call_number.retrieve',
1010 Returns an array of copy id's by callnumber id
1011 @param cnid The callnumber id
1012 @return An array of copy ids
1016 sub fetch_copy_by_cn {
1017 my( $self, $conn, $cnid ) = @_;
1018 return $U->storagereq(
1019 'open-ils.storage.id_list.asset.copy.search_where.atomic',
1020 { call_number => $cnid, deleted => 'f' } );
1023 __PACKAGE__->register_method (
1024 method => 'fetch_cn_by_info',
1025 api_name => 'open-ils.search.call_number.retrieve_by_info',
1027 @param label The callnumber label
1028 @param record The record the cn is attached to
1029 @param org The owning library of the cn
1030 @return The callnumber object
1035 sub fetch_cn_by_info {
1036 my( $self, $conn, $label, $record, $org ) = @_;
1037 return $U->storagereq(
1038 'open-ils.storage.direct.asset.call_number.search_where',
1039 { label => $label, record => $record, owning_lib => $org, deleted => 'f' });
1046 __PACKAGE__->register_method (
1047 method => 'bib_extras',
1048 api_name => 'open-ils.search.biblio.lit_form_map.retrieve.all');
1049 __PACKAGE__->register_method (
1050 method => 'bib_extras',
1051 api_name => 'open-ils.search.biblio.item_form_map.retrieve.all');
1052 __PACKAGE__->register_method (
1053 method => 'bib_extras',
1054 api_name => 'open-ils.search.biblio.item_type_map.retrieve.all');
1055 __PACKAGE__->register_method (
1056 method => 'bib_extras',
1057 api_name => 'open-ils.search.biblio.audience_map.retrieve.all');
1062 return $U->storagereq(
1063 'open-ils.storage.direct.config.lit_form_map.retrieve.all.atomic')
1064 if( $self->api_name =~ /lit_form/ );
1066 return $U->storagereq(
1067 'open-ils.storage.direct.config.item_form_map.retrieve.all.atomic')
1068 if( $self->api_name =~ /item_form_map/ );
1070 return $U->storagereq(
1071 'open-ils.storage.direct.config.item_type_map.retrieve.all.atomic')
1072 if( $self->api_name =~ /item_type_map/ );
1074 return $U->storagereq(
1075 'open-ils.storage.direct.config.audience_map.retrieve.all.atomic')
1076 if( $self->api_name =~ /audience/ );
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;