Lines 120-137
sub FindDuplicate {
Link Here
|
120 |
} |
120 |
} |
121 |
} |
121 |
} |
122 |
|
122 |
|
123 |
# FIXME: add error handling |
123 |
my ( $error, $searchresults, undef ) = SimpleSearch($query); # FIXME :: hardcoded ! |
124 |
my ( $error, $searchresults ) = SimpleSearch($query); # FIXME :: hardcoded ! |
|
|
125 |
my @results; |
124 |
my @results; |
126 |
foreach my $possible_duplicate_record (@$searchresults) { |
125 |
if (!defined $error) { |
127 |
my $marcrecord = |
126 |
foreach my $possible_duplicate_record (@{$searchresults}) { |
128 |
MARC::Record->new_from_usmarc($possible_duplicate_record); |
127 |
my $marcrecord = |
129 |
my $result = TransformMarcToKoha( $dbh, $marcrecord, '' ); |
128 |
MARC::Record->new_from_usmarc($possible_duplicate_record); |
130 |
|
129 |
my $result = TransformMarcToKoha( $dbh, $marcrecord, '' ); |
131 |
# FIXME :: why 2 $biblionumber ? |
130 |
|
132 |
if ($result) { |
131 |
# FIXME :: why 2 $biblionumber ? |
133 |
push @results, $result->{'biblionumber'}; |
132 |
if ($result) { |
134 |
push @results, $result->{'title'}; |
133 |
push @results, $result->{'biblionumber'}; |
|
|
134 |
push @results, $result->{'title'}; |
135 |
} |
135 |
} |
136 |
} |
136 |
} |
137 |
} |
137 |
return @results; |
138 |
return @results; |
Lines 153-164
This function provides a simple search API on the bibliographic catalog
Link Here
|
153 |
* $max_results - if present, determines the maximum number of records to fetch. undef is All. defaults to undef. |
154 |
* $max_results - if present, determines the maximum number of records to fetch. undef is All. defaults to undef. |
154 |
|
155 |
|
155 |
|
156 |
|
156 |
=item C<Output:> |
157 |
=item C<Return:> |
157 |
|
158 |
|
158 |
* $error is a empty unless an error is detected |
159 |
Returns an array consisting of three elements |
159 |
* \@results is an array of records. |
160 |
* $error is undefined unless an error is detected |
|
|
161 |
* $results is a reference to an array of records. |
160 |
* $total_hits is the number of hits that would have been returned with no limit |
162 |
* $total_hits is the number of hits that would have been returned with no limit |
161 |
|
163 |
|
|
|
164 |
If an error is returned the two other return elements are undefined. If error itself is undefined |
165 |
the other two elements are always defined |
166 |
|
162 |
=item C<usage in the script:> |
167 |
=item C<usage in the script:> |
163 |
|
168 |
|
164 |
=back |
169 |
=back |
Lines 172-194
if (defined $error) {
Link Here
|
172 |
exit; |
177 |
exit; |
173 |
} |
178 |
} |
174 |
|
179 |
|
175 |
my $hits = scalar @$marcresults; |
180 |
my $hits = @{$marcresults}; |
176 |
my @results; |
181 |
my @results; |
177 |
|
182 |
|
178 |
for my $i (0..$hits) { |
183 |
for my $r ( @{$marcresults} ) { |
179 |
my %resultsloop; |
184 |
my $marcrecord = MARC::File::USMARC::decode($r); |
180 |
my $marcrecord = MARC::File::USMARC::decode($marcresults->[$i]); |
185 |
my $biblio = TransformMarcToKoha(C4::Context->dbh,$marcrecord,q{}); |
181 |
my $biblio = TransformMarcToKoha(C4::Context->dbh,$marcrecord,''); |
186 |
|
182 |
|
187 |
#build the iarray of hashs for the template. |
183 |
#build the hash for the template. |
188 |
push @results, { |
184 |
$resultsloop{title} = $biblio->{'title'}; |
189 |
title => $biblio->{'title'}, |
185 |
$resultsloop{subtitle} = $biblio->{'subtitle'}; |
190 |
subtitle => $biblio->{'subtitle'}, |
186 |
$resultsloop{biblionumber} = $biblio->{'biblionumber'}; |
191 |
biblionumber => $biblio->{'biblionumber'}, |
187 |
$resultsloop{author} = $biblio->{'author'}; |
192 |
author => $biblio->{'author'}, |
188 |
$resultsloop{publishercode} = $biblio->{'publishercode'}; |
193 |
publishercode => $biblio->{'publishercode'}, |
189 |
$resultsloop{publicationyear} = $biblio->{'publicationyear'}; |
194 |
publicationyear => $biblio->{'publicationyear'}, |
|
|
195 |
}; |
190 |
|
196 |
|
191 |
push @results, \%resultsloop; |
|
|
192 |
} |
197 |
} |
193 |
|
198 |
|
194 |
$template->param(result=>\@results); |
199 |
$template->param(result=>\@results); |
Lines 206-219
sub SimpleSearch {
Link Here
|
206 |
return ( undef, $search_result, scalar($result->{hits}) ); |
211 |
return ( undef, $search_result, scalar($result->{hits}) ); |
207 |
} |
212 |
} |
208 |
else { |
213 |
else { |
|
|
214 |
return ( 'No query entered', undef, undef ) unless $query; |
209 |
# FIXME hardcoded value. See catalog/search.pl & opac-search.pl too. |
215 |
# FIXME hardcoded value. See catalog/search.pl & opac-search.pl too. |
210 |
my @servers = defined ( $servers ) ? @$servers : ( "biblioserver" ); |
216 |
my @servers = defined ( $servers ) ? @$servers : ( 'biblioserver' ); |
211 |
my @results; |
|
|
212 |
my @zoom_queries; |
217 |
my @zoom_queries; |
213 |
my @tmpresults; |
218 |
my @tmpresults; |
214 |
my @zconns; |
219 |
my @zconns; |
215 |
my $total_hits; |
220 |
my $results = []; |
216 |
return ( "No query entered", undef, undef ) unless $query; |
221 |
my $total_hits = 0; |
217 |
|
222 |
|
218 |
# Initialize & Search Zebra |
223 |
# Initialize & Search Zebra |
219 |
for ( my $i = 0 ; $i < @servers ; $i++ ) { |
224 |
for ( my $i = 0 ; $i < @servers ; $i++ ) { |
Lines 257-263
sub SimpleSearch {
Link Here
|
257 |
|
262 |
|
258 |
for my $j ( $first_record..$last_record ) { |
263 |
for my $j ( $first_record..$last_record ) { |
259 |
my $record = $tmpresults[ $i - 1 ]->record( $j-1 )->raw(); # 0 indexed |
264 |
my $record = $tmpresults[ $i - 1 ]->record( $j-1 )->raw(); # 0 indexed |
260 |
push @results, $record; |
265 |
push @{$results}, $record; |
261 |
} |
266 |
} |
262 |
} |
267 |
} |
263 |
} |
268 |
} |
Lines 269-275
sub SimpleSearch {
Link Here
|
269 |
$zoom_query->destroy(); |
274 |
$zoom_query->destroy(); |
270 |
} |
275 |
} |
271 |
|
276 |
|
272 |
return ( undef, \@results, $total_hits ); |
277 |
return ( undef, $results, $total_hits ); |
273 |
} |
278 |
} |
274 |
} |
279 |
} |
275 |
|
280 |
|
Lines 2559-2569
AND (authtypecode IS NOT NULL AND authtypecode<>\"\")|);
Link Here
|
2559 |
warn "BIBLIOADDSAUTHORITIES: $error"; |
2564 |
warn "BIBLIOADDSAUTHORITIES: $error"; |
2560 |
return (0,0) ; |
2565 |
return (0,0) ; |
2561 |
} |
2566 |
} |
2562 |
if ($results && scalar(@$results)==1) { |
2567 |
if ( @{$results} == 1 ) { |
2563 |
my $marcrecord = MARC::File::USMARC::decode($results->[0]); |
2568 |
my $marcrecord = MARC::File::USMARC::decode($results->[0]); |
2564 |
$field->add_subfields('9'=>$marcrecord->field('001')->data); |
2569 |
$field->add_subfields('9'=>$marcrecord->field('001')->data); |
2565 |
$countlinked++; |
2570 |
$countlinked++; |
2566 |
} elsif (scalar(@$results)>1) { |
2571 |
} elsif ( @{$results} > 1 ) { |
2567 |
#More than One result |
2572 |
#More than One result |
2568 |
#This can comes out of a lack of a subfield. |
2573 |
#This can comes out of a lack of a subfield. |
2569 |
# my $marcrecord = MARC::File::USMARC::decode($results->[0]); |
2574 |
# my $marcrecord = MARC::File::USMARC::decode($results->[0]); |
2570 |
- |
|
|