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;
13 my $U = "OpenILS::Application::AppUtils";
17 use Time::HiRes qw(time);
18 use OpenSRF::EX qw(:try);
19 use Digest::MD5 qw(md5_hex);
24 $Data::Dumper::Indent = 0;
25 use OpenSRF::Utils::Logger qw/:logger/;
27 my $apputils = "OpenILS::Application::AppUtils";
29 # Houses biblio search utilites
32 __PACKAGE__->register_method(
34 api_name => "open-ils.search.test");
36 sub test { return "test"; }
41 __PACKAGE__->register_method(
42 method => "biblio_search_marc",
43 api_name => "open-ils.search.biblio.marc",
45 note => "Searches biblio information by marc tag",
48 sub biblio_search_marc {
50 my( $self, $client, $search_hash, $string ) = @_;
52 warn "Building biblio marc session\n";
53 my $session = OpenSRF::AppSession->create("open-ils.storage");
56 warn "Sending biblio marc request. String $string\nSearch hash: " . Dumper($search_hash);
57 my $request = $session->request(
58 "open-ils.storage.direct.metabib.full_rec.search_fts.index_vector.atomic",
59 restrict => $search_hash,
61 my $data = $request->gather(1);
66 $session->disconnect();
75 # ---------------------------------------------------------------------------
76 # takes a list of record id's and turns the docs into friendly
77 # mods structures. Creates one MODS structure for each doc id.
78 # ---------------------------------------------------------------------------
79 sub _records_to_mods {
85 my $session = OpenSRF::AppSession->create("open-ils.storage");
86 my $request = $session->request(
87 "open-ils.storage.direct.biblio.record_entry.batch.retrieve", @ids );
89 my $last_content = undef;
91 while( my $response = $request->recv() ) {
94 my $u = OpenILS::Utils::ModsParser->new();
95 $u->start_mods_batch( $last_content->marc );
96 my $mods = $u->finish_mods_batch();
97 $mods->doc_id($last_content->id());
98 $mods->tcn($last_content->tcn_value);
99 warn "Turning doc " . $mods->doc_id() . " into MODS\n";
100 $last_content = undef;
101 push @results, $mods;
104 next unless $response;
106 if($response->isa("OpenSRF::EX")) {
107 throw $response ($response->stringify);
110 $last_content = $response->content;
114 if( $last_content ) {
115 my $u = OpenILS::Utils::ModsParser->new();
116 $u->start_mods_batch( $last_content->marc );
117 my $mods = $u->finish_mods_batch();
118 $mods->doc_id($last_content->id());
119 $mods->tcn($last_content->tcn_value);
120 push @results, $mods;
125 $session->disconnect();
131 __PACKAGE__->register_method(
132 method => "record_id_to_mods",
133 api_name => "open-ils.search.biblio.record.mods.retrieve",
135 note => "Provide ID, we provide the mods"
138 # converts a record into a mods object with copy counts attached
139 sub record_id_to_mods {
141 my( $self, $client, $org_id, $id ) = @_;
143 my $mods_list = _records_to_mods( $id );
144 my $mods_obj = $mods_list->[0];
145 my $cmethod = $self->method_lookup(
146 "open-ils.search.biblio.record.copy_count");
147 my ($count) = $cmethod->run($org_id, $id);
148 $mods_obj->copy_count($count);
155 __PACKAGE__->register_method(
156 method => "record_id_to_mods_slim",
157 api_name => "open-ils.search.biblio.record.mods_slim.retrieve",
159 note => "Provide ID, we provide the mods"
162 # converts a record into a mods object with NO copy counts attached
163 sub record_id_to_mods_slim {
164 my( $self, $client, $id ) = @_;
165 return undef unless defined $id;
167 if(ref($id) and ref($id) == 'ARRAY') {
168 return _records_to_mods( @$id );
170 my $mods_list = _records_to_mods( $id );
171 my $mods_obj = $mods_list->[0];
176 # Returns the number of copies attached to a record based on org location
177 __PACKAGE__->register_method(
178 method => "record_id_to_copy_count",
179 api_name => "open-ils.search.biblio.record.copy_count",
182 __PACKAGE__->register_method(
183 method => "record_id_to_copy_count",
184 api_name => "open-ils.search.biblio.metarecord.copy_count",
187 __PACKAGE__->register_method(
188 method => "record_id_to_copy_count",
189 api_name => "open-ils.search.biblio.metarecord.copy_count.staff",
191 sub record_id_to_copy_count {
192 my( $self, $client, $org_id, $record_id, $format ) = @_;
194 my $method = "open-ils.storage.biblio.record_entry.copy_count.atomic";
196 if($self->api_name =~ /metarecord/) {
197 $method = "open-ils.storage.metabib.metarecord.copy_count.atomic";
201 if($self->api_name =~ /staff/ ) {
202 $method =~ s/atomic/staff\.atomic/og;
203 warn "Doing staff search $method\n";
207 my $session = OpenSRF::AppSession->create("open-ils.storage");
208 warn "copy_count retrieve $record_id\n";
209 return undef unless(defined $record_id);
211 my $request = $session->request(
212 $method, org_unit => $org_id => $key => $record_id, format => $format );
215 my $count = $request->gather(1);
216 $session->disconnect();
217 return [ sort { $a->{depth} <=> $b->{depth} } @$count ];
222 # used for cat search classes
223 my $cat_search_hash = {
226 { tag => "100", subfield => "a"} ,
227 { tag => "700", subfield => "a"},
231 { tag => "245", subfield => "a"},
232 { tag => "242", subfield => "a"},
233 { tag => "240", subfield => "a"},
234 { tag => "210", subfield => "a"},
238 { tag => "650", subfield => "_" },
242 { tag => "035", subfield => "_" },
246 { tag => "020", subfield => "a" },
250 { tag => '022', subfield => 'a' },
256 __PACKAGE__->register_method(
257 method => "biblio_search_tcn",
258 api_name => "open-ils.search.biblio.tcn",
260 note => "Retrieve a record by TCN",
263 sub biblio_search_tcn {
265 my( $self, $client, $tcn ) = @_;
267 $tcn =~ s/.*?(\w+)\s*$/$1/o;
268 warn "Searching TCN $tcn\n";
270 my $session = OpenSRF::AppSession->create( "open-ils.storage" );
271 my $request = $session->request(
272 "open-ils.storage.direct.biblio.record_entry.search.tcn_value.atomic", $tcn );
273 my $record_entry = $request->gather(1);
276 for my $record (@$record_entry) {
277 push @ids, $record->id;
280 $session->disconnect();
282 warn "received ID's for tcn search @ids\n";
285 return { count => $size, ids => \@ids };
290 # --------------------------------------------------------------------------------
297 # --------------------------------------------------------------------------------
299 __PACKAGE__->register_method(
300 method => "biblio_barcode_to_copy",
301 api_name => "open-ils.search.asset.copy.find_by_barcode",
304 # turns a barcode into a copy object
305 sub biblio_barcode_to_copy {
306 my( $self, $client, $barcode ) = @_;
308 throw OpenSRF::EX::InvalidArg
309 ("search.biblio.barcode needs a barcode to search")
310 unless defined $barcode;
312 warn "copy search for barcode $barcode\n";
313 my $record = OpenILS::Application::AppUtils->simple_scalar_request(
315 "open-ils.storage.direct.asset.copy.search.barcode.atomic",
318 return undef unless($record);
323 __PACKAGE__->register_method(
324 method => "biblio_id_to_copy",
325 api_name => "open-ils.search.asset.copy.batch.retrieve",
328 # turns a barcode into a copy object
329 sub biblio_id_to_copy {
330 my( $self, $client, $ids ) = @_;
332 throw OpenSRF::EX::InvalidArg
333 ("search.biblio.batch.retrieve needs a id to search")
336 warn "copy search for ids @$ids\n";
337 my $record = OpenILS::Application::AppUtils->simple_scalar_request(
339 "open-ils.storage.direct.asset.copy.batch.retrieve.atomic",
347 __PACKAGE__->register_method(
348 method => "copy_retrieve",
349 api_name => "open-ils.search.asset.copy.retrieve",
353 my( $self, $client, $cid ) = @_;
354 my( $copy, $evt ) = $U->fetch_copy($cid);
360 __PACKAGE__->register_method(
361 method => "fleshed_copy_retrieve_batch",
362 api_name => "open-ils.search.asset.copy.fleshed.batch.retrieve",
365 sub fleshed_copy_retrieve_batch {
366 my( $self, $client, $ids ) = @_;
368 throw OpenSRF::EX::InvalidArg
369 ("search.biblio.batch.retrieve needs a id to search")
372 warn "fleshed copy search for id @$ids\n";
373 my $copy = OpenILS::Application::AppUtils->simple_scalar_request(
375 "open-ils.storage.fleshed.asset.copy.batch.retrieve.atomic",
381 __PACKAGE__->register_method(
382 method => "fleshed_copy_retrieve",
383 api_name => "open-ils.search.asset.copy.fleshed.retrieve",
386 sub fleshed_copy_retrieve {
387 my( $self, $client, $id ) = @_;
389 return undef unless defined $id;
390 warn "copy retrieve for id $id\n";
391 return OpenILS::Application::AppUtils->simple_scalar_request(
393 "open-ils.storage.fleshed.asset.copy.retrieve",
399 __PACKAGE__->register_method(
400 method => "biblio_barcode_to_title",
401 api_name => "open-ils.search.biblio.find_by_barcode",
404 sub biblio_barcode_to_title {
405 my( $self, $client, $barcode ) = @_;
408 throw OpenSRF::EX::ERROR
409 ("Not enough args to find_by_barcode");
412 my $title = $apputils->simple_scalar_request(
414 "open-ils.storage.biblio.record_entry.retrieve_by_barcode",
418 return { ids => [ $title->id ], count => 1 };
420 return { count => 0 };
426 __PACKAGE__->register_method(
427 method => "biblio_copy_to_mods",
428 api_name => "open-ils.search.biblio.copy.mods.retrieve",
431 # takes a copy object and returns it fleshed mods object
432 sub biblio_copy_to_mods {
433 my( $self, $client, $copy ) = @_;
435 throw OpenSRF::EX::InvalidArgs
436 ("copy.mods.retrieve needs a copy") unless( $copy );
438 new Fieldmapper::asset::copy($copy);
440 my $volume = OpenILS::Application::AppUtils->simple_scalar_request(
442 "open-ils.storage.direct.asset.call_number.retrieve",
443 $copy->call_number() );
445 my $mods = _records_to_mods($volume->record());
446 $mods = shift @$mods;
447 $volume->copies([$copy]);
448 push @{$mods->call_numbers()}, $volume;
454 sub barcode_to_mods {
459 # --------------------------------------------------------------------------------
464 __PACKAGE__->register_method(
465 method => "cat_biblio_search_class",
466 api_name => "open-ils.search.cat.biblio.class",
470 sub cat_biblio_search_class {
472 my( $self, $client, $org_id, $class, $sort, $string ) = @_;
474 throw OpenSRF::EX::InvalidArg
475 ("Not enough args to open-ils.search.cat.biblio.class")
476 unless( defined($org_id) and $class and $sort and $string );
481 my $method = $self->method_lookup("open-ils.search.biblio.marc");
483 throw OpenSRF::EX::PANIC
484 ("Can't lookup method 'open-ils.search.biblio.marc'");
487 my ($records) = $method->run( $cat_search_hash->{$class}, $string );
490 for my $i (@$records) { push @ids, $i->[0]; }
492 my $mods_list = _records_to_mods( @ids );
493 return undef unless (ref($mods_list) eq "ARRAY");
495 # ---------------------------------------------------------------
496 # append copy count information to the mods objects
497 my $session = OpenSRF::AppSession->create("open-ils.storage");
499 my $request = $session->request(
500 "open-ils.storage.direct.biblio.record_copy_count.batch", $org_id, @ids );
504 warn "receiving copy counts for doc $id\n";
506 my $response = $request->recv();
507 next unless $response;
509 if( $response and UNIVERSAL::isa($response, "Error")) {
510 throw $response ($response->stringify);
513 my $count = $response->content;
514 my $mods_obj = undef;
515 for my $m (@$mods_list) {
516 $mods_obj = $m if ($m->doc_id() == $id)
519 $mods_obj->copy_count($count);
522 $client->respond( $mods_obj );
528 $session->disconnect();
530 # ---------------------------------------------------------------
540 __PACKAGE__->register_method(
541 method => "biblio_search_class_count",
542 api_name => "open-ils.search.biblio.class.count",
545 __PACKAGE__->register_method(
546 method => "biblio_search_class_count",
547 api_name => "open-ils.search.biblio.class.count.staff",
550 sub biblio_search_class_count {
552 my( $self, $client, $class, $string, $org_id, $org_type, $format ) = @_;
554 warn "org: $org_id : depth: $org_type\n";
556 $org_id = "1" unless defined($org_id); # xxx
557 $org_type = 0 unless defined($org_type);
559 warn "Searching biblio.class.id\n" .
561 "org_id: $org_id\n" .
562 "depth: $org_type\n" .
565 if( !defined($org_id) or !$class or !$string ) {
566 warn "not enbough args to metarecord search\n";
567 throw OpenSRF::EX::InvalidArg
568 ("Not enough args to open-ils.search.cat.biblio.class")
573 if( ($class ne "title") and ($class ne "author") and
574 ($class ne "subject") and ($class ne "keyword")
575 and ($class ne "series" )) {
576 warn "Invalid search class: $class\n";
577 throw OpenSRF::EX::InvalidArg ("Not a valid search class: $class")
580 # grab the mr id's from storage
582 my $method = "open-ils.storage.cachable.metabib.$class.search_fts.metarecord_count";
583 if($self->api_name =~ /staff/) {
584 $method = "$method.staff";
585 $method =~ s/\.cachable//o;
587 warn "Performing count method $method\n";
588 warn "API name " . $self->api_name() . "\n";
590 my $session = OpenSRF::AppSession->create('open-ils.storage');
592 my $request = $session->request( $method,
595 cache_page_size => 1,
599 my $count = $request->gather(1);
600 warn "Received count $count\n";
606 __PACKAGE__->register_method(
607 method => "biblio_search_class",
608 api_name => "open-ils.search.biblio.class",
611 __PACKAGE__->register_method(
612 method => "biblio_search_class",
613 api_name => "open-ils.search.biblio.class.full",
616 __PACKAGE__->register_method(
617 method => "biblio_search_class",
618 api_name => "open-ils.search.biblio.class.full.staff",
621 __PACKAGE__->register_method(
622 method => "biblio_search_class",
623 api_name => "open-ils.search.biblio.class.staff",
626 sub biblio_search_class {
628 my( $self, $client, $class, $string,
629 $org_id, $org_type, $limit, $offset, $format ) = @_;
631 warn "org: $org_id : depth: $org_type : limit: $limit : offset: $offset\n";
634 $offset = 0 unless (defined($offset) and $offset > 0);
635 $limit = 100 unless (defined($limit) and $limit > 0);
636 $org_id = "1" unless (defined($org_id)); # xxx
637 $org_type = 0 unless (defined($org_type));
639 warn "Searching biblio.class.id\n" .
641 "\noffset: $offset\n" .
643 "org_id: $org_id\n" .
644 "depth: $org_type\n" .
647 warn "Search filtering string " . time() . "\n";
648 $string = OpenILS::Application::Search->filter_search($string);
649 if(!$string) { return undef; }
651 if( !defined($org_id) or !$class or !$string ) {
652 warn "not enbough args to metarecord search\n";
653 throw OpenSRF::EX::InvalidArg
654 ("Not enough args to open-ils.search.biblio.class")
659 if( ($class ne "title") and ($class ne "author") and
660 ($class ne "subject") and ($class ne "keyword")
661 and ($class ne "series") ) {
662 warn "Invalid search class: $class\n";
663 throw OpenSRF::EX::InvalidArg ("Not a valid search class: $class")
666 #my $method = "open-ils.storage.cachable.metabib.$class.post_filter.search_fts.metarecord.atomic";
667 my $method = "open-ils.storage.metabib.$class.post_filter.search_fts.metarecord.atomic";
669 if($self->api_name =~ /staff/) {
670 $method =~ s/atomic/staff\.atomic/og;
671 $method =~ s/\.cachable//o;
674 if($self->api_name =~ /full/) {
675 $method =~ s/\.cachable//o; #XXX testing..
678 warn "Performing search method $method\n";
679 warn "MR search method is $method\n";
681 my $session = OpenSRF::AppSession->create('open-ils.storage');
683 warn "Search making request " . time() . "\n";
684 my $request = $session->request(
692 cache_page_size => 200,
695 my $records = $request->gather(1);
696 if(!$records) {return { ids => [] }};
700 warn "Received " . scalar(@$records) . " id's from class search\n";
702 # for my $i (@$records) { if(defined($i)) { push @all_ids, $i; } }
703 # my @ids = @all_ids;
704 # @ids = grep { defined($_->[0]) } @ids;
707 $session->disconnect();
710 if( $records->[0] && defined($records->[0]->[3])) { $count = $records->[0]->[3];}
712 for my $r (@$records) { push( @$recs, $r ) if ($r and $r->[0]); }
714 # records has the form: [ mrid, rank, singleRecord / 0, hitCount ];
715 return { ids => $recs, count => $count };
722 __PACKAGE__->register_method(
723 method => "biblio_mrid_to_modsbatch_batch",
724 api_name => "open-ils.search.biblio.metarecord.mods_slim.batch.retrieve");
726 sub biblio_mrid_to_modsbatch_batch {
727 my( $self, $client, $mrids) = @_;
728 warn "Performing mrid_to_modsbatch_batch...";
730 my $method = $self->method_lookup("open-ils.search.biblio.metarecord.mods_slim.retrieve");
732 warn "Grabbing mods for " . Dumper($mrids) . "\n";
734 for my $id (@$mrids) {
735 next unless defined $id;
736 #push @mods, biblio_mrid_to_modsbatch($self, $client, $id);
737 my ($m) = $method->run($id);
744 __PACKAGE__->register_method(
745 method => "biblio_mrid_to_modsbatch",
746 api_name => "open-ils.search.biblio.metarecord.mods_slim.retrieve",
747 notes => <<" NOTES");
748 Returns the mvr associated with a given metarecod. If none exists,
752 __PACKAGE__->register_method(
753 method => "biblio_mrid_to_modsbatch",
754 api_name => "open-ils.search.biblio.metarecord.mods_slim.retrieve.staff",
755 notes => <<" NOTES");
756 Returns the mvr associated with a given metarecod. If none exists,
760 sub biblio_mrid_to_modsbatch {
761 my( $self, $client, $mrid ) = @_;
763 warn "Grabbing mvr for $mrid\n";
765 my $mr = _grab_metarecord($mrid);
766 return undef unless $mr;
768 if( my $m = $self->biblio_mrid_check_mvr($client, $mr)) {
772 return $self->biblio_mrid_make_modsbatch( $client, $mr );
775 # converts a metarecord to an mvr
778 my $perl = JSON->JSON2perl($mr->mods());
779 return Fieldmapper::metabib::virtual_record->new($perl);
782 # checks to see if a metarecord has mods, if so returns true;
784 __PACKAGE__->register_method(
785 method => "biblio_mrid_check_mvr",
786 api_name => "open-ils.search.biblio.metarecord.mods_slim.check",
787 notes => <<" NOTES");
788 Takes a metarecord ID or a metarecord object and returns true
789 if the metarecord already has an mvr associated with it.
792 sub biblio_mrid_check_mvr {
793 my( $self, $client, $mrid ) = @_;
796 if(ref($mrid)) { $mr = $mrid; }
797 else { $mr = _grab_metarecord($mrid); }
799 warn "Checking mvr for mr " . $mr->id . "\n";
801 return _mr_to_mvr($mr) if $mr->mods();
805 sub _grab_metarecord {
808 warn "Grabbing MR $mrid\n";
810 my $mr = OpenILS::Application::AppUtils->simple_scalar_request(
812 "open-ils.storage.direct.metabib.metarecord.retrieve", $mrid );
815 throw OpenSRF::EX::ERROR
816 ("No metarecord exists with the given id: $mrid");
822 __PACKAGE__->register_method(
823 method => "biblio_mrid_make_modsbatch",
824 api_name => "open-ils.search.biblio.metarecord.mods_slim.create",
825 notes => <<" NOTES");
826 Takes either a metarecord ID or a metarecord object.
827 Forces the creations of an mvr for the given metarecord.
828 The created mvr is returned.
831 sub biblio_mrid_make_modsbatch {
833 my( $self, $client, $mrid ) = @_;
836 if(ref($mrid)) { $mr = $mrid; }
837 else { $mr = _grab_metarecord($mrid); }
840 warn "Forcing mvr creation for mr " . $mr->id . "\n";
841 my $master_id = $mr->master_record;
843 my $session = OpenSRF::AppSession->create("open-ils.storage");
845 # grab the records attached to this metarecod
846 warn "Creating mods batch for metarecord $mrid\n";
847 my $meth = "open-ils.search.biblio.metarecord_to_records.staff";
848 $meth = $self->method_lookup($meth);
849 my ($id_hash) = $meth->run($mrid);
850 my @ids = @{$id_hash->{ids}};
851 if(@ids < 1) { return undef; }
853 warn "Master ID is $master_id\n";
854 # grab the master record to start the mods batch
856 $meth = "open-ils.storage.direct.biblio.record_entry.retrieve";
858 my $record = $session->request(
859 "open-ils.storage.direct.biblio.record_entry.retrieve", $master_id );
860 $record = $record->gather(1);
862 #my $record = OpenILS::Application::AppUtils->simple_scalar_request( "open-ils.storage",
865 warn "No record returned with id $master_id";
866 throw OpenSRF::EX::ERROR
869 my $u = OpenILS::Utils::ModsParser->new();
871 $u->start_mods_batch( $record->marc );
872 my $main_doc_id = $record->id();
874 @ids = grep { $_ ne $master_id } @ids;
876 # now we have to collect all of the marc objects and push them into a mods batch
877 my $request = $session->request(
878 "open-ils.storage.direct.biblio.record_entry.batch.retrieve", @ids );
880 while( my $response = $request->recv() ) {
882 next unless $response;
883 if(UNIVERSAL::isa( $response,"OpenSRF::EX")) {
884 throw $response ($response->stringify);
887 my $content = $response->content;
890 $u->push_mods_batch( $content->marc );
894 my $mods = $u->finish_mods_batch();
895 $mods->doc_id($mrid);
898 $client->respond_complete($mods);
900 my $mods_string = JSON->perl2JSON($mods->decast);
902 $mr->mods($mods_string);
904 my $req = $session->request(
905 "open-ils.storage.direct.metabib.metarecord.update", $mr );
910 $session->disconnect();
917 # converts a mr id into a list of record ids
919 __PACKAGE__->register_method(
920 method => "biblio_mrid_to_record_ids",
921 api_name => "open-ils.search.biblio.metarecord_to_records",
924 __PACKAGE__->register_method(
925 method => "biblio_mrid_to_record_ids",
926 api_name => "open-ils.search.biblio.metarecord_to_records.staff",
929 sub biblio_mrid_to_record_ids {
930 my( $self, $client, $mrid, $format ) = @_;
932 throw OpenSRF::EX::InvalidArg
933 ("search.biblio.metarecord_to_record_ids requires mr id")
934 unless defined( $mrid );
936 warn "Searching for record for MR $mrid and format $format\n";
938 my $method = "open-ils.storage.ordered.metabib.metarecord.records.atomic";
939 if($self and $self->api_name =~ /staff/) { $method =~ s/atomic/staff\.atomic/; }
940 warn "Performing record retrieval with method $method\n";
943 my $mrmaps = OpenILS::Application::AppUtils->simple_scalar_request(
944 "open-ils.storage", $method, $mrid, $format );
951 return { count => $size, ids => $mrmaps };
956 __PACKAGE__->register_method(
957 method => "biblio_record_to_marc_html",
958 api_name => "open-ils.search.biblio.record.html" );
960 my $parser = XML::LibXML->new();
961 my $xslt = XML::LibXSLT->new();
964 my $settings_client = OpenSRF::Utils::SettingsClient->new();
965 sub biblio_record_to_marc_html {
966 my( $self, $client, $recordid ) = @_;
969 my $dir = $settings_client->config_value( "dirs", "xsl" );
970 my $xsl = $settings_client->config_value(
971 "apps", "open-ils.search", "app_settings", "marc_html_xsl" );
973 $xsl = $parser->parse_file("$dir/$xsl");
974 $marc_sheet = $xslt->parse_stylesheet( $xsl );
978 my $record = $apputils->simple_scalar_request(
980 "open-ils.storage.direct.biblio.record_entry.retrieve",
983 my $xmldoc = $parser->parse_string($record->marc);
984 my $html = $marc_sheet->transform($xmldoc);
985 $html = $html->toString();
992 __PACKAGE__->register_method(
993 method => "retrieve_all_copy_locations",
994 api_name => "open-ils.search.config.copy_location.retrieve.all" );
996 my $shelving_locations;
997 sub retrieve_all_copy_locations {
998 my( $self, $client ) = @_;
999 if(!$shelving_locations) {
1000 $shelving_locations = $apputils->simple_scalar_request(
1002 "open-ils.storage.direct.asset.copy_location.retrieve.all.atomic");
1004 return $shelving_locations;
1009 __PACKAGE__->register_method(
1010 method => "retrieve_all_copy_statuses",
1011 api_name => "open-ils.search.config.copy_status.retrieve.all" );
1014 sub retrieve_all_copy_statuses {
1015 my( $self, $client ) = @_;
1016 if(!$copy_statuses) {
1017 $copy_statuses = $apputils->simple_scalar_request(
1019 "open-ils.storage.direct.config.copy_status.retrieve.all.atomic" );
1021 return $copy_statuses;
1025 __PACKAGE__->register_method(
1026 method => "copy_counts_per_org",
1027 api_name => "open-ils.search.biblio.copy_counts.retrieve");
1029 __PACKAGE__->register_method(
1030 method => "copy_counts_per_org",
1031 api_name => "open-ils.search.biblio.copy_counts.retrieve.staff");
1033 sub copy_counts_per_org {
1034 my( $self, $client, $record_id ) = @_;
1036 warn "Retreiveing copy copy counts for record $record_id and method " . $self->api_name . "\n";
1038 my $method = "open-ils.storage.biblio.record_entry.global_copy_count.atomic";
1039 if($self->api_name =~ /staff/) { $method =~ s/atomic/staff\.atomic/; }
1041 my $counts = $apputils->simple_scalar_request(
1042 "open-ils.storage", $method, $record_id );
1044 $counts = [ sort {$a->[0] <=> $b->[0]} @$counts ];
1049 __PACKAGE__->register_method(
1050 method => "copy_count_summary",
1051 api_name => "open-ils.search.biblio.copy_counts.summary.retrieve",
1052 notes => <<" NOTES");
1053 returns an array of these:
1054 [ org_id, callnumber_label, <status1_count>, <status2_cout>,...]
1055 where statusx is a copy status name. the statuses are sorted
1059 sub copy_count_summary {
1060 my( $self, $client, $rid ) = @_;
1061 my $method = "open-ils.storage.biblio.record_entry.status_copy_count.atomic";
1062 return $apputils->simple_scalar_request( "open-ils.storage", $method, $rid );
1066 __PACKAGE__->register_method(
1067 method => "multiclass_search",
1068 api_name => "open-ils.search.biblio.multiclass",
1069 notes => <<" NOTES");
1070 Performs a multiclass search
1071 PARAMS( searchBlob, org_unit, format, limit )
1072 where searchBlob is defined like this:
1074 "title" : { "term" : "water" },
1075 "author" : { "term" : "smith" },
1080 __PACKAGE__->register_method(
1081 method => "multiclass_search",
1082 api_name => "open-ils.search.biblio.multiclass.staff",
1083 notes => "see open-ils.search.biblio.multiclass" );
1085 sub multiclass_search {
1086 my( $self, $client, $searchBlob, $orgid, $format, $limit ) = @_;
1088 $logger->debug("Performing multiclass search with org => $orgid, " .
1089 "format => $format, limit => $limit, and search blob " . Dumper($searchBlob));
1091 my $meth = 'open-ils.storage.metabib.post_filter.multiclass.search_fts.metarecord.atomic';
1092 if($self->api_name =~ /staff/) { $meth =~ s/metarecord\.atomic/metarecord.staff.atomic/; }
1095 my $records = $apputils->simplereq(
1096 'open-ils.storage', $meth,
1097 org_unit => $orgid, searches => $searchBlob, format => $format, limit => $limit );
1102 if( ref($records) and $records->[0] and
1103 defined($records->[0]->[3])) { $count = $records->[0]->[3];}
1105 for my $r (@$records) { push( @$recs, $r ) if ($r and $r->[0]); }
1107 # records has the form: [ mrid, rank, singleRecord / 0, hitCount ];
1108 return { ids => $recs, count => $count };
1113 __PACKAGE__->register_method(
1114 method => "marc_search",
1115 api_name => "open-ils.search.biblio.marc",
1116 notes => <<" NOTES");
1117 Performs a multiclass search
1118 PARAMS( searchBlob, org_unit, format )
1119 where searchBlob is defined like this:
1122 "term":"shakespeare",
1123 "restrict":[{"tag":"245","subfield":"a"}]
1127 "restrict":[{"tag":"100","subfield":"a"}]
1135 my( $self, $client, $searchBlob, $orgid, $format ) = @_;
1137 $logger->debug("Performing MARC search with org => $orgid, " .
1138 "format => $format and search blob " . Dumper($searchBlob) );
1140 my $records = $apputils->simplereq(
1142 'open-ils.storage.metabib.full_rec.multi_search.atomic',
1143 searches => $searchBlob, org_unit => $orgid, format => $format );
1148 if( ref($records) and $records->[0] and
1149 defined($records->[0]->[3])) { $count = $records->[0]->[3];}
1151 for my $r (@$records) { push( @$recs, $r ) if ($r and $r->[0]); }
1153 # records has the form: [ mrid, rank, singleRecord / 0, hitCount ];
1154 return { ids => $recs, count => $count };
1160 __PACKAGE__->register_method(
1161 method => "biblio_search_isbn",
1162 api_name => "open-ils.search.biblio.isbn",
1165 sub biblio_search_isbn {
1166 my( $self, $client, $isbn ) = @_;
1168 $logger->debug("Searching ISBN $isbn");
1170 my $method = $self->method_lookup("open-ils.search.biblio.marc");
1172 my ($records) = $method->run(
1174 restrict => $cat_search_hash->{isbn} } ], 1);
1180 __PACKAGE__->register_method(
1181 method => "biblio_search_issn",
1182 api_name => "open-ils.search.biblio.issn",
1185 sub biblio_search_issn {
1186 my( $self, $client, $issn ) = @_;
1188 $logger->debug("Searching ISSN $issn");
1190 my $method = $self->method_lookup("open-ils.search.biblio.marc");
1192 my ($records) = $method->run(
1194 restrict => $cat_search_hash->{issn} } ], 1);
1202 __PACKAGE__->register_method(
1203 method => "fetch_mods_by_copy",
1204 api_name => "open-ils.search.biblio.mods_from_copy",
1207 sub fetch_mods_by_copy {
1208 my( $self, $client, $copyid ) = @_;
1209 my ($record, $evt) = $apputils->fetch_record_by_copy( $copyid );
1210 return $evt if $evt;
1211 return OpenILS::Event->new('ITEM_NOT_CATALOGED') unless $record->marc;
1212 return $apputils->record_to_mvr($record);
1219 # -------------------------------------------------------------------------------------
1221 __PACKAGE__->register_method(
1222 method => "cn_browse",
1223 api_name => "open-ils.search.callnumber.browse.target",
1224 notes => "Starts a callnumber browse"
1227 __PACKAGE__->register_method(
1228 method => "cn_browse",
1229 api_name => "open-ils.search.callnumber.browse.page_up",
1230 notes => "Returns the previous page of callnumbers",
1233 __PACKAGE__->register_method(
1234 method => "cn_browse",
1235 api_name => "open-ils.search.callnumber.browse.page_down",
1236 notes => "Returns the next page of callnumbers",
1240 # RETURNS array of arrays like so: label, owning_lib, record, id
1242 my( $self, $client, @params ) = @_;
1245 $method = 'open-ils.storage.asset.call_number.browse.target.atomic'
1246 if( $self->api_name =~ /target/ );
1247 $method = 'open-ils.storage.asset.call_number.browse.page_up.atomic'
1248 if( $self->api_name =~ /page_up/ );
1249 $method = 'open-ils.storage.asset.call_number.browse.page_down.atomic'
1250 if( $self->api_name =~ /page_down/ );
1252 return $apputils->simplereq( 'open-ils.storage', $method, @params );
1254 # -------------------------------------------------------------------------------------
1256 __PACKAGE__->register_method(
1257 method => "fetch_cn",
1258 api_name => "open-ils.search.callnumber.retrieve",
1259 notes => "retrieves a callnumber based on ID",
1263 my( $self, $client, $id ) = @_;
1264 my( $cn, $evt ) = $apputils->fetch_callnumber( $id );
1265 return $evt if $evt;