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 $type = ($type eq '-') ? 'keyword' : $type;
605 $type = ($type !~ /^(title|author|keyword|subject|series)$/o) ? 'keyword' : $type;
606 $search->{$type} = {} unless $search->{$type};
607 $search->{$type}->{term} =
608 ($search->{$type}->{term}) ? $search->{$type}->{term} . " $query" : $query;
611 # capture the original limit because the search method alters the limit internally
612 my $ol = $arghash->{limit};
614 my $sclient = OpenSRF::Utils::SettingsClient->new;
616 (my $method = $self->api_name) =~ s/\.query//o;
618 $method =~ s/multiclass/multiclass.staged/
619 if $sclient->config_value(apps => 'open-ils.search',
620 app_settings => 'use_staged_search') =~ /true/i;
622 $arghash->{preferred_language} = $U->get_org_locale($arghash->{org_unit})
623 unless $arghash->{preferred_language};
625 $method = $self->method_lookup($method);
626 my ($data) = $method->run($arghash, $docache);
628 $arghash->{limit} = $ol if $ol;
629 $data->{compiled_search} = $arghash;
630 $data->{query} = $orig_query;
632 $logger->info("compiled search is " . OpenSRF::Utils::JSON->perl2JSON($arghash));
637 __PACKAGE__->register_method(
638 method => 'cat_search_z_style_wrapper',
639 api_name => 'open-ils.search.biblio.zstyle',
641 signature => q/@see open-ils.search.biblio.multiclass/);
643 __PACKAGE__->register_method(
644 method => 'cat_search_z_style_wrapper',
645 api_name => 'open-ils.search.biblio.zstyle.staff',
647 signature => q/@see open-ils.search.biblio.multiclass/);
649 sub cat_search_z_style_wrapper {
652 my $authtoken = shift;
655 my $cstore = OpenSRF::AppSession->connect('open-ils.cstore');
657 my $ou = $cstore->request(
658 'open-ils.cstore.direct.actor.org_unit.search',
659 { parent_ou => undef }
662 my $result = { service => 'native-evergreen-catalog', records => [] };
663 my $searchhash = { limit => $$args{limit}, offset => $$args{offset}, org_unit => $ou->id };
665 $$searchhash{searches}{title}{term} = $$args{search}{title} if $$args{search}{title};
666 $$searchhash{searches}{author}{term} = $$args{search}{author} if $$args{search}{author};
667 $$searchhash{searches}{subject}{term} = $$args{search}{subject} if $$args{search}{subject};
668 $$searchhash{searches}{keyword}{term} = $$args{search}{keyword} if $$args{search}{keyword};
670 $$searchhash{searches}{keyword}{term} .= join ' ', $$searchhash{searches}{keyword}{term}, $$args{search}{tcn} if $$args{search}{tcn};
671 $$searchhash{searches}{keyword}{term} .= join ' ', $$searchhash{searches}{keyword}{term}, $$args{search}{isbn} if $$args{search}{isbn};
672 $$searchhash{searches}{keyword}{term} .= join ' ', $$searchhash{searches}{keyword}{term}, $$args{search}{issn} if $$args{search}{issn};
673 $$searchhash{searches}{keyword}{term} .= join ' ', $$searchhash{searches}{keyword}{term}, $$args{search}{publisher} if $$args{search}{publisher};
674 $$searchhash{searches}{keyword}{term} .= join ' ', $$searchhash{searches}{keyword}{term}, $$args{search}{pubdate} if $$args{search}{pubdate};
675 $$searchhash{searches}{keyword}{term} .= join ' ', $$searchhash{searches}{keyword}{term}, $$args{search}{item_type} if $$args{search}{item_type};
677 my $list = the_quest_for_knowledge( $self, $client, $searchhash );
679 if ($list->{count} > 0) {
680 $result->{count} = $list->{count};
682 my $records = $cstore->request(
683 'open-ils.cstore.direct.biblio.record_entry.search.atomic',
684 { id => [ map { ( $_->[0] ) } @{$list->{ids}} ] }
687 for my $rec ( @$records ) {
689 my $u = OpenILS::Utils::ModsParser->new();
690 $u->start_mods_batch( $rec->marc );
691 my $mods = $u->finish_mods_batch();
693 push @{ $result->{records} }, { mvr => $mods, marcxml => $rec->marc, bibid => $rec->id };
699 $cstore->disconnect();
703 # ----------------------------------------------------------------------------
704 # These are the main OPAC search methods
705 # ----------------------------------------------------------------------------
707 __PACKAGE__->register_method(
708 method => 'the_quest_for_knowledge',
709 api_name => 'open-ils.search.biblio.multiclass',
711 Performs a multi class biblio or metabib search
712 @param searchhash A search object layed out like so:
713 searches : { "$class" : "$value", ...}
714 org_unit : The org id to focus the search at
715 depth : The org depth
716 limit : The search limit
717 offset : The search offset
718 format : The MARC format
719 sort : What field to sort the results on [ author | title | pubdate ]
720 sort_dir : What direction do we sort? [ asc | desc ]
721 @return An object of the form
722 { "count" : $count, "ids" : [ [ $id, $relevancy, $total ], ...] }
726 __PACKAGE__->register_method(
727 method => 'the_quest_for_knowledge',
728 api_name => 'open-ils.search.biblio.multiclass.staff',
729 signature => q/@see open-ils.search.biblio.multiclass/);
730 __PACKAGE__->register_method(
731 method => 'the_quest_for_knowledge',
732 api_name => 'open-ils.search.metabib.multiclass',
733 signature => q/@see open-ils.search.biblio.multiclass/);
734 __PACKAGE__->register_method(
735 method => 'the_quest_for_knowledge',
736 api_name => 'open-ils.search.metabib.multiclass.staff',
737 signature => q/@see open-ils.search.biblio.multiclass/);
739 sub the_quest_for_knowledge {
740 my( $self, $conn, $searchhash, $docache ) = @_;
742 return { count => 0 } unless $searchhash and
743 ref $searchhash->{searches} eq 'HASH';
745 my $method = 'open-ils.storage.biblio.multiclass.search_fts';
749 if($self->api_name =~ /metabib/) {
751 $method =~ s/biblio/metabib/o;
755 my $offset = $searchhash->{offset} || 0;
756 my $limit = $searchhash->{limit} || 10;
757 my $end = $offset + $limit - 1;
759 # do some simple sanity checking
760 if(!$searchhash->{searches} or
761 ( !grep { /^(?:title|author|subject|series|keyword)/ } keys %{$searchhash->{searches}} ) ) {
762 return { count => 0 };
767 $searchhash->{offset} = 0;
768 $searchhash->{limit} = $maxlimit;
770 return { count => 0 } if $offset > $maxlimit;
773 push( @search, ($_ => $$searchhash{$_})) for (sort keys %$searchhash);
774 my $s = OpenSRF::Utils::JSON->perl2JSON(\@search);
775 my $ckey = $pfx . md5_hex($method . $s);
777 $logger->info("bib search for: $s");
779 $searchhash->{limit} -= $offset;
783 my $result = ($docache) ? search_cache($ckey, $offset, $limit) : undef;
787 $method .= ".staff" if($self->api_name =~ /staff/);
788 $method .= ".atomic";
790 for (keys %$searchhash) {
791 delete $$searchhash{$_}
792 unless defined $$searchhash{$_};
795 $result = $U->storagereq( $method, %$searchhash );
802 return {count => 0} unless ($result && $$result[0]);
806 my $count = ($ismeta) ? $result->[0]->[3] : $result->[0]->[2];
809 # If we didn't get this data from the cache, put it into the cache
810 # then return the correct offset of records
811 $logger->debug("putting search cache $ckey\n");
812 put_cache($ckey, $count, \@recs);
816 # if we have the full set of data, trim out
817 # the requested chunk based on limit and offset
819 for ($offset..$end) {
820 last unless $recs[$_];
826 return { ids => \@recs, count => $count };
830 __PACKAGE__->register_method(
831 method => 'staged_search',
832 api_name => 'open-ils.search.biblio.multiclass.staged');
833 __PACKAGE__->register_method(
834 method => 'staged_search',
835 api_name => 'open-ils.search.biblio.multiclass.staged.staff',
836 signature => q/@see open-ils.search.biblio.multiclass.staged/);
837 __PACKAGE__->register_method(
838 method => 'staged_search',
839 api_name => 'open-ils.search.metabib.multiclass.staged',
840 signature => q/@see open-ils.search.biblio.multiclass.staged/);
841 __PACKAGE__->register_method(
842 method => 'staged_search',
843 api_name => 'open-ils.search.metabib.multiclass.staged.staff',
844 signature => q/@see open-ils.search.biblio.multiclass.staged/);
847 my($self, $conn, $search_hash, $docache) = @_;
849 my $method = ($self->api_name =~ /metabib/) ?
850 'open-ils.storage.metabib.multiclass.staged.search_fts':
851 'open-ils.storage.biblio.multiclass.staged.search_fts';
853 $method .= '.staff' if $self->api_name =~ /staff$/;
854 $method .= '.atomic';
856 return {count => 0} unless (
858 $search_hash->{searches} and
859 scalar( keys %{$search_hash->{searches}} ));
862 my $user_offset = $search_hash->{offset} || 0; # user-specified offset
863 my $user_limit = $search_hash->{limit} || 10;
864 $user_offset = ($user_offset >= 0) ? $user_offset : 0;
865 $user_limit = ($user_limit >= 0) ? $user_limit : 10;
868 # we're grabbing results on a per-superpage basis, which means the
869 # limit and offset should coincide with superpage boundaries
870 $search_hash->{offset} = 0;
871 $search_hash->{limit} = $superpage_size;
873 # force a well-known check_limit
874 $search_hash->{check_limit} = $superpage_size;
875 # restrict total tested to superpage size * number of superpages
876 $search_hash->{core_limit} = $superpage_size * $max_superpages;
878 # Set the configured estimation strategy, defaults to 'inclusion'.
879 my $estimation_strategy = OpenSRF::Utils::SettingsClient
882 apps => 'open-ils.search', app_settings => 'estimation_strategy'
884 $search_hash->{estimation_strategy} = $estimation_strategy;
886 # pull any existing results from the cache
887 my $key = search_cache_key($method, $search_hash);
888 my $cache_data = $cache->get_cache($key) || {};
890 # keep retrieving results until we find enough to
891 # fulfill the user-specified limit and offset
892 my $all_results = [];
893 my $page; # current superpage
894 my $est_hit_count = 0;
895 my $current_page_summary = {};
896 my $global_summary = {checked => 0, visible => 0, excluded => 0, deleted => 0, total => 0};
897 my $is_real_hit_count = 0;
899 for($page = 0; $page < $max_superpages; $page++) {
901 my $data = $cache_data->{$page};
905 $logger->debug("staged search: analyzing superpage $page");
908 # this window of results is already cached
909 $logger->debug("staged search: found cached results");
910 $summary = $data->{summary};
911 $results = $data->{results};
914 # retrieve the window of results from the database
915 $logger->debug("staged search: fetching results from the database");
916 $search_hash->{skip_check} = $page * $superpage_size;
918 $results = $U->storagereq($method, %$search_hash);
919 $search_duration = time - $start;
920 $logger->info("staged search: DB call took $search_duration seconds");
921 $summary = shift(@$results);
924 $logger->info("search timed out: duration=$search_duration: params=".
925 OpenSRF::Utils::JSON->perl2JSON($search_hash));
929 my $hc = $summary->{estimated_hit_count} || $summary->{visible};
931 $logger->info("search returned 0 results: duration=$search_duration: params=".
932 OpenSRF::Utils::JSON->perl2JSON($search_hash));
935 # Create backwards-compatible result structures
936 if($self->api_name =~ /biblio/) {
937 $results = [map {[$_->{id}]} @$results];
939 $results = [map {[$_->{id}, $_->{rel}, $_->{record}]} @$results];
942 $results = [grep {defined $_->[0]} @$results];
943 cache_staged_search_page($key, $page, $summary, $results) if $docache;
946 $current_page_summary = $summary;
948 # add the new set of results to the set under construction
949 push(@$all_results, @$results);
951 my $current_count = scalar(@$all_results);
953 $est_hit_count = $summary->{estimated_hit_count} || $summary->{visible}
956 $logger->debug("staged search: located $current_count, with estimated hits=".
957 $summary->{estimated_hit_count}." : visible=".$summary->{visible}.", checked=".$summary->{checked});
959 if (defined($summary->{estimated_hit_count})) {
960 $global_summary->{checked} += $summary->{checked};
961 $global_summary->{visible} += $summary->{visible};
962 $global_summary->{excluded} += $summary->{excluded};
963 $global_summary->{deleted} += $summary->{deleted};
964 $global_summary->{total} = $summary->{total};
967 # we've found all the possible hits
968 last if $current_count == $summary->{visible}
969 and not defined $summary->{estimated_hit_count};
971 # we've found enough results to satisfy the requested limit/offset
972 last if $current_count >= ($user_limit + $user_offset);
974 # we've scanned all possible hits
975 if($summary->{checked} < $superpage_size) {
976 $est_hit_count = scalar(@$all_results);
977 # we have all possible results in hand, so we know the final hit count
978 $is_real_hit_count = 1;
983 my @results = grep {defined $_} @$all_results[$user_offset..($user_offset + $user_limit - 1)];
985 # refine the estimate if we have more than one superpage
986 if ($page > 0 and not $is_real_hit_count) {
987 if ($global_summary->{checked} >= $global_summary->{total}) {
988 $est_hit_count = $global_summary->{visible};
990 my $updated_hit_count = $U->storagereq(
991 'open-ils.storage.fts_paging_estimate',
992 $global_summary->{checked},
993 $global_summary->{visible},
994 $global_summary->{excluded},
995 $global_summary->{deleted},
996 $global_summary->{total}
998 $est_hit_count = $updated_hit_count->{$estimation_strategy};
1003 count => $est_hit_count,
1004 core_limit => $search_hash->{core_limit},
1005 superpage_size => $search_hash->{check_limit},
1006 superpage_summary => $current_page_summary,
1011 # creates a unique token to represent the query in the cache
1012 sub search_cache_key {
1014 my $search_hash = shift;
1016 for my $key (sort keys %$search_hash) {
1017 push(@sorted, ($key => $$search_hash{$key}))
1018 unless $key eq 'limit' or
1020 $key eq 'skip_check';
1022 my $s = OpenSRF::Utils::JSON->perl2JSON(\@sorted);
1023 return $pfx . md5_hex($method . $s);
1026 sub cache_staged_search_page {
1027 # puts this set of results into the cache
1028 my($key, $page, $summary, $results) = @_;
1029 my $data = $cache->get_cache($key);
1032 summary => $summary,
1036 $logger->info("staged search: cached with key=$key, superpage=$page, estimated=".
1037 $summary->{estimated_hit_count}.", visible=".$summary->{visible});
1039 $cache->put_cache($key, $data, $cache_timeout);
1047 my $start = $offset;
1048 my $end = $offset + $limit - 1;
1050 $logger->debug("searching cache for $key : $start..$end\n");
1052 return undef unless $cache;
1053 my $data = $cache->get_cache($key);
1055 return undef unless $data;
1057 my $count = $data->[0];
1060 return undef unless $offset < $count;
1063 for( my $i = $offset; $i <= $end; $i++ ) {
1064 last unless my $d = $$data[$i];
1065 push( @result, $d );
1068 $logger->debug("search_cache found ".scalar(@result)." items for count=$count, start=$start, end=$end");
1075 my( $key, $count, $data ) = @_;
1076 return undef unless $cache;
1077 $logger->debug("search_cache putting ".
1078 scalar(@$data)." items at key $key with timeout $cache_timeout");
1079 $cache->put_cache($key, [ $count, $data ], $cache_timeout);
1087 __PACKAGE__->register_method(
1088 method => "biblio_mrid_to_modsbatch_batch",
1089 api_name => "open-ils.search.biblio.metarecord.mods_slim.batch.retrieve");
1091 sub biblio_mrid_to_modsbatch_batch {
1092 my( $self, $client, $mrids) = @_;
1093 warn "Performing mrid_to_modsbatch_batch...";
1095 my $method = $self->method_lookup("open-ils.search.biblio.metarecord.mods_slim.retrieve");
1096 for my $id (@$mrids) {
1097 next unless defined $id;
1098 my ($m) = $method->run($id);
1105 __PACKAGE__->register_method(
1106 method => "biblio_mrid_to_modsbatch",
1107 api_name => "open-ils.search.biblio.metarecord.mods_slim.retrieve",
1108 notes => <<" NOTES");
1109 Returns the mvr associated with a given metarecod. If none exists,
1113 __PACKAGE__->register_method(
1114 method => "biblio_mrid_to_modsbatch",
1115 api_name => "open-ils.search.biblio.metarecord.mods_slim.retrieve.staff",
1116 notes => <<" NOTES");
1117 Returns the mvr associated with a given metarecod. If none exists,
1121 sub biblio_mrid_to_modsbatch {
1122 my( $self, $client, $mrid, $args) = @_;
1124 warn "Grabbing mvr for $mrid\n";
1126 my ($mr, $evt) = _grab_metarecord($mrid);
1127 return $evt unless $mr;
1129 my $mvr = biblio_mrid_check_mvr($self, $client, $mr);
1130 $mvr = biblio_mrid_make_modsbatch( $self, $client, $mr ) unless $mvr;
1132 return $mvr unless ref($args);
1134 # Here we find the lead record appropriate for the given filters
1135 # and use that for the title and author of the metarecord
1136 my $format = $$args{format};
1137 my $org = $$args{org};
1138 my $depth = $$args{depth};
1140 return $mvr unless $format or $org or $depth;
1142 my $method = "open-ils.storage.ordered.metabib.metarecord.records";
1143 $method = "$method.staff" if $self->api_name =~ /staff/o;
1145 my $rec = $U->storagereq($method, $format, $org, $depth, 1);
1147 if( my $mods = $U->record_to_mvr($rec) ) {
1149 $mvr->title($mods->title);
1150 $mvr->title($mods->author);
1151 $logger->debug("mods_slim updating title and ".
1152 "author in mvr with ".$mods->title." : ".$mods->author);
1158 # converts a metarecord to an mvr
1161 my $perl = OpenSRF::Utils::JSON->JSON2perl($mr->mods());
1162 return Fieldmapper::metabib::virtual_record->new($perl);
1165 # checks to see if a metarecord has mods, if so returns true;
1167 __PACKAGE__->register_method(
1168 method => "biblio_mrid_check_mvr",
1169 api_name => "open-ils.search.biblio.metarecord.mods_slim.check",
1170 notes => <<" NOTES");
1171 Takes a metarecord ID or a metarecord object and returns true
1172 if the metarecord already has an mvr associated with it.
1175 sub biblio_mrid_check_mvr {
1176 my( $self, $client, $mrid ) = @_;
1180 if(ref($mrid)) { $mr = $mrid; }
1181 else { ($mr, $evt) = _grab_metarecord($mrid); }
1182 return $evt if $evt;
1184 warn "Checking mvr for mr " . $mr->id . "\n";
1186 return _mr_to_mvr($mr) if $mr->mods();
1190 sub _grab_metarecord {
1192 #my $e = OpenILS::Utils::Editor->new;
1193 my $e = new_editor();
1194 my $mr = $e->retrieve_metabib_metarecord($mrid) or return ( undef, $e->event );
1199 __PACKAGE__->register_method(
1200 method => "biblio_mrid_make_modsbatch",
1201 api_name => "open-ils.search.biblio.metarecord.mods_slim.create",
1202 notes => <<" NOTES");
1203 Takes either a metarecord ID or a metarecord object.
1204 Forces the creations of an mvr for the given metarecord.
1205 The created mvr is returned.
1208 sub biblio_mrid_make_modsbatch {
1209 my( $self, $client, $mrid ) = @_;
1211 #my $e = OpenILS::Utils::Editor->new;
1212 my $e = new_editor();
1219 $mr = $e->retrieve_metabib_metarecord($mrid)
1220 or return $e->event;
1223 my $masterid = $mr->master_record;
1224 $logger->info("creating new mods batch for metarecord=$mrid, master record=$masterid");
1226 my $ids = $U->storagereq(
1227 'open-ils.storage.ordered.metabib.metarecord.records.staff.atomic', $mrid);
1228 return undef unless @$ids;
1230 my $master = $e->retrieve_biblio_record_entry($masterid)
1231 or return $e->event;
1233 # start the mods batch
1234 my $u = OpenILS::Utils::ModsParser->new();
1235 $u->start_mods_batch( $master->marc );
1237 # grab all of the sub-records and shove them into the batch
1238 my @ids = grep { $_ ne $masterid } @$ids;
1239 #my $subrecs = (@ids) ? $e->batch_retrieve_biblio_record_entry(\@ids) : [];
1244 my $r = $e->retrieve_biblio_record_entry($i);
1245 push( @$subrecs, $r ) if $r;
1250 $logger->debug("adding record ".$_->id." to mods batch for metarecord=$mrid");
1251 $u->push_mods_batch( $_->marc ) if $_->marc;
1255 # finish up and send to the client
1256 my $mods = $u->finish_mods_batch();
1257 $mods->doc_id($mrid);
1258 $client->respond_complete($mods);
1261 # now update the mods string in the db
1262 my $string = OpenSRF::Utils::JSON->perl2JSON($mods->decast);
1265 #$e = OpenILS::Utils::Editor->new(xact => 1);
1266 $e = new_editor(xact => 1);
1267 $e->update_metabib_metarecord($mr)
1268 or $logger->error("Error setting mods text on metarecord $mrid : " . Dumper($e->event));
1277 # converts a mr id into a list of record ids
1279 __PACKAGE__->register_method(
1280 method => "biblio_mrid_to_record_ids",
1281 api_name => "open-ils.search.biblio.metarecord_to_records",
1284 __PACKAGE__->register_method(
1285 method => "biblio_mrid_to_record_ids",
1286 api_name => "open-ils.search.biblio.metarecord_to_records.staff",
1289 sub biblio_mrid_to_record_ids {
1290 my( $self, $client, $mrid, $args ) = @_;
1292 my $format = $$args{format};
1293 my $org = $$args{org};
1294 my $depth = $$args{depth};
1296 my $method = "open-ils.storage.ordered.metabib.metarecord.records.atomic";
1297 $method =~ s/atomic/staff\.atomic/o if $self->api_name =~ /staff/o;
1298 my $recs = $U->storagereq($method, $mrid, $format, $org, $depth);
1300 return { count => scalar(@$recs), ids => $recs };
1304 __PACKAGE__->register_method(
1305 method => "biblio_record_to_marc_html",
1306 api_name => "open-ils.search.biblio.record.html" );
1308 __PACKAGE__->register_method(
1309 method => "biblio_record_to_marc_html",
1310 api_name => "open-ils.search.authority.to_html" );
1312 my $parser = XML::LibXML->new();
1313 my $xslt = XML::LibXSLT->new();
1315 my $slim_marc_sheet;
1316 my $settings_client = OpenSRF::Utils::SettingsClient->new();
1318 sub biblio_record_to_marc_html {
1319 my($self, $client, $recordid, $slim, $marcxml) = @_;
1322 my $dir = $settings_client->config_value("dirs", "xsl");
1325 unless($slim_marc_sheet) {
1326 my $xsl = $settings_client->config_value(
1327 "apps", "open-ils.search", "app_settings", 'marc_html_xsl_slim');
1329 $xsl = $parser->parse_file("$dir/$xsl");
1330 $slim_marc_sheet = $xslt->parse_stylesheet($xsl);
1333 $sheet = $slim_marc_sheet;
1337 unless($marc_sheet) {
1338 my $xsl_key = ($slim) ? 'marc_html_xsl_slim' : 'marc_html_xsl';
1339 my $xsl = $settings_client->config_value(
1340 "apps", "open-ils.search", "app_settings", 'marc_html_xsl');
1341 $xsl = $parser->parse_file("$dir/$xsl");
1342 $marc_sheet = $xslt->parse_stylesheet($xsl);
1344 $sheet = $marc_sheet;
1349 my $e = new_editor();
1350 if($self->api_name =~ /authority/) {
1351 $record = $e->retrieve_authority_record_entry($recordid)
1352 or return $e->event;
1354 $record = $e->retrieve_biblio_record_entry($recordid)
1355 or return $e->event;
1357 $marcxml = $record->marc;
1360 my $xmldoc = $parser->parse_string($marcxml);
1361 my $html = $sheet->transform($xmldoc);
1362 return $html->documentElement->toString();
1367 __PACKAGE__->register_method(
1368 method => "retrieve_all_copy_statuses",
1369 api_name => "open-ils.search.config.copy_status.retrieve.all" );
1371 sub retrieve_all_copy_statuses {
1372 my( $self, $client ) = @_;
1373 return new_editor()->retrieve_all_config_copy_status();
1377 __PACKAGE__->register_method(
1378 method => "copy_counts_per_org",
1379 api_name => "open-ils.search.biblio.copy_counts.retrieve");
1381 __PACKAGE__->register_method(
1382 method => "copy_counts_per_org",
1383 api_name => "open-ils.search.biblio.copy_counts.retrieve.staff");
1385 sub copy_counts_per_org {
1386 my( $self, $client, $record_id ) = @_;
1388 warn "Retreiveing copy copy counts for record $record_id and method " . $self->api_name . "\n";
1390 my $method = "open-ils.storage.biblio.record_entry.global_copy_count.atomic";
1391 if($self->api_name =~ /staff/) { $method =~ s/atomic/staff\.atomic/; }
1393 my $counts = $apputils->simple_scalar_request(
1394 "open-ils.storage", $method, $record_id );
1396 $counts = [ sort {$a->[0] <=> $b->[0]} @$counts ];
1401 __PACKAGE__->register_method(
1402 method => "copy_count_summary",
1403 api_name => "open-ils.search.biblio.copy_counts.summary.retrieve",
1404 notes => <<" NOTES");
1405 returns an array of these:
1406 [ org_id, callnumber_label, <status1_count>, <status2_count>,...]
1407 where statusx is a copy status name. the statuses are sorted
1411 sub copy_count_summary {
1412 my( $self, $client, $rid, $org, $depth ) = @_;
1415 my $data = $U->storagereq(
1416 'open-ils.storage.biblio.record_entry.status_copy_count.atomic', $rid, $org, $depth );
1418 return [ sort { $a->[1] cmp $b->[1] } @$data ];
1421 __PACKAGE__->register_method(
1422 method => "copy_location_count_summary",
1423 api_name => "open-ils.search.biblio.copy_location_counts.summary.retrieve",
1424 notes => <<" NOTES");
1425 returns an array of these:
1426 [ org_id, callnumber_label, copy_location, <status1_count>, <status2_count>,...]
1427 where statusx is a copy status name. the statuses are sorted
1431 sub copy_location_count_summary {
1432 my( $self, $client, $rid, $org, $depth ) = @_;
1435 my $data = $U->storagereq(
1436 'open-ils.storage.biblio.record_entry.status_copy_location_count.atomic', $rid, $org, $depth );
1438 return [ sort { $a->[1] cmp $b->[1] || $a->[2] cmp $b->[2] } @$data ];
1441 __PACKAGE__->register_method(
1442 method => "copy_count_location_summary",
1443 api_name => "open-ils.search.biblio.copy_counts.location.summary.retrieve",
1444 notes => <<" NOTES");
1445 returns an array of these:
1446 [ org_id, callnumber_label, <status1_count>, <status2_count>,...]
1447 where statusx is a copy status name. the statuses are sorted
1451 sub copy_count_location_summary {
1452 my( $self, $client, $rid, $org, $depth ) = @_;
1455 my $data = $U->storagereq(
1456 'open-ils.storage.biblio.record_entry.status_copy_location_count.atomic', $rid, $org, $depth );
1457 return [ sort { $a->[1] cmp $b->[1] } @$data ];
1461 __PACKAGE__->register_method(
1462 method => "marc_search",
1463 api_name => "open-ils.search.biblio.marc.staff");
1465 __PACKAGE__->register_method(
1466 method => "marc_search",
1467 api_name => "open-ils.search.biblio.marc",
1468 notes => <<" NOTES");
1470 open-ils.storage.biblio.full_rec.multi_search.atomic
1471 { "searches": [{"term":"harry","restrict": [{"tag":245,"subfield":"a"}]}], "org_unit": 1,
1472 "limit":5,"sort":"author","item_type":"g"}
1476 my( $self, $conn, $args, $limit, $offset ) = @_;
1478 my $method = 'open-ils.storage.biblio.full_rec.multi_search';
1479 $method .= ".staff" if $self->api_name =~ /staff/;
1480 $method .= ".atomic";
1486 push( @search, ($_ => $$args{$_}) ) for (sort keys %$args);
1487 my $ckey = $pfx . md5_hex($method . OpenSRF::Utils::JSON->perl2JSON(\@search));
1489 my $recs = search_cache($ckey, $offset, $limit);
1492 $recs = $U->storagereq($method, %$args) || [];
1494 put_cache($ckey, scalar(@$recs), $recs);
1495 $recs = [ @$recs[$offset..($offset + ($limit - 1))] ];
1502 $count = $recs->[0]->[2] if $recs->[0] and $recs->[0]->[2];
1503 my @recs = map { $_->[0] } @$recs;
1505 return { ids => \@recs, count => $count };
1509 __PACKAGE__->register_method(
1510 method => "biblio_search_isbn",
1511 api_name => "open-ils.search.biblio.isbn",
1514 sub biblio_search_isbn {
1515 my( $self, $client, $isbn ) = @_;
1516 $logger->debug("Searching ISBN $isbn");
1517 my $e = new_editor();
1518 my $recs = $U->storagereq(
1519 'open-ils.storage.id_list.biblio.record_entry.search.isbn.atomic', $isbn );
1520 return { ids => $recs, count => scalar(@$recs) };
1524 __PACKAGE__->register_method(
1525 method => "biblio_search_issn",
1526 api_name => "open-ils.search.biblio.issn",
1529 sub biblio_search_issn {
1530 my( $self, $client, $issn ) = @_;
1531 $logger->debug("Searching ISSN $issn");
1532 my $e = new_editor();
1534 my $recs = $U->storagereq(
1535 'open-ils.storage.id_list.biblio.record_entry.search.issn.atomic', $issn );
1536 return { ids => $recs, count => scalar(@$recs) };
1542 __PACKAGE__->register_method(
1543 method => "fetch_mods_by_copy",
1544 api_name => "open-ils.search.biblio.mods_from_copy",
1547 sub fetch_mods_by_copy {
1548 my( $self, $client, $copyid ) = @_;
1549 my ($record, $evt) = $apputils->fetch_record_by_copy( $copyid );
1550 return $evt if $evt;
1551 return OpenILS::Event->new('ITEM_NOT_CATALOGED') unless $record->marc;
1552 return $apputils->record_to_mvr($record);
1557 # -------------------------------------------------------------------------------------
1559 __PACKAGE__->register_method(
1560 method => "cn_browse",
1561 api_name => "open-ils.search.callnumber.browse.target",
1562 notes => "Starts a callnumber browse"
1565 __PACKAGE__->register_method(
1566 method => "cn_browse",
1567 api_name => "open-ils.search.callnumber.browse.page_up",
1568 notes => "Returns the previous page of callnumbers",
1571 __PACKAGE__->register_method(
1572 method => "cn_browse",
1573 api_name => "open-ils.search.callnumber.browse.page_down",
1574 notes => "Returns the next page of callnumbers",
1578 # RETURNS array of arrays like so: label, owning_lib, record, id
1580 my( $self, $client, @params ) = @_;
1583 $method = 'open-ils.storage.asset.call_number.browse.target.atomic'
1584 if( $self->api_name =~ /target/ );
1585 $method = 'open-ils.storage.asset.call_number.browse.page_up.atomic'
1586 if( $self->api_name =~ /page_up/ );
1587 $method = 'open-ils.storage.asset.call_number.browse.page_down.atomic'
1588 if( $self->api_name =~ /page_down/ );
1590 return $apputils->simplereq( 'open-ils.storage', $method, @params );
1592 # -------------------------------------------------------------------------------------
1594 __PACKAGE__->register_method(
1595 method => "fetch_cn",
1597 api_name => "open-ils.search.callnumber.retrieve",
1598 notes => "retrieves a callnumber based on ID",
1602 my( $self, $client, $id ) = @_;
1603 my( $cn, $evt ) = $apputils->fetch_callnumber( $id );
1604 return $evt if $evt;
1608 __PACKAGE__->register_method (
1609 method => "fetch_copy_by_cn",
1610 api_name => 'open-ils.search.copies_by_call_number.retrieve',
1612 Returns an array of copy id's by callnumber id
1613 @param cnid The callnumber id
1614 @return An array of copy ids
1618 sub fetch_copy_by_cn {
1619 my( $self, $conn, $cnid ) = @_;
1620 return $U->cstorereq(
1621 'open-ils.cstore.direct.asset.copy.id_list.atomic',
1622 { call_number => $cnid, deleted => 'f' } );
1625 __PACKAGE__->register_method (
1626 method => 'fetch_cn_by_info',
1627 api_name => 'open-ils.search.call_number.retrieve_by_info',
1629 @param label The callnumber label
1630 @param record The record the cn is attached to
1631 @param org The owning library of the cn
1632 @return The callnumber object
1637 sub fetch_cn_by_info {
1638 my( $self, $conn, $label, $record, $org ) = @_;
1639 return $U->cstorereq(
1640 'open-ils.cstore.direct.asset.call_number.search',
1641 { label => $label, record => $record, owning_lib => $org, deleted => 'f' });
1648 __PACKAGE__->register_method (
1649 method => 'bib_extras',
1650 api_name => 'open-ils.search.biblio.lit_form_map.retrieve.all');
1651 __PACKAGE__->register_method (
1652 method => 'bib_extras',
1653 api_name => 'open-ils.search.biblio.item_form_map.retrieve.all');
1654 __PACKAGE__->register_method (
1655 method => 'bib_extras',
1656 api_name => 'open-ils.search.biblio.item_type_map.retrieve.all');
1657 __PACKAGE__->register_method (
1658 method => 'bib_extras',
1659 api_name => 'open-ils.search.biblio.bib_level_map.retrieve.all');
1660 __PACKAGE__->register_method (
1661 method => 'bib_extras',
1662 api_name => 'open-ils.search.biblio.audience_map.retrieve.all');
1667 my $e = new_editor();
1669 return $e->retrieve_all_config_lit_form_map()
1670 if( $self->api_name =~ /lit_form/ );
1672 return $e->retrieve_all_config_item_form_map()
1673 if( $self->api_name =~ /item_form_map/ );
1675 return $e->retrieve_all_config_item_type_map()
1676 if( $self->api_name =~ /item_type_map/ );
1678 return $e->retrieve_all_config_bib_level_map()
1679 if( $self->api_name =~ /bib_level_map/ );
1681 return $e->retrieve_all_config_audience_map()
1682 if( $self->api_name =~ /audience_map/ );
1689 __PACKAGE__->register_method(
1690 method => 'fetch_slim_record',
1691 api_name => 'open-ils.search.biblio.record_entry.slim.retrieve',
1693 Returns a biblio.record_entry without the attached marcxml
1697 sub fetch_slim_record {
1698 my( $self, $conn, $ids ) = @_;
1700 #my $editor = OpenILS::Utils::Editor->new;
1701 my $editor = new_editor();
1704 return $editor->event unless
1705 my $r = $editor->retrieve_biblio_record_entry($_);
1714 __PACKAGE__->register_method(
1715 method => 'rec_to_mr_rec_descriptors',
1716 api_name => 'open-ils.search.metabib.record_to_descriptors',
1718 specialized method...
1719 Given a biblio record id or a metarecord id,
1720 this returns a list of metabib.record_descriptor
1721 objects that live within the same metarecord
1722 @param args Object of args including:
1726 sub rec_to_mr_rec_descriptors {
1727 my( $self, $conn, $args ) = @_;
1729 my $rec = $$args{record};
1730 my $mrec = $$args{metarecord};
1731 my $item_forms = $$args{item_forms};
1732 my $item_types = $$args{item_types};
1733 my $item_lang = $$args{item_lang};
1735 my $e = new_editor();
1739 my $map = $e->search_metabib_metarecord_source_map({source => $rec});
1740 return $e->event unless @$map;
1741 $mrec = $$map[0]->metarecord;
1744 $recs = $e->search_metabib_metarecord_source_map({metarecord => $mrec});
1745 return $e->event unless @$recs;
1747 my @recs = map { $_->source } @$recs;
1748 my $search = { record => \@recs };
1749 $search->{item_form} = $item_forms if $item_forms and @$item_forms;
1750 $search->{item_type} = $item_types if $item_types and @$item_types;
1751 $search->{item_lang} = $item_lang if $item_lang;
1753 my $desc = $e->search_metabib_record_descriptor($search);
1755 return { metarecord => $mrec, descriptors => $desc };
1761 __PACKAGE__->register_method(
1762 method => 'copies_created_on',
1766 sub copies_created_on {
1767 my( $self, $conn, $auth, $org, $date ) = @_;
1768 my $e = new_editor(authtoken=>$auth);
1769 return $e->event unless $e->checkauth;
1773 __PACKAGE__->register_method(
1774 method => 'fetch_age_protect',
1775 api_name => 'open-ils.search.copy.age_protect.retrieve.all',
1778 sub fetch_age_protect {
1779 return new_editor()->retrieve_all_config_rule_age_hold_protect();
1783 __PACKAGE__->register_method(
1784 method => 'copies_by_cn_label',
1785 api_name => 'open-ils.search.asset.copy.retrieve_by_cn_label',
1788 __PACKAGE__->register_method(
1789 method => 'copies_by_cn_label',
1790 api_name => 'open-ils.search.asset.copy.retrieve_by_cn_label.staff',
1793 sub copies_by_cn_label {
1794 my( $self, $conn, $record, $label, $circ_lib ) = @_;
1795 my $e = new_editor();
1796 my $cns = $e->search_asset_call_number({record => $record, label => $label, deleted => 'f'}, {idlist=>1});
1797 return [] unless @$cns;
1799 # show all non-deleted copies in the staff client ...
1800 if ($self->api_name =~ /staff$/o) {
1801 return $e->search_asset_copy({call_number => $cns, circ_lib => $circ_lib, deleted => 'f'}, {idlist=>1});
1804 # ... otherwise, grab the copies ...
1805 my $copies = $e->search_asset_copy(
1806 [ {call_number => $cns, circ_lib => $circ_lib, deleted => 'f', opac_visible => 't'},
1807 {flesh => 1, flesh_fields => { acp => [ qw/location status/] } }
1811 # ... and test for location and status visibility
1812 return [ map { ($U->is_true($_->location->opac_visible) && $U->is_true($_->status->opac_visible)) ? ($_->id) : () } @$copies ];