1 package OpenILS::Application::Search::Biblio;
2 use base qw/OpenILS::Application/;
3 use strict; use warnings;
6 use OpenSRF::Utils::JSON;
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;
14 use OpenSRF::Utils::Logger qw/:logger/;
17 use OpenSRF::Utils::JSON;
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::Const qw/:const/;
31 use OpenILS::Application::AppUtils;
32 my $apputils = "OpenILS::Application::AppUtils";
35 my $pfx = "open-ils.search_";
41 $cache = OpenSRF::Utils::Cache->new('global');
42 my $sclient = OpenSRF::Utils::SettingsClient->new();
43 $cache_timeout = $sclient->config_value(
44 "apps", "open-ils.search", "app_settings", "cache_timeout" ) || 300;
45 $logger->info("Search cache timeout is $cache_timeout");
50 # ---------------------------------------------------------------------------
51 # takes a list of record id's and turns the docs into friendly
52 # mods structures. Creates one MODS structure for each doc id.
53 # ---------------------------------------------------------------------------
54 sub _records_to_mods {
60 my $session = OpenSRF::AppSession->create("open-ils.cstore");
61 my $request = $session->request(
62 "open-ils.cstore.direct.biblio.record_entry.search", { id => \@ids } );
64 while( my $resp = $request->recv ) {
65 my $content = $resp->content;
66 next if $content->id == OILS_PRECAT_RECORD;
67 my $u = OpenILS::Utils::ModsParser->new();
68 $u->start_mods_batch( $content->marc );
69 my $mods = $u->finish_mods_batch();
70 $mods->doc_id($content->id());
71 $mods->tcn($content->tcn_value);
75 $session->disconnect();
79 __PACKAGE__->register_method(
80 method => "record_id_to_mods",
81 api_name => "open-ils.search.biblio.record.mods.retrieve",
83 note => "Provide ID, we provide the mods"
86 # converts a record into a mods object with copy counts attached
87 sub record_id_to_mods {
89 my( $self, $client, $org_id, $id ) = @_;
91 my $mods_list = _records_to_mods( $id );
92 my $mods_obj = $mods_list->[0];
93 my $cmethod = $self->method_lookup(
94 "open-ils.search.biblio.record.copy_count");
95 my ($count) = $cmethod->run($org_id, $id);
96 $mods_obj->copy_count($count);
103 __PACKAGE__->register_method(
104 method => "record_id_to_mods_slim",
106 api_name => "open-ils.search.biblio.record.mods_slim.retrieve",
108 note => "Provide ID, we provide the mods"
111 # converts a record into a mods object with NO copy counts attached
112 sub record_id_to_mods_slim {
113 my( $self, $client, $id ) = @_;
114 return undef unless defined $id;
116 if(ref($id) and ref($id) == 'ARRAY') {
117 return _records_to_mods( @$id );
119 my $mods_list = _records_to_mods( $id );
120 my $mods_obj = $mods_list->[0];
121 return OpenILS::Event->new('BIBLIO_RECORD_ENTRY_NOT_FOUND') unless $mods_obj;
126 # Returns the number of copies attached to a record based on org location
127 __PACKAGE__->register_method(
128 method => "record_id_to_copy_count",
129 api_name => "open-ils.search.biblio.record.copy_count",
132 __PACKAGE__->register_method(
133 method => "record_id_to_copy_count",
135 api_name => "open-ils.search.biblio.record.copy_count.staff",
138 __PACKAGE__->register_method(
139 method => "record_id_to_copy_count",
140 api_name => "open-ils.search.biblio.metarecord.copy_count",
143 __PACKAGE__->register_method(
144 method => "record_id_to_copy_count",
145 api_name => "open-ils.search.biblio.metarecord.copy_count.staff",
147 sub record_id_to_copy_count {
148 my( $self, $client, $org_id, $record_id, $format ) = @_;
150 return [] unless $record_id;
151 $format = undef if (!$format or $format eq 'all');
153 my $method = "open-ils.storage.biblio.record_entry.copy_count.atomic";
156 if($self->api_name =~ /metarecord/) {
157 $method = "open-ils.storage.metabib.metarecord.copy_count.atomic";
161 $method =~ s/atomic/staff\.atomic/og if($self->api_name =~ /staff/ );
163 my $count = $U->storagereq( $method,
164 org_unit => $org_id, $key => $record_id, format => $format );
166 return [ sort { $a->{depth} <=> $b->{depth} } @$count ];
172 __PACKAGE__->register_method(
173 method => "biblio_search_tcn",
174 api_name => "open-ils.search.biblio.tcn",
176 note => "Retrieve a record by TCN",
179 sub biblio_search_tcn {
181 my( $self, $client, $tcn, $include_deleted ) = @_;
183 $tcn =~ s/.*?(\w+)\s*$/$1/o;
185 my $e = new_editor();
186 my $search = {tcn_value => $tcn};
187 $search->{deleted} = 'f' unless $include_deleted;
188 my $recs = $e->search_biblio_record_entry( $search, {idlist =>1} );
190 return { count => scalar(@$recs), ids => $recs };
194 # --------------------------------------------------------------------------------
196 __PACKAGE__->register_method(
197 method => "biblio_barcode_to_copy",
198 api_name => "open-ils.search.asset.copy.find_by_barcode",);
199 sub biblio_barcode_to_copy {
200 my( $self, $client, $barcode ) = @_;
201 my( $copy, $evt ) = $U->fetch_copy_by_barcode($barcode);
206 __PACKAGE__->register_method(
207 method => "biblio_id_to_copy",
208 api_name => "open-ils.search.asset.copy.batch.retrieve",);
209 sub biblio_id_to_copy {
210 my( $self, $client, $ids ) = @_;
211 $logger->info("Fetching copies @$ids");
212 return $U->cstorereq(
213 "open-ils.cstore.direct.asset.copy.search.atomic", { id => $ids } );
217 __PACKAGE__->register_method(
218 method => "copy_retrieve",
219 api_name => "open-ils.search.asset.copy.retrieve",);
221 my( $self, $client, $cid ) = @_;
222 my( $copy, $evt ) = $U->fetch_copy($cid);
227 __PACKAGE__->register_method(
228 method => "volume_retrieve",
229 api_name => "open-ils.search.asset.call_number.retrieve");
230 sub volume_retrieve {
231 my( $self, $client, $vid ) = @_;
232 my $e = new_editor();
233 my $vol = $e->retrieve_asset_call_number($vid) or return $e->event;
237 __PACKAGE__->register_method(
238 method => "fleshed_copy_retrieve_batch",
240 api_name => "open-ils.search.asset.copy.fleshed.batch.retrieve");
242 sub fleshed_copy_retrieve_batch {
243 my( $self, $client, $ids ) = @_;
244 $logger->info("Fetching fleshed copies @$ids");
245 return $U->cstorereq(
246 "open-ils.cstore.direct.asset.copy.search.atomic",
249 flesh_fields => { acp => [ qw/ circ_lib location status stat_cat_entries / ] }
254 __PACKAGE__->register_method(
255 method => "fleshed_copy_retrieve",
256 api_name => "open-ils.search.asset.copy.fleshed.retrieve",);
258 sub fleshed_copy_retrieve {
259 my( $self, $client, $id ) = @_;
260 my( $c, $e) = $U->fetch_fleshed_copy($id);
267 __PACKAGE__->register_method(
268 method => 'fleshed_by_barcode',
269 api_name => "open-ils.search.asset.copy.fleshed2.find_by_barcode",);
270 sub fleshed_by_barcode {
271 my( $self, $conn, $barcode ) = @_;
272 my $e = new_editor();
273 my $copyid = $e->search_asset_copy(
274 {barcode => $barcode, deleted => 'f'}, {idlist=>1})->[0]
276 return fleshed_copy_retrieve2( $self, $conn, $copyid);
280 __PACKAGE__->register_method(
281 method => "fleshed_copy_retrieve2",
282 api_name => "open-ils.search.asset.copy.fleshed2.retrieve",);
284 sub fleshed_copy_retrieve2 {
285 my( $self, $client, $id ) = @_;
286 my $e = new_editor();
287 my $copy = $e->retrieve_asset_copy(
293 acp => [ qw/ location status stat_cat_entry_copy_maps notes age_protect / ],
294 ascecm => [ qw/ stat_cat stat_cat_entry / ],
298 ) or return $e->event;
300 # For backwards compatibility
301 #$copy->stat_cat_entries($copy->stat_cat_entry_copy_maps);
303 if( $copy->status->id == OILS_COPY_STATUS_CHECKED_OUT ) {
305 $e->search_action_circulation(
307 { target_copy => $copy->id },
309 order_by => { circ => 'xact_start desc' },
321 __PACKAGE__->register_method(
322 method => 'flesh_copy_custom',
323 api_name => 'open-ils.search.asset.copy.fleshed.custom'
326 sub flesh_copy_custom {
327 my( $self, $conn, $copyid, $fields ) = @_;
328 my $e = new_editor();
329 my $copy = $e->retrieve_asset_copy(
339 ) or return $e->event;
348 __PACKAGE__->register_method(
349 method => "biblio_barcode_to_title",
350 api_name => "open-ils.search.biblio.find_by_barcode",
353 sub biblio_barcode_to_title {
354 my( $self, $client, $barcode ) = @_;
356 my $title = $apputils->simple_scalar_request(
358 "open-ils.storage.biblio.record_entry.retrieve_by_barcode", $barcode );
360 return { ids => [ $title->id ], count => 1 } if $title;
361 return { count => 0 };
364 __PACKAGE__->register_method(
365 method => 'title_id_by_item_barcode',
366 api_name => 'open-ils.search.bib_id.by_barcode'
369 sub title_id_by_item_barcode {
370 my( $self, $conn, $barcode ) = @_;
371 my $e = new_editor();
372 my $copies = $e->search_asset_copy(
374 { deleted => 'f', barcode => $barcode },
378 acp => [ 'call_number' ],
385 return $e->event unless @$copies;
386 return $$copies[0]->call_number->record->id;
390 __PACKAGE__->register_method(
391 method => "biblio_copy_to_mods",
392 api_name => "open-ils.search.biblio.copy.mods.retrieve",
395 # takes a copy object and returns it fleshed mods object
396 sub biblio_copy_to_mods {
397 my( $self, $client, $copy ) = @_;
399 my $volume = $U->cstorereq(
400 "open-ils.cstore.direct.asset.call_number.retrieve",
401 $copy->call_number() );
403 my $mods = _records_to_mods($volume->record());
404 $mods = shift @$mods;
405 $volume->copies([$copy]);
406 push @{$mods->call_numbers()}, $volume;
412 __PACKAGE__->register_method(
413 api_name => 'open-ils.search.biblio.multiclass.query',
414 method => 'multiclass_query',
416 @param arghash @see open-ils.search.biblio.multiclass
417 @param query Raw human-readable query string.
418 Recognized search keys include:
419 keyword/kw - search keyword(s)
420 author/au/name - search author(s)
421 title/ti - search title
422 subject/su - search subject
423 series/se - search series
424 lang - limit by language (specifiy multiple langs with lang:l1 lang:l2 ...)
425 site - search at specified org unit, corresponds to actor.org_unit.shortname
426 sort - sort type (title, author, pubdate)
427 dir - sort direction (asc, desc)
428 available - if set to anything other than "false" or "0", limits to available items
430 keyword, title, author, subject, and series support additional search
431 subclasses, specified with a "|". For example, "title|proper:gone with the wind"
432 For more, see config.metabib_field
434 @param docache @see open-ils.search.biblio.multiclass
437 __PACKAGE__->register_method(
438 api_name => 'open-ils.search.biblio.multiclass.query.staff',
439 method => 'multiclass_query',
440 signature => '@see open-ils.search.biblio.multiclass.query');
441 __PACKAGE__->register_method(
442 api_name => 'open-ils.search.metabib.multiclass.query',
443 method => 'multiclass_query',
444 signature => '@see open-ils.search.biblio.multiclass.query');
445 __PACKAGE__->register_method(
446 api_name => 'open-ils.search.metabib.multiclass.query.staff',
447 method => 'multiclass_query',
448 signature => '@see open-ils.search.biblio.multiclass.query');
450 sub multiclass_query {
451 my($self, $conn, $arghash, $query, $docache) = @_;
453 $logger->debug("initial search query => $query");
454 my $orig_query = $query;
456 $query = decode_utf8($query);
459 $query =~ s/^\s+//go;
461 # convert convenience classes (e.g. kw for keyword) to the full class name
462 $query =~ s/kw(:|\|)/keyword$1/go;
463 $query =~ s/ti(:|\|)/title$1/go;
464 $query =~ s/au(:|\|)/author$1/go;
465 $query =~ s/su(:|\|)/subject$1/go;
466 $query =~ s/se(:|\|)/series$1/go;
467 $query =~ s/name(:|\|)/author$1/og;
469 $logger->debug("cleansed query string => $query");
470 my $search = $arghash->{searches} = {};
472 while ($query =~ s/((?:keyword(?:\|\w+)?|title(?:\|\w+)?|author(?:\|\w+)?|subject(?:\|\w+)?|series(?:\|\w+)?|site|dir|sort|lang|available):[^:]+)$//so) {
473 my($type, $value) = split(':', $1);
474 next unless $type and $value;
476 $value =~ s/^\s*//og;
477 $value =~ s/\s*$//og;
478 $type = 'sort_dir' if $type eq 'dir';
480 if($type eq 'site') {
481 # 'site' is the org shortname. when using this, we also want
482 # to search at the requested org's depth
483 my $e = new_editor();
484 if(my $org = $e->search_actor_org_unit({shortname => $value})->[0]) {
485 $arghash->{org_unit} = $org->id if $org;
486 $arghash->{depth} = $e->retrieve_actor_org_unit_type($org->ou_type)->depth;
488 $logger->warn("'site:' query used on invalid org shortname: $value ... ignoring");
491 } elsif($type eq 'available') {
493 $arghash->{available} = 1 unless $value eq 'false' or $value eq '0';
495 } elsif($type eq 'lang') {
496 # collect languages into an array of languages
497 $arghash->{language} = [] unless $arghash->{language};
498 push(@{$arghash->{language}}, $value);
500 } elsif($type =~ /^sort/o) {
501 # sort and sort_dir modifiers
502 $arghash->{$type} = $value;
505 # append the search term to the term under construction
506 $search->{$type} = {} unless $search->{$type};
507 $search->{$type}->{term} =
508 ($search->{$type}->{term}) ? $search->{$type}->{term} . " $value" : $value;
513 # This is the front part of the string before any special tokens were parsed.
514 # Add this data to the default search class
515 my $type = $arghash->{default_class} || 'keyword';
516 $search->{$type} = {} unless $search->{$type};
517 $search->{$type}->{term} =
518 ($search->{$type}->{term}) ? $search->{$type}->{term} . " $query" : $query;
521 # capture the original limit because the search method alters the limit internally
522 my $ol = $arghash->{limit};
524 my $sclient = OpenSRF::Utils::SettingsClient->new;
526 (my $method = $self->api_name) =~ s/\.query//o;
528 $method =~ s/multiclass/multiclass.staged/
529 if $sclient->config_value(apps => 'open-ils.search',
530 app_settings => 'use_staged_search') =~ /true/i;
533 $method = $self->method_lookup($method);
534 my ($data) = $method->run($arghash, $docache);
536 $arghash->{limit} = $ol if $ol;
537 $data->{compiled_search} = $arghash;
538 $data->{query} = $orig_query;
540 $logger->info("compiled search is " . OpenSRF::Utils::JSON->perl2JSON($arghash));
545 __PACKAGE__->register_method(
546 method => 'cat_search_z_style_wrapper',
547 api_name => 'open-ils.search.biblio.zstyle',
549 signature => q/@see open-ils.search.biblio.multiclass/);
551 sub cat_search_z_style_wrapper {
554 my $authtoken = shift;
557 my $cstore = OpenSRF::AppSession->connect('open-ils.cstore');
559 my $ou = $cstore->request(
560 'open-ils.cstore.direct.actor.org_unit.search',
561 { parent_ou => undef }
564 my $result = { service => 'native-evergreen-catalog', records => [] };
565 my $searchhash = { limit => $$args{limit}, offset => $$args{offset}, org_unit => $ou->id };
567 $$searchhash{searches}{title}{term} = $$args{search}{title} if $$args{search}{title};
568 $$searchhash{searches}{author}{term} = $$args{search}{author} if $$args{search}{author};
569 $$searchhash{searches}{subject}{term} = $$args{search}{subject} if $$args{search}{subject};
570 $$searchhash{searches}{keyword}{term} = $$args{search}{keyword} if $$args{search}{keyword};
572 $$searchhash{searches}{keyword}{term} .= join ' ', $$searchhash{searches}{keyword}{term}, $$args{search}{tcn} if $$args{search}{tcn};
573 $$searchhash{searches}{keyword}{term} .= join ' ', $$searchhash{searches}{keyword}{term}, $$args{search}{isbn} if $$args{search}{isbn};
574 $$searchhash{searches}{keyword}{term} .= join ' ', $$searchhash{searches}{keyword}{term}, $$args{search}{issn} if $$args{search}{issn};
575 $$searchhash{searches}{keyword}{term} .= join ' ', $$searchhash{searches}{keyword}{term}, $$args{search}{publisher} if $$args{search}{publisher};
576 $$searchhash{searches}{keyword}{term} .= join ' ', $$searchhash{searches}{keyword}{term}, $$args{search}{pubdate} if $$args{search}{pubdate};
577 $$searchhash{searches}{keyword}{term} .= join ' ', $$searchhash{searches}{keyword}{term}, $$args{search}{item_type} if $$args{search}{item_type};
579 my $list = the_quest_for_knowledge( $self, $client, $searchhash );
581 if ($list->{count} > 0) {
582 $result->{count} = $list->{count};
584 my $records = $cstore->request(
585 'open-ils.cstore.direct.biblio.record_entry.search.atomic',
586 { id => [ map { ( $_->[0] ) } @{$list->{ids}} ] }
589 for my $rec ( @$records ) {
591 my $u = OpenILS::Utils::ModsParser->new();
592 $u->start_mods_batch( $rec->marc );
593 my $mods = $u->finish_mods_batch();
595 push @{ $result->{records} }, { mvr => $mods, marcxml => $rec->marc, bibid => $rec->id };
601 $cstore->disconnect();
605 # ----------------------------------------------------------------------------
606 # These are the main OPAC search methods
607 # ----------------------------------------------------------------------------
609 __PACKAGE__->register_method(
610 method => 'the_quest_for_knowledge',
611 api_name => 'open-ils.search.biblio.multiclass',
613 Performs a multi class bilbli or metabib search
614 @param searchhash A search object layed out like so:
615 searches : { "$class" : "$value", ...}
616 org_unit : The org id to focus the search at
617 depth : The org depth
618 limit : The search limit
619 offset : The search offset
620 format : The MARC format
621 sort : What field to sort the results on [ author | title | pubdate ]
622 sort_dir : What direction do we sort? [ asc | desc ]
623 @return An object of the form
624 { "count" : $count, "ids" : [ [ $id, $relevancy, $total ], ...] }
628 __PACKAGE__->register_method(
629 method => 'the_quest_for_knowledge',
630 api_name => 'open-ils.search.biblio.multiclass.staff',
631 signature => q/@see open-ils.search.biblio.multiclass/);
632 __PACKAGE__->register_method(
633 method => 'the_quest_for_knowledge',
634 api_name => 'open-ils.search.metabib.multiclass',
635 signature => q/@see open-ils.search.biblio.multiclass/);
636 __PACKAGE__->register_method(
637 method => 'the_quest_for_knowledge',
638 api_name => 'open-ils.search.metabib.multiclass.staff',
639 signature => q/@see open-ils.search.biblio.multiclass/);
641 sub the_quest_for_knowledge {
642 my( $self, $conn, $searchhash, $docache ) = @_;
644 return { count => 0 } unless $searchhash and
645 ref $searchhash->{searches} eq 'HASH';
647 my $method = 'open-ils.storage.biblio.multiclass.search_fts';
651 if($self->api_name =~ /metabib/) {
653 $method =~ s/biblio/metabib/o;
657 my $offset = $searchhash->{offset} || 0;
658 my $limit = $searchhash->{limit} || 10;
659 my $end = $offset + $limit - 1;
661 # do some simple sanity checking
662 if(!$searchhash->{searches} or
663 ( !grep { /^(?:title|author|subject|series|keyword)/ } keys %{$searchhash->{searches}} ) ) {
664 return { count => 0 };
669 $searchhash->{offset} = 0;
670 $searchhash->{limit} = $maxlimit;
672 return { count => 0 } if $offset > $maxlimit;
675 push( @search, ($_ => $$searchhash{$_})) for (sort keys %$searchhash);
676 my $s = OpenSRF::Utils::JSON->perl2JSON(\@search);
677 my $ckey = $pfx . md5_hex($method . $s);
679 $logger->info("bib search for: $s");
681 $searchhash->{limit} -= $offset;
685 my $result = ($docache) ? search_cache($ckey, $offset, $limit) : undef;
689 $method .= ".staff" if($self->api_name =~ /staff/);
690 $method .= ".atomic";
692 for (keys %$searchhash) {
693 delete $$searchhash{$_}
694 unless defined $$searchhash{$_};
697 $result = $U->storagereq( $method, %$searchhash );
704 return {count => 0} unless ($result && $$result[0]);
708 my $count = ($ismeta) ? $result->[0]->[3] : $result->[0]->[2];
711 # If we didn't get this data from the cache, put it into the cache
712 # then return the correct offset of records
713 $logger->debug("putting search cache $ckey\n");
714 put_cache($ckey, $count, \@recs);
718 # if we have the full set of data, trim out
719 # the requested chunk based on limit and offset
721 for ($offset..$end) {
722 last unless $recs[$_];
728 return { ids => \@recs, count => $count };
732 __PACKAGE__->register_method(
733 method => 'staged_search',
734 api_name => 'open-ils.search.biblio.multiclass.staged');
735 __PACKAGE__->register_method(
736 method => 'staged_search',
737 api_name => 'open-ils.search.biblio.multiclass.staged.staff',
738 signature => q/@see open-ils.search.biblio.multiclass.staged/);
739 __PACKAGE__->register_method(
740 method => 'staged_search',
741 api_name => 'open-ils.search.metabib.multiclass.staged',
742 signature => q/@see open-ils.search.biblio.multiclass.staged/);
743 __PACKAGE__->register_method(
744 method => 'staged_search',
745 api_name => 'open-ils.search.metabib.multiclass.staged.staff',
746 signature => q/@see open-ils.search.biblio.multiclass.staged/);
748 my $PAGE_SIZE = 1000;
749 my $SEARCH_PAGES = 25;
751 my($self, $conn, $search_hash, $docache) = @_;
753 my $method = ($self->api_name =~ /metabib/) ?
754 'open-ils.storage.metabib.multiclass.staged.search_fts':
755 'open-ils.storage.biblio.multiclass.staged.search_fts';
757 $method .= '.staff' if $self->api_name =~ /staff$/;
758 $method .= '.atomic';
760 my $user_offset = $search_hash->{offset} || 0; # user-specified offset
761 my $user_limit = $search_hash->{limit} || 10;
763 # we're grabbing results on a per-superpage basis, which means the
764 # limit and offset should coincide with superpage boundaries
765 $search_hash->{offset} = 0;
766 $search_hash->{limit} = $PAGE_SIZE;
767 $search_hash->{check_limit} = $PAGE_SIZE; # force a well-known check_limit
769 # pull any existing results from the cache
770 my $key = search_cache_key($method, $search_hash);
771 my $cache_data = $cache->get_cache($key) || {};
773 # keep retrieving results until we find enough to
774 # fulfill the user-specified limit and offset
775 my $all_results = [];
776 my $page; # current superpage
779 for($page = 0; $page < $SEARCH_PAGES; $page++) {
781 my $data = $cache_data->{$page};
785 $logger->debug("staged search: analyzing superpage $page");
788 # this window of results is already cached
789 $logger->debug("staged search: found cached results");
790 $summary = $data->{summary};
791 $results = $data->{results};
794 # retrieve the window of results from the database
795 $logger->debug("staged search: fetching results from the database");
796 $search_hash->{skip_check} = $page * $PAGE_SIZE;
798 $results = $U->storagereq($method, %$search_hash);
799 $logger->info("staged search: DB call took ".(time - $start)." seconds");
800 $summary = shift(@$results);
802 # Create backwards-compatible result structures
803 if($self->api_name =~ /biblio/) {
804 $results = [map {[$_->{id}]} @$results];
806 $results = [map {[$_->{id}, $_->{rel}, $_->{record}]} @$results];
809 $results = [grep {defined $_->[0]} @$results];
810 cache_staged_search_page($key, $page, $summary, $results) if $docache;
813 # add the new set of results to the set under construction
814 push(@$all_results, @$results);
816 my $current_count = scalar(@$all_results);
818 $est_hit_count = $summary->{estimated_hit_count} || $summary->{visible}
821 $logger->debug("staged search: located $current_count, with estimated hits=".
822 $summary->{estimated_hit_count}." : visible=".$summary->{visible}.", checked=".$summary->{checked});
824 # we've found all the possible hits
825 last if $current_count == $summary->{visible}
826 and not defined $summary->{estimated_hit_count};
828 # we've found enough results to satisfy the requested limit/offset
829 last if $current_count >= ($user_limit + $user_offset);
831 # we've scanned all possible hits
832 last if $summary->{checked} < $PAGE_SIZE;
835 my @results = grep {defined $_} @$all_results[$user_offset..($user_offset + $user_limit - 1)];
838 count => $est_hit_count,
843 # creates a unique token to represent the query in the cache
844 sub search_cache_key {
846 my $search_hash = shift;
848 for my $key (sort keys %$search_hash) {
849 push(@sorted, ($key => $$search_hash{$key}))
850 unless $key eq 'limit' or
852 $key eq 'skip_check';
854 my $s = OpenSRF::Utils::JSON->perl2JSON(\@sorted);
855 return $pfx . md5_hex($method . $s);
858 sub cache_staged_search_page {
859 # puts this set of results into the cache
860 my($key, $page, $summary, $results) = @_;
861 my $data = $cache->get_cache($key);
868 $logger->info("staged search: cached with key=$key, superpage=$page, estimated=".
869 $summary->{estimated_hit_count}.", visible=".$summary->{visible});
871 $cache->put_cache($key, $data);
880 my $end = $offset + $limit - 1;
882 $logger->debug("searching cache for $key : $start..$end\n");
884 return undef unless $cache;
885 my $data = $cache->get_cache($key);
887 return undef unless $data;
889 my $count = $data->[0];
892 return undef unless $offset < $count;
895 for( my $i = $offset; $i <= $end; $i++ ) {
896 last unless my $d = $$data[$i];
900 $logger->debug("search_cache found ".scalar(@result)." items for count=$count, start=$start, end=$end");
907 my( $key, $count, $data ) = @_;
908 return undef unless $cache;
909 $logger->debug("search_cache putting ".
910 scalar(@$data)." items at key $key with timeout $cache_timeout");
911 $cache->put_cache($key, [ $count, $data ], $cache_timeout);
919 __PACKAGE__->register_method(
920 method => "biblio_mrid_to_modsbatch_batch",
921 api_name => "open-ils.search.biblio.metarecord.mods_slim.batch.retrieve");
923 sub biblio_mrid_to_modsbatch_batch {
924 my( $self, $client, $mrids) = @_;
925 warn "Performing mrid_to_modsbatch_batch...";
927 my $method = $self->method_lookup("open-ils.search.biblio.metarecord.mods_slim.retrieve");
928 for my $id (@$mrids) {
929 next unless defined $id;
930 my ($m) = $method->run($id);
937 __PACKAGE__->register_method(
938 method => "biblio_mrid_to_modsbatch",
939 api_name => "open-ils.search.biblio.metarecord.mods_slim.retrieve",
940 notes => <<" NOTES");
941 Returns the mvr associated with a given metarecod. If none exists,
945 __PACKAGE__->register_method(
946 method => "biblio_mrid_to_modsbatch",
947 api_name => "open-ils.search.biblio.metarecord.mods_slim.retrieve.staff",
948 notes => <<" NOTES");
949 Returns the mvr associated with a given metarecod. If none exists,
953 sub biblio_mrid_to_modsbatch {
954 my( $self, $client, $mrid, $args) = @_;
956 warn "Grabbing mvr for $mrid\n";
958 my ($mr, $evt) = _grab_metarecord($mrid);
959 return $evt unless $mr;
961 my $mvr = biblio_mrid_check_mvr($self, $client, $mr);
962 $mvr = biblio_mrid_make_modsbatch( $self, $client, $mr ) unless $mvr;
964 return $mvr unless ref($args);
966 # Here we find the lead record appropriate for the given filters
967 # and use that for the title and author of the metarecord
968 my $format = $$args{format};
969 my $org = $$args{org};
970 my $depth = $$args{depth};
972 return $mvr unless $format or $org or $depth;
974 my $method = "open-ils.storage.ordered.metabib.metarecord.records";
975 $method = "$method.staff" if $self->api_name =~ /staff/o;
977 my $rec = $U->storagereq($method, $format, $org, $depth, 1);
979 if( my $mods = $U->record_to_mvr($rec) ) {
981 $mvr->title($mods->title);
982 $mvr->title($mods->author);
983 $logger->debug("mods_slim updating title and ".
984 "author in mvr with ".$mods->title." : ".$mods->author);
990 # converts a metarecord to an mvr
993 my $perl = OpenSRF::Utils::JSON->JSON2perl($mr->mods());
994 return Fieldmapper::metabib::virtual_record->new($perl);
997 # checks to see if a metarecord has mods, if so returns true;
999 __PACKAGE__->register_method(
1000 method => "biblio_mrid_check_mvr",
1001 api_name => "open-ils.search.biblio.metarecord.mods_slim.check",
1002 notes => <<" NOTES");
1003 Takes a metarecord ID or a metarecord object and returns true
1004 if the metarecord already has an mvr associated with it.
1007 sub biblio_mrid_check_mvr {
1008 my( $self, $client, $mrid ) = @_;
1012 if(ref($mrid)) { $mr = $mrid; }
1013 else { ($mr, $evt) = _grab_metarecord($mrid); }
1014 return $evt if $evt;
1016 warn "Checking mvr for mr " . $mr->id . "\n";
1018 return _mr_to_mvr($mr) if $mr->mods();
1022 sub _grab_metarecord {
1024 #my $e = OpenILS::Utils::Editor->new;
1025 my $e = new_editor();
1026 my $mr = $e->retrieve_metabib_metarecord($mrid) or return ( undef, $e->event );
1031 __PACKAGE__->register_method(
1032 method => "biblio_mrid_make_modsbatch",
1033 api_name => "open-ils.search.biblio.metarecord.mods_slim.create",
1034 notes => <<" NOTES");
1035 Takes either a metarecord ID or a metarecord object.
1036 Forces the creations of an mvr for the given metarecord.
1037 The created mvr is returned.
1040 sub biblio_mrid_make_modsbatch {
1041 my( $self, $client, $mrid ) = @_;
1043 #my $e = OpenILS::Utils::Editor->new;
1044 my $e = new_editor();
1051 $mr = $e->retrieve_metabib_metarecord($mrid)
1052 or return $e->event;
1055 my $masterid = $mr->master_record;
1056 $logger->info("creating new mods batch for metarecord=$mrid, master record=$masterid");
1058 my $ids = $U->storagereq(
1059 'open-ils.storage.ordered.metabib.metarecord.records.staff.atomic', $mrid);
1060 return undef unless @$ids;
1062 my $master = $e->retrieve_biblio_record_entry($masterid)
1063 or return $e->event;
1065 # start the mods batch
1066 my $u = OpenILS::Utils::ModsParser->new();
1067 $u->start_mods_batch( $master->marc );
1069 # grab all of the sub-records and shove them into the batch
1070 my @ids = grep { $_ ne $masterid } @$ids;
1071 #my $subrecs = (@ids) ? $e->batch_retrieve_biblio_record_entry(\@ids) : [];
1076 my $r = $e->retrieve_biblio_record_entry($i);
1077 push( @$subrecs, $r ) if $r;
1082 $logger->debug("adding record ".$_->id." to mods batch for metarecord=$mrid");
1083 $u->push_mods_batch( $_->marc ) if $_->marc;
1087 # finish up and send to the client
1088 my $mods = $u->finish_mods_batch();
1089 $mods->doc_id($mrid);
1090 $client->respond_complete($mods);
1093 # now update the mods string in the db
1094 my $string = OpenSRF::Utils::JSON->perl2JSON($mods->decast);
1097 #$e = OpenILS::Utils::Editor->new(xact => 1);
1098 $e = new_editor(xact => 1);
1099 $e->update_metabib_metarecord($mr)
1100 or $logger->error("Error setting mods text on metarecord $mrid : " . Dumper($e->event));
1109 # converts a mr id into a list of record ids
1111 __PACKAGE__->register_method(
1112 method => "biblio_mrid_to_record_ids",
1113 api_name => "open-ils.search.biblio.metarecord_to_records",
1116 __PACKAGE__->register_method(
1117 method => "biblio_mrid_to_record_ids",
1118 api_name => "open-ils.search.biblio.metarecord_to_records.staff",
1121 sub biblio_mrid_to_record_ids {
1122 my( $self, $client, $mrid, $args ) = @_;
1124 my $format = $$args{format};
1125 my $org = $$args{org};
1126 my $depth = $$args{depth};
1128 my $method = "open-ils.storage.ordered.metabib.metarecord.records.atomic";
1129 $method =~ s/atomic/staff\.atomic/o if $self->api_name =~ /staff/o;
1130 my $recs = $U->storagereq($method, $mrid, $format, $org, $depth);
1132 return { count => scalar(@$recs), ids => $recs };
1136 __PACKAGE__->register_method(
1137 method => "biblio_record_to_marc_html",
1138 api_name => "open-ils.search.biblio.record.html" );
1140 my $parser = XML::LibXML->new();
1141 my $xslt = XML::LibXSLT->new();
1144 my $settings_client = OpenSRF::Utils::SettingsClient->new();
1145 sub biblio_record_to_marc_html {
1146 my( $self, $client, $recordid ) = @_;
1148 if( !$marc_sheet ) {
1149 my $dir = $settings_client->config_value( "dirs", "xsl" );
1150 my $xsl = $settings_client->config_value(
1151 "apps", "open-ils.search", "app_settings", "marc_html_xsl" );
1153 $xsl = $parser->parse_file("$dir/$xsl");
1154 $marc_sheet = $xslt->parse_stylesheet( $xsl );
1158 my $record = $apputils->simple_scalar_request(
1160 "open-ils.cstore.direct.biblio.record_entry.retrieve",
1163 my $xmldoc = $parser->parse_string($record->marc);
1164 my $html = $marc_sheet->transform($xmldoc);
1165 $html = $html->toString();
1172 __PACKAGE__->register_method(
1173 method => "retrieve_all_copy_locations",
1174 api_name => "open-ils.search.config.copy_location.retrieve.all" );
1176 my $shelving_locations;
1177 sub retrieve_all_copy_locations {
1178 my( $self, $client ) = @_;
1179 if(!$shelving_locations) {
1180 $shelving_locations = $apputils->simple_scalar_request(
1182 "open-ils.cstore.direct.asset.copy_location.search.atomic",
1183 { id => { "!=" => undef } }
1186 return $shelving_locations;
1192 __PACKAGE__->register_method(
1193 method => "retrieve_all_copy_statuses",
1194 api_name => "open-ils.search.config.copy_status.retrieve.all" );
1197 sub retrieve_all_copy_statuses {
1198 my( $self, $client ) = @_;
1199 return $copy_statuses if $copy_statuses;
1200 return $copy_statuses =
1201 new_editor()->retrieve_all_config_copy_status();
1205 __PACKAGE__->register_method(
1206 method => "copy_counts_per_org",
1207 api_name => "open-ils.search.biblio.copy_counts.retrieve");
1209 __PACKAGE__->register_method(
1210 method => "copy_counts_per_org",
1211 api_name => "open-ils.search.biblio.copy_counts.retrieve.staff");
1213 sub copy_counts_per_org {
1214 my( $self, $client, $record_id ) = @_;
1216 warn "Retreiveing copy copy counts for record $record_id and method " . $self->api_name . "\n";
1218 my $method = "open-ils.storage.biblio.record_entry.global_copy_count.atomic";
1219 if($self->api_name =~ /staff/) { $method =~ s/atomic/staff\.atomic/; }
1221 my $counts = $apputils->simple_scalar_request(
1222 "open-ils.storage", $method, $record_id );
1224 $counts = [ sort {$a->[0] <=> $b->[0]} @$counts ];
1229 __PACKAGE__->register_method(
1230 method => "copy_count_summary",
1231 api_name => "open-ils.search.biblio.copy_counts.summary.retrieve",
1232 notes => <<" NOTES");
1233 returns an array of these:
1234 [ org_id, callnumber_label, <status1_count>, <status2_cout>,...]
1235 where statusx is a copy status name. the statuses are sorted
1239 sub copy_count_summary {
1240 my( $self, $client, $rid, $org, $depth ) = @_;
1243 my $data = $U->storagereq(
1244 'open-ils.storage.biblio.record_entry.status_copy_count.atomic', $rid, $org, $depth );
1246 return [ sort { $a->[1] cmp $b->[1] } @$data ];
1252 __PACKAGE__->register_method(
1253 method => "multiclass_search",
1254 api_name => "open-ils.search.biblio.multiclass",
1255 notes => <<" NOTES");
1256 Performs a multiclass search
1257 PARAMS( searchBlob, org_unit, format, limit )
1258 where searchBlob is defined like this:
1260 "title" : { "term" : "water" },
1261 "author" : { "term" : "smith" },
1266 __PACKAGE__->register_method(
1267 method => "multiclass_search",
1268 api_name => "open-ils.search.biblio.multiclass.staff",
1269 notes => "see open-ils.search.biblio.multiclass" );
1271 sub multiclass_search {
1272 my( $self, $client, $searchBlob, $orgid, $format, $limit ) = @_;
1274 $logger->debug("Performing multiclass search with org => $orgid, " .
1275 "format => $format, limit => $limit, and search blob " . Dumper($searchBlob));
1277 my $meth = 'open-ils.storage.metabib.post_filter.multiclass.search_fts.metarecord.atomic';
1278 if($self->api_name =~ /staff/) { $meth =~ s/metarecord\.atomic/metarecord.staff.atomic/; }
1281 my $records = $apputils->simplereq(
1282 'open-ils.storage', $meth,
1283 org_unit => $orgid, searches => $searchBlob, format => $format, limit => $limit );
1288 if( ref($records) and $records->[0] and
1289 defined($records->[0]->[3])) { $count = $records->[0]->[3];}
1291 for my $r (@$records) { push( @$recs, $r ) if ($r and $r->[0]); }
1293 # records has the form: [ mrid, rank, singleRecord / 0, hitCount ];
1294 return { ids => $recs, count => $count };
1300 __PACKAGE__->register_method(
1301 method => "multiclass_search",
1302 api_name => "open-ils.search.biblio.multiclass",
1304 Performs a multiclass search
1305 @param args A names hash of arguments:
1306 org_unit : The org to focus the search on
1307 depth : The search depth
1308 format : Item format
1309 limit : Return limit
1310 offset : Search offset
1311 searches : A named hash of searches which has the following format:
1313 "title" : { "term" : "water" },
1314 "author" : { "term" : "smith" },
1317 @return { ids : <array of ids>, count : hitcount }
1321 __PACKAGE__->register_method(
1322 method => "multiclass_search",
1323 api_name => "open-ils.search.biblio.multiclass.staff",
1324 notes => q/@see open-ils.search.biblio.multiclass/ );
1326 sub multiclass_search {
1327 my( $self, $client, $args ) = @_;
1329 $logger->debug("Performing multiclass search with args:\n" . Dumper($args));
1330 my $meth = 'open-ils.storage.metabib.post_filter.multiclass.search_fts.metarecord.atomic';
1331 if($self->api_name =~ /staff/) { $meth =~ s/metarecord\.atomic/metarecord.staff.atomic/; }
1333 my $records = $apputils->simplereq( 'open-ils.storage', $meth, %$args );
1338 if( ref($records) and $records->[0] and
1339 defined($records->[0]->[3])) { $count = $records->[0]->[3];}
1341 for my $r (@$records) { push( @$recs, $r ) if ($r and $r->[0]); }
1343 return { ids => $recs, count => $count };
1350 __PACKAGE__->register_method(
1351 method => "marc_search",
1352 api_name => "open-ils.search.biblio.marc.staff");
1354 __PACKAGE__->register_method(
1355 method => "marc_search",
1356 api_name => "open-ils.search.biblio.marc",
1357 notes => <<" NOTES");
1359 open-ils.storage.biblio.full_rec.multi_search.atomic
1360 { "searches": [{"term":"harry","restrict": [{"tag":245,"subfield":"a"}]}], "org_unit": 1,
1361 "limit":5,"sort":"author","item_type":"g"}
1365 my( $self, $conn, $args, $limit, $offset ) = @_;
1367 my $method = 'open-ils.storage.biblio.full_rec.multi_search';
1368 $method .= ".staff" if $self->api_name =~ /staff/;
1369 $method .= ".atomic";
1375 push( @search, ($_ => $$args{$_}) ) for (sort keys %$args);
1376 my $ckey = $pfx . md5_hex($method . OpenSRF::Utils::JSON->perl2JSON(\@search));
1378 my $recs = search_cache($ckey, $offset, $limit);
1381 $recs = $U->storagereq($method, %$args) || [];
1383 put_cache($ckey, scalar(@$recs), $recs);
1384 $recs = [ @$recs[$offset..($offset + ($limit - 1))] ];
1391 $count = $recs->[0]->[2] if $recs->[0] and $recs->[0]->[2];
1392 my @recs = map { $_->[0] } @$recs;
1394 return { ids => \@recs, count => $count };
1398 __PACKAGE__->register_method(
1399 method => "biblio_search_isbn",
1400 api_name => "open-ils.search.biblio.isbn",
1403 sub biblio_search_isbn {
1404 my( $self, $client, $isbn ) = @_;
1405 $logger->debug("Searching ISBN $isbn");
1406 my $e = new_editor();
1407 my $recs = $U->storagereq(
1408 'open-ils.storage.id_list.biblio.record_entry.search.isbn.atomic', $isbn );
1409 return { ids => $recs, count => scalar(@$recs) };
1413 __PACKAGE__->register_method(
1414 method => "biblio_search_issn",
1415 api_name => "open-ils.search.biblio.issn",
1418 sub biblio_search_issn {
1419 my( $self, $client, $issn ) = @_;
1420 $logger->debug("Searching ISSN $issn");
1421 my $e = new_editor();
1422 my $recs = $U->storagereq(
1423 'open-ils.storage.id_list.biblio.record_entry.search.issn.atomic', $issn );
1424 return { ids => $recs, count => scalar(@$recs) };
1430 __PACKAGE__->register_method(
1431 method => "fetch_mods_by_copy",
1432 api_name => "open-ils.search.biblio.mods_from_copy",
1435 sub fetch_mods_by_copy {
1436 my( $self, $client, $copyid ) = @_;
1437 my ($record, $evt) = $apputils->fetch_record_by_copy( $copyid );
1438 return $evt if $evt;
1439 return OpenILS::Event->new('ITEM_NOT_CATALOGED') unless $record->marc;
1440 return $apputils->record_to_mvr($record);
1445 # -------------------------------------------------------------------------------------
1447 __PACKAGE__->register_method(
1448 method => "cn_browse",
1449 api_name => "open-ils.search.callnumber.browse.target",
1450 notes => "Starts a callnumber browse"
1453 __PACKAGE__->register_method(
1454 method => "cn_browse",
1455 api_name => "open-ils.search.callnumber.browse.page_up",
1456 notes => "Returns the previous page of callnumbers",
1459 __PACKAGE__->register_method(
1460 method => "cn_browse",
1461 api_name => "open-ils.search.callnumber.browse.page_down",
1462 notes => "Returns the next page of callnumbers",
1466 # RETURNS array of arrays like so: label, owning_lib, record, id
1468 my( $self, $client, @params ) = @_;
1471 $method = 'open-ils.storage.asset.call_number.browse.target.atomic'
1472 if( $self->api_name =~ /target/ );
1473 $method = 'open-ils.storage.asset.call_number.browse.page_up.atomic'
1474 if( $self->api_name =~ /page_up/ );
1475 $method = 'open-ils.storage.asset.call_number.browse.page_down.atomic'
1476 if( $self->api_name =~ /page_down/ );
1478 return $apputils->simplereq( 'open-ils.storage', $method, @params );
1480 # -------------------------------------------------------------------------------------
1482 __PACKAGE__->register_method(
1483 method => "fetch_cn",
1485 api_name => "open-ils.search.callnumber.retrieve",
1486 notes => "retrieves a callnumber based on ID",
1490 my( $self, $client, $id ) = @_;
1491 my( $cn, $evt ) = $apputils->fetch_callnumber( $id );
1492 return $evt if $evt;
1496 __PACKAGE__->register_method (
1497 method => "fetch_copy_by_cn",
1498 api_name => 'open-ils.search.copies_by_call_number.retrieve',
1500 Returns an array of copy id's by callnumber id
1501 @param cnid The callnumber id
1502 @return An array of copy ids
1506 sub fetch_copy_by_cn {
1507 my( $self, $conn, $cnid ) = @_;
1508 return $U->cstorereq(
1509 'open-ils.cstore.direct.asset.copy.id_list.atomic',
1510 { call_number => $cnid, deleted => 'f' } );
1513 __PACKAGE__->register_method (
1514 method => 'fetch_cn_by_info',
1515 api_name => 'open-ils.search.call_number.retrieve_by_info',
1517 @param label The callnumber label
1518 @param record The record the cn is attached to
1519 @param org The owning library of the cn
1520 @return The callnumber object
1525 sub fetch_cn_by_info {
1526 my( $self, $conn, $label, $record, $org ) = @_;
1527 return $U->cstorereq(
1528 'open-ils.cstore.direct.asset.call_number.search',
1529 { label => $label, record => $record, owning_lib => $org, deleted => 'f' });
1536 __PACKAGE__->register_method (
1537 method => 'bib_extras',
1538 api_name => 'open-ils.search.biblio.lit_form_map.retrieve.all');
1539 __PACKAGE__->register_method (
1540 method => 'bib_extras',
1541 api_name => 'open-ils.search.biblio.item_form_map.retrieve.all');
1542 __PACKAGE__->register_method (
1543 method => 'bib_extras',
1544 api_name => 'open-ils.search.biblio.item_type_map.retrieve.all');
1545 __PACKAGE__->register_method (
1546 method => 'bib_extras',
1547 api_name => 'open-ils.search.biblio.audience_map.retrieve.all');
1552 my $e = new_editor();
1554 return $e->retrieve_all_config_lit_form_map()
1555 if( $self->api_name =~ /lit_form/ );
1557 return $e->retrieve_all_config_item_form_map()
1558 if( $self->api_name =~ /item_form_map/ );
1560 return $e->retrieve_all_config_item_type_map()
1561 if( $self->api_name =~ /item_type_map/ );
1563 return $e->retrieve_all_config_audience_map()
1564 if( $self->api_name =~ /audience_map/ );
1571 __PACKAGE__->register_method(
1572 method => 'fetch_slim_record',
1573 api_name => 'open-ils.search.biblio.record_entry.slim.retrieve',
1575 Returns a biblio.record_entry without the attached marcxml
1579 sub fetch_slim_record {
1580 my( $self, $conn, $ids ) = @_;
1582 #my $editor = OpenILS::Utils::Editor->new;
1583 my $editor = new_editor();
1586 return $editor->event unless
1587 my $r = $editor->retrieve_biblio_record_entry($_);
1596 __PACKAGE__->register_method(
1597 method => 'rec_to_mr_rec_descriptors',
1598 api_name => 'open-ils.search.metabib.record_to_descriptors',
1600 specialized method...
1601 Given a biblio record id or a metarecord id,
1602 this returns a list of metabib.record_descriptor
1603 objects that live within the same metarecord
1604 @param args Object of args including:
1608 sub rec_to_mr_rec_descriptors {
1609 my( $self, $conn, $args ) = @_;
1611 my $rec = $$args{record};
1612 my $mrec = $$args{metarecord};
1613 my $item_forms = $$args{item_forms};
1614 my $item_types = $$args{item_types};
1615 my $item_lang = $$args{item_lang};
1617 my $e = new_editor();
1621 my $map = $e->search_metabib_metarecord_source_map({source => $rec});
1622 return $e->event unless @$map;
1623 $mrec = $$map[0]->metarecord;
1626 $recs = $e->search_metabib_metarecord_source_map({metarecord => $mrec});
1627 return $e->event unless @$recs;
1629 my @recs = map { $_->source } @$recs;
1630 my $search = { record => \@recs };
1631 $search->{item_form} = $item_forms if $item_forms and @$item_forms;
1632 $search->{item_type} = $item_types if $item_types and @$item_types;
1633 $search->{item_lang} = $item_lang if $item_lang;
1635 my $desc = $e->search_metabib_record_descriptor($search);
1637 return { metarecord => $mrec, descriptors => $desc };
1643 __PACKAGE__->register_method(
1644 method => 'copies_created_on',
1648 sub copies_created_on {
1649 my( $self, $conn, $auth, $org, $date ) = @_;
1650 my $e = new_editor(authtoken=>$auth);
1651 return $e->event unless $e->checkauth;
1655 __PACKAGE__->register_method(
1656 method => 'fetch_age_protect',
1657 api_name => 'open-ils.search.copy.age_protect.retrieve.all',
1660 sub fetch_age_protect {
1661 return new_editor()->retrieve_all_config_rule_age_hold_protect();
1665 __PACKAGE__->register_method(
1666 method => 'copies_by_cn_label',
1667 api_name => 'open-ils.search.asset.copy.retrieve_by_cn_label',
1670 __PACKAGE__->register_method(
1671 method => 'copies_by_cn_label',
1672 api_name => 'open-ils.search.asset.copy.retrieve_by_cn_label.staff',
1675 sub copies_by_cn_label {
1676 my( $self, $conn, $record, $label, $circ_lib ) = @_;
1677 my $e = new_editor();
1678 my $cns = $e->search_asset_call_number({record => $record, label => $label, deleted => 'f'}, {idlist=>1});
1679 return [] unless @$cns;
1681 # show all non-deleted copies in the staff client ...
1682 if ($self->api_name =~ /staff$/o) {
1683 return $e->search_asset_copy({call_number => $cns, circ_lib => $circ_lib, deleted => 'f'}, {idlist=>1});
1686 # ... otherwise, grab the copies ...
1687 my $copies = $e->search_asset_copy(
1688 [ {call_number => $cns, circ_lib => $circ_lib, deleted => 'f', opac_visible => 't'},
1689 {flesh => 1, flesh_fields => { acp => [ qw/location status/] } }
1693 # ... and test for location and status visibility
1694 return [ map { ($U->is_true($_->location->opac_visible) && $U->is_true($_->status->holdable)) ? ($_->id) : () } @$copies ];