1 package OpenILS::Application::Search::Biblio;
2 use base qw/OpenSRF::Application/;
3 use strict; use warnings;
8 use OpenILS::Utils::Fieldmapper;
9 use OpenILS::Utils::ModsParser;
10 use OpenSRF::Utils::SettingsClient;
12 use OpenILS::Application::AppUtils;
16 use Time::HiRes qw(time);
17 use OpenSRF::EX qw(:try);
18 use Digest::MD5 qw(md5_hex);
23 $Data::Dumper::Indent = 0;
24 use OpenSRF::Utils::Logger qw/:logger/;
26 my $apputils = "OpenILS::Application::AppUtils";
28 # Houses biblio search utilites
31 __PACKAGE__->register_method(
33 api_name => "open-ils.search.test");
35 sub test { return "test"; }
40 __PACKAGE__->register_method(
41 method => "biblio_search_marc",
42 api_name => "open-ils.search.biblio.marc",
44 note => "Searches biblio information by marc tag",
47 sub biblio_search_marc {
49 my( $self, $client, $search_hash, $string ) = @_;
51 warn "Building biblio marc session\n";
52 my $session = OpenSRF::AppSession->create("open-ils.storage");
55 warn "Sending biblio marc request. String $string\nSearch hash: " . Dumper($search_hash);
56 my $request = $session->request(
57 "open-ils.storage.direct.metabib.full_rec.search_fts.index_vector.atomic",
58 restrict => $search_hash,
60 my $data = $request->gather(1);
65 $session->disconnect();
74 # ---------------------------------------------------------------------------
75 # takes a list of record id's and turns the docs into friendly
76 # mods structures. Creates one MODS structure for each doc id.
77 # ---------------------------------------------------------------------------
78 sub _records_to_mods {
84 my $session = OpenSRF::AppSession->create("open-ils.storage");
85 my $request = $session->request(
86 "open-ils.storage.direct.biblio.record_entry.batch.retrieve", @ids );
88 my $last_content = undef;
90 while( my $response = $request->recv() ) {
93 my $u = OpenILS::Utils::ModsParser->new();
94 $u->start_mods_batch( $last_content->marc );
95 my $mods = $u->finish_mods_batch();
96 $mods->doc_id($last_content->id());
97 $mods->tcn($last_content->tcn_value);
98 warn "Turning doc " . $mods->doc_id() . " into MODS\n";
99 $last_content = undef;
100 push @results, $mods;
103 next unless $response;
105 if($response->isa("OpenSRF::EX")) {
106 throw $response ($response->stringify);
109 $last_content = $response->content;
113 if( $last_content ) {
114 my $u = OpenILS::Utils::ModsParser->new();
115 $u->start_mods_batch( $last_content->marc );
116 my $mods = $u->finish_mods_batch();
117 $mods->doc_id($last_content->id());
118 $mods->tcn($last_content->tcn_value);
119 push @results, $mods;
124 $session->disconnect();
130 __PACKAGE__->register_method(
131 method => "record_id_to_mods",
132 api_name => "open-ils.search.biblio.record.mods.retrieve",
134 note => "Provide ID, we provide the mods"
137 # converts a record into a mods object with copy counts attached
138 sub record_id_to_mods {
140 my( $self, $client, $org_id, $id ) = @_;
142 my $mods_list = _records_to_mods( $id );
143 my $mods_obj = $mods_list->[0];
144 my $cmethod = $self->method_lookup(
145 "open-ils.search.biblio.record.copy_count");
146 my ($count) = $cmethod->run($org_id, $id);
147 $mods_obj->copy_count($count);
154 __PACKAGE__->register_method(
155 method => "record_id_to_mods_slim",
156 api_name => "open-ils.search.biblio.record.mods_slim.retrieve",
158 note => "Provide ID, we provide the mods"
161 # converts a record into a mods object with NO copy counts attached
162 sub record_id_to_mods_slim {
163 my( $self, $client, $id ) = @_;
164 return undef unless defined $id;
166 if(ref($id) and ref($id) == 'ARRAY') {
167 return _records_to_mods( @$id );
169 my $mods_list = _records_to_mods( $id );
170 my $mods_obj = $mods_list->[0];
175 # Returns the number of copies attached to a record based on org location
176 __PACKAGE__->register_method(
177 method => "record_id_to_copy_count",
178 api_name => "open-ils.search.biblio.record.copy_count",
181 __PACKAGE__->register_method(
182 method => "record_id_to_copy_count",
183 api_name => "open-ils.search.biblio.metarecord.copy_count",
186 __PACKAGE__->register_method(
187 method => "record_id_to_copy_count",
188 api_name => "open-ils.search.biblio.metarecord.copy_count.staff",
190 sub record_id_to_copy_count {
191 my( $self, $client, $org_id, $record_id, $format ) = @_;
193 my $method = "open-ils.storage.biblio.record_entry.copy_count.atomic";
195 if($self->api_name =~ /metarecord/) {
196 $method = "open-ils.storage.metabib.metarecord.copy_count.atomic";
200 if($self->api_name =~ /staff/ ) {
201 $method =~ s/atomic/staff\.atomic/og;
202 warn "Doing staff search $method\n";
206 my $session = OpenSRF::AppSession->create("open-ils.storage");
207 warn "copy_count retrieve $record_id\n";
208 return undef unless(defined $record_id);
210 my $request = $session->request(
211 $method, org_unit => $org_id => $key => $record_id, format => $format );
214 my $count = $request->gather(1);
215 $session->disconnect();
216 return [ sort { $a->{depth} <=> $b->{depth} } @$count ];
221 # used for cat search classes
222 my $cat_search_hash = {
225 { tag => "100", subfield => "a"} ,
226 { tag => "700", subfield => "a"},
230 { tag => "245", subfield => "a"},
231 { tag => "242", subfield => "a"},
232 { tag => "240", subfield => "a"},
233 { tag => "210", subfield => "a"},
237 { tag => "650", subfield => "_" },
241 { tag => "035", subfield => "_" },
245 { tag => "020", subfield => "a" },
251 __PACKAGE__->register_method(
252 method => "biblio_search_tcn",
253 api_name => "open-ils.search.biblio.tcn",
255 note => "Retrieve a record by TCN",
258 sub biblio_search_tcn {
260 my( $self, $client, $tcn ) = @_;
262 $tcn =~ s/.*?(\w+)\s*$/$1/o;
263 warn "Searching TCN $tcn\n";
265 my $session = OpenSRF::AppSession->create( "open-ils.storage" );
266 my $request = $session->request(
267 "open-ils.storage.direct.biblio.record_entry.search.tcn_value.atomic", $tcn );
268 my $record_entry = $request->gather(1);
271 for my $record (@$record_entry) {
272 push @ids, $record->id;
275 $session->disconnect();
277 warn "received ID's for tcn search @ids\n";
280 return { count => $size, ids => \@ids };
285 # --------------------------------------------------------------------------------
292 # --------------------------------------------------------------------------------
294 __PACKAGE__->register_method(
295 method => "biblio_barcode_to_copy",
296 api_name => "open-ils.search.asset.copy.find_by_barcode",
299 # turns a barcode into a copy object
300 sub biblio_barcode_to_copy {
301 my( $self, $client, $barcode ) = @_;
303 throw OpenSRF::EX::InvalidArg
304 ("search.biblio.barcode needs a barcode to search")
305 unless defined $barcode;
307 warn "copy search for barcode $barcode\n";
308 my $record = OpenILS::Application::AppUtils->simple_scalar_request(
310 "open-ils.storage.direct.asset.copy.search.barcode.atomic",
313 return undef unless($record);
318 __PACKAGE__->register_method(
319 method => "biblio_id_to_copy",
320 api_name => "open-ils.search.asset.copy.batch.retrieve",
323 # turns a barcode into a copy object
324 sub biblio_id_to_copy {
325 my( $self, $client, $ids ) = @_;
327 throw OpenSRF::EX::InvalidArg
328 ("search.biblio.batch.retrieve needs a id to search")
331 warn "copy search for ids @$ids\n";
332 my $record = OpenILS::Application::AppUtils->simple_scalar_request(
334 "open-ils.storage.direct.asset.copy.batch.retrieve.atomic",
342 __PACKAGE__->register_method(
343 method => "fleshed_copy_retrieve_batch",
344 api_name => "open-ils.search.asset.copy.fleshed.batch.retrieve",
347 sub fleshed_copy_retrieve_batch {
348 my( $self, $client, $ids ) = @_;
350 throw OpenSRF::EX::InvalidArg
351 ("search.biblio.batch.retrieve needs a id to search")
354 warn "fleshed copy search for id @$ids\n";
355 my $copy = OpenILS::Application::AppUtils->simple_scalar_request(
357 "open-ils.storage.fleshed.asset.copy.batch.retrieve.atomic",
363 __PACKAGE__->register_method(
364 method => "fleshed_copy_retrieve",
365 api_name => "open-ils.search.asset.copy.fleshed.retrieve",
368 sub fleshed_copy_retrieve {
369 my( $self, $client, $id ) = @_;
371 return undef unless defined $id;
372 warn "copy retrieve for id $id\n";
373 return OpenILS::Application::AppUtils->simple_scalar_request(
375 "open-ils.storage.fleshed.asset.copy.retrieve.atomic",
381 __PACKAGE__->register_method(
382 method => "biblio_barcode_to_title",
383 api_name => "open-ils.search.biblio.find_by_barcode",
386 sub biblio_barcode_to_title {
387 my( $self, $client, $barcode ) = @_;
390 throw OpenSRF::EX::ERROR
391 ("Not enough args to find_by_barcode");
394 my $title = $apputils->simple_scalar_request(
396 "open-ils.storage.biblio.record_entry.retrieve_by_barcode",
400 return { ids => [ $title->id ], count => 1 };
402 return { count => 0 };
408 __PACKAGE__->register_method(
409 method => "biblio_copy_to_mods",
410 api_name => "open-ils.search.biblio.copy.mods.retrieve",
413 # takes a copy object and returns it fleshed mods object
414 sub biblio_copy_to_mods {
415 my( $self, $client, $copy ) = @_;
417 throw OpenSRF::EX::InvalidArgs
418 ("copy.mods.retrieve needs a copy") unless( $copy );
420 new Fieldmapper::asset::copy($copy);
422 my $volume = OpenILS::Application::AppUtils->simple_scalar_request(
424 "open-ils.storage.direct.asset.call_number.retrieve",
425 $copy->call_number() );
427 my $mods = _records_to_mods($volume->record());
428 $mods = shift @$mods;
429 $volume->copies([$copy]);
430 push @{$mods->call_numbers()}, $volume;
436 sub barcode_to_mods {
441 # --------------------------------------------------------------------------------
446 __PACKAGE__->register_method(
447 method => "cat_biblio_search_class",
448 api_name => "open-ils.search.cat.biblio.class",
452 sub cat_biblio_search_class {
454 my( $self, $client, $org_id, $class, $sort, $string ) = @_;
456 throw OpenSRF::EX::InvalidArg
457 ("Not enough args to open-ils.search.cat.biblio.class")
458 unless( defined($org_id) and $class and $sort and $string );
463 my $method = $self->method_lookup("open-ils.search.biblio.marc");
465 throw OpenSRF::EX::PANIC
466 ("Can't lookup method 'open-ils.search.biblio.marc'");
469 my ($records) = $method->run( $cat_search_hash->{$class}, $string );
472 for my $i (@$records) { push @ids, $i->[0]; }
474 my $mods_list = _records_to_mods( @ids );
475 return undef unless (ref($mods_list) eq "ARRAY");
477 # ---------------------------------------------------------------
478 # append copy count information to the mods objects
479 my $session = OpenSRF::AppSession->create("open-ils.storage");
481 my $request = $session->request(
482 "open-ils.storage.direct.biblio.record_copy_count.batch", $org_id, @ids );
486 warn "receiving copy counts for doc $id\n";
488 my $response = $request->recv();
489 next unless $response;
491 if( $response and UNIVERSAL::isa($response, "Error")) {
492 throw $response ($response->stringify);
495 my $count = $response->content;
496 my $mods_obj = undef;
497 for my $m (@$mods_list) {
498 $mods_obj = $m if ($m->doc_id() == $id)
501 $mods_obj->copy_count($count);
504 $client->respond( $mods_obj );
510 $session->disconnect();
512 # ---------------------------------------------------------------
522 __PACKAGE__->register_method(
523 method => "biblio_search_class_count",
524 api_name => "open-ils.search.biblio.class.count",
527 __PACKAGE__->register_method(
528 method => "biblio_search_class_count",
529 api_name => "open-ils.search.biblio.class.count.staff",
532 sub biblio_search_class_count {
534 my( $self, $client, $class, $string, $org_id, $org_type, $format ) = @_;
536 warn "org: $org_id : depth: $org_type\n";
538 $org_id = "1" unless defined($org_id); # xxx
539 $org_type = 0 unless defined($org_type);
541 warn "Searching biblio.class.id\n" .
543 "org_id: $org_id\n" .
544 "depth: $org_type\n" .
547 if( !defined($org_id) or !$class or !$string ) {
548 warn "not enbough args to metarecord search\n";
549 throw OpenSRF::EX::InvalidArg
550 ("Not enough args to open-ils.search.cat.biblio.class")
555 if( ($class ne "title") and ($class ne "author") and
556 ($class ne "subject") and ($class ne "keyword")
557 and ($class ne "series" )) {
558 warn "Invalid search class: $class\n";
559 throw OpenSRF::EX::InvalidArg ("Not a valid search class: $class")
562 # grab the mr id's from storage
564 my $method = "open-ils.storage.cachable.metabib.$class.search_fts.metarecord_count";
565 if($self->api_name =~ /staff/) {
566 $method = "$method.staff";
567 $method =~ s/\.cachable//o;
569 warn "Performing count method $method\n";
570 warn "API name " . $self->api_name() . "\n";
572 my $session = OpenSRF::AppSession->create('open-ils.storage');
574 my $request = $session->request( $method,
577 cache_page_size => 1,
581 my $count = $request->gather(1);
582 warn "Received count $count\n";
588 __PACKAGE__->register_method(
589 method => "biblio_search_class",
590 api_name => "open-ils.search.biblio.class",
593 __PACKAGE__->register_method(
594 method => "biblio_search_class",
595 api_name => "open-ils.search.biblio.class.full",
598 __PACKAGE__->register_method(
599 method => "biblio_search_class",
600 api_name => "open-ils.search.biblio.class.full.staff",
603 __PACKAGE__->register_method(
604 method => "biblio_search_class",
605 api_name => "open-ils.search.biblio.class.staff",
608 sub biblio_search_class {
610 my( $self, $client, $class, $string,
611 $org_id, $org_type, $limit, $offset, $format ) = @_;
613 warn "org: $org_id : depth: $org_type : limit: $limit : offset: $offset\n";
616 $offset = 0 unless (defined($offset) and $offset > 0);
617 $limit = 100 unless (defined($limit) and $limit > 0);
618 $org_id = "1" unless (defined($org_id)); # xxx
619 $org_type = 0 unless (defined($org_type));
621 warn "Searching biblio.class.id\n" .
623 "\noffset: $offset\n" .
625 "org_id: $org_id\n" .
626 "depth: $org_type\n" .
629 warn "Search filtering string " . time() . "\n";
630 $string = OpenILS::Application::Search->filter_search($string);
631 if(!$string) { return undef; }
633 if( !defined($org_id) or !$class or !$string ) {
634 warn "not enbough args to metarecord search\n";
635 throw OpenSRF::EX::InvalidArg
636 ("Not enough args to open-ils.search.biblio.class")
641 if( ($class ne "title") and ($class ne "author") and
642 ($class ne "subject") and ($class ne "keyword")
643 and ($class ne "series") ) {
644 warn "Invalid search class: $class\n";
645 throw OpenSRF::EX::InvalidArg ("Not a valid search class: $class")
648 #my $method = "open-ils.storage.cachable.metabib.$class.post_filter.search_fts.metarecord.atomic";
649 my $method = "open-ils.storage.metabib.$class.post_filter.search_fts.metarecord.atomic";
651 if($self->api_name =~ /staff/) {
652 $method =~ s/atomic/staff\.atomic/og;
653 $method =~ s/\.cachable//o;
656 if($self->api_name =~ /full/) {
657 $method =~ s/\.cachable//o; #XXX testing..
660 warn "Performing search method $method\n";
661 warn "MR search method is $method\n";
663 my $session = OpenSRF::AppSession->create('open-ils.storage');
665 warn "Search making request " . time() . "\n";
666 my $request = $session->request(
674 cache_page_size => 200,
677 my $records = $request->gather(1);
678 if(!$records) {return { ids => [] }};
682 warn "Received " . scalar(@$records) . " id's from class search\n";
684 # for my $i (@$records) { if(defined($i)) { push @all_ids, $i; } }
685 # my @ids = @all_ids;
686 # @ids = grep { defined($_->[0]) } @ids;
689 $session->disconnect();
692 if( $records->[0] && defined($records->[0]->[3])) { $count = $records->[0]->[3];}
694 for my $r (@$records) { push( @$recs, $r ) if ($r and $r->[0]); }
696 # records has the form: [ mrid, rank, singleRecord / 0, hitCount ];
697 return { ids => $recs, count => $count };
704 __PACKAGE__->register_method(
705 method => "biblio_mrid_to_modsbatch_batch",
706 api_name => "open-ils.search.biblio.metarecord.mods_slim.batch.retrieve");
708 sub biblio_mrid_to_modsbatch_batch {
709 my( $self, $client, $mrids) = @_;
710 warn "Performing mrid_to_modsbatch_batch...";
712 my $method = $self->method_lookup("open-ils.search.biblio.metarecord.mods_slim.retrieve");
714 warn "Grabbing mods for " . Dumper($mrids) . "\n";
716 for my $id (@$mrids) {
717 next unless defined $id;
718 #push @mods, biblio_mrid_to_modsbatch($self, $client, $id);
719 my ($m) = $method->run($id);
726 __PACKAGE__->register_method(
727 method => "biblio_mrid_to_modsbatch",
728 api_name => "open-ils.search.biblio.metarecord.mods_slim.retrieve",
729 notes => <<" NOTES");
730 Returns the mvr associated with a given metarecod. If none exists,
734 __PACKAGE__->register_method(
735 method => "biblio_mrid_to_modsbatch",
736 api_name => "open-ils.search.biblio.metarecord.mods_slim.retrieve.staff",
737 notes => <<" NOTES");
738 Returns the mvr associated with a given metarecod. If none exists,
742 sub biblio_mrid_to_modsbatch {
743 my( $self, $client, $mrid ) = @_;
745 warn "Grabbing mvr for $mrid\n";
747 my $mr = _grab_metarecord($mrid);
748 return undef unless $mr;
750 if( my $m = $self->biblio_mrid_check_mvr($client, $mr)) {
754 return $self->biblio_mrid_make_modsbatch( $client, $mr );
757 # converts a metarecord to an mvr
760 my $perl = JSON->JSON2perl($mr->mods());
761 return Fieldmapper::metabib::virtual_record->new($perl);
764 # checks to see if a metarecord has mods, if so returns true;
766 __PACKAGE__->register_method(
767 method => "biblio_mrid_check_mvr",
768 api_name => "open-ils.search.biblio.metarecord.mods_slim.check",
769 notes => <<" NOTES");
770 Takes a metarecord ID or a metarecord object and returns true
771 if the metarecord already has an mvr associated with it.
774 sub biblio_mrid_check_mvr {
775 my( $self, $client, $mrid ) = @_;
778 if(ref($mrid)) { $mr = $mrid; }
779 else { $mr = _grab_metarecord($mrid); }
781 warn "Checking mvr for mr " . $mr->id . "\n";
783 return _mr_to_mvr($mr) if $mr->mods();
787 sub _grab_metarecord {
790 warn "Grabbing MR $mrid\n";
792 my $mr = OpenILS::Application::AppUtils->simple_scalar_request(
794 "open-ils.storage.direct.metabib.metarecord.retrieve", $mrid );
797 throw OpenSRF::EX::ERROR
798 ("No metarecord exists with the given id: $mrid");
804 __PACKAGE__->register_method(
805 method => "biblio_mrid_make_modsbatch",
806 api_name => "open-ils.search.biblio.metarecord.mods_slim.create",
807 notes => <<" NOTES");
808 Takes either a metarecord ID or a metarecord object.
809 Forces the creations of an mvr for the given metarecord.
810 The created mvr is returned.
813 sub biblio_mrid_make_modsbatch {
815 my( $self, $client, $mrid ) = @_;
818 if(ref($mrid)) { $mr = $mrid; }
819 else { $mr = _grab_metarecord($mrid); }
822 warn "Forcing mvr creation for mr " . $mr->id . "\n";
823 my $master_id = $mr->master_record;
825 my $session = OpenSRF::AppSession->create("open-ils.storage");
827 # grab the records attached to this metarecod
828 warn "Creating mods batch for metarecord $mrid\n";
829 my $meth = "open-ils.search.biblio.metarecord_to_records.staff";
830 $meth = $self->method_lookup($meth);
831 my ($id_hash) = $meth->run($mrid);
832 my @ids = @{$id_hash->{ids}};
833 if(@ids < 1) { return undef; }
835 warn "Master ID is $master_id\n";
836 # grab the master record to start the mods batch
838 $meth = "open-ils.storage.direct.biblio.record_entry.retrieve";
840 my $record = $session->request(
841 "open-ils.storage.direct.biblio.record_entry.retrieve", $master_id );
842 $record = $record->gather(1);
844 #my $record = OpenILS::Application::AppUtils->simple_scalar_request( "open-ils.storage",
847 warn "No record returned with id $master_id";
848 throw OpenSRF::EX::ERROR
851 my $u = OpenILS::Utils::ModsParser->new();
853 $u->start_mods_batch( $record->marc );
854 my $main_doc_id = $record->id();
856 @ids = grep { $_ ne $master_id } @ids;
858 # now we have to collect all of the marc objects and push them into a mods batch
859 my $request = $session->request(
860 "open-ils.storage.direct.biblio.record_entry.batch.retrieve", @ids );
862 while( my $response = $request->recv() ) {
864 next unless $response;
865 if(UNIVERSAL::isa( $response,"OpenSRF::EX")) {
866 throw $response ($response->stringify);
869 my $content = $response->content;
872 $u->push_mods_batch( $content->marc );
876 my $mods = $u->finish_mods_batch();
877 $mods->doc_id($mrid);
880 $client->respond_complete($mods);
882 my $mods_string = JSON->perl2JSON($mods->decast);
884 $mr->mods($mods_string);
886 my $req = $session->request(
887 "open-ils.storage.direct.metabib.metarecord.update", $mr );
892 $session->disconnect();
899 # converts a mr id into a list of record ids
901 __PACKAGE__->register_method(
902 method => "biblio_mrid_to_record_ids",
903 api_name => "open-ils.search.biblio.metarecord_to_records",
906 __PACKAGE__->register_method(
907 method => "biblio_mrid_to_record_ids",
908 api_name => "open-ils.search.biblio.metarecord_to_records.staff",
911 sub biblio_mrid_to_record_ids {
912 my( $self, $client, $mrid, $format ) = @_;
914 throw OpenSRF::EX::InvalidArg
915 ("search.biblio.metarecord_to_record_ids requires mr id")
916 unless defined( $mrid );
918 warn "Searching for record for MR $mrid and format $format\n";
920 my $method = "open-ils.storage.ordered.metabib.metarecord.records.atomic";
921 if($self and $self->api_name =~ /staff/) { $method =~ s/atomic/staff\.atomic/; }
922 warn "Performing record retrieval with method $method\n";
925 my $mrmaps = OpenILS::Application::AppUtils->simple_scalar_request(
926 "open-ils.storage", $method, $mrid, $format );
933 return { count => $size, ids => $mrmaps };
938 __PACKAGE__->register_method(
939 method => "biblio_record_to_marc_html",
940 api_name => "open-ils.search.biblio.record.html" );
942 my $parser = XML::LibXML->new();
943 my $xslt = XML::LibXSLT->new();
946 my $settings_client = OpenSRF::Utils::SettingsClient->new();
947 sub biblio_record_to_marc_html {
948 my( $self, $client, $recordid ) = @_;
951 my $dir = $settings_client->config_value( "dirs", "xsl" );
952 my $xsl = $settings_client->config_value(
953 "apps", "open-ils.search", "app_settings", "marc_html_xsl" );
955 $xsl = $parser->parse_file("$dir/$xsl");
956 $marc_sheet = $xslt->parse_stylesheet( $xsl );
960 my $record = $apputils->simple_scalar_request(
962 "open-ils.storage.direct.biblio.record_entry.retrieve",
965 my $xmldoc = $parser->parse_string($record->marc);
966 my $html = $marc_sheet->transform($xmldoc);
967 $html = $html->toString();
974 __PACKAGE__->register_method(
975 method => "retrieve_all_copy_locations",
976 api_name => "open-ils.search.config.copy_location.retrieve.all" );
978 my $shelving_locations;
979 sub retrieve_all_copy_locations {
980 my( $self, $client ) = @_;
981 if(!$shelving_locations) {
982 $shelving_locations = $apputils->simple_scalar_request(
984 "open-ils.storage.direct.asset.copy_location.retrieve.all.atomic");
986 return $shelving_locations;
991 __PACKAGE__->register_method(
992 method => "retrieve_all_copy_statuses",
993 api_name => "open-ils.search.config.copy_status.retrieve.all" );
996 sub retrieve_all_copy_statuses {
997 my( $self, $client ) = @_;
998 if(!$copy_statuses) {
999 $copy_statuses = $apputils->simple_scalar_request(
1001 "open-ils.storage.direct.config.copy_status.retrieve.all.atomic" );
1003 return $copy_statuses;
1007 __PACKAGE__->register_method(
1008 method => "copy_counts_per_org",
1009 api_name => "open-ils.search.biblio.copy_counts.retrieve");
1011 __PACKAGE__->register_method(
1012 method => "copy_counts_per_org",
1013 api_name => "open-ils.search.biblio.copy_counts.retrieve.staff");
1015 sub copy_counts_per_org {
1016 my( $self, $client, $record_id ) = @_;
1018 warn "Retreiveing copy copy counts for record $record_id and method " . $self->api_name . "\n";
1020 my $method = "open-ils.storage.biblio.record_entry.global_copy_count.atomic";
1021 if($self->api_name =~ /staff/) { $method =~ s/atomic/staff\.atomic/; }
1023 my $counts = $apputils->simple_scalar_request(
1024 "open-ils.storage", $method, $record_id );
1026 $counts = [ sort {$a->[0] <=> $b->[0]} @$counts ];
1031 __PACKAGE__->register_method(
1032 method => "copy_count_summary",
1033 api_name => "open-ils.search.biblio.copy_counts.summary.retrieve",
1034 notes => <<" NOTES");
1035 returns an array of these:
1036 [ org_id, callnumber_label, <status1_count>, <status2_cout>,...]
1037 where statusx is a copy status name. the statuses are sorted
1041 sub copy_count_summary {
1042 my( $self, $client, $rid ) = @_;
1043 my $method = "open-ils.storage.biblio.record_entry.status_copy_count.atomic";
1044 return $apputils->simple_scalar_request( "open-ils.storage", $method, $rid );
1048 __PACKAGE__->register_method(
1049 method => "multiclass_search",
1050 api_name => "open-ils.search.biblio.multiclass",
1051 notes => <<" NOTES");
1052 Performs a multiclass search
1053 PARAMS( searchBlob, org_unit, format, limit )
1054 where searchBlob is defined like this:
1056 "title" : { "term" : "water" },
1057 "author" : { "term" : "smith" },
1062 __PACKAGE__->register_method(
1063 method => "multiclass_search",
1064 api_name => "open-ils.search.biblio.multiclass.staff",
1065 notes => "see open-ils.search.biblio.multiclass" );
1067 sub multiclass_search {
1068 my( $self, $client, $searchBlob, $orgid, $format, $limit ) = @_;
1070 $logger->debug("Performing multiclass search with org => $orgid, " .
1071 "format => $format, limit => $limit, and search blob " . Dumper($searchBlob));
1073 my $meth = 'open-ils.storage.metabib.post_filter.multiclass.search_fts.metarecord.atomic';
1074 if($self->api_name =~ /staff/) { $meth =~ s/metarecord\.atomic/metarecord.staff.atomic/; }
1077 my $records = $apputils->simplereq(
1078 'open-ils.storage', $meth,
1079 org_unit => $orgid, searches => $searchBlob, format => $format, limit => $limit );
1084 if( ref($records) and $records->[0] and
1085 defined($records->[0]->[3])) { $count = $records->[0]->[3];}
1087 for my $r (@$records) { push( @$recs, $r ) if ($r and $r->[0]); }
1089 # records has the form: [ mrid, rank, singleRecord / 0, hitCount ];
1090 return { ids => $recs, count => $count };
1095 __PACKAGE__->register_method(
1096 method => "marc_search",
1097 api_name => "open-ils.search.biblio.marc",
1098 notes => <<" NOTES");
1099 Performs a multiclass search
1100 PARAMS( searchBlob, org_unit, format )
1101 where searchBlob is defined like this:
1104 "term":"shakespeare",
1105 "restrict":[{"tag":"245","subfield":"a"}]
1109 "restrict":[{"tag":"100","subfield":"a"}]
1117 my( $self, $client, $searchBlob, $orgid, $format ) = @_;
1119 $logger->debug("Performing MARC search with org => $orgid, " .
1120 "format => $format and search blob " . Dumper($searchBlob) );
1122 my $records = $apputils->simplereq(
1124 'open-ils.storage.metabib.full_rec.multi_search.atomic',
1125 searches => $searchBlob, org_unit => $orgid, format => $format );
1130 if( ref($records) and $records->[0] and
1131 defined($records->[0]->[3])) { $count = $records->[0]->[3];}
1133 for my $r (@$records) { push( @$recs, $r ) if ($r and $r->[0]); }
1135 # records has the form: [ mrid, rank, singleRecord / 0, hitCount ];
1136 return { ids => $recs, count => $count };
1142 __PACKAGE__->register_method(
1143 method => "biblio_search_isbn",
1144 api_name => "open-ils.search.biblio.isbn",
1147 sub biblio_search_isbn {
1148 my( $self, $client, $isbn ) = @_;
1150 $logger->debug("Searching ISBN $isbn");
1152 my $method = $self->method_lookup("open-ils.search.biblio.marc");
1154 my ($records) = $method->run(
1156 restrict => $cat_search_hash->{isbn} } ], 1);
1158 return { count => 0 } unless($records and @$records);
1159 my $size = @$records;
1160 return { count => $size, ids => $records };
1164 __PACKAGE__->register_method(
1165 method => "fetch_mods_by_copy",
1166 api_name => "open-ils.search.biblio.mods_from_copy",
1169 sub fetch_mods_by_copy {
1170 my( $self, $client, $copyid ) = @_;
1171 my ($record, $evt) = $apputils->fetch_record_by_copy( $copyid );
1172 return $evt if $evt;
1173 return $apputils->record_to_mvr($record);
1180 # -------------------------------------------------------------------------------------
1182 __PACKAGE__->register_method(
1183 method => "cn_browse",
1184 api_name => "open-ils.search.callnumber.browse.target",
1185 notes => "Starts a callnumber browse"
1188 __PACKAGE__->register_method(
1189 method => "cn_browse",
1190 api_name => "open-ils.search.callnumber.browse.page_up",
1191 notes => "Returns the previous page of callnumbers",
1194 __PACKAGE__->register_method(
1195 method => "cn_browse",
1196 api_name => "open-ils.search.callnumber.browse.page_down",
1197 notes => "Returns the next page of callnumbers",
1201 # RETURNS array of arrays like so: label, owning_lib, record, id
1203 my( $self, $client, @params ) = @_;
1206 $method = 'open-ils.storage.asset.call_number.browse.target.atomic'
1207 if( $self->api_name =~ /target/ );
1208 $method = 'open-ils.storage.asset.call_number.browse.page_up.atomic'
1209 if( $self->api_name =~ /page_up/ );
1210 $method = 'open-ils.storage.asset.call_number.browse.page_down.atomic'
1211 if( $self->api_name =~ /page_down/ );
1213 return $apputils->simplereq( 'open-ils.storage', $method, @params );
1215 # -------------------------------------------------------------------------------------