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" },
249 { tag => '022', subfield => 'a' },
255 __PACKAGE__->register_method(
256 method => "biblio_search_tcn",
257 api_name => "open-ils.search.biblio.tcn",
259 note => "Retrieve a record by TCN",
262 sub biblio_search_tcn {
264 my( $self, $client, $tcn ) = @_;
266 $tcn =~ s/.*?(\w+)\s*$/$1/o;
267 warn "Searching TCN $tcn\n";
269 my $session = OpenSRF::AppSession->create( "open-ils.storage" );
270 my $request = $session->request(
271 "open-ils.storage.direct.biblio.record_entry.search.tcn_value.atomic", $tcn );
272 my $record_entry = $request->gather(1);
275 for my $record (@$record_entry) {
276 push @ids, $record->id;
279 $session->disconnect();
281 warn "received ID's for tcn search @ids\n";
284 return { count => $size, ids => \@ids };
289 # --------------------------------------------------------------------------------
296 # --------------------------------------------------------------------------------
298 __PACKAGE__->register_method(
299 method => "biblio_barcode_to_copy",
300 api_name => "open-ils.search.asset.copy.find_by_barcode",
303 # turns a barcode into a copy object
304 sub biblio_barcode_to_copy {
305 my( $self, $client, $barcode ) = @_;
307 throw OpenSRF::EX::InvalidArg
308 ("search.biblio.barcode needs a barcode to search")
309 unless defined $barcode;
311 warn "copy search for barcode $barcode\n";
312 my $record = OpenILS::Application::AppUtils->simple_scalar_request(
314 "open-ils.storage.direct.asset.copy.search.barcode.atomic",
317 return undef unless($record);
322 __PACKAGE__->register_method(
323 method => "biblio_id_to_copy",
324 api_name => "open-ils.search.asset.copy.batch.retrieve",
327 # turns a barcode into a copy object
328 sub biblio_id_to_copy {
329 my( $self, $client, $ids ) = @_;
331 throw OpenSRF::EX::InvalidArg
332 ("search.biblio.batch.retrieve needs a id to search")
335 warn "copy search for ids @$ids\n";
336 my $record = OpenILS::Application::AppUtils->simple_scalar_request(
338 "open-ils.storage.direct.asset.copy.batch.retrieve.atomic",
346 __PACKAGE__->register_method(
347 method => "fleshed_copy_retrieve_batch",
348 api_name => "open-ils.search.asset.copy.fleshed.batch.retrieve",
351 sub fleshed_copy_retrieve_batch {
352 my( $self, $client, $ids ) = @_;
354 throw OpenSRF::EX::InvalidArg
355 ("search.biblio.batch.retrieve needs a id to search")
358 warn "fleshed copy search for id @$ids\n";
359 my $copy = OpenILS::Application::AppUtils->simple_scalar_request(
361 "open-ils.storage.fleshed.asset.copy.batch.retrieve.atomic",
367 __PACKAGE__->register_method(
368 method => "fleshed_copy_retrieve",
369 api_name => "open-ils.search.asset.copy.fleshed.retrieve",
372 sub fleshed_copy_retrieve {
373 my( $self, $client, $id ) = @_;
375 return undef unless defined $id;
376 warn "copy retrieve for id $id\n";
377 return OpenILS::Application::AppUtils->simple_scalar_request(
379 "open-ils.storage.fleshed.asset.copy.retrieve",
385 __PACKAGE__->register_method(
386 method => "biblio_barcode_to_title",
387 api_name => "open-ils.search.biblio.find_by_barcode",
390 sub biblio_barcode_to_title {
391 my( $self, $client, $barcode ) = @_;
394 throw OpenSRF::EX::ERROR
395 ("Not enough args to find_by_barcode");
398 my $title = $apputils->simple_scalar_request(
400 "open-ils.storage.biblio.record_entry.retrieve_by_barcode",
404 return { ids => [ $title->id ], count => 1 };
406 return { count => 0 };
412 __PACKAGE__->register_method(
413 method => "biblio_copy_to_mods",
414 api_name => "open-ils.search.biblio.copy.mods.retrieve",
417 # takes a copy object and returns it fleshed mods object
418 sub biblio_copy_to_mods {
419 my( $self, $client, $copy ) = @_;
421 throw OpenSRF::EX::InvalidArgs
422 ("copy.mods.retrieve needs a copy") unless( $copy );
424 new Fieldmapper::asset::copy($copy);
426 my $volume = OpenILS::Application::AppUtils->simple_scalar_request(
428 "open-ils.storage.direct.asset.call_number.retrieve",
429 $copy->call_number() );
431 my $mods = _records_to_mods($volume->record());
432 $mods = shift @$mods;
433 $volume->copies([$copy]);
434 push @{$mods->call_numbers()}, $volume;
440 sub barcode_to_mods {
445 # --------------------------------------------------------------------------------
450 __PACKAGE__->register_method(
451 method => "cat_biblio_search_class",
452 api_name => "open-ils.search.cat.biblio.class",
456 sub cat_biblio_search_class {
458 my( $self, $client, $org_id, $class, $sort, $string ) = @_;
460 throw OpenSRF::EX::InvalidArg
461 ("Not enough args to open-ils.search.cat.biblio.class")
462 unless( defined($org_id) and $class and $sort and $string );
467 my $method = $self->method_lookup("open-ils.search.biblio.marc");
469 throw OpenSRF::EX::PANIC
470 ("Can't lookup method 'open-ils.search.biblio.marc'");
473 my ($records) = $method->run( $cat_search_hash->{$class}, $string );
476 for my $i (@$records) { push @ids, $i->[0]; }
478 my $mods_list = _records_to_mods( @ids );
479 return undef unless (ref($mods_list) eq "ARRAY");
481 # ---------------------------------------------------------------
482 # append copy count information to the mods objects
483 my $session = OpenSRF::AppSession->create("open-ils.storage");
485 my $request = $session->request(
486 "open-ils.storage.direct.biblio.record_copy_count.batch", $org_id, @ids );
490 warn "receiving copy counts for doc $id\n";
492 my $response = $request->recv();
493 next unless $response;
495 if( $response and UNIVERSAL::isa($response, "Error")) {
496 throw $response ($response->stringify);
499 my $count = $response->content;
500 my $mods_obj = undef;
501 for my $m (@$mods_list) {
502 $mods_obj = $m if ($m->doc_id() == $id)
505 $mods_obj->copy_count($count);
508 $client->respond( $mods_obj );
514 $session->disconnect();
516 # ---------------------------------------------------------------
526 __PACKAGE__->register_method(
527 method => "biblio_search_class_count",
528 api_name => "open-ils.search.biblio.class.count",
531 __PACKAGE__->register_method(
532 method => "biblio_search_class_count",
533 api_name => "open-ils.search.biblio.class.count.staff",
536 sub biblio_search_class_count {
538 my( $self, $client, $class, $string, $org_id, $org_type, $format ) = @_;
540 warn "org: $org_id : depth: $org_type\n";
542 $org_id = "1" unless defined($org_id); # xxx
543 $org_type = 0 unless defined($org_type);
545 warn "Searching biblio.class.id\n" .
547 "org_id: $org_id\n" .
548 "depth: $org_type\n" .
551 if( !defined($org_id) or !$class or !$string ) {
552 warn "not enbough args to metarecord search\n";
553 throw OpenSRF::EX::InvalidArg
554 ("Not enough args to open-ils.search.cat.biblio.class")
559 if( ($class ne "title") and ($class ne "author") and
560 ($class ne "subject") and ($class ne "keyword")
561 and ($class ne "series" )) {
562 warn "Invalid search class: $class\n";
563 throw OpenSRF::EX::InvalidArg ("Not a valid search class: $class")
566 # grab the mr id's from storage
568 my $method = "open-ils.storage.cachable.metabib.$class.search_fts.metarecord_count";
569 if($self->api_name =~ /staff/) {
570 $method = "$method.staff";
571 $method =~ s/\.cachable//o;
573 warn "Performing count method $method\n";
574 warn "API name " . $self->api_name() . "\n";
576 my $session = OpenSRF::AppSession->create('open-ils.storage');
578 my $request = $session->request( $method,
581 cache_page_size => 1,
585 my $count = $request->gather(1);
586 warn "Received count $count\n";
592 __PACKAGE__->register_method(
593 method => "biblio_search_class",
594 api_name => "open-ils.search.biblio.class",
597 __PACKAGE__->register_method(
598 method => "biblio_search_class",
599 api_name => "open-ils.search.biblio.class.full",
602 __PACKAGE__->register_method(
603 method => "biblio_search_class",
604 api_name => "open-ils.search.biblio.class.full.staff",
607 __PACKAGE__->register_method(
608 method => "biblio_search_class",
609 api_name => "open-ils.search.biblio.class.staff",
612 sub biblio_search_class {
614 my( $self, $client, $class, $string,
615 $org_id, $org_type, $limit, $offset, $format ) = @_;
617 warn "org: $org_id : depth: $org_type : limit: $limit : offset: $offset\n";
620 $offset = 0 unless (defined($offset) and $offset > 0);
621 $limit = 100 unless (defined($limit) and $limit > 0);
622 $org_id = "1" unless (defined($org_id)); # xxx
623 $org_type = 0 unless (defined($org_type));
625 warn "Searching biblio.class.id\n" .
627 "\noffset: $offset\n" .
629 "org_id: $org_id\n" .
630 "depth: $org_type\n" .
633 warn "Search filtering string " . time() . "\n";
634 $string = OpenILS::Application::Search->filter_search($string);
635 if(!$string) { return undef; }
637 if( !defined($org_id) or !$class or !$string ) {
638 warn "not enbough args to metarecord search\n";
639 throw OpenSRF::EX::InvalidArg
640 ("Not enough args to open-ils.search.biblio.class")
645 if( ($class ne "title") and ($class ne "author") and
646 ($class ne "subject") and ($class ne "keyword")
647 and ($class ne "series") ) {
648 warn "Invalid search class: $class\n";
649 throw OpenSRF::EX::InvalidArg ("Not a valid search class: $class")
652 #my $method = "open-ils.storage.cachable.metabib.$class.post_filter.search_fts.metarecord.atomic";
653 my $method = "open-ils.storage.metabib.$class.post_filter.search_fts.metarecord.atomic";
655 if($self->api_name =~ /staff/) {
656 $method =~ s/atomic/staff\.atomic/og;
657 $method =~ s/\.cachable//o;
660 if($self->api_name =~ /full/) {
661 $method =~ s/\.cachable//o; #XXX testing..
664 warn "Performing search method $method\n";
665 warn "MR search method is $method\n";
667 my $session = OpenSRF::AppSession->create('open-ils.storage');
669 warn "Search making request " . time() . "\n";
670 my $request = $session->request(
678 cache_page_size => 200,
681 my $records = $request->gather(1);
682 if(!$records) {return { ids => [] }};
686 warn "Received " . scalar(@$records) . " id's from class search\n";
688 # for my $i (@$records) { if(defined($i)) { push @all_ids, $i; } }
689 # my @ids = @all_ids;
690 # @ids = grep { defined($_->[0]) } @ids;
693 $session->disconnect();
696 if( $records->[0] && defined($records->[0]->[3])) { $count = $records->[0]->[3];}
698 for my $r (@$records) { push( @$recs, $r ) if ($r and $r->[0]); }
700 # records has the form: [ mrid, rank, singleRecord / 0, hitCount ];
701 return { ids => $recs, count => $count };
708 __PACKAGE__->register_method(
709 method => "biblio_mrid_to_modsbatch_batch",
710 api_name => "open-ils.search.biblio.metarecord.mods_slim.batch.retrieve");
712 sub biblio_mrid_to_modsbatch_batch {
713 my( $self, $client, $mrids) = @_;
714 warn "Performing mrid_to_modsbatch_batch...";
716 my $method = $self->method_lookup("open-ils.search.biblio.metarecord.mods_slim.retrieve");
718 warn "Grabbing mods for " . Dumper($mrids) . "\n";
720 for my $id (@$mrids) {
721 next unless defined $id;
722 #push @mods, biblio_mrid_to_modsbatch($self, $client, $id);
723 my ($m) = $method->run($id);
730 __PACKAGE__->register_method(
731 method => "biblio_mrid_to_modsbatch",
732 api_name => "open-ils.search.biblio.metarecord.mods_slim.retrieve",
733 notes => <<" NOTES");
734 Returns the mvr associated with a given metarecod. If none exists,
738 __PACKAGE__->register_method(
739 method => "biblio_mrid_to_modsbatch",
740 api_name => "open-ils.search.biblio.metarecord.mods_slim.retrieve.staff",
741 notes => <<" NOTES");
742 Returns the mvr associated with a given metarecod. If none exists,
746 sub biblio_mrid_to_modsbatch {
747 my( $self, $client, $mrid ) = @_;
749 warn "Grabbing mvr for $mrid\n";
751 my $mr = _grab_metarecord($mrid);
752 return undef unless $mr;
754 if( my $m = $self->biblio_mrid_check_mvr($client, $mr)) {
758 return $self->biblio_mrid_make_modsbatch( $client, $mr );
761 # converts a metarecord to an mvr
764 my $perl = JSON->JSON2perl($mr->mods());
765 return Fieldmapper::metabib::virtual_record->new($perl);
768 # checks to see if a metarecord has mods, if so returns true;
770 __PACKAGE__->register_method(
771 method => "biblio_mrid_check_mvr",
772 api_name => "open-ils.search.biblio.metarecord.mods_slim.check",
773 notes => <<" NOTES");
774 Takes a metarecord ID or a metarecord object and returns true
775 if the metarecord already has an mvr associated with it.
778 sub biblio_mrid_check_mvr {
779 my( $self, $client, $mrid ) = @_;
782 if(ref($mrid)) { $mr = $mrid; }
783 else { $mr = _grab_metarecord($mrid); }
785 warn "Checking mvr for mr " . $mr->id . "\n";
787 return _mr_to_mvr($mr) if $mr->mods();
791 sub _grab_metarecord {
794 warn "Grabbing MR $mrid\n";
796 my $mr = OpenILS::Application::AppUtils->simple_scalar_request(
798 "open-ils.storage.direct.metabib.metarecord.retrieve", $mrid );
801 throw OpenSRF::EX::ERROR
802 ("No metarecord exists with the given id: $mrid");
808 __PACKAGE__->register_method(
809 method => "biblio_mrid_make_modsbatch",
810 api_name => "open-ils.search.biblio.metarecord.mods_slim.create",
811 notes => <<" NOTES");
812 Takes either a metarecord ID or a metarecord object.
813 Forces the creations of an mvr for the given metarecord.
814 The created mvr is returned.
817 sub biblio_mrid_make_modsbatch {
819 my( $self, $client, $mrid ) = @_;
822 if(ref($mrid)) { $mr = $mrid; }
823 else { $mr = _grab_metarecord($mrid); }
826 warn "Forcing mvr creation for mr " . $mr->id . "\n";
827 my $master_id = $mr->master_record;
829 my $session = OpenSRF::AppSession->create("open-ils.storage");
831 # grab the records attached to this metarecod
832 warn "Creating mods batch for metarecord $mrid\n";
833 my $meth = "open-ils.search.biblio.metarecord_to_records.staff";
834 $meth = $self->method_lookup($meth);
835 my ($id_hash) = $meth->run($mrid);
836 my @ids = @{$id_hash->{ids}};
837 if(@ids < 1) { return undef; }
839 warn "Master ID is $master_id\n";
840 # grab the master record to start the mods batch
842 $meth = "open-ils.storage.direct.biblio.record_entry.retrieve";
844 my $record = $session->request(
845 "open-ils.storage.direct.biblio.record_entry.retrieve", $master_id );
846 $record = $record->gather(1);
848 #my $record = OpenILS::Application::AppUtils->simple_scalar_request( "open-ils.storage",
851 warn "No record returned with id $master_id";
852 throw OpenSRF::EX::ERROR
855 my $u = OpenILS::Utils::ModsParser->new();
857 $u->start_mods_batch( $record->marc );
858 my $main_doc_id = $record->id();
860 @ids = grep { $_ ne $master_id } @ids;
862 # now we have to collect all of the marc objects and push them into a mods batch
863 my $request = $session->request(
864 "open-ils.storage.direct.biblio.record_entry.batch.retrieve", @ids );
866 while( my $response = $request->recv() ) {
868 next unless $response;
869 if(UNIVERSAL::isa( $response,"OpenSRF::EX")) {
870 throw $response ($response->stringify);
873 my $content = $response->content;
876 $u->push_mods_batch( $content->marc );
880 my $mods = $u->finish_mods_batch();
881 $mods->doc_id($mrid);
884 $client->respond_complete($mods);
886 my $mods_string = JSON->perl2JSON($mods->decast);
888 $mr->mods($mods_string);
890 my $req = $session->request(
891 "open-ils.storage.direct.metabib.metarecord.update", $mr );
896 $session->disconnect();
903 # converts a mr id into a list of record ids
905 __PACKAGE__->register_method(
906 method => "biblio_mrid_to_record_ids",
907 api_name => "open-ils.search.biblio.metarecord_to_records",
910 __PACKAGE__->register_method(
911 method => "biblio_mrid_to_record_ids",
912 api_name => "open-ils.search.biblio.metarecord_to_records.staff",
915 sub biblio_mrid_to_record_ids {
916 my( $self, $client, $mrid, $format ) = @_;
918 throw OpenSRF::EX::InvalidArg
919 ("search.biblio.metarecord_to_record_ids requires mr id")
920 unless defined( $mrid );
922 warn "Searching for record for MR $mrid and format $format\n";
924 my $method = "open-ils.storage.ordered.metabib.metarecord.records.atomic";
925 if($self and $self->api_name =~ /staff/) { $method =~ s/atomic/staff\.atomic/; }
926 warn "Performing record retrieval with method $method\n";
929 my $mrmaps = OpenILS::Application::AppUtils->simple_scalar_request(
930 "open-ils.storage", $method, $mrid, $format );
937 return { count => $size, ids => $mrmaps };
942 __PACKAGE__->register_method(
943 method => "biblio_record_to_marc_html",
944 api_name => "open-ils.search.biblio.record.html" );
946 my $parser = XML::LibXML->new();
947 my $xslt = XML::LibXSLT->new();
950 my $settings_client = OpenSRF::Utils::SettingsClient->new();
951 sub biblio_record_to_marc_html {
952 my( $self, $client, $recordid ) = @_;
955 my $dir = $settings_client->config_value( "dirs", "xsl" );
956 my $xsl = $settings_client->config_value(
957 "apps", "open-ils.search", "app_settings", "marc_html_xsl" );
959 $xsl = $parser->parse_file("$dir/$xsl");
960 $marc_sheet = $xslt->parse_stylesheet( $xsl );
964 my $record = $apputils->simple_scalar_request(
966 "open-ils.storage.direct.biblio.record_entry.retrieve",
969 my $xmldoc = $parser->parse_string($record->marc);
970 my $html = $marc_sheet->transform($xmldoc);
971 $html = $html->toString();
978 __PACKAGE__->register_method(
979 method => "retrieve_all_copy_locations",
980 api_name => "open-ils.search.config.copy_location.retrieve.all" );
982 my $shelving_locations;
983 sub retrieve_all_copy_locations {
984 my( $self, $client ) = @_;
985 if(!$shelving_locations) {
986 $shelving_locations = $apputils->simple_scalar_request(
988 "open-ils.storage.direct.asset.copy_location.retrieve.all.atomic");
990 return $shelving_locations;
995 __PACKAGE__->register_method(
996 method => "retrieve_all_copy_statuses",
997 api_name => "open-ils.search.config.copy_status.retrieve.all" );
1000 sub retrieve_all_copy_statuses {
1001 my( $self, $client ) = @_;
1002 if(!$copy_statuses) {
1003 $copy_statuses = $apputils->simple_scalar_request(
1005 "open-ils.storage.direct.config.copy_status.retrieve.all.atomic" );
1007 return $copy_statuses;
1011 __PACKAGE__->register_method(
1012 method => "copy_counts_per_org",
1013 api_name => "open-ils.search.biblio.copy_counts.retrieve");
1015 __PACKAGE__->register_method(
1016 method => "copy_counts_per_org",
1017 api_name => "open-ils.search.biblio.copy_counts.retrieve.staff");
1019 sub copy_counts_per_org {
1020 my( $self, $client, $record_id ) = @_;
1022 warn "Retreiveing copy copy counts for record $record_id and method " . $self->api_name . "\n";
1024 my $method = "open-ils.storage.biblio.record_entry.global_copy_count.atomic";
1025 if($self->api_name =~ /staff/) { $method =~ s/atomic/staff\.atomic/; }
1027 my $counts = $apputils->simple_scalar_request(
1028 "open-ils.storage", $method, $record_id );
1030 $counts = [ sort {$a->[0] <=> $b->[0]} @$counts ];
1035 __PACKAGE__->register_method(
1036 method => "copy_count_summary",
1037 api_name => "open-ils.search.biblio.copy_counts.summary.retrieve",
1038 notes => <<" NOTES");
1039 returns an array of these:
1040 [ org_id, callnumber_label, <status1_count>, <status2_cout>,...]
1041 where statusx is a copy status name. the statuses are sorted
1045 sub copy_count_summary {
1046 my( $self, $client, $rid ) = @_;
1047 my $method = "open-ils.storage.biblio.record_entry.status_copy_count.atomic";
1048 return $apputils->simple_scalar_request( "open-ils.storage", $method, $rid );
1052 __PACKAGE__->register_method(
1053 method => "multiclass_search",
1054 api_name => "open-ils.search.biblio.multiclass",
1055 notes => <<" NOTES");
1056 Performs a multiclass search
1057 PARAMS( searchBlob, org_unit, format, limit )
1058 where searchBlob is defined like this:
1060 "title" : { "term" : "water" },
1061 "author" : { "term" : "smith" },
1066 __PACKAGE__->register_method(
1067 method => "multiclass_search",
1068 api_name => "open-ils.search.biblio.multiclass.staff",
1069 notes => "see open-ils.search.biblio.multiclass" );
1071 sub multiclass_search {
1072 my( $self, $client, $searchBlob, $orgid, $format, $limit ) = @_;
1074 $logger->debug("Performing multiclass search with org => $orgid, " .
1075 "format => $format, limit => $limit, and search blob " . Dumper($searchBlob));
1077 my $meth = 'open-ils.storage.metabib.post_filter.multiclass.search_fts.metarecord.atomic';
1078 if($self->api_name =~ /staff/) { $meth =~ s/metarecord\.atomic/metarecord.staff.atomic/; }
1081 my $records = $apputils->simplereq(
1082 'open-ils.storage', $meth,
1083 org_unit => $orgid, searches => $searchBlob, format => $format, limit => $limit );
1088 if( ref($records) and $records->[0] and
1089 defined($records->[0]->[3])) { $count = $records->[0]->[3];}
1091 for my $r (@$records) { push( @$recs, $r ) if ($r and $r->[0]); }
1093 # records has the form: [ mrid, rank, singleRecord / 0, hitCount ];
1094 return { ids => $recs, count => $count };
1099 __PACKAGE__->register_method(
1100 method => "marc_search",
1101 api_name => "open-ils.search.biblio.marc",
1102 notes => <<" NOTES");
1103 Performs a multiclass search
1104 PARAMS( searchBlob, org_unit, format )
1105 where searchBlob is defined like this:
1108 "term":"shakespeare",
1109 "restrict":[{"tag":"245","subfield":"a"}]
1113 "restrict":[{"tag":"100","subfield":"a"}]
1121 my( $self, $client, $searchBlob, $orgid, $format ) = @_;
1123 $logger->debug("Performing MARC search with org => $orgid, " .
1124 "format => $format and search blob " . Dumper($searchBlob) );
1126 my $records = $apputils->simplereq(
1128 'open-ils.storage.metabib.full_rec.multi_search.atomic',
1129 searches => $searchBlob, org_unit => $orgid, format => $format );
1134 if( ref($records) and $records->[0] and
1135 defined($records->[0]->[3])) { $count = $records->[0]->[3];}
1137 for my $r (@$records) { push( @$recs, $r ) if ($r and $r->[0]); }
1139 # records has the form: [ mrid, rank, singleRecord / 0, hitCount ];
1140 return { ids => $recs, count => $count };
1146 __PACKAGE__->register_method(
1147 method => "biblio_search_isbn",
1148 api_name => "open-ils.search.biblio.isbn",
1151 sub biblio_search_isbn {
1152 my( $self, $client, $isbn ) = @_;
1154 $logger->debug("Searching ISBN $isbn");
1156 my $method = $self->method_lookup("open-ils.search.biblio.marc");
1158 my ($records) = $method->run(
1160 restrict => $cat_search_hash->{isbn} } ], 1);
1166 __PACKAGE__->register_method(
1167 method => "biblio_search_issn",
1168 api_name => "open-ils.search.biblio.issn",
1171 sub biblio_search_issn {
1172 my( $self, $client, $issn ) = @_;
1174 $logger->debug("Searching ISSN $issn");
1176 my $method = $self->method_lookup("open-ils.search.biblio.marc");
1178 my ($records) = $method->run(
1180 restrict => $cat_search_hash->{issn} } ], 1);
1188 __PACKAGE__->register_method(
1189 method => "fetch_mods_by_copy",
1190 api_name => "open-ils.search.biblio.mods_from_copy",
1193 sub fetch_mods_by_copy {
1194 my( $self, $client, $copyid ) = @_;
1195 my ($record, $evt) = $apputils->fetch_record_by_copy( $copyid );
1196 return $evt if $evt;
1197 return $apputils->record_to_mvr($record);
1204 # -------------------------------------------------------------------------------------
1206 __PACKAGE__->register_method(
1207 method => "cn_browse",
1208 api_name => "open-ils.search.callnumber.browse.target",
1209 notes => "Starts a callnumber browse"
1212 __PACKAGE__->register_method(
1213 method => "cn_browse",
1214 api_name => "open-ils.search.callnumber.browse.page_up",
1215 notes => "Returns the previous page of callnumbers",
1218 __PACKAGE__->register_method(
1219 method => "cn_browse",
1220 api_name => "open-ils.search.callnumber.browse.page_down",
1221 notes => "Returns the next page of callnumbers",
1225 # RETURNS array of arrays like so: label, owning_lib, record, id
1227 my( $self, $client, @params ) = @_;
1230 $method = 'open-ils.storage.asset.call_number.browse.target.atomic'
1231 if( $self->api_name =~ /target/ );
1232 $method = 'open-ils.storage.asset.call_number.browse.page_up.atomic'
1233 if( $self->api_name =~ /page_up/ );
1234 $method = 'open-ils.storage.asset.call_number.browse.page_down.atomic'
1235 if( $self->api_name =~ /page_down/ );
1237 return $apputils->simplereq( 'open-ils.storage', $method, @params );
1239 # -------------------------------------------------------------------------------------
1241 __PACKAGE__->register_method(
1242 method => "fetch_cn",
1243 api_name => "open-ils.search.callnumber.retrieve",
1244 notes => "retrieves a callnumber based on ID",
1248 my( $self, $client, $id ) = @_;
1249 my( $cn, $evt ) = $apputils->fetch_callnumber( $id );
1250 return $evt if $evt;