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_";
43 $cache = OpenSRF::Utils::Cache->new('global');
44 my $sclient = OpenSRF::Utils::SettingsClient->new();
45 $cache_timeout = $sclient->config_value(
46 "apps", "open-ils.search", "app_settings", "cache_timeout" ) || 300;
48 $superpage_size = $sclient->config_value(
49 "apps", "open-ils.search", "app_settings", "superpage_size" ) || 500;
51 $max_superpages = $sclient->config_value(
52 "apps", "open-ils.search", "app_settings", "max_superpages" ) || 20;
54 $logger->info("Search cache timeout is $cache_timeout, ".
55 " superpage_size is $superpage_size, max_superpages is $max_superpages");
60 # ---------------------------------------------------------------------------
61 # takes a list of record id's and turns the docs into friendly
62 # mods structures. Creates one MODS structure for each doc id.
63 # ---------------------------------------------------------------------------
64 sub _records_to_mods {
70 my $session = OpenSRF::AppSession->create("open-ils.cstore");
71 my $request = $session->request(
72 "open-ils.cstore.direct.biblio.record_entry.search", { id => \@ids } );
74 while( my $resp = $request->recv ) {
75 my $content = $resp->content;
76 next if $content->id == OILS_PRECAT_RECORD;
77 my $u = OpenILS::Utils::ModsParser->new();
78 $u->start_mods_batch( $content->marc );
79 my $mods = $u->finish_mods_batch();
80 $mods->doc_id($content->id());
81 $mods->tcn($content->tcn_value);
85 $session->disconnect();
89 __PACKAGE__->register_method(
90 method => "record_id_to_mods",
91 api_name => "open-ils.search.biblio.record.mods.retrieve",
93 note => "Provide ID, we provide the mods"
96 # converts a record into a mods object with copy counts attached
97 sub record_id_to_mods {
99 my( $self, $client, $org_id, $id ) = @_;
101 my $mods_list = _records_to_mods( $id );
102 my $mods_obj = $mods_list->[0];
103 my $cmethod = $self->method_lookup(
104 "open-ils.search.biblio.record.copy_count");
105 my ($count) = $cmethod->run($org_id, $id);
106 $mods_obj->copy_count($count);
113 __PACKAGE__->register_method(
114 method => "record_id_to_mods_slim",
116 api_name => "open-ils.search.biblio.record.mods_slim.retrieve",
118 note => "Provide ID, we provide the mods"
121 # converts a record into a mods object with NO copy counts attached
122 sub record_id_to_mods_slim {
123 my( $self, $client, $id ) = @_;
124 return undef unless defined $id;
126 if(ref($id) and ref($id) == 'ARRAY') {
127 return _records_to_mods( @$id );
129 my $mods_list = _records_to_mods( $id );
130 my $mods_obj = $mods_list->[0];
131 return OpenILS::Event->new('BIBLIO_RECORD_ENTRY_NOT_FOUND') unless $mods_obj;
137 __PACKAGE__->register_method(
138 method => "record_id_to_mods_slim_batch",
139 api_name => "open-ils.search.biblio.record.mods_slim.batch.retrieve",
142 sub record_id_to_mods_slim_batch {
143 my($self, $conn, $id_list) = @_;
144 $conn->respond(_records_to_mods($_)->[0]) for @$id_list;
149 # Returns the number of copies attached to a record based on org location
150 __PACKAGE__->register_method(
151 method => "record_id_to_copy_count",
152 api_name => "open-ils.search.biblio.record.copy_count",
155 __PACKAGE__->register_method(
156 method => "record_id_to_copy_count",
158 api_name => "open-ils.search.biblio.record.copy_count.staff",
161 __PACKAGE__->register_method(
162 method => "record_id_to_copy_count",
163 api_name => "open-ils.search.biblio.metarecord.copy_count",
166 __PACKAGE__->register_method(
167 method => "record_id_to_copy_count",
168 api_name => "open-ils.search.biblio.metarecord.copy_count.staff",
170 sub record_id_to_copy_count {
171 my( $self, $client, $org_id, $record_id, $format ) = @_;
173 return [] unless $record_id;
174 $format = undef if (!$format or $format eq 'all');
176 my $method = "open-ils.storage.biblio.record_entry.copy_count.atomic";
179 if($self->api_name =~ /metarecord/) {
180 $method = "open-ils.storage.metabib.metarecord.copy_count.atomic";
184 $method =~ s/atomic/staff\.atomic/og if($self->api_name =~ /staff/ );
186 my $count = $U->storagereq( $method,
187 org_unit => $org_id, $key => $record_id, format => $format );
189 return [ sort { $a->{depth} <=> $b->{depth} } @$count ];
195 __PACKAGE__->register_method(
196 method => "biblio_search_tcn",
197 api_name => "open-ils.search.biblio.tcn",
199 note => "Retrieve a record by TCN",
202 sub biblio_search_tcn {
204 my( $self, $client, $tcn, $include_deleted ) = @_;
206 $tcn =~ s/^\s+|\s+$//og;
208 my $e = new_editor();
209 my $search = {tcn_value => $tcn};
210 $search->{deleted} = 'f' unless $include_deleted;
211 my $recs = $e->search_biblio_record_entry( $search, {idlist =>1} );
213 return { count => scalar(@$recs), ids => $recs };
217 # --------------------------------------------------------------------------------
219 __PACKAGE__->register_method(
220 method => "biblio_barcode_to_copy",
221 api_name => "open-ils.search.asset.copy.find_by_barcode",);
222 sub biblio_barcode_to_copy {
223 my( $self, $client, $barcode ) = @_;
224 my( $copy, $evt ) = $U->fetch_copy_by_barcode($barcode);
229 __PACKAGE__->register_method(
230 method => "biblio_id_to_copy",
231 api_name => "open-ils.search.asset.copy.batch.retrieve",);
232 sub biblio_id_to_copy {
233 my( $self, $client, $ids ) = @_;
234 $logger->info("Fetching copies @$ids");
235 return $U->cstorereq(
236 "open-ils.cstore.direct.asset.copy.search.atomic", { id => $ids } );
240 __PACKAGE__->register_method(
241 method => "biblio_id_to_uris",
242 api_name=> "open-ils.search.asset.uri.retrieve_by_bib",
246 @param BibID Which bib record contains the URIs
247 @param OrgID Where to look for URIs
248 @param OrgDepth Range adjustment for OrgID
249 @return A stream or list of 'auri' objects
253 sub biblio_id_to_uris {
254 my( $self, $client, $bib, $org, $depth ) = @_;
255 die "Org ID required" unless defined($org);
256 die "Bib ID required" unless defined($bib);
259 push @params, $depth if (defined $depth);
261 my $ids = $U->cstorereq( "open-ils.cstore.json_query.atomic",
262 { select => { auri => [ 'id' ] },
266 field => 'call_number',
272 filter => { active => 't' }
283 select => { aou => [ { column => 'id', transform => 'actor.org_unit_descendants', params => \@params, result_field => 'id' } ] },
285 where => { id => $org },
295 my $uris = $U->cstorereq(
296 "open-ils.cstore.direct.asset.uri.search.atomic",
297 { id => [ map { (values %$_) } @$ids ] }
300 $client->respond($_) for (@$uris);
306 __PACKAGE__->register_method(
307 method => "copy_retrieve",
308 api_name => "open-ils.search.asset.copy.retrieve",);
310 my( $self, $client, $cid ) = @_;
311 my( $copy, $evt ) = $U->fetch_copy($cid);
316 __PACKAGE__->register_method(
317 method => "volume_retrieve",
318 api_name => "open-ils.search.asset.call_number.retrieve");
319 sub volume_retrieve {
320 my( $self, $client, $vid ) = @_;
321 my $e = new_editor();
322 my $vol = $e->retrieve_asset_call_number($vid) or return $e->event;
326 __PACKAGE__->register_method(
327 method => "fleshed_copy_retrieve_batch",
329 api_name => "open-ils.search.asset.copy.fleshed.batch.retrieve");
331 sub fleshed_copy_retrieve_batch {
332 my( $self, $client, $ids ) = @_;
333 $logger->info("Fetching fleshed copies @$ids");
334 return $U->cstorereq(
335 "open-ils.cstore.direct.asset.copy.search.atomic",
338 flesh_fields => { acp => [ qw/ circ_lib location status stat_cat_entries / ] }
343 __PACKAGE__->register_method(
344 method => "fleshed_copy_retrieve",
345 api_name => "open-ils.search.asset.copy.fleshed.retrieve",);
347 sub fleshed_copy_retrieve {
348 my( $self, $client, $id ) = @_;
349 my( $c, $e) = $U->fetch_fleshed_copy($id);
356 __PACKAGE__->register_method(
357 method => 'fleshed_by_barcode',
358 api_name => "open-ils.search.asset.copy.fleshed2.find_by_barcode",);
359 sub fleshed_by_barcode {
360 my( $self, $conn, $barcode ) = @_;
361 my $e = new_editor();
362 my $copyid = $e->search_asset_copy(
363 {barcode => $barcode, deleted => 'f'}, {idlist=>1})->[0]
365 return fleshed_copy_retrieve2( $self, $conn, $copyid);
369 __PACKAGE__->register_method(
370 method => "fleshed_copy_retrieve2",
371 api_name => "open-ils.search.asset.copy.fleshed2.retrieve",);
373 sub fleshed_copy_retrieve2 {
374 my( $self, $client, $id ) = @_;
375 my $e = new_editor();
376 my $copy = $e->retrieve_asset_copy(
382 acp => [ qw/ location status stat_cat_entry_copy_maps notes age_protect / ],
383 ascecm => [ qw/ stat_cat stat_cat_entry / ],
387 ) or return $e->event;
389 # For backwards compatibility
390 #$copy->stat_cat_entries($copy->stat_cat_entry_copy_maps);
392 if( $copy->status->id == OILS_COPY_STATUS_CHECKED_OUT ) {
394 $e->search_action_circulation(
396 { target_copy => $copy->id },
398 order_by => { circ => 'xact_start desc' },
410 __PACKAGE__->register_method(
411 method => 'flesh_copy_custom',
412 api_name => 'open-ils.search.asset.copy.fleshed.custom'
415 sub flesh_copy_custom {
416 my( $self, $conn, $copyid, $fields ) = @_;
417 my $e = new_editor();
418 my $copy = $e->retrieve_asset_copy(
428 ) or return $e->event;
437 __PACKAGE__->register_method(
438 method => "biblio_barcode_to_title",
439 api_name => "open-ils.search.biblio.find_by_barcode",
442 sub biblio_barcode_to_title {
443 my( $self, $client, $barcode ) = @_;
445 my $title = $apputils->simple_scalar_request(
447 "open-ils.storage.biblio.record_entry.retrieve_by_barcode", $barcode );
449 return { ids => [ $title->id ], count => 1 } if $title;
450 return { count => 0 };
453 __PACKAGE__->register_method(
454 method => 'title_id_by_item_barcode',
455 api_name => 'open-ils.search.bib_id.by_barcode'
458 sub title_id_by_item_barcode {
459 my( $self, $conn, $barcode ) = @_;
460 my $e = new_editor();
461 my $copies = $e->search_asset_copy(
463 { deleted => 'f', barcode => $barcode },
467 acp => [ 'call_number' ],
474 return $e->event unless @$copies;
475 return $$copies[0]->call_number->record->id;
479 __PACKAGE__->register_method(
480 method => "biblio_copy_to_mods",
481 api_name => "open-ils.search.biblio.copy.mods.retrieve",
484 # takes a copy object and returns it fleshed mods object
485 sub biblio_copy_to_mods {
486 my( $self, $client, $copy ) = @_;
488 my $volume = $U->cstorereq(
489 "open-ils.cstore.direct.asset.call_number.retrieve",
490 $copy->call_number() );
492 my $mods = _records_to_mods($volume->record());
493 $mods = shift @$mods;
494 $volume->copies([$copy]);
495 push @{$mods->call_numbers()}, $volume;
501 __PACKAGE__->register_method(
502 api_name => 'open-ils.search.biblio.multiclass.query',
503 method => 'multiclass_query',
505 @param arghash @see open-ils.search.biblio.multiclass
506 @param query Raw human-readable query string.
507 Recognized search keys include:
508 keyword/kw - search keyword(s)
509 author/au/name - search author(s)
510 title/ti - search title
511 subject/su - search subject
512 series/se - search series
513 lang - limit by language (specifiy multiple langs with lang:l1 lang:l2 ...)
514 site - search at specified org unit, corresponds to actor.org_unit.shortname
515 sort - sort type (title, author, pubdate)
516 dir - sort direction (asc, desc)
517 available - if set to anything other than "false" or "0", limits to available items
519 keyword, title, author, subject, and series support additional search
520 subclasses, specified with a "|". For example, "title|proper:gone with the wind"
521 For more, see config.metabib_field
523 @param docache @see open-ils.search.biblio.multiclass
526 __PACKAGE__->register_method(
527 api_name => 'open-ils.search.biblio.multiclass.query.staff',
528 method => 'multiclass_query',
529 signature => '@see open-ils.search.biblio.multiclass.query');
530 __PACKAGE__->register_method(
531 api_name => 'open-ils.search.metabib.multiclass.query',
532 method => 'multiclass_query',
533 signature => '@see open-ils.search.biblio.multiclass.query');
534 __PACKAGE__->register_method(
535 api_name => 'open-ils.search.metabib.multiclass.query.staff',
536 method => 'multiclass_query',
537 signature => '@see open-ils.search.biblio.multiclass.query');
539 sub multiclass_query {
540 my($self, $conn, $arghash, $query, $docache) = @_;
542 $logger->debug("initial search query => $query");
543 my $orig_query = $query;
547 $query =~ s/^\s+//go;
549 # convert convenience classes (e.g. kw for keyword) to the full class name
550 $query =~ s/kw(:|\|)/keyword$1/go;
551 $query =~ s/ti(:|\|)/title$1/go;
552 $query =~ s/au(:|\|)/author$1/go;
553 $query =~ s/su(:|\|)/subject$1/go;
554 $query =~ s/se(:|\|)/series$1/go;
555 $query =~ s/name(:|\|)/author$1/og;
557 $logger->debug("cleansed query string => $query");
558 my $search = $arghash->{searches} = {};
560 while ($query =~ s/((?:keyword(?:\|\w+)?|title(?:\|\w+)?|author(?:\|\w+)?|subject(?:\|\w+)?|series(?:\|\w+)?|site|dir|sort|lang|available):[^:]+)$//so) {
561 my($type, $value) = split(':', $1);
562 next unless $type and $value;
564 $value =~ s/^\s*//og;
565 $value =~ s/\s*$//og;
566 $type = 'sort_dir' if $type eq 'dir';
568 if($type eq 'site') {
569 # 'site' is the org shortname. when using this, we also want
570 # to search at the requested org's depth
571 my $e = new_editor();
572 if(my $org = $e->search_actor_org_unit({shortname => $value})->[0]) {
573 $arghash->{org_unit} = $org->id if $org;
574 $arghash->{depth} = $e->retrieve_actor_org_unit_type($org->ou_type)->depth;
576 $logger->warn("'site:' query used on invalid org shortname: $value ... ignoring");
579 } elsif($type eq 'available') {
581 $arghash->{available} = 1 unless $value eq 'false' or $value eq '0';
583 } elsif($type eq 'lang') {
584 # collect languages into an array of languages
585 $arghash->{language} = [] unless $arghash->{language};
586 push(@{$arghash->{language}}, $value);
588 } elsif($type =~ /^sort/o) {
589 # sort and sort_dir modifiers
590 $arghash->{$type} = $value;
593 # append the search term to the term under construction
594 $search->{$type} = {} unless $search->{$type};
595 $search->{$type}->{term} =
596 ($search->{$type}->{term}) ? $search->{$type}->{term} . " $value" : $value;
601 # This is the front part of the string before any special tokens were parsed.
602 # Add this data to the default search class
603 my $type = $arghash->{default_class} || 'keyword';
604 $search->{$type} = {} unless $search->{$type};
605 $search->{$type}->{term} =
606 ($search->{$type}->{term}) ? $search->{$type}->{term} . " $query" : $query;
609 # capture the original limit because the search method alters the limit internally
610 my $ol = $arghash->{limit};
612 my $sclient = OpenSRF::Utils::SettingsClient->new;
614 (my $method = $self->api_name) =~ s/\.query//o;
616 $method =~ s/multiclass/multiclass.staged/
617 if $sclient->config_value(apps => 'open-ils.search',
618 app_settings => 'use_staged_search') =~ /true/i;
620 $arghash->{preferred_language} = $U->get_org_locale($arghash->{org_unit})
621 unless $arghash->{preferred_language};
623 $method = $self->method_lookup($method);
624 my ($data) = $method->run($arghash, $docache);
626 $arghash->{limit} = $ol if $ol;
627 $data->{compiled_search} = $arghash;
628 $data->{query} = $orig_query;
630 $logger->info("compiled search is " . OpenSRF::Utils::JSON->perl2JSON($arghash));
635 __PACKAGE__->register_method(
636 method => 'cat_search_z_style_wrapper',
637 api_name => 'open-ils.search.biblio.zstyle',
639 signature => q/@see open-ils.search.biblio.multiclass/);
641 __PACKAGE__->register_method(
642 method => 'cat_search_z_style_wrapper',
643 api_name => 'open-ils.search.biblio.zstyle.staff',
645 signature => q/@see open-ils.search.biblio.multiclass/);
647 sub cat_search_z_style_wrapper {
650 my $authtoken = shift;
653 my $cstore = OpenSRF::AppSession->connect('open-ils.cstore');
655 my $ou = $cstore->request(
656 'open-ils.cstore.direct.actor.org_unit.search',
657 { parent_ou => undef }
660 my $result = { service => 'native-evergreen-catalog', records => [] };
661 my $searchhash = { limit => $$args{limit}, offset => $$args{offset}, org_unit => $ou->id };
663 $$searchhash{searches}{title}{term} = $$args{search}{title} if $$args{search}{title};
664 $$searchhash{searches}{author}{term} = $$args{search}{author} if $$args{search}{author};
665 $$searchhash{searches}{subject}{term} = $$args{search}{subject} if $$args{search}{subject};
666 $$searchhash{searches}{keyword}{term} = $$args{search}{keyword} if $$args{search}{keyword};
668 $$searchhash{searches}{keyword}{term} .= join ' ', $$searchhash{searches}{keyword}{term}, $$args{search}{tcn} if $$args{search}{tcn};
669 $$searchhash{searches}{keyword}{term} .= join ' ', $$searchhash{searches}{keyword}{term}, $$args{search}{isbn} if $$args{search}{isbn};
670 $$searchhash{searches}{keyword}{term} .= join ' ', $$searchhash{searches}{keyword}{term}, $$args{search}{issn} if $$args{search}{issn};
671 $$searchhash{searches}{keyword}{term} .= join ' ', $$searchhash{searches}{keyword}{term}, $$args{search}{publisher} if $$args{search}{publisher};
672 $$searchhash{searches}{keyword}{term} .= join ' ', $$searchhash{searches}{keyword}{term}, $$args{search}{pubdate} if $$args{search}{pubdate};
673 $$searchhash{searches}{keyword}{term} .= join ' ', $$searchhash{searches}{keyword}{term}, $$args{search}{item_type} if $$args{search}{item_type};
675 my $list = the_quest_for_knowledge( $self, $client, $searchhash );
677 if ($list->{count} > 0) {
678 $result->{count} = $list->{count};
680 my $records = $cstore->request(
681 'open-ils.cstore.direct.biblio.record_entry.search.atomic',
682 { id => [ map { ( $_->[0] ) } @{$list->{ids}} ] }
685 for my $rec ( @$records ) {
687 my $u = OpenILS::Utils::ModsParser->new();
688 $u->start_mods_batch( $rec->marc );
689 my $mods = $u->finish_mods_batch();
691 push @{ $result->{records} }, { mvr => $mods, marcxml => $rec->marc, bibid => $rec->id };
697 $cstore->disconnect();
701 # ----------------------------------------------------------------------------
702 # These are the main OPAC search methods
703 # ----------------------------------------------------------------------------
705 __PACKAGE__->register_method(
706 method => 'the_quest_for_knowledge',
707 api_name => 'open-ils.search.biblio.multiclass',
709 Performs a multi class biblio or metabib search
710 @param searchhash A search object layed out like so:
711 searches : { "$class" : "$value", ...}
712 org_unit : The org id to focus the search at
713 depth : The org depth
714 limit : The search limit
715 offset : The search offset
716 format : The MARC format
717 sort : What field to sort the results on [ author | title | pubdate ]
718 sort_dir : What direction do we sort? [ asc | desc ]
719 @return An object of the form
720 { "count" : $count, "ids" : [ [ $id, $relevancy, $total ], ...] }
724 __PACKAGE__->register_method(
725 method => 'the_quest_for_knowledge',
726 api_name => 'open-ils.search.biblio.multiclass.staff',
727 signature => q/@see open-ils.search.biblio.multiclass/);
728 __PACKAGE__->register_method(
729 method => 'the_quest_for_knowledge',
730 api_name => 'open-ils.search.metabib.multiclass',
731 signature => q/@see open-ils.search.biblio.multiclass/);
732 __PACKAGE__->register_method(
733 method => 'the_quest_for_knowledge',
734 api_name => 'open-ils.search.metabib.multiclass.staff',
735 signature => q/@see open-ils.search.biblio.multiclass/);
737 sub the_quest_for_knowledge {
738 my( $self, $conn, $searchhash, $docache ) = @_;
740 return { count => 0 } unless $searchhash and
741 ref $searchhash->{searches} eq 'HASH';
743 my $method = 'open-ils.storage.biblio.multiclass.search_fts';
747 if($self->api_name =~ /metabib/) {
749 $method =~ s/biblio/metabib/o;
753 my $offset = $searchhash->{offset} || 0;
754 my $limit = $searchhash->{limit} || 10;
755 my $end = $offset + $limit - 1;
757 # do some simple sanity checking
758 if(!$searchhash->{searches} or
759 ( !grep { /^(?:title|author|subject|series|keyword)/ } keys %{$searchhash->{searches}} ) ) {
760 return { count => 0 };
765 $searchhash->{offset} = 0;
766 $searchhash->{limit} = $maxlimit;
768 return { count => 0 } if $offset > $maxlimit;
771 push( @search, ($_ => $$searchhash{$_})) for (sort keys %$searchhash);
772 my $s = OpenSRF::Utils::JSON->perl2JSON(\@search);
773 my $ckey = $pfx . md5_hex($method . $s);
775 $logger->info("bib search for: $s");
777 $searchhash->{limit} -= $offset;
781 my $result = ($docache) ? search_cache($ckey, $offset, $limit) : undef;
785 $method .= ".staff" if($self->api_name =~ /staff/);
786 $method .= ".atomic";
788 for (keys %$searchhash) {
789 delete $$searchhash{$_}
790 unless defined $$searchhash{$_};
793 $result = $U->storagereq( $method, %$searchhash );
800 return {count => 0} unless ($result && $$result[0]);
804 my $count = ($ismeta) ? $result->[0]->[3] : $result->[0]->[2];
807 # If we didn't get this data from the cache, put it into the cache
808 # then return the correct offset of records
809 $logger->debug("putting search cache $ckey\n");
810 put_cache($ckey, $count, \@recs);
814 # if we have the full set of data, trim out
815 # the requested chunk based on limit and offset
817 for ($offset..$end) {
818 last unless $recs[$_];
824 return { ids => \@recs, count => $count };
828 __PACKAGE__->register_method(
829 method => 'staged_search',
830 api_name => 'open-ils.search.biblio.multiclass.staged');
831 __PACKAGE__->register_method(
832 method => 'staged_search',
833 api_name => 'open-ils.search.biblio.multiclass.staged.staff',
834 signature => q/@see open-ils.search.biblio.multiclass.staged/);
835 __PACKAGE__->register_method(
836 method => 'staged_search',
837 api_name => 'open-ils.search.metabib.multiclass.staged',
838 signature => q/@see open-ils.search.biblio.multiclass.staged/);
839 __PACKAGE__->register_method(
840 method => 'staged_search',
841 api_name => 'open-ils.search.metabib.multiclass.staged.staff',
842 signature => q/@see open-ils.search.biblio.multiclass.staged/);
845 my($self, $conn, $search_hash, $docache) = @_;
847 my $method = ($self->api_name =~ /metabib/) ?
848 'open-ils.storage.metabib.multiclass.staged.search_fts':
849 'open-ils.storage.biblio.multiclass.staged.search_fts';
851 $method .= '.staff' if $self->api_name =~ /staff$/;
852 $method .= '.atomic';
855 my $user_offset = $search_hash->{offset} || 0; # user-specified offset
856 my $user_limit = $search_hash->{limit} || 10;
857 $user_offset = ($user_offset >= 0) ? $user_offset : 0;
858 $user_limit = ($user_limit >= 0) ? $user_limit : 10;
861 # we're grabbing results on a per-superpage basis, which means the
862 # limit and offset should coincide with superpage boundaries
863 $search_hash->{offset} = 0;
864 $search_hash->{limit} = $superpage_size;
866 # force a well-known check_limit
867 $search_hash->{check_limit} = $superpage_size;
868 # restrict total tested to superpage size * number of superpages
869 $search_hash->{core_limit} = $superpage_size * $max_superpages;
871 # Set the configured estimation strategy, defaults to 'inclusion'.
872 my $estimation_strategy = OpenSRF::Utils::SettingsClient
875 apps => 'open-ils.search', app_settings => 'estimation_strategy'
877 $search_hash->{estimation_strategy} = $estimation_strategy;
879 # pull any existing results from the cache
880 my $key = search_cache_key($method, $search_hash);
881 my $cache_data = $cache->get_cache($key) || {};
883 # keep retrieving results until we find enough to
884 # fulfill the user-specified limit and offset
885 my $all_results = [];
886 my $page; # current superpage
887 my $est_hit_count = 0;
888 my $current_page_summary = {};
889 my $global_summary = {checked => 0, visible => 0, excluded => 0, deleted => 0, total => 0};
890 my $is_real_hit_count = 0;
892 for($page = 0; $page < $max_superpages; $page++) {
894 my $data = $cache_data->{$page};
898 $logger->debug("staged search: analyzing superpage $page");
901 # this window of results is already cached
902 $logger->debug("staged search: found cached results");
903 $summary = $data->{summary};
904 $results = $data->{results};
907 # retrieve the window of results from the database
908 $logger->debug("staged search: fetching results from the database");
909 $search_hash->{skip_check} = $page * $superpage_size;
911 $results = $U->storagereq($method, %$search_hash);
912 $search_duration = time - $start;
913 $logger->info("staged search: DB call took $search_duration seconds");
914 $summary = shift(@$results);
917 $logger->info("search timed out: duration=$search_duration: params=".
918 OpenSRF::Utils::JSON->perl2JSON($search_hash));
922 my $hc = $summary->{estimated_hit_count} || $summary->{visible};
924 $logger->info("search returned 0 results: duration=$search_duration: params=".
925 OpenSRF::Utils::JSON->perl2JSON($search_hash));
928 # Create backwards-compatible result structures
929 if($self->api_name =~ /biblio/) {
930 $results = [map {[$_->{id}]} @$results];
932 $results = [map {[$_->{id}, $_->{rel}, $_->{record}]} @$results];
935 $results = [grep {defined $_->[0]} @$results];
936 cache_staged_search_page($key, $page, $summary, $results) if $docache;
939 $current_page_summary = $summary;
941 # add the new set of results to the set under construction
942 push(@$all_results, @$results);
944 my $current_count = scalar(@$all_results);
946 $est_hit_count = $summary->{estimated_hit_count} || $summary->{visible}
949 $logger->debug("staged search: located $current_count, with estimated hits=".
950 $summary->{estimated_hit_count}." : visible=".$summary->{visible}.", checked=".$summary->{checked});
952 if (defined($summary->{estimated_hit_count})) {
953 $global_summary->{checked} += $summary->{checked};
954 $global_summary->{visible} += $summary->{visible};
955 $global_summary->{excluded} += $summary->{excluded};
956 $global_summary->{deleted} += $summary->{deleted};
957 $global_summary->{total} = $summary->{total};
960 # we've found all the possible hits
961 last if $current_count == $summary->{visible}
962 and not defined $summary->{estimated_hit_count};
964 # we've found enough results to satisfy the requested limit/offset
965 last if $current_count >= ($user_limit + $user_offset);
967 # we've scanned all possible hits
968 if($summary->{checked} < $superpage_size) {
969 $est_hit_count = scalar(@$all_results);
970 # we have all possible results in hand, so we know the final hit count
971 $is_real_hit_count = 1;
976 my @results = grep {defined $_} @$all_results[$user_offset..($user_offset + $user_limit - 1)];
978 # refine the estimate if we have more than one superpage
979 if ($page > 0 and not $is_real_hit_count) {
980 if ($global_summary->{checked} >= $global_summary->{total}) {
981 $est_hit_count = $global_summary->{visible};
983 my $updated_hit_count = $U->storagereq(
984 'open-ils.storage.fts_paging_estimate',
985 $global_summary->{checked},
986 $global_summary->{visible},
987 $global_summary->{excluded},
988 $global_summary->{deleted},
989 $global_summary->{total}
991 $est_hit_count = $updated_hit_count->{$estimation_strategy};
996 count => $est_hit_count,
997 core_limit => $search_hash->{core_limit},
998 superpage_size => $search_hash->{check_limit},
999 superpage_summary => $current_page_summary,
1004 # creates a unique token to represent the query in the cache
1005 sub search_cache_key {
1007 my $search_hash = shift;
1009 for my $key (sort keys %$search_hash) {
1010 push(@sorted, ($key => $$search_hash{$key}))
1011 unless $key eq 'limit' or
1013 $key eq 'skip_check';
1015 my $s = OpenSRF::Utils::JSON->perl2JSON(\@sorted);
1016 return $pfx . md5_hex($method . $s);
1019 sub cache_staged_search_page {
1020 # puts this set of results into the cache
1021 my($key, $page, $summary, $results) = @_;
1022 my $data = $cache->get_cache($key);
1025 summary => $summary,
1029 $logger->info("staged search: cached with key=$key, superpage=$page, estimated=".
1030 $summary->{estimated_hit_count}.", visible=".$summary->{visible});
1032 $cache->put_cache($key, $data, $cache_timeout);
1040 my $start = $offset;
1041 my $end = $offset + $limit - 1;
1043 $logger->debug("searching cache for $key : $start..$end\n");
1045 return undef unless $cache;
1046 my $data = $cache->get_cache($key);
1048 return undef unless $data;
1050 my $count = $data->[0];
1053 return undef unless $offset < $count;
1056 for( my $i = $offset; $i <= $end; $i++ ) {
1057 last unless my $d = $$data[$i];
1058 push( @result, $d );
1061 $logger->debug("search_cache found ".scalar(@result)." items for count=$count, start=$start, end=$end");
1068 my( $key, $count, $data ) = @_;
1069 return undef unless $cache;
1070 $logger->debug("search_cache putting ".
1071 scalar(@$data)." items at key $key with timeout $cache_timeout");
1072 $cache->put_cache($key, [ $count, $data ], $cache_timeout);
1080 __PACKAGE__->register_method(
1081 method => "biblio_mrid_to_modsbatch_batch",
1082 api_name => "open-ils.search.biblio.metarecord.mods_slim.batch.retrieve");
1084 sub biblio_mrid_to_modsbatch_batch {
1085 my( $self, $client, $mrids) = @_;
1086 warn "Performing mrid_to_modsbatch_batch...";
1088 my $method = $self->method_lookup("open-ils.search.biblio.metarecord.mods_slim.retrieve");
1089 for my $id (@$mrids) {
1090 next unless defined $id;
1091 my ($m) = $method->run($id);
1098 __PACKAGE__->register_method(
1099 method => "biblio_mrid_to_modsbatch",
1100 api_name => "open-ils.search.biblio.metarecord.mods_slim.retrieve",
1101 notes => <<" NOTES");
1102 Returns the mvr associated with a given metarecod. If none exists,
1106 __PACKAGE__->register_method(
1107 method => "biblio_mrid_to_modsbatch",
1108 api_name => "open-ils.search.biblio.metarecord.mods_slim.retrieve.staff",
1109 notes => <<" NOTES");
1110 Returns the mvr associated with a given metarecod. If none exists,
1114 sub biblio_mrid_to_modsbatch {
1115 my( $self, $client, $mrid, $args) = @_;
1117 warn "Grabbing mvr for $mrid\n";
1119 my ($mr, $evt) = _grab_metarecord($mrid);
1120 return $evt unless $mr;
1122 my $mvr = biblio_mrid_check_mvr($self, $client, $mr);
1123 $mvr = biblio_mrid_make_modsbatch( $self, $client, $mr ) unless $mvr;
1125 return $mvr unless ref($args);
1127 # Here we find the lead record appropriate for the given filters
1128 # and use that for the title and author of the metarecord
1129 my $format = $$args{format};
1130 my $org = $$args{org};
1131 my $depth = $$args{depth};
1133 return $mvr unless $format or $org or $depth;
1135 my $method = "open-ils.storage.ordered.metabib.metarecord.records";
1136 $method = "$method.staff" if $self->api_name =~ /staff/o;
1138 my $rec = $U->storagereq($method, $format, $org, $depth, 1);
1140 if( my $mods = $U->record_to_mvr($rec) ) {
1142 $mvr->title($mods->title);
1143 $mvr->title($mods->author);
1144 $logger->debug("mods_slim updating title and ".
1145 "author in mvr with ".$mods->title." : ".$mods->author);
1151 # converts a metarecord to an mvr
1154 my $perl = OpenSRF::Utils::JSON->JSON2perl($mr->mods());
1155 return Fieldmapper::metabib::virtual_record->new($perl);
1158 # checks to see if a metarecord has mods, if so returns true;
1160 __PACKAGE__->register_method(
1161 method => "biblio_mrid_check_mvr",
1162 api_name => "open-ils.search.biblio.metarecord.mods_slim.check",
1163 notes => <<" NOTES");
1164 Takes a metarecord ID or a metarecord object and returns true
1165 if the metarecord already has an mvr associated with it.
1168 sub biblio_mrid_check_mvr {
1169 my( $self, $client, $mrid ) = @_;
1173 if(ref($mrid)) { $mr = $mrid; }
1174 else { ($mr, $evt) = _grab_metarecord($mrid); }
1175 return $evt if $evt;
1177 warn "Checking mvr for mr " . $mr->id . "\n";
1179 return _mr_to_mvr($mr) if $mr->mods();
1183 sub _grab_metarecord {
1185 #my $e = OpenILS::Utils::Editor->new;
1186 my $e = new_editor();
1187 my $mr = $e->retrieve_metabib_metarecord($mrid) or return ( undef, $e->event );
1192 __PACKAGE__->register_method(
1193 method => "biblio_mrid_make_modsbatch",
1194 api_name => "open-ils.search.biblio.metarecord.mods_slim.create",
1195 notes => <<" NOTES");
1196 Takes either a metarecord ID or a metarecord object.
1197 Forces the creations of an mvr for the given metarecord.
1198 The created mvr is returned.
1201 sub biblio_mrid_make_modsbatch {
1202 my( $self, $client, $mrid ) = @_;
1204 #my $e = OpenILS::Utils::Editor->new;
1205 my $e = new_editor();
1212 $mr = $e->retrieve_metabib_metarecord($mrid)
1213 or return $e->event;
1216 my $masterid = $mr->master_record;
1217 $logger->info("creating new mods batch for metarecord=$mrid, master record=$masterid");
1219 my $ids = $U->storagereq(
1220 'open-ils.storage.ordered.metabib.metarecord.records.staff.atomic', $mrid);
1221 return undef unless @$ids;
1223 my $master = $e->retrieve_biblio_record_entry($masterid)
1224 or return $e->event;
1226 # start the mods batch
1227 my $u = OpenILS::Utils::ModsParser->new();
1228 $u->start_mods_batch( $master->marc );
1230 # grab all of the sub-records and shove them into the batch
1231 my @ids = grep { $_ ne $masterid } @$ids;
1232 #my $subrecs = (@ids) ? $e->batch_retrieve_biblio_record_entry(\@ids) : [];
1237 my $r = $e->retrieve_biblio_record_entry($i);
1238 push( @$subrecs, $r ) if $r;
1243 $logger->debug("adding record ".$_->id." to mods batch for metarecord=$mrid");
1244 $u->push_mods_batch( $_->marc ) if $_->marc;
1248 # finish up and send to the client
1249 my $mods = $u->finish_mods_batch();
1250 $mods->doc_id($mrid);
1251 $client->respond_complete($mods);
1254 # now update the mods string in the db
1255 my $string = OpenSRF::Utils::JSON->perl2JSON($mods->decast);
1258 #$e = OpenILS::Utils::Editor->new(xact => 1);
1259 $e = new_editor(xact => 1);
1260 $e->update_metabib_metarecord($mr)
1261 or $logger->error("Error setting mods text on metarecord $mrid : " . Dumper($e->event));
1270 # converts a mr id into a list of record ids
1272 __PACKAGE__->register_method(
1273 method => "biblio_mrid_to_record_ids",
1274 api_name => "open-ils.search.biblio.metarecord_to_records",
1277 __PACKAGE__->register_method(
1278 method => "biblio_mrid_to_record_ids",
1279 api_name => "open-ils.search.biblio.metarecord_to_records.staff",
1282 sub biblio_mrid_to_record_ids {
1283 my( $self, $client, $mrid, $args ) = @_;
1285 my $format = $$args{format};
1286 my $org = $$args{org};
1287 my $depth = $$args{depth};
1289 my $method = "open-ils.storage.ordered.metabib.metarecord.records.atomic";
1290 $method =~ s/atomic/staff\.atomic/o if $self->api_name =~ /staff/o;
1291 my $recs = $U->storagereq($method, $mrid, $format, $org, $depth);
1293 return { count => scalar(@$recs), ids => $recs };
1297 __PACKAGE__->register_method(
1298 method => "biblio_record_to_marc_html",
1299 api_name => "open-ils.search.biblio.record.html" );
1301 __PACKAGE__->register_method(
1302 method => "biblio_record_to_marc_html",
1303 api_name => "open-ils.search.authority.to_html" );
1305 my $parser = XML::LibXML->new();
1306 my $xslt = XML::LibXSLT->new();
1308 my $slim_marc_sheet;
1309 my $settings_client = OpenSRF::Utils::SettingsClient->new();
1311 sub biblio_record_to_marc_html {
1312 my($self, $client, $recordid, $slim, $marcxml) = @_;
1315 my $dir = $settings_client->config_value("dirs", "xsl");
1318 unless($slim_marc_sheet) {
1319 my $xsl = $settings_client->config_value(
1320 "apps", "open-ils.search", "app_settings", 'marc_html_xsl_slim');
1322 $xsl = $parser->parse_file("$dir/$xsl");
1323 $slim_marc_sheet = $xslt->parse_stylesheet($xsl);
1326 $sheet = $slim_marc_sheet;
1330 unless($marc_sheet) {
1331 my $xsl_key = ($slim) ? 'marc_html_xsl_slim' : 'marc_html_xsl';
1332 my $xsl = $settings_client->config_value(
1333 "apps", "open-ils.search", "app_settings", 'marc_html_xsl');
1334 $xsl = $parser->parse_file("$dir/$xsl");
1335 $marc_sheet = $xslt->parse_stylesheet($xsl);
1337 $sheet = $marc_sheet;
1342 my $e = new_editor();
1343 if($self->api_name =~ /authority/) {
1344 $record = $e->retrieve_authority_record_entry($recordid)
1345 or return $e->event;
1347 $record = $e->retrieve_biblio_record_entry($recordid)
1348 or return $e->event;
1350 $marcxml = $record->marc;
1353 my $xmldoc = $parser->parse_string($marcxml);
1354 my $html = $sheet->transform($xmldoc);
1355 return $html->documentElement->toString();
1360 __PACKAGE__->register_method(
1361 method => "retrieve_all_copy_statuses",
1362 api_name => "open-ils.search.config.copy_status.retrieve.all" );
1364 sub retrieve_all_copy_statuses {
1365 my( $self, $client ) = @_;
1366 return new_editor()->retrieve_all_config_copy_status();
1370 __PACKAGE__->register_method(
1371 method => "copy_counts_per_org",
1372 api_name => "open-ils.search.biblio.copy_counts.retrieve");
1374 __PACKAGE__->register_method(
1375 method => "copy_counts_per_org",
1376 api_name => "open-ils.search.biblio.copy_counts.retrieve.staff");
1378 sub copy_counts_per_org {
1379 my( $self, $client, $record_id ) = @_;
1381 warn "Retreiveing copy copy counts for record $record_id and method " . $self->api_name . "\n";
1383 my $method = "open-ils.storage.biblio.record_entry.global_copy_count.atomic";
1384 if($self->api_name =~ /staff/) { $method =~ s/atomic/staff\.atomic/; }
1386 my $counts = $apputils->simple_scalar_request(
1387 "open-ils.storage", $method, $record_id );
1389 $counts = [ sort {$a->[0] <=> $b->[0]} @$counts ];
1394 __PACKAGE__->register_method(
1395 method => "copy_count_summary",
1396 api_name => "open-ils.search.biblio.copy_counts.summary.retrieve",
1397 notes => <<" NOTES");
1398 returns an array of these:
1399 [ org_id, callnumber_label, <status1_count>, <status2_count>,...]
1400 where statusx is a copy status name. the statuses are sorted
1404 sub copy_count_summary {
1405 my( $self, $client, $rid, $org, $depth ) = @_;
1408 my $data = $U->storagereq(
1409 'open-ils.storage.biblio.record_entry.status_copy_count.atomic', $rid, $org, $depth );
1411 return [ sort { $a->[1] cmp $b->[1] } @$data ];
1414 __PACKAGE__->register_method(
1415 method => "copy_location_count_summary",
1416 api_name => "open-ils.search.biblio.copy_location_counts.summary.retrieve",
1417 notes => <<" NOTES");
1418 returns an array of these:
1419 [ org_id, callnumber_label, copy_location, <status1_count>, <status2_count>,...]
1420 where statusx is a copy status name. the statuses are sorted
1424 sub copy_location_count_summary {
1425 my( $self, $client, $rid, $org, $depth ) = @_;
1428 my $data = $U->storagereq(
1429 'open-ils.storage.biblio.record_entry.status_copy_location_count.atomic', $rid, $org, $depth );
1431 return [ sort { $a->[1] cmp $b->[1] || $a->[2] cmp $b->[2] } @$data ];
1434 __PACKAGE__->register_method(
1435 method => "copy_count_location_summary",
1436 api_name => "open-ils.search.biblio.copy_counts.location.summary.retrieve",
1437 notes => <<" NOTES");
1438 returns an array of these:
1439 [ org_id, callnumber_label, <status1_count>, <status2_count>,...]
1440 where statusx is a copy status name. the statuses are sorted
1444 sub copy_count_location_summary {
1445 my( $self, $client, $rid, $org, $depth ) = @_;
1448 my $data = $U->storagereq(
1449 'open-ils.storage.biblio.record_entry.status_copy_location_count.atomic', $rid, $org, $depth );
1450 return [ sort { $a->[1] cmp $b->[1] } @$data ];
1454 __PACKAGE__->register_method(
1455 method => "marc_search",
1456 api_name => "open-ils.search.biblio.marc.staff");
1458 __PACKAGE__->register_method(
1459 method => "marc_search",
1460 api_name => "open-ils.search.biblio.marc",
1461 notes => <<" NOTES");
1463 open-ils.storage.biblio.full_rec.multi_search.atomic
1464 { "searches": [{"term":"harry","restrict": [{"tag":245,"subfield":"a"}]}], "org_unit": 1,
1465 "limit":5,"sort":"author","item_type":"g"}
1469 my( $self, $conn, $args, $limit, $offset ) = @_;
1471 my $method = 'open-ils.storage.biblio.full_rec.multi_search';
1472 $method .= ".staff" if $self->api_name =~ /staff/;
1473 $method .= ".atomic";
1479 push( @search, ($_ => $$args{$_}) ) for (sort keys %$args);
1480 my $ckey = $pfx . md5_hex($method . OpenSRF::Utils::JSON->perl2JSON(\@search));
1482 my $recs = search_cache($ckey, $offset, $limit);
1485 $recs = $U->storagereq($method, %$args) || [];
1487 put_cache($ckey, scalar(@$recs), $recs);
1488 $recs = [ @$recs[$offset..($offset + ($limit - 1))] ];
1495 $count = $recs->[0]->[2] if $recs->[0] and $recs->[0]->[2];
1496 my @recs = map { $_->[0] } @$recs;
1498 return { ids => \@recs, count => $count };
1502 __PACKAGE__->register_method(
1503 method => "biblio_search_isbn",
1504 api_name => "open-ils.search.biblio.isbn",
1507 sub biblio_search_isbn {
1508 my( $self, $client, $isbn ) = @_;
1509 $logger->debug("Searching ISBN $isbn");
1510 my $e = new_editor();
1511 my $recs = $U->storagereq(
1512 'open-ils.storage.id_list.biblio.record_entry.search.isbn.atomic', $isbn );
1513 return { ids => $recs, count => scalar(@$recs) };
1517 __PACKAGE__->register_method(
1518 method => "biblio_search_issn",
1519 api_name => "open-ils.search.biblio.issn",
1522 sub biblio_search_issn {
1523 my( $self, $client, $issn ) = @_;
1524 $logger->debug("Searching ISSN $issn");
1525 my $e = new_editor();
1527 my $recs = $U->storagereq(
1528 'open-ils.storage.id_list.biblio.record_entry.search.issn.atomic', $issn );
1529 return { ids => $recs, count => scalar(@$recs) };
1535 __PACKAGE__->register_method(
1536 method => "fetch_mods_by_copy",
1537 api_name => "open-ils.search.biblio.mods_from_copy",
1540 sub fetch_mods_by_copy {
1541 my( $self, $client, $copyid ) = @_;
1542 my ($record, $evt) = $apputils->fetch_record_by_copy( $copyid );
1543 return $evt if $evt;
1544 return OpenILS::Event->new('ITEM_NOT_CATALOGED') unless $record->marc;
1545 return $apputils->record_to_mvr($record);
1550 # -------------------------------------------------------------------------------------
1552 __PACKAGE__->register_method(
1553 method => "cn_browse",
1554 api_name => "open-ils.search.callnumber.browse.target",
1555 notes => "Starts a callnumber browse"
1558 __PACKAGE__->register_method(
1559 method => "cn_browse",
1560 api_name => "open-ils.search.callnumber.browse.page_up",
1561 notes => "Returns the previous page of callnumbers",
1564 __PACKAGE__->register_method(
1565 method => "cn_browse",
1566 api_name => "open-ils.search.callnumber.browse.page_down",
1567 notes => "Returns the next page of callnumbers",
1571 # RETURNS array of arrays like so: label, owning_lib, record, id
1573 my( $self, $client, @params ) = @_;
1576 $method = 'open-ils.storage.asset.call_number.browse.target.atomic'
1577 if( $self->api_name =~ /target/ );
1578 $method = 'open-ils.storage.asset.call_number.browse.page_up.atomic'
1579 if( $self->api_name =~ /page_up/ );
1580 $method = 'open-ils.storage.asset.call_number.browse.page_down.atomic'
1581 if( $self->api_name =~ /page_down/ );
1583 return $apputils->simplereq( 'open-ils.storage', $method, @params );
1585 # -------------------------------------------------------------------------------------
1587 __PACKAGE__->register_method(
1588 method => "fetch_cn",
1590 api_name => "open-ils.search.callnumber.retrieve",
1591 notes => "retrieves a callnumber based on ID",
1595 my( $self, $client, $id ) = @_;
1596 my( $cn, $evt ) = $apputils->fetch_callnumber( $id );
1597 return $evt if $evt;
1601 __PACKAGE__->register_method (
1602 method => "fetch_copy_by_cn",
1603 api_name => 'open-ils.search.copies_by_call_number.retrieve',
1605 Returns an array of copy id's by callnumber id
1606 @param cnid The callnumber id
1607 @return An array of copy ids
1611 sub fetch_copy_by_cn {
1612 my( $self, $conn, $cnid ) = @_;
1613 return $U->cstorereq(
1614 'open-ils.cstore.direct.asset.copy.id_list.atomic',
1615 { call_number => $cnid, deleted => 'f' } );
1618 __PACKAGE__->register_method (
1619 method => 'fetch_cn_by_info',
1620 api_name => 'open-ils.search.call_number.retrieve_by_info',
1622 @param label The callnumber label
1623 @param record The record the cn is attached to
1624 @param org The owning library of the cn
1625 @return The callnumber object
1630 sub fetch_cn_by_info {
1631 my( $self, $conn, $label, $record, $org ) = @_;
1632 return $U->cstorereq(
1633 'open-ils.cstore.direct.asset.call_number.search',
1634 { label => $label, record => $record, owning_lib => $org, deleted => 'f' });
1641 __PACKAGE__->register_method (
1642 method => 'bib_extras',
1643 api_name => 'open-ils.search.biblio.lit_form_map.retrieve.all');
1644 __PACKAGE__->register_method (
1645 method => 'bib_extras',
1646 api_name => 'open-ils.search.biblio.item_form_map.retrieve.all');
1647 __PACKAGE__->register_method (
1648 method => 'bib_extras',
1649 api_name => 'open-ils.search.biblio.item_type_map.retrieve.all');
1650 __PACKAGE__->register_method (
1651 method => 'bib_extras',
1652 api_name => 'open-ils.search.biblio.bib_level_map.retrieve.all');
1653 __PACKAGE__->register_method (
1654 method => 'bib_extras',
1655 api_name => 'open-ils.search.biblio.audience_map.retrieve.all');
1660 my $e = new_editor();
1662 return $e->retrieve_all_config_lit_form_map()
1663 if( $self->api_name =~ /lit_form/ );
1665 return $e->retrieve_all_config_item_form_map()
1666 if( $self->api_name =~ /item_form_map/ );
1668 return $e->retrieve_all_config_item_type_map()
1669 if( $self->api_name =~ /item_type_map/ );
1671 return $e->retrieve_all_config_bib_level_map()
1672 if( $self->api_name =~ /bib_level_map/ );
1674 return $e->retrieve_all_config_audience_map()
1675 if( $self->api_name =~ /audience_map/ );
1682 __PACKAGE__->register_method(
1683 method => 'fetch_slim_record',
1684 api_name => 'open-ils.search.biblio.record_entry.slim.retrieve',
1686 Returns a biblio.record_entry without the attached marcxml
1690 sub fetch_slim_record {
1691 my( $self, $conn, $ids ) = @_;
1693 #my $editor = OpenILS::Utils::Editor->new;
1694 my $editor = new_editor();
1697 return $editor->event unless
1698 my $r = $editor->retrieve_biblio_record_entry($_);
1707 __PACKAGE__->register_method(
1708 method => 'rec_to_mr_rec_descriptors',
1709 api_name => 'open-ils.search.metabib.record_to_descriptors',
1711 specialized method...
1712 Given a biblio record id or a metarecord id,
1713 this returns a list of metabib.record_descriptor
1714 objects that live within the same metarecord
1715 @param args Object of args including:
1719 sub rec_to_mr_rec_descriptors {
1720 my( $self, $conn, $args ) = @_;
1722 my $rec = $$args{record};
1723 my $mrec = $$args{metarecord};
1724 my $item_forms = $$args{item_forms};
1725 my $item_types = $$args{item_types};
1726 my $item_lang = $$args{item_lang};
1728 my $e = new_editor();
1732 my $map = $e->search_metabib_metarecord_source_map({source => $rec});
1733 return $e->event unless @$map;
1734 $mrec = $$map[0]->metarecord;
1737 $recs = $e->search_metabib_metarecord_source_map({metarecord => $mrec});
1738 return $e->event unless @$recs;
1740 my @recs = map { $_->source } @$recs;
1741 my $search = { record => \@recs };
1742 $search->{item_form} = $item_forms if $item_forms and @$item_forms;
1743 $search->{item_type} = $item_types if $item_types and @$item_types;
1744 $search->{item_lang} = $item_lang if $item_lang;
1746 my $desc = $e->search_metabib_record_descriptor($search);
1748 return { metarecord => $mrec, descriptors => $desc };
1754 __PACKAGE__->register_method(
1755 method => 'copies_created_on',
1759 sub copies_created_on {
1760 my( $self, $conn, $auth, $org, $date ) = @_;
1761 my $e = new_editor(authtoken=>$auth);
1762 return $e->event unless $e->checkauth;
1766 __PACKAGE__->register_method(
1767 method => 'fetch_age_protect',
1768 api_name => 'open-ils.search.copy.age_protect.retrieve.all',
1771 sub fetch_age_protect {
1772 return new_editor()->retrieve_all_config_rule_age_hold_protect();
1776 __PACKAGE__->register_method(
1777 method => 'copies_by_cn_label',
1778 api_name => 'open-ils.search.asset.copy.retrieve_by_cn_label',
1781 __PACKAGE__->register_method(
1782 method => 'copies_by_cn_label',
1783 api_name => 'open-ils.search.asset.copy.retrieve_by_cn_label.staff',
1786 sub copies_by_cn_label {
1787 my( $self, $conn, $record, $label, $circ_lib ) = @_;
1788 my $e = new_editor();
1789 my $cns = $e->search_asset_call_number({record => $record, label => $label, deleted => 'f'}, {idlist=>1});
1790 return [] unless @$cns;
1792 # show all non-deleted copies in the staff client ...
1793 if ($self->api_name =~ /staff$/o) {
1794 return $e->search_asset_copy({call_number => $cns, circ_lib => $circ_lib, deleted => 'f'}, {idlist=>1});
1797 # ... otherwise, grab the copies ...
1798 my $copies = $e->search_asset_copy(
1799 [ {call_number => $cns, circ_lib => $circ_lib, deleted => 'f', opac_visible => 't'},
1800 {flesh => 1, flesh_fields => { acp => [ qw/location status/] } }
1804 # ... and test for location and status visibility
1805 return [ map { ($U->is_true($_->location->opac_visible) && $U->is_true($_->status->opac_visible)) ? ($_->id) : () } @$copies ];