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 $format = undef if ($format eq 'all');
196 my $method = "open-ils.storage.biblio.record_entry.copy_count.atomic";
198 if($self->api_name =~ /metarecord/) {
199 $method = "open-ils.storage.metabib.metarecord.copy_count.atomic";
203 if($self->api_name =~ /staff/ ) {
204 $method =~ s/atomic/staff\.atomic/og;
205 warn "Doing staff search $method\n";
209 my $session = OpenSRF::AppSession->create("open-ils.storage");
210 warn "copy_count retrieve $record_id\n";
211 return undef unless(defined $record_id);
213 my $request = $session->request(
214 $method, org_unit => $org_id => $key => $record_id, format => $format );
217 my $count = $request->gather(1);
218 $session->disconnect();
219 return [ sort { $a->{depth} <=> $b->{depth} } @$count ];
224 # used for cat search classes
225 my $cat_search_hash = {
228 { tag => "100", subfield => "a"} ,
229 { tag => "700", subfield => "a"},
233 { tag => "245", subfield => "a"},
234 { tag => "242", subfield => "a"},
235 { tag => "240", subfield => "a"},
236 { tag => "210", subfield => "a"},
240 { tag => "650", subfield => "_" },
244 { tag => "035", subfield => "_" },
248 { tag => "020", subfield => "a" },
252 { tag => '022', subfield => 'a' },
258 __PACKAGE__->register_method(
259 method => "biblio_search_tcn",
260 api_name => "open-ils.search.biblio.tcn",
262 note => "Retrieve a record by TCN",
265 sub biblio_search_tcn {
267 my( $self, $client, $tcn ) = @_;
269 $tcn =~ s/.*?(\w+)\s*$/$1/o;
270 warn "Searching TCN $tcn\n";
272 my $session = OpenSRF::AppSession->create( "open-ils.storage" );
273 my $request = $session->request(
274 "open-ils.storage.direct.biblio.record_entry.search.tcn_value.atomic", $tcn );
275 my $record_entry = $request->gather(1);
278 for my $record (@$record_entry) {
279 push @ids, $record->id;
282 $session->disconnect();
284 warn "received ID's for tcn search @ids\n";
287 return { count => $size, ids => \@ids };
292 # --------------------------------------------------------------------------------
299 # --------------------------------------------------------------------------------
301 __PACKAGE__->register_method(
302 method => "biblio_barcode_to_copy",
303 api_name => "open-ils.search.asset.copy.find_by_barcode",
306 # turns a barcode into a copy object
307 sub biblio_barcode_to_copy {
308 my( $self, $client, $barcode ) = @_;
310 throw OpenSRF::EX::InvalidArg
311 ("search.biblio.barcode needs a barcode to search")
312 unless defined $barcode;
314 warn "copy search for barcode $barcode\n";
315 my $record = OpenILS::Application::AppUtils->simple_scalar_request(
317 "open-ils.storage.direct.asset.copy.search.barcode.atomic",
320 return undef unless($record);
325 __PACKAGE__->register_method(
326 method => "biblio_id_to_copy",
327 api_name => "open-ils.search.asset.copy.batch.retrieve",
330 # turns a barcode into a copy object
331 sub biblio_id_to_copy {
332 my( $self, $client, $ids ) = @_;
334 throw OpenSRF::EX::InvalidArg
335 ("search.biblio.batch.retrieve needs a id to search")
338 warn "copy search for ids @$ids\n";
339 my $record = OpenILS::Application::AppUtils->simple_scalar_request(
341 "open-ils.storage.direct.asset.copy.batch.retrieve.atomic",
349 __PACKAGE__->register_method(
350 method => "copy_retrieve",
351 api_name => "open-ils.search.asset.copy.retrieve",
355 my( $self, $client, $cid ) = @_;
356 my( $copy, $evt ) = $U->fetch_copy($cid);
362 __PACKAGE__->register_method(
363 method => "fleshed_copy_retrieve_batch",
364 api_name => "open-ils.search.asset.copy.fleshed.batch.retrieve",
367 sub fleshed_copy_retrieve_batch {
368 my( $self, $client, $ids ) = @_;
370 throw OpenSRF::EX::InvalidArg
371 ("search.biblio.batch.retrieve needs a id to search")
374 warn "fleshed copy search for id @$ids\n";
375 my $copy = OpenILS::Application::AppUtils->simple_scalar_request(
377 "open-ils.storage.fleshed.asset.copy.batch.retrieve.atomic",
383 __PACKAGE__->register_method(
384 method => "fleshed_copy_retrieve",
385 api_name => "open-ils.search.asset.copy.fleshed.retrieve",
388 sub fleshed_copy_retrieve {
389 my( $self, $client, $id ) = @_;
391 return undef unless defined $id;
392 warn "copy retrieve for id $id\n";
393 return OpenILS::Application::AppUtils->simple_scalar_request(
395 "open-ils.storage.fleshed.asset.copy.retrieve",
401 __PACKAGE__->register_method(
402 method => "biblio_barcode_to_title",
403 api_name => "open-ils.search.biblio.find_by_barcode",
406 sub biblio_barcode_to_title {
407 my( $self, $client, $barcode ) = @_;
410 throw OpenSRF::EX::ERROR
411 ("Not enough args to find_by_barcode");
414 my $title = $apputils->simple_scalar_request(
416 "open-ils.storage.biblio.record_entry.retrieve_by_barcode",
420 return { ids => [ $title->id ], count => 1 };
422 return { count => 0 };
428 __PACKAGE__->register_method(
429 method => "biblio_copy_to_mods",
430 api_name => "open-ils.search.biblio.copy.mods.retrieve",
433 # takes a copy object and returns it fleshed mods object
434 sub biblio_copy_to_mods {
435 my( $self, $client, $copy ) = @_;
437 throw OpenSRF::EX::InvalidArgs
438 ("copy.mods.retrieve needs a copy") unless( $copy );
440 new Fieldmapper::asset::copy($copy);
442 my $volume = OpenILS::Application::AppUtils->simple_scalar_request(
444 "open-ils.storage.direct.asset.call_number.retrieve",
445 $copy->call_number() );
447 my $mods = _records_to_mods($volume->record());
448 $mods = shift @$mods;
449 $volume->copies([$copy]);
450 push @{$mods->call_numbers()}, $volume;
456 sub barcode_to_mods {
461 # --------------------------------------------------------------------------------
466 __PACKAGE__->register_method(
467 method => "cat_biblio_search_class",
468 api_name => "open-ils.search.cat.biblio.class",
472 sub cat_biblio_search_class {
474 my( $self, $client, $org_id, $class, $sort, $string ) = @_;
476 throw OpenSRF::EX::InvalidArg
477 ("Not enough args to open-ils.search.cat.biblio.class")
478 unless( defined($org_id) and $class and $sort and $string );
483 my $method = $self->method_lookup("open-ils.search.biblio.marc");
485 throw OpenSRF::EX::PANIC
486 ("Can't lookup method 'open-ils.search.biblio.marc'");
489 my ($records) = $method->run( $cat_search_hash->{$class}, $string );
492 for my $i (@$records) { push @ids, $i->[0]; }
494 my $mods_list = _records_to_mods( @ids );
495 return undef unless (ref($mods_list) eq "ARRAY");
497 # ---------------------------------------------------------------
498 # append copy count information to the mods objects
499 my $session = OpenSRF::AppSession->create("open-ils.storage");
501 my $request = $session->request(
502 "open-ils.storage.direct.biblio.record_copy_count.batch", $org_id, @ids );
506 warn "receiving copy counts for doc $id\n";
508 my $response = $request->recv();
509 next unless $response;
511 if( $response and UNIVERSAL::isa($response, "Error")) {
512 throw $response ($response->stringify);
515 my $count = $response->content;
516 my $mods_obj = undef;
517 for my $m (@$mods_list) {
518 $mods_obj = $m if ($m->doc_id() == $id)
521 $mods_obj->copy_count($count);
524 $client->respond( $mods_obj );
530 $session->disconnect();
532 # ---------------------------------------------------------------
542 __PACKAGE__->register_method(
543 method => "biblio_search_class_count",
544 api_name => "open-ils.search.biblio.class.count",
547 __PACKAGE__->register_method(
548 method => "biblio_search_class_count",
549 api_name => "open-ils.search.biblio.class.count.staff",
552 sub biblio_search_class_count {
554 my( $self, $client, $class, $string, $org_id, $org_type, $format ) = @_;
556 warn "org: $org_id : depth: $org_type\n";
558 $org_id = "1" unless defined($org_id); # xxx
559 $org_type = 0 unless defined($org_type);
561 warn "Searching biblio.class.id\n" .
563 "org_id: $org_id\n" .
564 "depth: $org_type\n" .
567 if( !defined($org_id) or !$class or !$string ) {
568 warn "not enbough args to metarecord search\n";
569 throw OpenSRF::EX::InvalidArg
570 ("Not enough args to open-ils.search.cat.biblio.class")
575 if( ($class ne "title") and ($class ne "author") and
576 ($class ne "subject") and ($class ne "keyword")
577 and ($class ne "series" )) {
578 warn "Invalid search class: $class\n";
579 throw OpenSRF::EX::InvalidArg ("Not a valid search class: $class")
582 # grab the mr id's from storage
584 my $method = "open-ils.storage.cachable.metabib.$class.search_fts.metarecord_count";
585 if($self->api_name =~ /staff/) {
586 $method = "$method.staff";
587 $method =~ s/\.cachable//o;
589 warn "Performing count method $method\n";
590 warn "API name " . $self->api_name() . "\n";
592 my $session = OpenSRF::AppSession->create('open-ils.storage');
594 my $request = $session->request( $method,
597 cache_page_size => 1,
601 my $count = $request->gather(1);
602 warn "Received count $count\n";
608 __PACKAGE__->register_method(
609 method => "biblio_search_class",
610 api_name => "open-ils.search.biblio.class",
613 __PACKAGE__->register_method(
614 method => "biblio_search_class",
615 api_name => "open-ils.search.biblio.class.full",
618 __PACKAGE__->register_method(
619 method => "biblio_search_class",
620 api_name => "open-ils.search.biblio.class.full.staff",
623 __PACKAGE__->register_method(
624 method => "biblio_search_class",
625 api_name => "open-ils.search.biblio.class.staff",
628 sub biblio_search_class {
630 my( $self, $client, $class, $string,
631 $org_id, $org_type, $limit, $offset, $format ) = @_;
633 warn "org: $org_id : depth: $org_type : limit: $limit : offset: $offset\n";
636 $offset = 0 unless (defined($offset) and $offset > 0);
637 $limit = 100 unless (defined($limit) and $limit > 0);
638 $org_id = "1" unless (defined($org_id)); # xxx
639 $org_type = 0 unless (defined($org_type));
641 warn "Searching biblio.class.id\n" .
643 "\noffset: $offset\n" .
645 "org_id: $org_id\n" .
646 "depth: $org_type\n" .
649 warn "Search filtering string " . time() . "\n";
650 $string = OpenILS::Application::Search->filter_search($string);
651 if(!$string) { return undef; }
653 if( !defined($org_id) or !$class or !$string ) {
654 warn "not enbough args to metarecord search\n";
655 throw OpenSRF::EX::InvalidArg
656 ("Not enough args to open-ils.search.biblio.class")
661 if( ($class ne "title") and ($class ne "author") and
662 ($class ne "subject") and ($class ne "keyword")
663 and ($class ne "series") ) {
664 warn "Invalid search class: $class\n";
665 throw OpenSRF::EX::InvalidArg ("Not a valid search class: $class")
668 #my $method = "open-ils.storage.cachable.metabib.$class.post_filter.search_fts.metarecord.atomic";
669 my $method = "open-ils.storage.metabib.$class.post_filter.search_fts.metarecord.atomic";
671 if($self->api_name =~ /staff/) {
672 $method =~ s/atomic/staff\.atomic/og;
673 $method =~ s/\.cachable//o;
676 if($self->api_name =~ /full/) {
677 $method =~ s/\.cachable//o; #XXX testing..
680 warn "Performing search method $method\n";
681 warn "MR search method is $method\n";
683 my $session = OpenSRF::AppSession->create('open-ils.storage');
685 warn "Search making request " . time() . "\n";
686 my $request = $session->request(
694 cache_page_size => 200,
697 my $records = $request->gather(1);
698 if(!$records) {return { ids => [] }};
702 warn "Received " . scalar(@$records) . " id's from class search\n";
704 # for my $i (@$records) { if(defined($i)) { push @all_ids, $i; } }
705 # my @ids = @all_ids;
706 # @ids = grep { defined($_->[0]) } @ids;
709 $session->disconnect();
712 if( $records->[0] && defined($records->[0]->[3])) { $count = $records->[0]->[3];}
714 for my $r (@$records) { push( @$recs, $r ) if ($r and $r->[0]); }
716 # records has the form: [ mrid, rank, singleRecord / 0, hitCount ];
717 return { ids => $recs, count => $count };
724 __PACKAGE__->register_method(
725 method => "biblio_mrid_to_modsbatch_batch",
726 api_name => "open-ils.search.biblio.metarecord.mods_slim.batch.retrieve");
728 sub biblio_mrid_to_modsbatch_batch {
729 my( $self, $client, $mrids) = @_;
730 warn "Performing mrid_to_modsbatch_batch...";
732 my $method = $self->method_lookup("open-ils.search.biblio.metarecord.mods_slim.retrieve");
734 warn "Grabbing mods for " . Dumper($mrids) . "\n";
736 for my $id (@$mrids) {
737 next unless defined $id;
738 #push @mods, biblio_mrid_to_modsbatch($self, $client, $id);
739 my ($m) = $method->run($id);
746 __PACKAGE__->register_method(
747 method => "biblio_mrid_to_modsbatch",
748 api_name => "open-ils.search.biblio.metarecord.mods_slim.retrieve",
749 notes => <<" NOTES");
750 Returns the mvr associated with a given metarecod. If none exists,
754 __PACKAGE__->register_method(
755 method => "biblio_mrid_to_modsbatch",
756 api_name => "open-ils.search.biblio.metarecord.mods_slim.retrieve.staff",
757 notes => <<" NOTES");
758 Returns the mvr associated with a given metarecod. If none exists,
762 sub biblio_mrid_to_modsbatch {
763 my( $self, $client, $mrid ) = @_;
765 warn "Grabbing mvr for $mrid\n";
767 my $mr = _grab_metarecord($mrid);
768 return undef unless $mr;
770 if( my $m = $self->biblio_mrid_check_mvr($client, $mr)) {
774 return $self->biblio_mrid_make_modsbatch( $client, $mr );
777 # converts a metarecord to an mvr
780 my $perl = JSON->JSON2perl($mr->mods());
781 return Fieldmapper::metabib::virtual_record->new($perl);
784 # checks to see if a metarecord has mods, if so returns true;
786 __PACKAGE__->register_method(
787 method => "biblio_mrid_check_mvr",
788 api_name => "open-ils.search.biblio.metarecord.mods_slim.check",
789 notes => <<" NOTES");
790 Takes a metarecord ID or a metarecord object and returns true
791 if the metarecord already has an mvr associated with it.
794 sub biblio_mrid_check_mvr {
795 my( $self, $client, $mrid ) = @_;
798 if(ref($mrid)) { $mr = $mrid; }
799 else { $mr = _grab_metarecord($mrid); }
801 warn "Checking mvr for mr " . $mr->id . "\n";
803 return _mr_to_mvr($mr) if $mr->mods();
807 sub _grab_metarecord {
810 warn "Grabbing MR $mrid\n";
812 my $mr = OpenILS::Application::AppUtils->simple_scalar_request(
814 "open-ils.storage.direct.metabib.metarecord.retrieve", $mrid );
817 throw OpenSRF::EX::ERROR
818 ("No metarecord exists with the given id: $mrid");
824 __PACKAGE__->register_method(
825 method => "biblio_mrid_make_modsbatch",
826 api_name => "open-ils.search.biblio.metarecord.mods_slim.create",
827 notes => <<" NOTES");
828 Takes either a metarecord ID or a metarecord object.
829 Forces the creations of an mvr for the given metarecord.
830 The created mvr is returned.
833 sub biblio_mrid_make_modsbatch {
835 my( $self, $client, $mrid ) = @_;
838 if(ref($mrid)) { $mr = $mrid; }
839 else { $mr = _grab_metarecord($mrid); }
842 warn "Forcing mvr creation for mr " . $mr->id . "\n";
843 my $master_id = $mr->master_record;
845 my $session = OpenSRF::AppSession->create("open-ils.storage");
847 # grab the records attached to this metarecod
848 warn "Creating mods batch for metarecord $mrid\n";
849 my $meth = "open-ils.search.biblio.metarecord_to_records.staff";
850 $meth = $self->method_lookup($meth);
851 my ($id_hash) = $meth->run($mrid);
852 my @ids = @{$id_hash->{ids}};
853 if(@ids < 1) { return undef; }
855 warn "Master ID is $master_id\n";
856 # grab the master record to start the mods batch
858 $meth = "open-ils.storage.direct.biblio.record_entry.retrieve";
860 my $record = $session->request(
861 "open-ils.storage.direct.biblio.record_entry.retrieve", $master_id );
862 $record = $record->gather(1);
864 #my $record = OpenILS::Application::AppUtils->simple_scalar_request( "open-ils.storage",
867 warn "No record returned with id $master_id";
868 throw OpenSRF::EX::ERROR
871 my $u = OpenILS::Utils::ModsParser->new();
873 $u->start_mods_batch( $record->marc );
874 my $main_doc_id = $record->id();
876 @ids = grep { $_ ne $master_id } @ids;
878 # now we have to collect all of the marc objects and push them into a mods batch
879 my $request = $session->request(
880 "open-ils.storage.direct.biblio.record_entry.batch.retrieve", @ids );
882 while( my $response = $request->recv() ) {
884 next unless $response;
885 if(UNIVERSAL::isa( $response,"OpenSRF::EX")) {
886 throw $response ($response->stringify);
889 my $content = $response->content;
892 $u->push_mods_batch( $content->marc );
896 my $mods = $u->finish_mods_batch();
897 $mods->doc_id($mrid);
900 $client->respond_complete($mods);
902 my $mods_string = JSON->perl2JSON($mods->decast);
904 $mr->mods($mods_string);
906 my $req = $session->request(
907 "open-ils.storage.direct.metabib.metarecord.update", $mr );
912 $session->disconnect();
919 # converts a mr id into a list of record ids
921 __PACKAGE__->register_method(
922 method => "biblio_mrid_to_record_ids",
923 api_name => "open-ils.search.biblio.metarecord_to_records",
926 __PACKAGE__->register_method(
927 method => "biblio_mrid_to_record_ids",
928 api_name => "open-ils.search.biblio.metarecord_to_records.staff",
931 sub biblio_mrid_to_record_ids {
932 my( $self, $client, $mrid, $format ) = @_;
934 throw OpenSRF::EX::InvalidArg
935 ("search.biblio.metarecord_to_record_ids requires mr id")
936 unless defined( $mrid );
938 warn "Searching for record for MR $mrid and format $format\n";
940 my $method = "open-ils.storage.ordered.metabib.metarecord.records.atomic";
941 if($self and $self->api_name =~ /staff/) { $method =~ s/atomic/staff\.atomic/; }
942 warn "Performing record retrieval with method $method\n";
945 my $mrmaps = OpenILS::Application::AppUtils->simple_scalar_request(
946 "open-ils.storage", $method, $mrid, $format );
953 return { count => $size, ids => $mrmaps };
958 __PACKAGE__->register_method(
959 method => "biblio_record_to_marc_html",
960 api_name => "open-ils.search.biblio.record.html" );
962 my $parser = XML::LibXML->new();
963 my $xslt = XML::LibXSLT->new();
966 my $settings_client = OpenSRF::Utils::SettingsClient->new();
967 sub biblio_record_to_marc_html {
968 my( $self, $client, $recordid ) = @_;
971 my $dir = $settings_client->config_value( "dirs", "xsl" );
972 my $xsl = $settings_client->config_value(
973 "apps", "open-ils.search", "app_settings", "marc_html_xsl" );
975 $xsl = $parser->parse_file("$dir/$xsl");
976 $marc_sheet = $xslt->parse_stylesheet( $xsl );
980 my $record = $apputils->simple_scalar_request(
982 "open-ils.storage.direct.biblio.record_entry.retrieve",
985 my $xmldoc = $parser->parse_string($record->marc);
986 my $html = $marc_sheet->transform($xmldoc);
987 $html = $html->toString();
994 __PACKAGE__->register_method(
995 method => "retrieve_all_copy_locations",
996 api_name => "open-ils.search.config.copy_location.retrieve.all" );
998 my $shelving_locations;
999 sub retrieve_all_copy_locations {
1000 my( $self, $client ) = @_;
1001 if(!$shelving_locations) {
1002 $shelving_locations = $apputils->simple_scalar_request(
1004 "open-ils.storage.direct.asset.copy_location.retrieve.all.atomic");
1006 return $shelving_locations;
1011 __PACKAGE__->register_method(
1012 method => "retrieve_all_copy_statuses",
1013 api_name => "open-ils.search.config.copy_status.retrieve.all" );
1016 sub retrieve_all_copy_statuses {
1017 my( $self, $client ) = @_;
1018 if(!$copy_statuses) {
1019 $copy_statuses = $apputils->simple_scalar_request(
1021 "open-ils.storage.direct.config.copy_status.retrieve.all.atomic" );
1023 return $copy_statuses;
1027 __PACKAGE__->register_method(
1028 method => "copy_counts_per_org",
1029 api_name => "open-ils.search.biblio.copy_counts.retrieve");
1031 __PACKAGE__->register_method(
1032 method => "copy_counts_per_org",
1033 api_name => "open-ils.search.biblio.copy_counts.retrieve.staff");
1035 sub copy_counts_per_org {
1036 my( $self, $client, $record_id ) = @_;
1038 warn "Retreiveing copy copy counts for record $record_id and method " . $self->api_name . "\n";
1040 my $method = "open-ils.storage.biblio.record_entry.global_copy_count.atomic";
1041 if($self->api_name =~ /staff/) { $method =~ s/atomic/staff\.atomic/; }
1043 my $counts = $apputils->simple_scalar_request(
1044 "open-ils.storage", $method, $record_id );
1046 $counts = [ sort {$a->[0] <=> $b->[0]} @$counts ];
1051 __PACKAGE__->register_method(
1052 method => "copy_count_summary",
1053 api_name => "open-ils.search.biblio.copy_counts.summary.retrieve",
1054 notes => <<" NOTES");
1055 returns an array of these:
1056 [ org_id, callnumber_label, <status1_count>, <status2_cout>,...]
1057 where statusx is a copy status name. the statuses are sorted
1061 sub copy_count_summary {
1062 my( $self, $client, $rid ) = @_;
1063 my $method = "open-ils.storage.biblio.record_entry.status_copy_count.atomic";
1064 return $apputils->simple_scalar_request( "open-ils.storage", $method, $rid );
1068 __PACKAGE__->register_method(
1069 method => "multiclass_search",
1070 api_name => "open-ils.search.biblio.multiclass",
1071 notes => <<" NOTES");
1072 Performs a multiclass search
1073 PARAMS( searchBlob, org_unit, format, limit )
1074 where searchBlob is defined like this:
1076 "title" : { "term" : "water" },
1077 "author" : { "term" : "smith" },
1082 __PACKAGE__->register_method(
1083 method => "multiclass_search",
1084 api_name => "open-ils.search.biblio.multiclass.staff",
1085 notes => "see open-ils.search.biblio.multiclass" );
1087 sub multiclass_search {
1088 my( $self, $client, $searchBlob, $orgid, $format, $limit ) = @_;
1090 $logger->debug("Performing multiclass search with org => $orgid, " .
1091 "format => $format, limit => $limit, and search blob " . Dumper($searchBlob));
1093 my $meth = 'open-ils.storage.metabib.post_filter.multiclass.search_fts.metarecord.atomic';
1094 if($self->api_name =~ /staff/) { $meth =~ s/metarecord\.atomic/metarecord.staff.atomic/; }
1097 my $records = $apputils->simplereq(
1098 'open-ils.storage', $meth,
1099 org_unit => $orgid, searches => $searchBlob, format => $format, limit => $limit );
1104 if( ref($records) and $records->[0] and
1105 defined($records->[0]->[3])) { $count = $records->[0]->[3];}
1107 for my $r (@$records) { push( @$recs, $r ) if ($r and $r->[0]); }
1109 # records has the form: [ mrid, rank, singleRecord / 0, hitCount ];
1110 return { ids => $recs, count => $count };
1115 __PACKAGE__->register_method(
1116 method => "marc_search",
1117 api_name => "open-ils.search.biblio.marc",
1118 notes => <<" NOTES");
1119 Performs a multiclass search
1120 PARAMS( searchBlob, org_unit, format )
1121 where searchBlob is defined like this:
1124 "term":"shakespeare",
1125 "restrict":[{"tag":"245","subfield":"a"}]
1129 "restrict":[{"tag":"100","subfield":"a"}]
1137 my( $self, $client, $searchBlob, $orgid, $format ) = @_;
1139 $logger->debug("Performing MARC search with org => $orgid, " .
1140 "format => $format and search blob " . Dumper($searchBlob) );
1142 my $records = $apputils->simplereq(
1144 'open-ils.storage.metabib.full_rec.multi_search.atomic',
1145 searches => $searchBlob, org_unit => $orgid, format => $format );
1150 if( ref($records) and $records->[0] and
1151 defined($records->[0]->[3])) { $count = $records->[0]->[3];}
1153 for my $r (@$records) { push( @$recs, $r ) if ($r and $r->[0]); }
1155 # records has the form: [ mrid, rank, singleRecord / 0, hitCount ];
1156 return { ids => $recs, count => $count };
1162 __PACKAGE__->register_method(
1163 method => "biblio_search_isbn",
1164 api_name => "open-ils.search.biblio.isbn",
1167 sub biblio_search_isbn {
1168 my( $self, $client, $isbn ) = @_;
1170 $logger->debug("Searching ISBN $isbn");
1172 my $method = $self->method_lookup("open-ils.search.biblio.marc");
1174 my ($records) = $method->run(
1176 restrict => $cat_search_hash->{isbn} } ], 1);
1182 __PACKAGE__->register_method(
1183 method => "biblio_search_issn",
1184 api_name => "open-ils.search.biblio.issn",
1187 sub biblio_search_issn {
1188 my( $self, $client, $issn ) = @_;
1190 $logger->debug("Searching ISSN $issn");
1192 my $method = $self->method_lookup("open-ils.search.biblio.marc");
1194 my ($records) = $method->run(
1196 restrict => $cat_search_hash->{issn} } ], 1);
1204 __PACKAGE__->register_method(
1205 method => "fetch_mods_by_copy",
1206 api_name => "open-ils.search.biblio.mods_from_copy",
1209 sub fetch_mods_by_copy {
1210 my( $self, $client, $copyid ) = @_;
1211 my ($record, $evt) = $apputils->fetch_record_by_copy( $copyid );
1212 return $evt if $evt;
1213 return OpenILS::Event->new('ITEM_NOT_CATALOGED') unless $record->marc;
1214 return $apputils->record_to_mvr($record);
1221 # -------------------------------------------------------------------------------------
1223 __PACKAGE__->register_method(
1224 method => "cn_browse",
1225 api_name => "open-ils.search.callnumber.browse.target",
1226 notes => "Starts a callnumber browse"
1229 __PACKAGE__->register_method(
1230 method => "cn_browse",
1231 api_name => "open-ils.search.callnumber.browse.page_up",
1232 notes => "Returns the previous page of callnumbers",
1235 __PACKAGE__->register_method(
1236 method => "cn_browse",
1237 api_name => "open-ils.search.callnumber.browse.page_down",
1238 notes => "Returns the next page of callnumbers",
1242 # RETURNS array of arrays like so: label, owning_lib, record, id
1244 my( $self, $client, @params ) = @_;
1247 $method = 'open-ils.storage.asset.call_number.browse.target.atomic'
1248 if( $self->api_name =~ /target/ );
1249 $method = 'open-ils.storage.asset.call_number.browse.page_up.atomic'
1250 if( $self->api_name =~ /page_up/ );
1251 $method = 'open-ils.storage.asset.call_number.browse.page_down.atomic'
1252 if( $self->api_name =~ /page_down/ );
1254 return $apputils->simplereq( 'open-ils.storage', $method, @params );
1256 # -------------------------------------------------------------------------------------
1258 __PACKAGE__->register_method(
1259 method => "fetch_cn",
1260 api_name => "open-ils.search.callnumber.retrieve",
1261 notes => "retrieves a callnumber based on ID",
1265 my( $self, $client, $id ) = @_;
1266 my( $cn, $evt ) = $apputils->fetch_callnumber( $id );
1267 return $evt if $evt;