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 nocache @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 $method = $self->api_name) =~ s/\.query//o;
525 $method = $self->method_lookup($method);
526 my ($data) = $method->run($arghash, $docache);
528 $arghash->{limit} = $ol if $ol;
529 $data->{compiled_search} = $arghash;
530 $data->{query} = $orig_query;
532 $logger->info("compiled search is " . OpenSRF::Utils::JSON->perl2JSON($arghash));
537 __PACKAGE__->register_method(
538 method => 'cat_search_z_style_wrapper',
539 api_name => 'open-ils.search.biblio.zstyle',
541 signature => q/@see open-ils.search.biblio.multiclass/);
543 sub cat_search_z_style_wrapper {
546 my $authtoken = shift;
549 my $cstore = OpenSRF::AppSession->connect('open-ils.cstore');
551 my $ou = $cstore->request(
552 'open-ils.cstore.direct.actor.org_unit.search',
553 { parent_ou => undef }
556 my $result = { service => 'native-evergreen-catalog', records => [] };
557 my $searchhash = { limit => $$args{limit}, offset => $$args{offset}, org_unit => $ou->id };
559 $$searchhash{searches}{title}{term} = $$args{search}{title} if $$args{search}{title};
560 $$searchhash{searches}{author}{term} = $$args{search}{author} if $$args{search}{author};
561 $$searchhash{searches}{subject}{term} = $$args{search}{subject} if $$args{search}{subject};
562 $$searchhash{searches}{keyword}{term} = $$args{search}{keyword} if $$args{search}{keyword};
564 $$searchhash{searches}{keyword}{term} .= join ' ', $$searchhash{searches}{keyword}{term}, $$args{search}{tcn} if $$args{search}{tcn};
565 $$searchhash{searches}{keyword}{term} .= join ' ', $$searchhash{searches}{keyword}{term}, $$args{search}{isbn} if $$args{search}{isbn};
566 $$searchhash{searches}{keyword}{term} .= join ' ', $$searchhash{searches}{keyword}{term}, $$args{search}{issn} if $$args{search}{issn};
567 $$searchhash{searches}{keyword}{term} .= join ' ', $$searchhash{searches}{keyword}{term}, $$args{search}{publisher} if $$args{search}{publisher};
568 $$searchhash{searches}{keyword}{term} .= join ' ', $$searchhash{searches}{keyword}{term}, $$args{search}{pubdate} if $$args{search}{pubdate};
569 $$searchhash{searches}{keyword}{term} .= join ' ', $$searchhash{searches}{keyword}{term}, $$args{search}{item_type} if $$args{search}{item_type};
571 my $list = the_quest_for_knowledge( $self, $client, $searchhash );
573 if ($list->{count} > 0) {
574 $result->{count} = $list->{count};
576 my $records = $cstore->request(
577 'open-ils.cstore.direct.biblio.record_entry.search.atomic',
578 { id => [ map { ( $_->[0] ) } @{$list->{ids}} ] }
581 for my $rec ( @$records ) {
583 my $u = OpenILS::Utils::ModsParser->new();
584 $u->start_mods_batch( $rec->marc );
585 my $mods = $u->finish_mods_batch();
587 push @{ $result->{records} }, { mvr => $mods, marcxml => $rec->marc, bibid => $rec->id };
593 $cstore->disconnect();
597 # ----------------------------------------------------------------------------
598 # These are the main OPAC search methods
599 # ----------------------------------------------------------------------------
601 __PACKAGE__->register_method(
602 method => 'the_quest_for_knowledge',
603 api_name => 'open-ils.search.biblio.multiclass',
605 Performs a multi class bilbli or metabib search
606 @param searchhash A search object layed out like so:
607 searches : { "$class" : "$value", ...}
608 org_unit : The org id to focus the search at
609 depth : The org depth
610 limit : The search limit
611 offset : The search offset
612 format : The MARC format
613 sort : What field to sort the results on [ author | title | pubdate ]
614 sort_dir : What direction do we sort? [ asc | desc ]
615 @return An object of the form
616 { "count" : $count, "ids" : [ [ $id, $relevancy, $total ], ...] }
620 __PACKAGE__->register_method(
621 method => 'the_quest_for_knowledge',
622 api_name => 'open-ils.search.biblio.multiclass.staff',
623 signature => q/@see open-ils.search.biblio.multiclass/);
624 __PACKAGE__->register_method(
625 method => 'the_quest_for_knowledge',
626 api_name => 'open-ils.search.metabib.multiclass',
627 signature => q/@see open-ils.search.biblio.multiclass/);
628 __PACKAGE__->register_method(
629 method => 'the_quest_for_knowledge',
630 api_name => 'open-ils.search.metabib.multiclass.staff',
631 signature => q/@see open-ils.search.biblio.multiclass/);
633 sub the_quest_for_knowledge {
634 my( $self, $conn, $searchhash, $docache ) = @_;
636 return { count => 0 } unless $searchhash and
637 ref $searchhash->{searches} eq 'HASH';
639 my $method = 'open-ils.storage.biblio.multiclass.search_fts';
643 if($self->api_name =~ /metabib/) {
645 $method =~ s/biblio/metabib/o;
649 my $offset = $searchhash->{offset} || 0;
650 my $limit = $searchhash->{limit} || 10;
651 my $end = $offset + $limit - 1;
653 # do some simple sanity checking
654 if(!$searchhash->{searches} or
655 ( !grep { /^(?:title|author|subject|series|keyword)/ } keys %{$searchhash->{searches}} ) ) {
656 return { count => 0 };
661 $searchhash->{offset} = 0;
662 $searchhash->{limit} = $maxlimit;
664 return { count => 0 } if $offset > $maxlimit;
667 push( @search, ($_ => $$searchhash{$_})) for (sort keys %$searchhash);
668 my $s = OpenSRF::Utils::JSON->perl2JSON(\@search);
669 my $ckey = $pfx . md5_hex($method . $s);
671 $logger->info("bib search for: $s");
673 $searchhash->{limit} -= $offset;
677 my $result = ($docache) ? search_cache($ckey, $offset, $limit) : undef;
681 $method .= ".staff" if($self->api_name =~ /staff/);
682 $method .= ".atomic";
684 for (keys %$searchhash) {
685 delete $$searchhash{$_}
686 unless defined $$searchhash{$_};
689 $result = $U->storagereq( $method, %$searchhash );
696 return {count => 0} unless ($result && $$result[0]);
700 my $count = ($ismeta) ? $result->[0]->[3] : $result->[0]->[2];
703 # If we didn't get this data from the cache, put it into the cache
704 # then return the correct offset of records
705 $logger->debug("putting search cache $ckey\n");
706 put_cache($ckey, $count, \@recs);
710 # if we have the full set of data, trim out
711 # the requested chunk based on limit and offset
713 for ($offset..$end) {
714 last unless $recs[$_];
720 return { ids => \@recs, count => $count };
724 __PACKAGE__->register_method(
725 method => 'staged_search',
726 api_name => 'open-ils.search.biblio.multiclass.staged');
727 __PACKAGE__->register_method(
728 method => 'staged_search',
729 api_name => 'open-ils.search.biblio.multiclass.staged.staff',
730 signature => q/@see open-ils.search.biblio.multiclass.staged/);
731 __PACKAGE__->register_method(
732 method => 'staged_search',
733 api_name => 'open-ils.search.metabib.multiclass.staged',
734 signature => q/@see open-ils.search.biblio.multiclass.staged/);
735 __PACKAGE__->register_method(
736 method => 'staged_search',
737 api_name => 'open-ils.search.metabib.multiclass.staged.staff',
738 signature => q/@see open-ils.search.biblio.multiclass.staged/);
740 my $CACHE_LIMIT = 200;
741 my $CHECK_LIMIT = 1000;
744 my($self, $conn, $search_hash, $nocache) = @_;
746 my $method = ($self->api_name =~ /metabib/) ?
747 'open-ils.storage.metabib.multiclass.staged.search_fts':
748 'open-ils.storage.biblio.multiclass.staged.search_fts';
750 $method .= '.staff' if $self->api_name =~ /staff$/;
751 $method .= '.atomic';
753 $search_hash->{skip_check} ||= 0;
755 my ($hit_count, $results) = try_staged_search_cache($method, $search_hash);
761 $results = $U->storagereq($method, %$search_hash);
762 my $summary = shift(@$results);
763 $hit_count = $summary->{estimated_hit_count};
765 # Clean up the results
766 if($self->api_name =~ /biblio/) {
767 $results = [map {$_->{id}} @$results];
769 delete $_->{rel} for @$results;
772 cache_staged_search($method, $search_hash, $summary, $results) unless $nocache;
781 sub try_staged_search_cache {
783 my $search_hash = shift;
785 my $key = search_cache_key($method, $search_hash);
786 my $start = $search_hash->{offset};
787 my $end = $start + $search_hash->{limit} - 1;
788 my $data = $cache->get_cache($key);
790 $logger->info("searching search cache $key with skip_check $$search_hash{skip_check}");
791 return undef unless $data;
792 $logger->info("searching search cache $key with skip_check $$search_hash{skip_check}");
793 return undef unless $data = $data->{$$search_hash{skip_check}};
794 $logger->info("returning search cache $key with skip_check $$search_hash{skip_check}");
797 $data->{summary}->{estimated_hit_count},
802 # creates a unique token to represent the query in the cache
803 sub search_cache_key {
805 my $search_hash = shift;
807 for my $key (sort keys %$search_hash) {
808 push(@sorted, ($key => $$search_hash{$key}))
809 unless $key eq 'limit' or
811 $key eq 'skip_check';
813 my $s = OpenSRF::Utils::JSON->perl2JSON(\@sorted);
814 return $pfx . md5_hex($method . $s);
817 sub cache_staged_search {
818 my($method, $search_hash, $summary, $results) = @_;
819 my $cache_key = search_cache_key($method, $search_hash);
820 my $data = $cache->get_cache($cache_key);
822 $data->{$search_hash->{skip_check}} = {
826 $logger->info("cached ranged search with skip_check $$search_hash{skip_check} and key $cache_key");
827 $cache->put_cache($data);
836 my $end = $offset + $limit - 1;
838 $logger->debug("searching cache for $key : $start..$end\n");
840 return undef unless $cache;
841 my $data = $cache->get_cache($key);
843 return undef unless $data;
845 my $count = $data->[0];
848 return undef unless $offset < $count;
851 for( my $i = $offset; $i <= $end; $i++ ) {
852 last unless my $d = $$data[$i];
856 $logger->debug("search_cache found ".scalar(@result)." items for count=$count, start=$start, end=$end");
863 my( $key, $count, $data ) = @_;
864 return undef unless $cache;
865 $logger->debug("search_cache putting ".
866 scalar(@$data)." items at key $key with timeout $cache_timeout");
867 $cache->put_cache($key, [ $count, $data ], $cache_timeout);
875 __PACKAGE__->register_method(
876 method => "biblio_mrid_to_modsbatch_batch",
877 api_name => "open-ils.search.biblio.metarecord.mods_slim.batch.retrieve");
879 sub biblio_mrid_to_modsbatch_batch {
880 my( $self, $client, $mrids) = @_;
881 warn "Performing mrid_to_modsbatch_batch...";
883 my $method = $self->method_lookup("open-ils.search.biblio.metarecord.mods_slim.retrieve");
884 for my $id (@$mrids) {
885 next unless defined $id;
886 my ($m) = $method->run($id);
893 __PACKAGE__->register_method(
894 method => "biblio_mrid_to_modsbatch",
895 api_name => "open-ils.search.biblio.metarecord.mods_slim.retrieve",
896 notes => <<" NOTES");
897 Returns the mvr associated with a given metarecod. If none exists,
901 __PACKAGE__->register_method(
902 method => "biblio_mrid_to_modsbatch",
903 api_name => "open-ils.search.biblio.metarecord.mods_slim.retrieve.staff",
904 notes => <<" NOTES");
905 Returns the mvr associated with a given metarecod. If none exists,
909 sub biblio_mrid_to_modsbatch {
910 my( $self, $client, $mrid, $args) = @_;
912 warn "Grabbing mvr for $mrid\n";
914 my ($mr, $evt) = _grab_metarecord($mrid);
915 return $evt unless $mr;
917 my $mvr = biblio_mrid_check_mvr($self, $client, $mr);
918 $mvr = biblio_mrid_make_modsbatch( $self, $client, $mr ) unless $mvr;
920 return $mvr unless ref($args);
922 # Here we find the lead record appropriate for the given filters
923 # and use that for the title and author of the metarecord
924 my $format = $$args{format};
925 my $org = $$args{org};
926 my $depth = $$args{depth};
928 return $mvr unless $format or $org or $depth;
930 my $method = "open-ils.storage.ordered.metabib.metarecord.records";
931 $method = "$method.staff" if $self->api_name =~ /staff/o;
933 my $rec = $U->storagereq($method, $format, $org, $depth, 1);
935 if( my $mods = $U->record_to_mvr($rec) ) {
937 $mvr->title($mods->title);
938 $mvr->title($mods->author);
939 $logger->debug("mods_slim updating title and ".
940 "author in mvr with ".$mods->title." : ".$mods->author);
946 # converts a metarecord to an mvr
949 my $perl = OpenSRF::Utils::JSON->JSON2perl($mr->mods());
950 return Fieldmapper::metabib::virtual_record->new($perl);
953 # checks to see if a metarecord has mods, if so returns true;
955 __PACKAGE__->register_method(
956 method => "biblio_mrid_check_mvr",
957 api_name => "open-ils.search.biblio.metarecord.mods_slim.check",
958 notes => <<" NOTES");
959 Takes a metarecord ID or a metarecord object and returns true
960 if the metarecord already has an mvr associated with it.
963 sub biblio_mrid_check_mvr {
964 my( $self, $client, $mrid ) = @_;
968 if(ref($mrid)) { $mr = $mrid; }
969 else { ($mr, $evt) = _grab_metarecord($mrid); }
972 warn "Checking mvr for mr " . $mr->id . "\n";
974 return _mr_to_mvr($mr) if $mr->mods();
978 sub _grab_metarecord {
980 #my $e = OpenILS::Utils::Editor->new;
981 my $e = new_editor();
982 my $mr = $e->retrieve_metabib_metarecord($mrid) or return ( undef, $e->event );
987 __PACKAGE__->register_method(
988 method => "biblio_mrid_make_modsbatch",
989 api_name => "open-ils.search.biblio.metarecord.mods_slim.create",
990 notes => <<" NOTES");
991 Takes either a metarecord ID or a metarecord object.
992 Forces the creations of an mvr for the given metarecord.
993 The created mvr is returned.
996 sub biblio_mrid_make_modsbatch {
997 my( $self, $client, $mrid ) = @_;
999 #my $e = OpenILS::Utils::Editor->new;
1000 my $e = new_editor();
1007 $mr = $e->retrieve_metabib_metarecord($mrid)
1008 or return $e->event;
1011 my $masterid = $mr->master_record;
1012 $logger->info("creating new mods batch for metarecord=$mrid, master record=$masterid");
1014 my $ids = $U->storagereq(
1015 'open-ils.storage.ordered.metabib.metarecord.records.staff.atomic', $mrid);
1016 return undef unless @$ids;
1018 my $master = $e->retrieve_biblio_record_entry($masterid)
1019 or return $e->event;
1021 # start the mods batch
1022 my $u = OpenILS::Utils::ModsParser->new();
1023 $u->start_mods_batch( $master->marc );
1025 # grab all of the sub-records and shove them into the batch
1026 my @ids = grep { $_ ne $masterid } @$ids;
1027 #my $subrecs = (@ids) ? $e->batch_retrieve_biblio_record_entry(\@ids) : [];
1032 my $r = $e->retrieve_biblio_record_entry($i);
1033 push( @$subrecs, $r ) if $r;
1038 $logger->debug("adding record ".$_->id." to mods batch for metarecord=$mrid");
1039 $u->push_mods_batch( $_->marc ) if $_->marc;
1043 # finish up and send to the client
1044 my $mods = $u->finish_mods_batch();
1045 $mods->doc_id($mrid);
1046 $client->respond_complete($mods);
1049 # now update the mods string in the db
1050 my $string = OpenSRF::Utils::JSON->perl2JSON($mods->decast);
1053 #$e = OpenILS::Utils::Editor->new(xact => 1);
1054 $e = new_editor(xact => 1);
1055 $e->update_metabib_metarecord($mr)
1056 or $logger->error("Error setting mods text on metarecord $mrid : " . Dumper($e->event));
1065 # converts a mr id into a list of record ids
1067 __PACKAGE__->register_method(
1068 method => "biblio_mrid_to_record_ids",
1069 api_name => "open-ils.search.biblio.metarecord_to_records",
1072 __PACKAGE__->register_method(
1073 method => "biblio_mrid_to_record_ids",
1074 api_name => "open-ils.search.biblio.metarecord_to_records.staff",
1077 sub biblio_mrid_to_record_ids {
1078 my( $self, $client, $mrid, $args ) = @_;
1080 my $format = $$args{format};
1081 my $org = $$args{org};
1082 my $depth = $$args{depth};
1084 my $method = "open-ils.storage.ordered.metabib.metarecord.records.atomic";
1085 $method =~ s/atomic/staff\.atomic/o if $self->api_name =~ /staff/o;
1086 my $recs = $U->storagereq($method, $mrid, $format, $org, $depth);
1088 return { count => scalar(@$recs), ids => $recs };
1092 __PACKAGE__->register_method(
1093 method => "biblio_record_to_marc_html",
1094 api_name => "open-ils.search.biblio.record.html" );
1096 my $parser = XML::LibXML->new();
1097 my $xslt = XML::LibXSLT->new();
1100 my $settings_client = OpenSRF::Utils::SettingsClient->new();
1101 sub biblio_record_to_marc_html {
1102 my( $self, $client, $recordid ) = @_;
1104 if( !$marc_sheet ) {
1105 my $dir = $settings_client->config_value( "dirs", "xsl" );
1106 my $xsl = $settings_client->config_value(
1107 "apps", "open-ils.search", "app_settings", "marc_html_xsl" );
1109 $xsl = $parser->parse_file("$dir/$xsl");
1110 $marc_sheet = $xslt->parse_stylesheet( $xsl );
1114 my $record = $apputils->simple_scalar_request(
1116 "open-ils.cstore.direct.biblio.record_entry.retrieve",
1119 my $xmldoc = $parser->parse_string($record->marc);
1120 my $html = $marc_sheet->transform($xmldoc);
1121 $html = $html->toString();
1128 __PACKAGE__->register_method(
1129 method => "retrieve_all_copy_locations",
1130 api_name => "open-ils.search.config.copy_location.retrieve.all" );
1132 my $shelving_locations;
1133 sub retrieve_all_copy_locations {
1134 my( $self, $client ) = @_;
1135 if(!$shelving_locations) {
1136 $shelving_locations = $apputils->simple_scalar_request(
1138 "open-ils.cstore.direct.asset.copy_location.search.atomic",
1139 { id => { "!=" => undef } }
1142 return $shelving_locations;
1148 __PACKAGE__->register_method(
1149 method => "retrieve_all_copy_statuses",
1150 api_name => "open-ils.search.config.copy_status.retrieve.all" );
1153 sub retrieve_all_copy_statuses {
1154 my( $self, $client ) = @_;
1155 return $copy_statuses if $copy_statuses;
1156 return $copy_statuses =
1157 new_editor()->retrieve_all_config_copy_status();
1161 __PACKAGE__->register_method(
1162 method => "copy_counts_per_org",
1163 api_name => "open-ils.search.biblio.copy_counts.retrieve");
1165 __PACKAGE__->register_method(
1166 method => "copy_counts_per_org",
1167 api_name => "open-ils.search.biblio.copy_counts.retrieve.staff");
1169 sub copy_counts_per_org {
1170 my( $self, $client, $record_id ) = @_;
1172 warn "Retreiveing copy copy counts for record $record_id and method " . $self->api_name . "\n";
1174 my $method = "open-ils.storage.biblio.record_entry.global_copy_count.atomic";
1175 if($self->api_name =~ /staff/) { $method =~ s/atomic/staff\.atomic/; }
1177 my $counts = $apputils->simple_scalar_request(
1178 "open-ils.storage", $method, $record_id );
1180 $counts = [ sort {$a->[0] <=> $b->[0]} @$counts ];
1185 __PACKAGE__->register_method(
1186 method => "copy_count_summary",
1187 api_name => "open-ils.search.biblio.copy_counts.summary.retrieve",
1188 notes => <<" NOTES");
1189 returns an array of these:
1190 [ org_id, callnumber_label, <status1_count>, <status2_cout>,...]
1191 where statusx is a copy status name. the statuses are sorted
1195 sub copy_count_summary {
1196 my( $self, $client, $rid, $org, $depth ) = @_;
1199 my $data = $U->storagereq(
1200 'open-ils.storage.biblio.record_entry.status_copy_count.atomic', $rid, $org, $depth );
1202 return [ sort { $a->[1] cmp $b->[1] } @$data ];
1208 __PACKAGE__->register_method(
1209 method => "multiclass_search",
1210 api_name => "open-ils.search.biblio.multiclass",
1211 notes => <<" NOTES");
1212 Performs a multiclass search
1213 PARAMS( searchBlob, org_unit, format, limit )
1214 where searchBlob is defined like this:
1216 "title" : { "term" : "water" },
1217 "author" : { "term" : "smith" },
1222 __PACKAGE__->register_method(
1223 method => "multiclass_search",
1224 api_name => "open-ils.search.biblio.multiclass.staff",
1225 notes => "see open-ils.search.biblio.multiclass" );
1227 sub multiclass_search {
1228 my( $self, $client, $searchBlob, $orgid, $format, $limit ) = @_;
1230 $logger->debug("Performing multiclass search with org => $orgid, " .
1231 "format => $format, limit => $limit, and search blob " . Dumper($searchBlob));
1233 my $meth = 'open-ils.storage.metabib.post_filter.multiclass.search_fts.metarecord.atomic';
1234 if($self->api_name =~ /staff/) { $meth =~ s/metarecord\.atomic/metarecord.staff.atomic/; }
1237 my $records = $apputils->simplereq(
1238 'open-ils.storage', $meth,
1239 org_unit => $orgid, searches => $searchBlob, format => $format, limit => $limit );
1244 if( ref($records) and $records->[0] and
1245 defined($records->[0]->[3])) { $count = $records->[0]->[3];}
1247 for my $r (@$records) { push( @$recs, $r ) if ($r and $r->[0]); }
1249 # records has the form: [ mrid, rank, singleRecord / 0, hitCount ];
1250 return { ids => $recs, count => $count };
1256 __PACKAGE__->register_method(
1257 method => "multiclass_search",
1258 api_name => "open-ils.search.biblio.multiclass",
1260 Performs a multiclass search
1261 @param args A names hash of arguments:
1262 org_unit : The org to focus the search on
1263 depth : The search depth
1264 format : Item format
1265 limit : Return limit
1266 offset : Search offset
1267 searches : A named hash of searches which has the following format:
1269 "title" : { "term" : "water" },
1270 "author" : { "term" : "smith" },
1273 @return { ids : <array of ids>, count : hitcount }
1277 __PACKAGE__->register_method(
1278 method => "multiclass_search",
1279 api_name => "open-ils.search.biblio.multiclass.staff",
1280 notes => q/@see open-ils.search.biblio.multiclass/ );
1282 sub multiclass_search {
1283 my( $self, $client, $args ) = @_;
1285 $logger->debug("Performing multiclass search with args:\n" . Dumper($args));
1286 my $meth = 'open-ils.storage.metabib.post_filter.multiclass.search_fts.metarecord.atomic';
1287 if($self->api_name =~ /staff/) { $meth =~ s/metarecord\.atomic/metarecord.staff.atomic/; }
1289 my $records = $apputils->simplereq( 'open-ils.storage', $meth, %$args );
1294 if( ref($records) and $records->[0] and
1295 defined($records->[0]->[3])) { $count = $records->[0]->[3];}
1297 for my $r (@$records) { push( @$recs, $r ) if ($r and $r->[0]); }
1299 return { ids => $recs, count => $count };
1306 __PACKAGE__->register_method(
1307 method => "marc_search",
1308 api_name => "open-ils.search.biblio.marc.staff");
1310 __PACKAGE__->register_method(
1311 method => "marc_search",
1312 api_name => "open-ils.search.biblio.marc",
1313 notes => <<" NOTES");
1315 open-ils.storage.biblio.full_rec.multi_search.atomic
1316 { "searches": [{"term":"harry","restrict": [{"tag":245,"subfield":"a"}]}], "org_unit": 1,
1317 "limit":5,"sort":"author","item_type":"g"}
1321 my( $self, $conn, $args, $limit, $offset ) = @_;
1323 my $method = 'open-ils.storage.biblio.full_rec.multi_search';
1324 $method .= ".staff" if $self->api_name =~ /staff/;
1325 $method .= ".atomic";
1331 push( @search, ($_ => $$args{$_}) ) for (sort keys %$args);
1332 my $ckey = $pfx . md5_hex($method . OpenSRF::Utils::JSON->perl2JSON(\@search));
1334 my $recs = search_cache($ckey, $offset, $limit);
1337 $recs = $U->storagereq($method, %$args) || [];
1339 put_cache($ckey, scalar(@$recs), $recs);
1340 $recs = [ @$recs[$offset..($offset + ($limit - 1))] ];
1347 $count = $recs->[0]->[2] if $recs->[0] and $recs->[0]->[2];
1348 my @recs = map { $_->[0] } @$recs;
1350 return { ids => \@recs, count => $count };
1354 __PACKAGE__->register_method(
1355 method => "biblio_search_isbn",
1356 api_name => "open-ils.search.biblio.isbn",
1359 sub biblio_search_isbn {
1360 my( $self, $client, $isbn ) = @_;
1361 $logger->debug("Searching ISBN $isbn");
1362 my $e = new_editor();
1363 my $recs = $U->storagereq(
1364 'open-ils.storage.id_list.biblio.record_entry.search.isbn.atomic', $isbn );
1365 return { ids => $recs, count => scalar(@$recs) };
1369 __PACKAGE__->register_method(
1370 method => "biblio_search_issn",
1371 api_name => "open-ils.search.biblio.issn",
1374 sub biblio_search_issn {
1375 my( $self, $client, $issn ) = @_;
1376 $logger->debug("Searching ISSN $issn");
1377 my $e = new_editor();
1378 my $recs = $U->storagereq(
1379 'open-ils.storage.id_list.biblio.record_entry.search.issn.atomic', $issn );
1380 return { ids => $recs, count => scalar(@$recs) };
1386 __PACKAGE__->register_method(
1387 method => "fetch_mods_by_copy",
1388 api_name => "open-ils.search.biblio.mods_from_copy",
1391 sub fetch_mods_by_copy {
1392 my( $self, $client, $copyid ) = @_;
1393 my ($record, $evt) = $apputils->fetch_record_by_copy( $copyid );
1394 return $evt if $evt;
1395 return OpenILS::Event->new('ITEM_NOT_CATALOGED') unless $record->marc;
1396 return $apputils->record_to_mvr($record);
1401 # -------------------------------------------------------------------------------------
1403 __PACKAGE__->register_method(
1404 method => "cn_browse",
1405 api_name => "open-ils.search.callnumber.browse.target",
1406 notes => "Starts a callnumber browse"
1409 __PACKAGE__->register_method(
1410 method => "cn_browse",
1411 api_name => "open-ils.search.callnumber.browse.page_up",
1412 notes => "Returns the previous page of callnumbers",
1415 __PACKAGE__->register_method(
1416 method => "cn_browse",
1417 api_name => "open-ils.search.callnumber.browse.page_down",
1418 notes => "Returns the next page of callnumbers",
1422 # RETURNS array of arrays like so: label, owning_lib, record, id
1424 my( $self, $client, @params ) = @_;
1427 $method = 'open-ils.storage.asset.call_number.browse.target.atomic'
1428 if( $self->api_name =~ /target/ );
1429 $method = 'open-ils.storage.asset.call_number.browse.page_up.atomic'
1430 if( $self->api_name =~ /page_up/ );
1431 $method = 'open-ils.storage.asset.call_number.browse.page_down.atomic'
1432 if( $self->api_name =~ /page_down/ );
1434 return $apputils->simplereq( 'open-ils.storage', $method, @params );
1436 # -------------------------------------------------------------------------------------
1438 __PACKAGE__->register_method(
1439 method => "fetch_cn",
1441 api_name => "open-ils.search.callnumber.retrieve",
1442 notes => "retrieves a callnumber based on ID",
1446 my( $self, $client, $id ) = @_;
1447 my( $cn, $evt ) = $apputils->fetch_callnumber( $id );
1448 return $evt if $evt;
1452 __PACKAGE__->register_method (
1453 method => "fetch_copy_by_cn",
1454 api_name => 'open-ils.search.copies_by_call_number.retrieve',
1456 Returns an array of copy id's by callnumber id
1457 @param cnid The callnumber id
1458 @return An array of copy ids
1462 sub fetch_copy_by_cn {
1463 my( $self, $conn, $cnid ) = @_;
1464 return $U->cstorereq(
1465 'open-ils.cstore.direct.asset.copy.id_list.atomic',
1466 { call_number => $cnid, deleted => 'f' } );
1469 __PACKAGE__->register_method (
1470 method => 'fetch_cn_by_info',
1471 api_name => 'open-ils.search.call_number.retrieve_by_info',
1473 @param label The callnumber label
1474 @param record The record the cn is attached to
1475 @param org The owning library of the cn
1476 @return The callnumber object
1481 sub fetch_cn_by_info {
1482 my( $self, $conn, $label, $record, $org ) = @_;
1483 return $U->cstorereq(
1484 'open-ils.cstore.direct.asset.call_number.search',
1485 { label => $label, record => $record, owning_lib => $org, deleted => 'f' });
1492 __PACKAGE__->register_method (
1493 method => 'bib_extras',
1494 api_name => 'open-ils.search.biblio.lit_form_map.retrieve.all');
1495 __PACKAGE__->register_method (
1496 method => 'bib_extras',
1497 api_name => 'open-ils.search.biblio.item_form_map.retrieve.all');
1498 __PACKAGE__->register_method (
1499 method => 'bib_extras',
1500 api_name => 'open-ils.search.biblio.item_type_map.retrieve.all');
1501 __PACKAGE__->register_method (
1502 method => 'bib_extras',
1503 api_name => 'open-ils.search.biblio.audience_map.retrieve.all');
1508 my $e = new_editor();
1510 return $e->retrieve_all_config_lit_form_map()
1511 if( $self->api_name =~ /lit_form/ );
1513 return $e->retrieve_all_config_item_form_map()
1514 if( $self->api_name =~ /item_form_map/ );
1516 return $e->retrieve_all_config_item_type_map()
1517 if( $self->api_name =~ /item_type_map/ );
1519 return $e->retrieve_all_config_audience_map()
1520 if( $self->api_name =~ /audience_map/ );
1527 __PACKAGE__->register_method(
1528 method => 'fetch_slim_record',
1529 api_name => 'open-ils.search.biblio.record_entry.slim.retrieve',
1531 Returns a biblio.record_entry without the attached marcxml
1535 sub fetch_slim_record {
1536 my( $self, $conn, $ids ) = @_;
1538 #my $editor = OpenILS::Utils::Editor->new;
1539 my $editor = new_editor();
1542 return $editor->event unless
1543 my $r = $editor->retrieve_biblio_record_entry($_);
1552 __PACKAGE__->register_method(
1553 method => 'rec_to_mr_rec_descriptors',
1554 api_name => 'open-ils.search.metabib.record_to_descriptors',
1556 specialized method...
1557 Given a biblio record id or a metarecord id,
1558 this returns a list of metabib.record_descriptor
1559 objects that live within the same metarecord
1560 @param args Object of args including:
1564 sub rec_to_mr_rec_descriptors {
1565 my( $self, $conn, $args ) = @_;
1567 my $rec = $$args{record};
1568 my $mrec = $$args{metarecord};
1569 my $item_forms = $$args{item_forms};
1570 my $item_types = $$args{item_types};
1571 my $item_lang = $$args{item_lang};
1573 my $e = new_editor();
1577 my $map = $e->search_metabib_metarecord_source_map({source => $rec});
1578 return $e->event unless @$map;
1579 $mrec = $$map[0]->metarecord;
1582 $recs = $e->search_metabib_metarecord_source_map({metarecord => $mrec});
1583 return $e->event unless @$recs;
1585 my @recs = map { $_->source } @$recs;
1586 my $search = { record => \@recs };
1587 $search->{item_form} = $item_forms if $item_forms and @$item_forms;
1588 $search->{item_type} = $item_types if $item_types and @$item_types;
1589 $search->{item_lang} = $item_lang if $item_lang;
1591 my $desc = $e->search_metabib_record_descriptor($search);
1593 return { metarecord => $mrec, descriptors => $desc };
1599 __PACKAGE__->register_method(
1600 method => 'copies_created_on',
1604 sub copies_created_on {
1605 my( $self, $conn, $auth, $org, $date ) = @_;
1606 my $e = new_editor(authtoken=>$auth);
1607 return $e->event unless $e->checkauth;
1611 __PACKAGE__->register_method(
1612 method => 'fetch_age_protect',
1613 api_name => 'open-ils.search.copy.age_protect.retrieve.all',
1616 sub fetch_age_protect {
1617 return new_editor()->retrieve_all_config_rule_age_hold_protect();
1621 __PACKAGE__->register_method(
1622 method => 'copies_by_cn_label',
1623 api_name => 'open-ils.search.asset.copy.retrieve_by_cn_label',
1626 __PACKAGE__->register_method(
1627 method => 'copies_by_cn_label',
1628 api_name => 'open-ils.search.asset.copy.retrieve_by_cn_label.staff',
1631 sub copies_by_cn_label {
1632 my( $self, $conn, $record, $label, $circ_lib ) = @_;
1633 my $e = new_editor();
1634 my $cns = $e->search_asset_call_number({record => $record, label => $label, deleted => 'f'}, {idlist=>1});
1635 return [] unless @$cns;
1637 # show all non-deleted copies in the staff client ...
1638 if ($self->api_name =~ /staff$/o) {
1639 return $e->search_asset_copy({call_number => $cns, circ_lib => $circ_lib, deleted => 'f'}, {idlist=>1});
1642 # ... otherwise, grab the copies ...
1643 my $copies = $e->search_asset_copy(
1644 [ {call_number => $cns, circ_lib => $circ_lib, deleted => 'f', opac_visible => 't'},
1645 {flesh => 1, flesh_fields => { acp => [ qw/location status/] } }
1649 # ... and test for location and status visibility
1650 return [ map { ($U->is_true($_->location->opac_visible) && $U->is_true($_->status->holdable)) ? ($_->id) : () } @$copies ];