]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Search.pm
generic search interface
[Evergreen.git] / Open-ILS / src / perlmods / OpenILS / Application / Search.pm
1 package OpenILS::Application::Search;
2 use base qw/OpenSRF::Application/;
3 use OpenSRF::EX qw(:try);
4 use strict; use warnings;
5 use OpenILS::Utils::Fieldmapper;
6 use Time::HiRes qw(time);
7 use OpenILS::Application::Cat::Utils;
8
9 sub child_init {
10
11         try {
12                 OpenSRF::Application->method_lookup( "blah" );
13
14         } catch Error with { 
15                 warn "Child Init Failed: " . shift() . "\n";
16         };
17
18 }
19
20
21
22 __PACKAGE__->register_method(
23         method  => "cat_biblio_search_class",
24         api_name        => "open-ils.search.cat.biblio.class",
25         argc            => 3, 
26         note            => "Searches biblio information by search class",
27 );
28
29 sub cat_biblio_search_class {
30         my( $self, $client, $class, $sort, $string ) = @_;
31
32         # sort = title, author, pubdate
33
34         warn "Starting search " . time() . "\n";
35         
36         my $search_hash;
37
38         warn "Searching $class, $sort, $string\n";
39
40         if( $class eq "author" ) {
41
42                 $search_hash =  [ 
43                                 { tag => "100", subfield => "a"} ,
44                                 { tag => "700", subfield => "a"} ]; 
45
46         } elsif( $class eq "title" ) { 
47
48                 $search_hash = [ 
49                                 { tag => "245", subfield => "a"},
50                                 { tag => "242", subfield => "a"}, 
51                                 { tag => "240", subfield => "a"},
52                                 { tag => "210", subfield => "a"},
53                 ];
54
55         } elsif( $class eq "subject" ) { 
56
57                 $search_hash =  [ { tag => "650", subfield => "_" } ];
58
59         } elsif( $class eq "tcn" ) { 
60
61                 $search_hash = [        { tag => "035", subfield => "_" } ];
62         }
63
64         
65         warn "Looking up method: "  . time() . "\n";
66
67         my $method = $self->method_lookup("open-ils.search.biblio.marc");
68         if(!$method) {
69                 throw OpenSRF::EX::PANIC 
70                         ("Can't lookup method 'open-ils.search.biblio.marc'");
71         }
72
73         warn "Running: "  . time() . "\n";
74
75         my ($records) = $method->run( $search_hash, $string );
76
77         warn "Search For Id's complete, fixing: "  . time() . "\n";
78         
79
80         my @results = ();
81
82
83         $method = $self->method_lookup("open-ils.storage.biblio.record_marc.batch.retrieve");
84         warn "Found method batch " . time() . "\n";
85
86         if(!$method) {
87                 throw OpenSRF::EX::PANIC ("Can't lookup method 'open-ils.storage.biblio.record_marc.batch.retrieve");
88         }
89
90         warn "running batch " . time() . "\n";
91         my @marxml_objs = $method->run( @$records );
92         warn "done running batch " . time() . "\n";
93
94         my $start = 1;
95         for my $marcxml (@marxml_objs) { 
96                 warn "Starting batch " . time() . "\n";
97                 my $u = OpenILS::Application::Cat::Utils->new();
98                 $u->start_mods_batch( $marcxml->marc );
99                 my $mods = $u->finish_mods_batch();
100                 push @results, $mods;
101         }
102         warn "REturning \n";
103
104         use Data::Dumper;
105         warn Dumper \@results;
106
107
108         #@records = sort { $a->{$sort} <=> $b->{$sort} } @records;
109
110         return \@results;
111
112 }
113
114
115
116 __PACKAGE__->register_method(
117         method  => "biblio_search_marc",
118         api_name        => "open-ils.search.biblio.marc",
119         argc            => 1, 
120         note            => "Searches biblio information by marc tag",
121 );
122
123 sub biblio_search_marc {
124         my( $self, $client, $search_hash, $string ) = @_;
125
126
127         warn "Looking up search method: "  . time() . "\n";
128         my $method = $self->method_lookup( "open-ils.storage.metabib.full_rec.search.fts" );
129         if(!$method) {
130                 throw OpenSRF::EX::PANIC 
131                         ("Can't lookup method 'open-ils.storage open-ils.storage.metabib.full_rec.search.fts'");
132         }
133
134         warn "Running search method: "  . time() . "\n";
135         my ($data) = $method->run( $search_hash, $string );
136         my @ids;
137
138         for my $i (@$data) {
139                 push @ids, $i->[0];
140         }
141         
142         warn "returning id's @ids\n";
143
144         return \@ids;
145
146 }
147
148
149
150
151 1;