1 package OpenILS::Application::Search::Biblio;
2 use base qw/OpenSRF::Application/;
3 use strict; use warnings;
7 use OpenILS::Utils::Fieldmapper;
8 use OpenILS::Utils::ModsParser;
9 use OpenSRF::Utils::SettingsClient;
10 use OpenILS::Utils::CStoreEditor q/:funcs/;
11 use OpenSRF::Utils::Cache;
13 use OpenSRF::Utils::Logger qw/:logger/;
18 use Time::HiRes qw(time);
19 use OpenSRF::EX qw(:try);
20 use Digest::MD5 qw(md5_hex);
26 $Data::Dumper::Indent = 0;
28 use OpenILS::Application::AppUtils;
29 my $apputils = "OpenILS::Application::AppUtils";
32 my $pfx = "open-ils.search_";
38 $cache = OpenSRF::Utils::Cache->new('global');
39 my $sclient = OpenSRF::Utils::SettingsClient->new();
40 $cache_timeout = $sclient->config_value(
41 "apps", "open-ils.search", "app_settings", "cache_timeout" ) || 300;
42 $logger->info("Search cache timeout is $cache_timeout");
47 # ---------------------------------------------------------------------------
48 # takes a list of record id's and turns the docs into friendly
49 # mods structures. Creates one MODS structure for each doc id.
50 # ---------------------------------------------------------------------------
51 sub _records_to_mods {
57 my $session = OpenSRF::AppSession->create("open-ils.cstore");
58 my $request = $session->request(
59 "open-ils.cstore.direct.biblio.record_entry.search", { id => \@ids } );
61 while( my $resp = $request->recv ) {
62 my $content = $resp->content;
63 my $u = OpenILS::Utils::ModsParser->new();
64 $u->start_mods_batch( $content->marc );
65 my $mods = $u->finish_mods_batch();
66 $mods->doc_id($content->id());
67 $mods->tcn($content->tcn_value);
71 $session->disconnect();
75 __PACKAGE__->register_method(
76 method => "record_id_to_mods",
77 api_name => "open-ils.search.biblio.record.mods.retrieve",
79 note => "Provide ID, we provide the mods"
82 # converts a record into a mods object with copy counts attached
83 sub record_id_to_mods {
85 my( $self, $client, $org_id, $id ) = @_;
87 my $mods_list = _records_to_mods( $id );
88 my $mods_obj = $mods_list->[0];
89 my $cmethod = $self->method_lookup(
90 "open-ils.search.biblio.record.copy_count");
91 my ($count) = $cmethod->run($org_id, $id);
92 $mods_obj->copy_count($count);
99 __PACKAGE__->register_method(
100 method => "record_id_to_mods_slim",
101 api_name => "open-ils.search.biblio.record.mods_slim.retrieve",
103 note => "Provide ID, we provide the mods"
106 # converts a record into a mods object with NO copy counts attached
107 sub record_id_to_mods_slim {
108 my( $self, $client, $id ) = @_;
109 return undef unless defined $id;
111 if(ref($id) and ref($id) == 'ARRAY') {
112 return _records_to_mods( @$id );
114 my $mods_list = _records_to_mods( $id );
115 my $mods_obj = $mods_list->[0];
120 # Returns the number of copies attached to a record based on org location
121 __PACKAGE__->register_method(
122 method => "record_id_to_copy_count",
123 api_name => "open-ils.search.biblio.record.copy_count",
126 __PACKAGE__->register_method(
127 method => "record_id_to_copy_count",
128 api_name => "open-ils.search.biblio.record.copy_count.staff",
131 __PACKAGE__->register_method(
132 method => "record_id_to_copy_count",
133 api_name => "open-ils.search.biblio.metarecord.copy_count",
136 __PACKAGE__->register_method(
137 method => "record_id_to_copy_count",
138 api_name => "open-ils.search.biblio.metarecord.copy_count.staff",
140 sub record_id_to_copy_count {
141 my( $self, $client, $org_id, $record_id, $format ) = @_;
143 return [] unless $record_id;
144 $format = undef if (!$format or $format eq 'all');
146 my $method = "open-ils.storage.biblio.record_entry.copy_count.atomic";
149 if($self->api_name =~ /metarecord/) {
150 $method = "open-ils.storage.metabib.metarecord.copy_count.atomic";
154 $method =~ s/atomic/staff\.atomic/og if($self->api_name =~ /staff/ );
156 my $count = $U->storagereq( $method,
157 org_unit => $org_id, $key => $record_id, format => $format );
159 return [ sort { $a->{depth} <=> $b->{depth} } @$count ];
165 __PACKAGE__->register_method(
166 method => "biblio_search_tcn",
167 api_name => "open-ils.search.biblio.tcn",
169 note => "Retrieve a record by TCN",
172 sub biblio_search_tcn {
174 my( $self, $client, $tcn ) = @_;
176 $tcn =~ s/.*?(\w+)\s*$/$1/o;
178 my $e = new_editor();
179 my $recs = $e->search_biblio_record_entry(
180 {deleted => 'f', tcn_value => $tcn}, {idlist =>1});
182 return { count => scalar(@$recs), ids => $recs };
186 # --------------------------------------------------------------------------------
188 __PACKAGE__->register_method(
189 method => "biblio_barcode_to_copy",
190 api_name => "open-ils.search.asset.copy.find_by_barcode",);
191 sub biblio_barcode_to_copy {
192 my( $self, $client, $barcode ) = @_;
193 my( $copy, $evt ) = $U->fetch_copy_by_barcode($barcode);
198 __PACKAGE__->register_method(
199 method => "biblio_id_to_copy",
200 api_name => "open-ils.search.asset.copy.batch.retrieve",);
201 sub biblio_id_to_copy {
202 my( $self, $client, $ids ) = @_;
203 $logger->info("Fetching copies @$ids");
204 return $U->cstorereq(
205 "open-ils.cstore.direct.asset.copy.search.atomic", { id => $ids } );
209 __PACKAGE__->register_method(
210 method => "copy_retrieve",
211 api_name => "open-ils.search.asset.copy.retrieve",);
213 my( $self, $client, $cid ) = @_;
214 my( $copy, $evt ) = $U->fetch_copy($cid);
219 __PACKAGE__->register_method(
220 method => "volume_retrieve",
221 api_name => "open-ils.search.asset.call_number.retrieve");
222 sub volume_retrieve {
223 my( $self, $client, $vid ) = @_;
224 my $e = new_editor();
225 my $vol = $e->retrieve_asset_call_number($vid) or return $e->event;
229 __PACKAGE__->register_method(
230 method => "fleshed_copy_retrieve_batch",
231 api_name => "open-ils.search.asset.copy.fleshed.batch.retrieve");
233 sub fleshed_copy_retrieve_batch {
234 my( $self, $client, $ids ) = @_;
235 $logger->info("Fetching fleshed copies @$ids");
236 return $U->cstorereq(
237 "open-ils.cstore.direct.asset.copy.search.atomic",
240 flesh_fields => { acp => [ qw/ circ_lib location status stat_cat_entries / ] }
245 __PACKAGE__->register_method(
246 method => "fleshed_copy_retrieve",
247 api_name => "open-ils.search.asset.copy.fleshed.retrieve",);
249 sub fleshed_copy_retrieve {
250 my( $self, $client, $id ) = @_;
251 my( $c, $e) = $U->fetch_fleshed_copy($id);
256 __PACKAGE__->register_method(
257 method => "fleshed_copy_retrieve2",
258 api_name => "open-ils.search.asset.copy.fleshed2.retrieve",);
260 sub fleshed_copy_retrieve2 {
261 my( $self, $client, $id ) = @_;
262 my $e = new_editor();
263 my $copy = $e->retrieve_asset_copy(
269 acp => [ qw/ location status stat_cat_entry_copy_maps notes age_protect / ],
270 ascecm => [ qw/ stat_cat stat_cat_entry / ],
274 ) or return $e->event;
276 # For backwards compatibility
277 $copy->stat_cat_entries($copy->stat_cat_entry_copy_maps);
281 # return $copy unless $copy->stat_cat_entries;
283 # for my $map (@{$copy->stat_cat_entries}) {
285 # $e->retrieve_asset_stat_cat($map->stat_cat));
286 # $map->stat_cat_entry(
287 # $e->retrieve_asset_stat_cat_entry($map->stat_cat_entry));
297 __PACKAGE__->register_method(
298 method => "biblio_barcode_to_title",
299 api_name => "open-ils.search.biblio.find_by_barcode",
302 sub biblio_barcode_to_title {
303 my( $self, $client, $barcode ) = @_;
305 my $title = $apputils->simple_scalar_request(
307 "open-ils.storage.biblio.record_entry.retrieve_by_barcode", $barcode );
309 return { ids => [ $title->id ], count => 1 } if $title;
310 return { count => 0 };
314 __PACKAGE__->register_method(
315 method => "biblio_copy_to_mods",
316 api_name => "open-ils.search.biblio.copy.mods.retrieve",
319 # takes a copy object and returns it fleshed mods object
320 sub biblio_copy_to_mods {
321 my( $self, $client, $copy ) = @_;
323 my $volume = $U->cstorereq(
324 "open-ils.cstore.direct.asset.call_number.retrieve",
325 $copy->call_number() );
327 my $mods = _records_to_mods($volume->record());
328 $mods = shift @$mods;
329 $volume->copies([$copy]);
330 push @{$mods->call_numbers()}, $volume;
336 # ----------------------------------------------------------------------------
337 # These are the main OPAC search methods
338 # ----------------------------------------------------------------------------
340 __PACKAGE__->register_method(
341 method => 'the_quest_for_knowledge',
342 api_name => 'open-ils.search.biblio.multiclass',
344 Performs a multi class bilbli or metabib search
345 @param searchhash A search object layed out like so:
346 searches : { "$class" : "$value", ...}
347 org_unit : The org id to focus the search at
348 depth : The org depth
349 limit : The search limit
350 offset : The search offset
351 format : The MARC format
352 sort : What field to sort the results on [ author | title | pubdate ]
353 sort_dir : What direction do we sort? [ asc | desc ]
354 @return An object of the form
355 { "count" : $count, "ids" : [ [ $id, $relevancy, $total ], ...] }
359 __PACKAGE__->register_method(
360 method => 'the_quest_for_knowledge',
361 api_name => 'open-ils.search.biblio.multiclass.staff',
362 signature => q/@see open-ils.search.biblio.multiclass/);
363 __PACKAGE__->register_method(
364 method => 'the_quest_for_knowledge',
365 api_name => 'open-ils.search.metabib.multiclass',
366 signature => q/@see open-ils.search.biblio.multiclass/);
367 __PACKAGE__->register_method(
368 method => 'the_quest_for_knowledge',
369 api_name => 'open-ils.search.metabib.multiclass.staff',
370 signature => q/@see open-ils.search.biblio.multiclass/);
374 sub the_quest_for_knowledge {
375 my( $self, $conn, $searchhash, $docache ) = @_;
377 return { count => 0 } unless $searchhash and
378 ref $searchhash->{searches} eq 'HASH';
380 my $method = 'open-ils.storage.biblio.multiclass.search_fts';
385 my $offset = $searchhash->{offset} || 0;
386 my $limit = $searchhash->{limit} || 10;
387 my $end = $offset + $limit - 1;
389 for( keys %{$searchhash->{searches}} ) {
393 # do some simple sanity checking
394 if(!$searchhash->{searches} or
396 !$searchhash->{searches}->{title} and
397 !$searchhash->{searches}->{author} and
398 !$searchhash->{searches}->{subject} and
399 !$searchhash->{searches}->{series} and
400 !$searchhash->{searches}->{keyword} ) ) {
401 return { count => 0 };
406 $searchhash->{offset} = 0;
407 $searchhash->{limit} = $maxlimit;
409 return { count => 0 } if $offset > $maxlimit;
412 push( @search, ($_ => $$searchhash{$_})) for (sort keys %$searchhash);
413 my $s = JSON->perl2JSON(\@search);
414 my $ckey = $pfx . md5_hex($method . $s);
416 $logger->info("bib search for: $s");
418 $searchhash->{limit} -= $offset;
420 if($self->api_name =~ /metabib/) {
422 $method =~ s/biblio/metabib/o;
425 my $result = ($docache) ? search_cache($ckey, $offset, $limit) : undef;
429 $method .= ".staff" if($self->api_name =~ /staff/);
430 $method .= ".atomic";
432 for (keys %$searchhash) {
433 delete $$searchhash{$_}
434 unless defined $$searchhash{$_};
437 $result = $U->storagereq( $method, %$searchhash );
443 return {count => 0} unless ($result && $$result[0]);
445 #for my $r (@$result) { push(@recs, $r) if ($r and $$r[0]); }
448 my $count = ($ismeta) ? $result->[0]->[3] : $result->[0]->[2];
453 # If we didn't get this data from the cache, put it into the cache
454 # then return the correct offset of records
455 $logger->debug("putting search cache $ckey\n");
456 put_cache($ckey, $count, \@recs);
459 for ($offset..$end) {
460 last unless $recs[$_];
465 #$logger->debug("cache done .. returning $offset..$end : " . JSON->perl2JSON(\@recs));
468 return { ids => \@recs, count => $count };
479 my $end = $offset + $limit - 1;
481 $logger->debug("searching cache for $key : $start..$end\n");
483 return undef unless $cache;
484 my $data = $cache->get_cache($key);
486 return undef unless $data;
488 my $count = $data->[0];
491 return undef unless $offset < $count;
495 for( my $i = $offset; $i <= $end; $i++ ) {
496 last unless my $d = $$data[$i];
500 $logger->debug("search_cache found ".scalar(@result)." items for count=$count, start=$start, end=$end");
507 my( $key, $count, $data ) = @_;
508 return undef unless $cache;
509 $logger->debug("search_cache putting ".
510 scalar(@$data)." items at key $key with timeout $cache_timeout");
511 $cache->put_cache($key, [ $count, $data ], $cache_timeout);
519 __PACKAGE__->register_method(
520 method => "biblio_mrid_to_modsbatch_batch",
521 api_name => "open-ils.search.biblio.metarecord.mods_slim.batch.retrieve");
523 sub biblio_mrid_to_modsbatch_batch {
524 my( $self, $client, $mrids) = @_;
525 warn "Performing mrid_to_modsbatch_batch...";
527 my $method = $self->method_lookup("open-ils.search.biblio.metarecord.mods_slim.retrieve");
528 for my $id (@$mrids) {
529 next unless defined $id;
530 my ($m) = $method->run($id);
537 __PACKAGE__->register_method(
538 method => "biblio_mrid_to_modsbatch",
539 api_name => "open-ils.search.biblio.metarecord.mods_slim.retrieve",
540 notes => <<" NOTES");
541 Returns the mvr associated with a given metarecod. If none exists,
545 __PACKAGE__->register_method(
546 method => "biblio_mrid_to_modsbatch",
547 api_name => "open-ils.search.biblio.metarecord.mods_slim.retrieve.staff",
548 notes => <<" NOTES");
549 Returns the mvr associated with a given metarecod. If none exists,
553 sub biblio_mrid_to_modsbatch {
554 my( $self, $client, $mrid ) = @_;
556 warn "Grabbing mvr for $mrid\n";
558 my ($mr, $evt) = _grab_metarecord($mrid);
559 return $evt unless $mr;
561 if( my $m = $self->biblio_mrid_check_mvr($client, $mr)) {
565 return $self->biblio_mrid_make_modsbatch( $client, $mr );
568 # converts a metarecord to an mvr
571 my $perl = JSON->JSON2perl($mr->mods());
572 return Fieldmapper::metabib::virtual_record->new($perl);
575 # checks to see if a metarecord has mods, if so returns true;
577 __PACKAGE__->register_method(
578 method => "biblio_mrid_check_mvr",
579 api_name => "open-ils.search.biblio.metarecord.mods_slim.check",
580 notes => <<" NOTES");
581 Takes a metarecord ID or a metarecord object and returns true
582 if the metarecord already has an mvr associated with it.
585 sub biblio_mrid_check_mvr {
586 my( $self, $client, $mrid ) = @_;
590 if(ref($mrid)) { $mr = $mrid; }
591 else { ($mr, $evt) = _grab_metarecord($mrid); }
594 warn "Checking mvr for mr " . $mr->id . "\n";
596 return _mr_to_mvr($mr) if $mr->mods();
600 sub _grab_metarecord {
602 #my $e = OpenILS::Utils::Editor->new;
603 my $e = new_editor();
604 my $mr = $e->retrieve_metabib_metarecord($mrid) or return ( undef, $e->event );
609 __PACKAGE__->register_method(
610 method => "biblio_mrid_make_modsbatch",
611 api_name => "open-ils.search.biblio.metarecord.mods_slim.create",
612 notes => <<" NOTES");
613 Takes either a metarecord ID or a metarecord object.
614 Forces the creations of an mvr for the given metarecord.
615 The created mvr is returned.
618 sub biblio_mrid_make_modsbatch {
619 my( $self, $client, $mrid ) = @_;
621 #my $e = OpenILS::Utils::Editor->new;
622 my $e = new_editor();
629 $mr = $e->retrieve_metabib_metarecord($mrid)
633 my $masterid = $mr->master_record;
634 $logger->info("creating new mods batch for metarecord=$mrid, master record=$masterid");
636 my $ids = $U->storagereq(
637 'open-ils.storage.ordered.metabib.metarecord.records.staff.atomic', $mrid);
638 return undef unless @$ids;
640 my $master = $e->retrieve_biblio_record_entry($masterid)
643 # start the mods batch
644 my $u = OpenILS::Utils::ModsParser->new();
645 $u->start_mods_batch( $master->marc );
647 # grab all of the sub-records and shove them into the batch
648 my @ids = grep { $_ ne $masterid } @$ids;
649 my $subrecs = (@ids) ? $e->batch_retrieve_biblio_record_entry(\@ids) : [];
652 $logger->debug("adding record ".$_->id." to mods batch for metarecord=$mrid");
653 $u->push_mods_batch( $_->marc ) if $_->marc;
657 # finish up and send to the client
658 my $mods = $u->finish_mods_batch();
659 $mods->doc_id($mrid);
660 $client->respond_complete($mods);
663 # now update the mods string in the db
664 my $string = JSON->perl2JSON($mods->decast);
667 #$e = OpenILS::Utils::Editor->new(xact => 1);
668 $e = new_editor(xact => 1);
669 $e->update_metabib_metarecord($mr)
670 or $logger->error("Error setting mods text on metarecord $mrid : " . Dumper($e->event));
679 # converts a mr id into a list of record ids
681 __PACKAGE__->register_method(
682 method => "biblio_mrid_to_record_ids",
683 api_name => "open-ils.search.biblio.metarecord_to_records",
686 __PACKAGE__->register_method(
687 method => "biblio_mrid_to_record_ids",
688 api_name => "open-ils.search.biblio.metarecord_to_records.staff",
691 sub biblio_mrid_to_record_ids {
692 my( $self, $client, $mrid, $args ) = @_;
694 my $format = $$args{format};
695 my $org = $$args{org};
696 my $depth = $$args{depth};
698 my $method = "open-ils.storage.ordered.metabib.metarecord.records.atomic";
699 $method =~ s/atomic/staff\.atomic/o if $self->api_name =~ /staff/o;
700 my $recs = $U->storagereq($method, $mrid, $format, $org, $depth);
702 return { count => scalar(@$recs), ids => $recs };
706 __PACKAGE__->register_method(
707 method => "biblio_record_to_marc_html",
708 api_name => "open-ils.search.biblio.record.html" );
710 my $parser = XML::LibXML->new();
711 my $xslt = XML::LibXSLT->new();
714 my $settings_client = OpenSRF::Utils::SettingsClient->new();
715 sub biblio_record_to_marc_html {
716 my( $self, $client, $recordid ) = @_;
719 my $dir = $settings_client->config_value( "dirs", "xsl" );
720 my $xsl = $settings_client->config_value(
721 "apps", "open-ils.search", "app_settings", "marc_html_xsl" );
723 $xsl = $parser->parse_file("$dir/$xsl");
724 $marc_sheet = $xslt->parse_stylesheet( $xsl );
728 my $record = $apputils->simple_scalar_request(
730 "open-ils.cstore.direct.biblio.record_entry.retrieve",
733 my $xmldoc = $parser->parse_string($record->marc);
734 my $html = $marc_sheet->transform($xmldoc);
735 $html = $html->toString();
742 __PACKAGE__->register_method(
743 method => "retrieve_all_copy_locations",
744 api_name => "open-ils.search.config.copy_location.retrieve.all" );
746 my $shelving_locations;
747 sub retrieve_all_copy_locations {
748 my( $self, $client ) = @_;
749 if(!$shelving_locations) {
750 $shelving_locations = $apputils->simple_scalar_request(
752 "open-ils.cstore.direct.asset.copy_location.search.atomic",
753 { id => { "!=" => undef } }
756 return $shelving_locations;
762 __PACKAGE__->register_method(
763 method => "retrieve_all_copy_statuses",
764 api_name => "open-ils.search.config.copy_status.retrieve.all" );
767 sub retrieve_all_copy_statuses {
768 my( $self, $client ) = @_;
769 return $copy_statuses if $copy_statuses;
770 return $copy_statuses =
771 new_editor()->retrieve_all_config_copy_status();
775 __PACKAGE__->register_method(
776 method => "copy_counts_per_org",
777 api_name => "open-ils.search.biblio.copy_counts.retrieve");
779 __PACKAGE__->register_method(
780 method => "copy_counts_per_org",
781 api_name => "open-ils.search.biblio.copy_counts.retrieve.staff");
783 sub copy_counts_per_org {
784 my( $self, $client, $record_id ) = @_;
786 warn "Retreiveing copy copy counts for record $record_id and method " . $self->api_name . "\n";
788 my $method = "open-ils.storage.biblio.record_entry.global_copy_count.atomic";
789 if($self->api_name =~ /staff/) { $method =~ s/atomic/staff\.atomic/; }
791 my $counts = $apputils->simple_scalar_request(
792 "open-ils.storage", $method, $record_id );
794 $counts = [ sort {$a->[0] <=> $b->[0]} @$counts ];
799 __PACKAGE__->register_method(
800 method => "copy_count_summary",
801 api_name => "open-ils.search.biblio.copy_counts.summary.retrieve",
802 notes => <<" NOTES");
803 returns an array of these:
804 [ org_id, callnumber_label, <status1_count>, <status2_cout>,...]
805 where statusx is a copy status name. the statuses are sorted
809 sub copy_count_summary {
810 my( $self, $client, $rid, $org, $depth ) = @_;
813 return $U->storagereq(
814 'open-ils.storage.biblio.record_entry.status_copy_count.atomic', $rid, $org, $depth );
820 __PACKAGE__->register_method(
821 method => "multiclass_search",
822 api_name => "open-ils.search.biblio.multiclass",
823 notes => <<" NOTES");
824 Performs a multiclass search
825 PARAMS( searchBlob, org_unit, format, limit )
826 where searchBlob is defined like this:
828 "title" : { "term" : "water" },
829 "author" : { "term" : "smith" },
834 __PACKAGE__->register_method(
835 method => "multiclass_search",
836 api_name => "open-ils.search.biblio.multiclass.staff",
837 notes => "see open-ils.search.biblio.multiclass" );
839 sub multiclass_search {
840 my( $self, $client, $searchBlob, $orgid, $format, $limit ) = @_;
842 $logger->debug("Performing multiclass search with org => $orgid, " .
843 "format => $format, limit => $limit, and search blob " . Dumper($searchBlob));
845 my $meth = 'open-ils.storage.metabib.post_filter.multiclass.search_fts.metarecord.atomic';
846 if($self->api_name =~ /staff/) { $meth =~ s/metarecord\.atomic/metarecord.staff.atomic/; }
849 my $records = $apputils->simplereq(
850 'open-ils.storage', $meth,
851 org_unit => $orgid, searches => $searchBlob, format => $format, limit => $limit );
856 if( ref($records) and $records->[0] and
857 defined($records->[0]->[3])) { $count = $records->[0]->[3];}
859 for my $r (@$records) { push( @$recs, $r ) if ($r and $r->[0]); }
861 # records has the form: [ mrid, rank, singleRecord / 0, hitCount ];
862 return { ids => $recs, count => $count };
868 __PACKAGE__->register_method(
869 method => "multiclass_search",
870 api_name => "open-ils.search.biblio.multiclass",
872 Performs a multiclass search
873 @param args A names hash of arguments:
874 org_unit : The org to focus the search on
875 depth : The search depth
878 offset : Search offset
879 searches : A named hash of searches which has the following format:
881 "title" : { "term" : "water" },
882 "author" : { "term" : "smith" },
885 @return { ids : <array of ids>, count : hitcount }
889 __PACKAGE__->register_method(
890 method => "multiclass_search",
891 api_name => "open-ils.search.biblio.multiclass.staff",
892 notes => q/@see open-ils.search.biblio.multiclass/ );
894 sub multiclass_search {
895 my( $self, $client, $args ) = @_;
897 $logger->debug("Performing multiclass search with args:\n" . Dumper($args));
898 my $meth = 'open-ils.storage.metabib.post_filter.multiclass.search_fts.metarecord.atomic';
899 if($self->api_name =~ /staff/) { $meth =~ s/metarecord\.atomic/metarecord.staff.atomic/; }
901 my $records = $apputils->simplereq( 'open-ils.storage', $meth, %$args );
906 if( ref($records) and $records->[0] and
907 defined($records->[0]->[3])) { $count = $records->[0]->[3];}
909 for my $r (@$records) { push( @$recs, $r ) if ($r and $r->[0]); }
911 return { ids => $recs, count => $count };
918 __PACKAGE__->register_method(
919 method => "marc_search",
920 api_name => "open-ils.search.biblio.marc.staff");
922 __PACKAGE__->register_method(
923 method => "marc_search",
924 api_name => "open-ils.search.biblio.marc",
925 notes => <<" NOTES");
927 open-ils.storage.biblio.full_rec.multi_search.atomic
928 { "searches": [{"term":"harry","restrict": [{"tag":245,"subfield":"a"}]}], "org_unit": 1,
929 "limit":5,"sort":"author","item_type":"g"}
933 my( $self, $conn, $args, $limit, $offset ) = @_;
935 my $method = 'open-ils.storage.biblio.full_rec.multi_search';
936 $method .= ".staff" if $self->api_name =~ /staff/;
937 $method .= ".atomic";
943 push( @search, ($_ => $$args{$_}) ) for (sort keys %$args);
944 my $ckey = $pfx . md5_hex($method . JSON->perl2JSON(\@search));
946 my $recs = search_cache($ckey, $offset, $limit);
949 $recs = $U->storagereq($method, %$args);
950 put_cache($ckey, scalar(@$recs), $recs);
951 $recs = [ @$recs[$offset..($offset + ($limit - 1))] ];
955 $count = $recs->[0]->[2] if $recs->[0] and $recs->[0]->[2];
956 my @recs = map { $_->[0] } @$recs;
958 return { ids => \@recs, count => $count };
962 __PACKAGE__->register_method(
963 method => "biblio_search_isbn",
964 api_name => "open-ils.search.biblio.isbn",
967 sub biblio_search_isbn {
968 my( $self, $client, $isbn ) = @_;
969 $logger->debug("Searching ISBN $isbn");
970 my $e = new_editor();
971 my $recs = $U->storagereq(
972 'open-ils.storage.id_list.biblio.record_entry.search.isbn.atomic', $isbn );
973 return { ids => $recs, count => scalar(@$recs) };
977 __PACKAGE__->register_method(
978 method => "biblio_search_issn",
979 api_name => "open-ils.search.biblio.issn",
982 sub biblio_search_issn {
983 my( $self, $client, $issn ) = @_;
984 $logger->debug("Searching ISSN $issn");
985 my $e = new_editor();
986 my $recs = $U->storagereq(
987 'open-ils.storage.id_list.biblio.record_entry.search.issn.atomic', $issn );
988 return { ids => $recs, count => scalar(@$recs) };
994 __PACKAGE__->register_method(
995 method => "fetch_mods_by_copy",
996 api_name => "open-ils.search.biblio.mods_from_copy",
999 sub fetch_mods_by_copy {
1000 my( $self, $client, $copyid ) = @_;
1001 my ($record, $evt) = $apputils->fetch_record_by_copy( $copyid );
1002 return $evt if $evt;
1003 return OpenILS::Event->new('ITEM_NOT_CATALOGED') unless $record->marc;
1004 return $apputils->record_to_mvr($record);
1009 # -------------------------------------------------------------------------------------
1011 __PACKAGE__->register_method(
1012 method => "cn_browse",
1013 api_name => "open-ils.search.callnumber.browse.target",
1014 notes => "Starts a callnumber browse"
1017 __PACKAGE__->register_method(
1018 method => "cn_browse",
1019 api_name => "open-ils.search.callnumber.browse.page_up",
1020 notes => "Returns the previous page of callnumbers",
1023 __PACKAGE__->register_method(
1024 method => "cn_browse",
1025 api_name => "open-ils.search.callnumber.browse.page_down",
1026 notes => "Returns the next page of callnumbers",
1030 # RETURNS array of arrays like so: label, owning_lib, record, id
1032 my( $self, $client, @params ) = @_;
1035 $method = 'open-ils.storage.asset.call_number.browse.target.atomic'
1036 if( $self->api_name =~ /target/ );
1037 $method = 'open-ils.storage.asset.call_number.browse.page_up.atomic'
1038 if( $self->api_name =~ /page_up/ );
1039 $method = 'open-ils.storage.asset.call_number.browse.page_down.atomic'
1040 if( $self->api_name =~ /page_down/ );
1042 return $apputils->simplereq( 'open-ils.storage', $method, @params );
1044 # -------------------------------------------------------------------------------------
1046 __PACKAGE__->register_method(
1047 method => "fetch_cn",
1048 api_name => "open-ils.search.callnumber.retrieve",
1049 notes => "retrieves a callnumber based on ID",
1053 my( $self, $client, $id ) = @_;
1054 my( $cn, $evt ) = $apputils->fetch_callnumber( $id );
1055 return $evt if $evt;
1059 __PACKAGE__->register_method (
1060 method => "fetch_copy_by_cn",
1061 api_name => 'open-ils.search.copies_by_call_number.retrieve',
1063 Returns an array of copy id's by callnumber id
1064 @param cnid The callnumber id
1065 @return An array of copy ids
1069 sub fetch_copy_by_cn {
1070 my( $self, $conn, $cnid ) = @_;
1071 return $U->cstorereq(
1072 'open-ils.cstore.direct.asset.copy.id_list.atomic',
1073 { call_number => $cnid, deleted => 'f' } );
1076 __PACKAGE__->register_method (
1077 method => 'fetch_cn_by_info',
1078 api_name => 'open-ils.search.call_number.retrieve_by_info',
1080 @param label The callnumber label
1081 @param record The record the cn is attached to
1082 @param org The owning library of the cn
1083 @return The callnumber object
1088 sub fetch_cn_by_info {
1089 my( $self, $conn, $label, $record, $org ) = @_;
1090 return $U->cstorereq(
1091 'open-ils.cstore.direct.asset.call_number.search',
1092 { label => $label, record => $record, owning_lib => $org, deleted => 'f' });
1099 __PACKAGE__->register_method (
1100 method => 'bib_extras',
1101 api_name => 'open-ils.search.biblio.lit_form_map.retrieve.all');
1102 __PACKAGE__->register_method (
1103 method => 'bib_extras',
1104 api_name => 'open-ils.search.biblio.item_form_map.retrieve.all');
1105 __PACKAGE__->register_method (
1106 method => 'bib_extras',
1107 api_name => 'open-ils.search.biblio.item_type_map.retrieve.all');
1108 __PACKAGE__->register_method (
1109 method => 'bib_extras',
1110 api_name => 'open-ils.search.biblio.audience_map.retrieve.all');
1115 my $e = new_editor();
1117 return $e->retrieve_all_config_lit_form_map()
1118 if( $self->api_name =~ /lit_form/ );
1120 return $e->retrieve_all_config_item_form_map()
1121 if( $self->api_name =~ /item_form_map/ );
1123 return $e->retrieve_all_config_item_type_map()
1124 if( $self->api_name =~ /item_type_map/ );
1126 return $e->retrieve_all_config_audience_map()
1127 if( $self->api_name =~ /audience_map/ );
1134 __PACKAGE__->register_method(
1135 method => 'fetch_slim_record',
1136 api_name => 'open-ils.search.biblio.record_entry.slim.retrieve',
1138 Returns a biblio.record_entry without the attached marcxml
1142 sub fetch_slim_record {
1143 my( $self, $conn, $ids ) = @_;
1145 #my $editor = OpenILS::Utils::Editor->new;
1146 my $editor = new_editor();
1149 return $editor->event unless
1150 my $r = $editor->retrieve_biblio_record_entry($_);
1159 __PACKAGE__->register_method(
1160 method => 'rec_to_mr_rec_descriptors',
1161 api_name => 'open-ils.search.metabib.record_to_descriptors',
1163 specialized method...
1164 Given a biblio record id or a metarecord id,
1165 this returns a list of metabib.record_descriptor
1166 objects that live within the same metarecord
1167 @param args Object of args including:
1171 sub rec_to_mr_rec_descriptors {
1172 my( $self, $conn, $args ) = @_;
1174 my $rec = $$args{record};
1175 my $mrec = $$args{metarecord};
1176 my $item_forms = $$args{item_forms};
1177 my $item_types = $$args{item_types};
1178 my $item_lang = $$args{item_lang};
1180 my $e = new_editor();
1184 my $map = $e->search_metabib_metarecord_source_map({source => $rec});
1185 return $e->event unless @$map;
1186 $mrec = $$map[0]->metarecord;
1189 $recs = $e->search_metabib_metarecord_source_map({metarecord => $mrec});
1190 return $e->event unless @$recs;
1192 my @recs = map { $_->source } @$recs;
1193 my $search = { record => \@recs };
1194 $search->{item_form} = $item_forms if $item_forms and @$item_forms;
1195 $search->{item_type} = $item_types if $item_types and @$item_types;
1196 $search->{item_lang} = $item_lang if $item_lang;
1198 my $desc = $e->search_metabib_record_descriptor($search);
1200 return { metarecord => $mrec, descriptors => $desc };
1206 __PACKAGE__->register_method(
1207 method => 'copies_created_on',
1211 sub copies_created_on {
1212 my( $self, $conn, $auth, $org, $date ) = @_;
1213 my $e = new_editor(authtoken=>$auth);
1214 return $e->event unless $e->checkauth;
1218 __PACKAGE__->register_method(
1219 method => 'fetch_age_protect',
1220 api_name => 'open-ils.search.copy.age_protect.retrieve.all',
1223 sub fetch_age_protect {
1224 return new_editor()->retrieve_all_config_rule_age_hold_protect();