bugfix #168 + "breedingsearch" sub added+ "isbnsearch" (used only in acqui.simple, should disappear soon) now works on title and isbn

This commit is contained in:
tipaul 2003-01-28 14:46:50 +00:00
parent 0333765bed
commit 4cbb08cd5e

View file

@ -61,7 +61,8 @@ on what is passed to it, it calls the appropriate search function.
&borrdata2 &NewBorrowerNumber &bibitemdata &borrissues &borrdata2 &NewBorrowerNumber &bibitemdata &borrissues
&getboracctrecord &ItemType &itemissues &subject &subtitle &getboracctrecord &ItemType &itemissues &subject &subtitle
&addauthor &bibitems &barcodes &findguarantees &allissues &addauthor &bibitems &barcodes &findguarantees &allissues
&findguarantor &getwebsites &getwebbiblioitems &catalogsearch &itemcount2); &findguarantor &getwebsites &getwebbiblioitems &catalogsearch &itemcount2
&isbnsearch &breedingsearch);
# make all your functions, whether exported or not; # make all your functions, whether exported or not;
=item findguarantees =item findguarantees
@ -193,71 +194,70 @@ HTML.
=cut =cut
#' #'
sub catalogsearch { sub catalogsearch {
my ($env,$type,$search,$num,$offset)=@_; my ($env,$type,$search,$num,$offset)=@_;
my $dbh = C4::Context->dbh; my $dbh = C4::Context->dbh;
# foreach my $key (%$search){ # foreach my $key (%$search){
# $search->{$key}=$dbh->quote($search->{$key}); # $search->{$key}=$dbh->quote($search->{$key});
# } # }
my ($count,@results); my ($count,@results);
# print STDERR "Doing a search \n"; # print STDERR "Doing a search \n";
# FIXME - Use "elsif" to avoid this sort of deep nesting # FIXME - Use "elsif" to avoid this sort of deep nesting
if ($search->{'itemnumber'} ne '' || $search->{'isbn'} ne ''){ if ($search->{'itemnumber'} ne '' || $search->{'isbn'} ne ''){
print STDERR "Doing a precise search\n"; print STDERR "Doing a precise search\n";
($count,@results)=CatSearch($env,'precise',$search,$num,$offset); ($count,@results)=CatSearch($env,'precise',$search,$num,$offset);
} else {
if ($search->{'subject'} ne ''){
($count,@results)=CatSearch($env,'subject',$search,$num,$offset);
} else {
if ($search->{'keyword'} ne ''){
($count,@results)=&KeywordSearch($env,'keyword',$search,$num,$offset);
} else {
($count,@results)=CatSearch($env,'loose',$search,$num,$offset);
} else { }
if ($search->{'subject'} ne ''){ }
($count,@results)=CatSearch($env,'subject',$search,$num,$offset); }
} else { if ($env->{itemcount} eq '1') {
if ($search->{'keyword'} ne ''){ foreach my $data (@results){
($count,@results)=&KeywordSearch($env,'keyword',$search,$num,$offset); my ($counts) = itemcount2($env, $data->{'biblionumber'}, 'intra');
} else { my $subject2=$data->{'subject'};
($count,@results)=CatSearch($env,'loose',$search,$num,$offset); $subject2=~ s/ /%20/g;
$data->{'itemcount'}=$counts->{'total'};
} my $totalitemcounts=0;
} foreach my $key (keys %$counts){
} if ($key ne 'total'){ # FIXME - Should ignore 'order', too.
if ($env->{itemcount} eq '1') { #$data->{'location'}.="$key $counts->{$key} ";
foreach my $data (@results){ $totalitemcounts+=$counts->{$key};
my ($counts) = itemcount2($env, $data->{'biblionumber'}, 'intra'); $data->{'locationhash'}->{$key}=$counts->{$key};
my $subject2=$data->{'subject'}; }
$subject2=~ s/ /%20/g; }
$data->{'itemcount'}=$counts->{'total'}; my $locationtext='';
my $totalitemcounts=0; my $notavailabletext='';
foreach my $key (keys %$counts){ foreach (sort keys %{$data->{'locationhash'}}) {
if ($key ne 'total'){ # FIXME - Should ignore 'order', too. if ($_ eq 'notavailable') {
#$data->{'location'}.="$key $counts->{$key} "; $notavailabletext="Not available";
$totalitemcounts+=$counts->{$key}; my $c=$data->{'locationhash'}->{$_};
$data->{'locationhash'}->{$key}=$counts->{$key}; if ($totalitemcounts>1) {
} $notavailabletext.=" ($c)";
} }
my $locationtext=''; } else {
my $notavailabletext=''; $locationtext.="$_";
foreach (sort keys %{$data->{'locationhash'}}) { my $c=$data->{'locationhash'}->{$_};
if ($_ eq 'notavailable') { if ($totalitemcounts>1) {
$notavailabletext="Not available"; $locationtext.=" ($c), ";
my $c=$data->{'locationhash'}->{$_}; }
if ($totalitemcounts>1) { }
$notavailabletext.=" ($c)"; }
} if ($notavailabletext) {
} else { $locationtext.=$notavailabletext;
$locationtext.="$_"; } else {
my $c=$data->{'locationhash'}->{$_}; $locationtext=~s/, $//;
if ($totalitemcounts>1) { }
$locationtext.=" ($c), "; $data->{'location'}=$locationtext;
} $data->{'subject2'}=$subject2;
} }
} }
if ($notavailabletext) { return ($count,@results);
$locationtext.=$notavailabletext;
} else {
$locationtext=~s/, $//;
}
$data->{'location'}=$locationtext;
$data->{'subject2'}=$subject2;
}
}
return ($count,@results);
} }
=item KeywordSearch =item KeywordSearch
@ -859,307 +859,295 @@ not ordered.
=cut =cut
#' #'
sub CatSearch { sub CatSearch {
my ($env,$type,$search,$num,$offset)=@_; my ($env,$type,$search,$num,$offset)=@_;
my $dbh = C4::Context->dbh; warn "type = $type";
my $query = ''; my $dbh = C4::Context->dbh;
my @results; my $query = '';
# FIXME - Why not just my @results;
# $search->{'title'} = quotemeta($search->{'title'}) # FIXME - Why not just
# to escape all questionable characters, not just single-quotes? # $search->{'title'} = quotemeta($search->{'title'})
$search->{'title'}=~ s/'/\\'/g; # to escape all questionable characters, not just single-quotes?
$search->{'author'}=~ s/'/\\'/g; $search->{'title'}=~ s/'/\\'/g;
$search->{'illustrator'}=~ s/'/\\'/g; $search->{'author'}=~ s/'/\\'/g;
my $title = lc($search->{'title'}); $search->{'illustrator'}=~ s/'/\\'/g;
my $title = lc($search->{'title'});
if ($type eq 'loose') { if ($type eq 'loose') {
if ($search->{'author'} ne ''){ if ($search->{'author'} ne ''){
my @key=split(' ',$search->{'author'}); my @key=split(' ',$search->{'author'});
my $count=@key; my $count=@key;
my $i=1; my $i=1;
$query="select *,biblio.author,biblio.biblionumber from $query="select *,biblio.author,biblio.biblionumber from
biblio biblio
left join additionalauthors left join additionalauthors
on additionalauthors.biblionumber =biblio.biblionumber on additionalauthors.biblionumber =biblio.biblionumber
where where
((biblio.author like '$key[0]%' or biblio.author like '% $key[0]%' or ((biblio.author like '$key[0]%' or biblio.author like '% $key[0]%' or
additionalauthors.author like '$key[0]%' or additionalauthors.author additionalauthors.author like '$key[0]%' or additionalauthors.author
like '% $key[0]%' like '% $key[0]%'
)"; )";
while ($i < $count){ while ($i < $count){
$query .= " and ( $query .= " and (
biblio.author like '$key[$i]%' or biblio.author like '% $key[$i]%' or biblio.author like '$key[$i]%' or biblio.author like '% $key[$i]%' or
additionalauthors.author like '$key[$i]%' or additionalauthors.author like '% $key[$i]%' additionalauthors.author like '$key[$i]%' or additionalauthors.author like '% $key[$i]%'
)"; )";
$i++; $i++;
} }
$query .= ")"; $query .= ")";
if ($search->{'title'} ne ''){ if ($search->{'title'} ne ''){
my @key=split(' ',$search->{'title'}); my @key=split(' ',$search->{'title'});
my $count=@key; my $count=@key;
my $i=0; my $i=0;
$query.= " and (((title like '$key[0]%' or title like '% $key[0]%' or title like '% $key[0]')"; $query.= " and (((title like '$key[0]%' or title like '% $key[0]%' or title like '% $key[0]')";
while ($i<$count){ while ($i<$count){
$query .= " and (title like '$key[$i]%' or title like '% $key[$i]%' or title like '% $key[$i]')"; $query .= " and (title like '$key[$i]%' or title like '% $key[$i]%' or title like '% $key[$i]')";
$i++; $i++;
} }
# $query.=") or ((subtitle like '$key[0]%' or subtitle like '% $key[0] %' or subtitle like '% $key[0]')"; $query.=") or ((seriestitle like '$key[0]%' or seriestitle like '% $key[0]%' or seriestitle like '% $key[0]')";
# for ($i=1;$i<$count;$i++){ for ($i=1;$i<$count;$i++){
# $query.=" and (subtitle like '$key[$i]%' or subtitle like '% $key[$i] %' or subtitle like '% $key[$i]')"; $query.=" and (seriestitle like '$key[$i]%' or seriestitle like '% $key[$i]%')";
# } }
$query.=") or ((seriestitle like '$key[0]%' or seriestitle like '% $key[0]%' or seriestitle like '% $key[0]')"; $query.=") or ((unititle like '$key[0]%' or unititle like '% $key[0]%' or unititle like '% $key[0]')";
for ($i=1;$i<$count;$i++){ for ($i=1;$i<$count;$i++){
$query.=" and (seriestitle like '$key[$i]%' or seriestitle like '% $key[$i]%')"; $query.=" and (unititle like '$key[$i]%' or unititle like '% $key[$i]%')";
} }
$query.=") or ((unititle like '$key[0]%' or unititle like '% $key[0]%' or unititle like '% $key[0]')"; $query .= "))";
for ($i=1;$i<$count;$i++){ #$query=$query. " and (title like '%$search->{'title'}%'
$query.=" and (unititle like '$key[$i]%' or unititle like '% $key[$i]%')"; #or seriestitle like '%$search->{'title'}%')";
} }
$query .= "))"; if ($search->{'abstract'} ne ''){
#$query=$query. " and (title like '%$search->{'title'}%' $query.= " and (abstract like '%$search->{'abstract'}%')";
#or seriestitle like '%$search->{'title'}%')"; }
} if ($search->{'date-before'} ne ''){
if ($search->{'abstract'} ne ''){ $query.= " and (copyrightdate like '%$search->{'date-before'}%')";
$query.= " and (abstract like '%$search->{'abstract'}%')"; }
} $query.=" group by biblio.biblionumber";
if ($search->{'date-before'} ne ''){ } else {
$query.= " and (copyrightdate like '%$search->{'date-before'}%')"; if ($search->{'title'} ne '') {
} if ($search->{'ttype'} eq 'exact'){
$query="select * from biblio
$query.=" group by biblio.biblionumber"; where
} else { (biblio.title='$search->{'title'}' or (biblio.unititle = '$search->{'title'}'
if ($search->{'title'} ne '') { or biblio.unititle like '$search->{'title'} |%' or
if ($search->{'ttype'} eq 'exact'){ biblio.unititle like '%| $search->{'title'} |%' or
$query="select * from biblio biblio.unititle like '%| $search->{'title'}') or
where (biblio.seriestitle = '$search->{'title'}' or
(biblio.title='$search->{'title'}' or (biblio.unititle = '$search->{'title'}' biblio.seriestitle like '$search->{'title'} |%' or
or biblio.unititle like '$search->{'title'} |%' or biblio.seriestitle like '%| $search->{'title'} |%' or
biblio.unititle like '%| $search->{'title'} |%' or biblio.seriestitle like '%| $search->{'title'}')
biblio.unititle like '%| $search->{'title'}') or )";
(biblio.seriestitle = '$search->{'title'}' or } else {
biblio.seriestitle like '$search->{'title'} |%' or my @key=split(' ',$search->{'title'});
biblio.seriestitle like '%| $search->{'title'} |%' or my $count=@key;
biblio.seriestitle like '%| $search->{'title'}') my $i=1;
)"; $query="select biblio.biblionumber,author,title,unititle,notes,abstract,serial,seriestitle,copyrightdate,timestamp,subtitle from biblio
} else { left join bibliosubtitle on
my @key=split(' ',$search->{'title'}); biblio.biblionumber=bibliosubtitle.biblionumber
my $count=@key; where
my $i=1; (((title like '$key[0]%' or title like '% $key[0]%' or title like '% $key[0]')";
$query="select * from biblio while ($i<$count){
left join bibliosubtitle on $query .= " and (title like '$key[$i]%' or title like '% $key[$i]%' or title like '% $key[$i]')";
biblio.biblionumber=bibliosubtitle.biblionumber $i++;
where }
(((title like '$key[0]%' or title like '% $key[0]%' or title like '% $key[0]')"; $query.=") or ((subtitle like '$key[0]%' or subtitle like '% $key[0]%' or subtitle like '% $key[0]')";
while ($i<$count){ for ($i=1;$i<$count;$i++){
$query .= " and (title like '$key[$i]%' or title like '% $key[$i]%' or title like '% $key[$i]')"; $query.=" and (subtitle like '$key[$i]%' or subtitle like '% $key[$i]%' or subtitle like '% $key[$i]')";
$i++; }
} $query.=") or ((seriestitle like '$key[0]%' or seriestitle like '% $key[0]%' or seriestitle like '% $key[0]')";
$query.=") or ((subtitle like '$key[0]%' or subtitle like '% $key[0]%' or subtitle like '% $key[0]')"; for ($i=1;$i<$count;$i++){
for ($i=1;$i<$count;$i++){ $query.=" and (seriestitle like '$key[$i]%' or seriestitle like '% $key[$i]%')";
$query.=" and (subtitle like '$key[$i]%' or subtitle like '% $key[$i]%' or subtitle like '% $key[$i]')"; }
} $query.=") or ((unititle like '$key[0]%' or unititle like '% $key[0]%' or unititle like '% $key[0]')";
$query.=") or ((seriestitle like '$key[0]%' or seriestitle like '% $key[0]%' or seriestitle like '% $key[0]')"; for ($i=1;$i<$count;$i++){
for ($i=1;$i<$count;$i++){ $query.=" and (unititle like '$key[$i]%' or unititle like '% $key[$i]%')";
$query.=" and (seriestitle like '$key[$i]%' or seriestitle like '% $key[$i]%')"; }
} $query .= "))";
$query.=") or ((unititle like '$key[0]%' or unititle like '% $key[0]%' or unititle like '% $key[0]')"; }
for ($i=1;$i<$count;$i++){ if ($search->{'abstract'} ne ''){
$query.=" and (unititle like '$key[$i]%' or unititle like '% $key[$i]%')"; $query.= " and (abstract like '%$search->{'abstract'}%')";
} }
$query .= "))"; if ($search->{'date-before'} ne ''){
} $query.= " and (copyrightdate like '%$search->{'date-before'}%')";
if ($search->{'abstract'} ne ''){ }
$query.= " and (abstract like '%$search->{'abstract'}%')"; } elsif ($search->{'class'} ne ''){
} $query="select * from biblioitems,biblio where biblio.biblionumber=biblioitems.biblionumber";
if ($search->{'date-before'} ne ''){ my @temp=split(/\|/,$search->{'class'});
$query.= " and (copyrightdate like '%$search->{'date-before'}%')"; my $count=@temp;
} $query.= " and ( itemtype='$temp[0]'";
} elsif ($search->{'class'} ne ''){ for (my $i=1;$i<$count;$i++){
$query="select * from biblioitems,biblio where biblio.biblionumber=biblioitems.biblionumber"; $query.=" or itemtype='$temp[$i]'";
my @temp=split(/\|/,$search->{'class'}); }
my $count=@temp; $query.=")";
$query.= " and ( itemtype='$temp[0]'"; if ($search->{'illustrator'} ne ''){
for (my $i=1;$i<$count;$i++){ $query.=" and illus like '%".$search->{'illustrator'}."%' ";
$query.=" or itemtype='$temp[$i]'"; }
} if ($search->{'dewey'} ne ''){
$query.=")"; $query.=" and biblioitems.dewey like '$search->{'dewey'}%'";
if ($search->{'illustrator'} ne ''){ }
$query.=" and illus like '%".$search->{'illustrator'}."%' "; } elsif ($search->{'dewey'} ne ''){
} $query="select * from biblioitems,biblio
if ($search->{'dewey'} ne ''){ where biblio.biblionumber=biblioitems.biblionumber
$query.=" and biblioitems.dewey like '$search->{'dewey'}%'"; and biblioitems.dewey like '$search->{'dewey'}%'";
} } elsif ($search->{'illustrator'} ne '') {
} elsif ($search->{'dewey'} ne ''){ $query="select * from biblioitems,biblio
$query="select * from biblioitems,biblio where biblio.biblionumber=biblioitems.biblionumber
where biblio.biblionumber=biblioitems.biblionumber and biblioitems.illus like '%".$search->{'illustrator'}."%'";
and biblioitems.dewey like '$search->{'dewey'}%'"; } elsif ($search->{'publisher'} ne ''){
} elsif ($search->{'illustrator'} ne '') { $query.= "Select * from biblio,biblioitems where biblio.biblionumber
$query="select * from biblioitems,biblio =biblioitems.biblionumber and (publishercode like '%$search->{'publisher'}%')";
where biblio.biblionumber=biblioitems.biblionumber } elsif ($search->{'abstract'} ne ''){
and biblioitems.illus like '%".$search->{'illustrator'}."%'"; $query.= "Select * from biblio where abstract like '%$search->{'abstract'}%'";
} elsif ($search->{'publisher'} ne ''){ } elsif ($search->{'date-before'} ne ''){
$query.= "Select * from biblio,biblioitems where biblio.biblionumber $query.= "Select * from biblio where copyrightdate like '%$search->{'date-before'}%'";
=biblioitems.biblionumber and (publishercode like '%$search->{'publisher'}%')"; }
} elsif ($search->{'abstract'} ne ''){ $query .=" group by biblio.biblionumber";
$query.= "Select * from biblio where abstract like '%$search->{'abstract'}%'"; }
} elsif ($search->{'date-before'} ne ''){
$query.= "Select * from biblio where copyrightdate like '%$search->{'date-before'}%'";
}
$query .=" group by biblio.biblionumber";
}
}
if ($type eq 'subject'){
# FIXME - Subject search is badly broken. The query defined by
# $query returns a single item (the subject), but later code
# expects a ref-to-hash with all sorts of stuff in it.
# Also, the count of items (biblios?) with the given subject is
# wrong.
my @key=split(' ',$search->{'subject'});
my $count=@key;
my $i=1;
$query="select distinct(subject) from bibliosubject where( subject like
'$key[0]%' or subject like '% $key[0]%' or subject like '% $key[0]' or subject like '%($key[0])%')";
while ($i<$count){
$query.=" and (subject like '$key[$i]%' or subject like '% $key[$i]%'
or subject like '% $key[$i]'
or subject like '%($key[$i])%')";
$i++;
}
# FIXME - Wouldn't it be better to fix the database so that if a
# book has a subject "NZ", then it also gets added the subject
# "New Zealand"?
# This can also be generalized by adding a table of subject
# synonyms to the database: just declare "NZ" to be a synonym for
# "New Zealand", "SF" a synonym for both "Science fiction" and
# "Fantastic fiction", etc.
# FIXME - This can be rewritten as
# if (lc($search->{"subject"}) eq "nz") {
if ($search->{'subject'} eq 'NZ' || $search->{'subject'} eq 'nz'){
$query.= " or (subject like 'NEW ZEALAND %' or subject like '% NEW ZEALAND %'
or subject like '% NEW ZEALAND' or subject like '%(NEW ZEALAND)%' ) ";
} elsif ( $search->{'subject'} =~ /^nz /i || $search->{'subject'} =~ / nz /i || $search->{'subject'} =~ / nz$/i){
$query=~ s/ nz/ NEW ZEALAND/ig;
$query=~ s/nz /NEW ZEALAND /ig;
$query=~ s/\(nz\)/\(NEW ZEALAND\)/gi;
}
}
if ($type eq 'precise'){
if ($search->{'item'} ne ''){
$query="select * from items,biblio ";
my $search2=uc $search->{'item'};
$query=$query." where
items.biblionumber=biblio.biblionumber
and barcode='$search2'";
# FIXME - .= <<EOT;
}
if ($search->{'isbn'} ne ''){
my $search2=uc $search->{'isbn'};
my $query1 = "select * from biblioitems where isbn='$search2'";
my $sth1=$dbh->prepare($query1);
# print STDERR "$query1\n";
$sth1->execute;
my $i2=0;
while (my $data=$sth1->fetchrow_hashref) {
$query="select * from biblioitems,biblio where
biblio.biblionumber = $data->{'biblionumber'}
and biblioitems.biblionumber = biblio.biblionumber";
my $sth=$dbh->prepare($query);
$sth->execute;
# FIXME - There's already a $data in this scope.
my $data=$sth->fetchrow_hashref;
my ($dewey, $subclass) = ($data->{'dewey'}, $data->{'subclass'});
# FIXME - The following assumes that the Dewey code is a
# floating-point number. It isn't: it's a string.
$dewey=~s/\.*0*$//;
($dewey == 0) && ($dewey='');
($dewey) && ($dewey.=" $subclass");
$data->{'dewey'}=$dewey;
$results[$i2]=$data;
# $results[$i2]="$data->{'author'}\t$data->{'title'}\t$data->{'biblionumber'}\t$data->{'copyrightdate'}\t$dewey\t$data->{'isbn'}\t$data->{'itemtype'}";
$i2++;
$sth->finish;
} }
$sth1->finish; if ($type eq 'subject'){
} # FIXME - Subject search is badly broken. The query defined by
} # $query returns a single item (the subject), but later code
#print $query; # expects a ref-to-hash with all sorts of stuff in it.
if ($type ne 'precise' && $type ne 'subject'){ # Also, the count of items (biblios?) with the given subject is
if ($search->{'author'} ne ''){ # wrong.
$query .= " order by biblio.author,title";
} else {
$query .= " order by title";
}
} else {
if ($type eq 'subject'){
$query .= " order by subject";
}
}
#print STDERR "$query\n";
my $sth=$dbh->prepare($query);
$sth->execute;
my $count=1;
my $i=0;
my $limit= $num+$offset;
while (my $data=$sth->fetchrow_hashref){
my $query="select dewey,subclass,publishercode from biblioitems where biblionumber=$data->{'biblionumber'}";
if ($search->{'class'} ne ''){
my @temp=split(/\|/,$search->{'class'});
my $count=@temp;
$query.= " and ( itemtype='$temp[0]'";
for (my $i=1;$i<$count;$i++){
$query.=" or itemtype='$temp[$i]'";
}
$query.=")";
}
if ($search->{'dewey'} ne ''){
$query.=" and dewey='$search->{'dewey'}' ";
}
if ($search->{'illustrator'} ne ''){
$query.=" and illus like '%".$search->{'illustrator'}."%' ";
}
if ($search->{'publisher'} ne ''){
$query.= " and (publishercode like '%$search->{'publisher'}%')";
}
my $sti=$dbh->prepare($query); my @key=split(' ',$search->{'subject'});
$sti->execute; my $count=@key;
my $dewey; my $i=1;
my $subclass; $query="select distinct(subject) from bibliosubject where( subject like
my $true=0; '$key[0]%' or subject like '% $key[0]%' or subject like '% $key[0]' or subject like '%($key[0])%')";
my $publishercode; while ($i<$count){
my $bibitemdata; $query.=" and (subject like '$key[$i]%' or subject like '% $key[$i]%'
if ($bibitemdata = $sti->fetchrow_hashref() || $type eq 'subject'){ or subject like '% $key[$i]'
$true=1; or subject like '%($key[$i])%')";
$dewey=$bibitemdata->{'dewey'}; $i++;
$subclass=$bibitemdata->{'subclass'}; }
$publishercode=$bibitemdata->{'publishercode'};
} # FIXME - Wouldn't it be better to fix the database so that if a
# print STDERR "$dewey $subclass $publishercode\n"; # book has a subject "NZ", then it also gets added the subject
# FIXME - The Dewey code is a string, not a number. # "New Zealand"?
$dewey=~s/\.*0*$//; # This can also be generalized by adding a table of subject
($dewey == 0) && ($dewey=''); # synonyms to the database: just declare "NZ" to be a synonym for
($dewey) && ($dewey.=" $subclass"); # "New Zealand", "SF" a synonym for both "Science fiction" and
$data->{'dewey'}=$dewey; # "Fantastic fiction", etc.
$data->{'publishercode'}=$publishercode;
$sti->finish; # FIXME - This can be rewritten as
if ($true == 1){ # if (lc($search->{"subject"}) eq "nz") {
if ($count > $offset && $count <= $limit){ if ($search->{'subject'} eq 'NZ' || $search->{'subject'} eq 'nz'){
$results[$i]=$data; $query.= " or (subject like 'NEW ZEALAND %' or subject like '% NEW ZEALAND %'
$i++; or subject like '% NEW ZEALAND' or subject like '%(NEW ZEALAND)%' ) ";
} } elsif ( $search->{'subject'} =~ /^nz /i || $search->{'subject'} =~ / nz /i || $search->{'subject'} =~ / nz$/i){
$count++; $query=~ s/ nz/ NEW ZEALAND/ig;
} $query=~ s/nz /NEW ZEALAND /ig;
} $query=~ s/\(nz\)/\(NEW ZEALAND\)/gi;
$sth->finish; }
#if ($type ne 'precise'){ }
$count--; if ($type eq 'precise'){
#} if ($search->{'itemnumber'} ne ''){
#$count--; $query="select * from items,biblio ";
return($count,@results); my $search2=uc $search->{'itemnumber'};
$query=$query." where
items.biblionumber=biblio.biblionumber
and barcode='$search2'";
# FIXME - .= <<EOT;
}
if ($search->{'isbn'} ne ''){
my $search2=uc $search->{'isbn'};
my $query1 = "select * from biblioitems where isbn='$search2'";
my $sth1=$dbh->prepare($query1);
# print STDERR "$query1\n";
$sth1->execute;
my $i2=0;
while (my $data=$sth1->fetchrow_hashref) {
$query="select * from biblioitems,biblio where
biblio.biblionumber = $data->{'biblionumber'}
and biblioitems.biblionumber = biblio.biblionumber";
my $sth=$dbh->prepare($query);
$sth->execute;
# FIXME - There's already a $data in this scope.
my $data=$sth->fetchrow_hashref;
my ($dewey, $subclass) = ($data->{'dewey'}, $data->{'subclass'});
# FIXME - The following assumes that the Dewey code is a
# floating-point number. It isn't: it's a string.
$dewey=~s/\.*0*$//;
($dewey == 0) && ($dewey='');
($dewey) && ($dewey.=" $subclass");
$data->{'dewey'}=$dewey;
$results[$i2]=$data;
# $results[$i2]="$data->{'author'}\t$data->{'title'}\t$data->{'biblionumber'}\t$data->{'copyrightdate'}\t$dewey\t$data->{'isbn'}\t$data->{'itemtype'}";
$i2++;
$sth->finish;
}
$sth1->finish;
}
}
if ($type ne 'precise' && $type ne 'subject'){
if ($search->{'author'} ne ''){
$query .= " order by biblio.author,title";
} else {
$query .= " order by title";
}
} else {
if ($type eq 'subject'){
$query .= " order by subject";
}
}
my $sth=$dbh->prepare($query);
$sth->execute;
my $count=1;
my $i=0;
my $limit= $num+$offset;
while (my $data=$sth->fetchrow_hashref){
my $query="select dewey,subclass,publishercode from biblioitems where biblionumber=$data->{'biblionumber'}";
if ($search->{'class'} ne ''){
my @temp=split(/\|/,$search->{'class'});
my $count=@temp;
$query.= " and ( itemtype='$temp[0]'";
for (my $i=1;$i<$count;$i++){
$query.=" or itemtype='$temp[$i]'";
}
$query.=")";
}
if ($search->{'dewey'} ne ''){
$query.=" and dewey='$search->{'dewey'}' ";
}
if ($search->{'illustrator'} ne ''){
$query.=" and illus like '%".$search->{'illustrator'}."%' ";
}
if ($search->{'publisher'} ne ''){
$query.= " and (publishercode like '%$search->{'publisher'}%')";
}
warn $query;
my $sti=$dbh->prepare($query);
$sti->execute;
my $dewey;
my $subclass;
my $true=0;
my $publishercode;
my $bibitemdata;
if ($bibitemdata = $sti->fetchrow_hashref() || $type eq 'subject'){
$true=1;
$dewey=$bibitemdata->{'dewey'};
$subclass=$bibitemdata->{'subclass'};
$publishercode=$bibitemdata->{'publishercode'};
}
# print STDERR "$dewey $subclass $publishercode\n";
# FIXME - The Dewey code is a string, not a number.
$dewey=~s/\.*0*$//;
($dewey == 0) && ($dewey='');
($dewey) && ($dewey.=" $subclass");
$data->{'dewey'}=$dewey;
$data->{'publishercode'}=$publishercode;
$sti->finish;
if ($true == 1){
if ($count > $offset && $count <= $limit){
$results[$i]=$data;
$i++;
}
$count++;
}
}
$sth->finish;
$count--;
return($count,@results);
} }
sub updatesearchstats{ sub updatesearchstats{
@ -2382,6 +2370,87 @@ and itemtype = 'WEB'";
} # sub getwebbiblioitems } # sub getwebbiblioitems
=item breedingsearch
($count, @results) = &breedingsearch($title);
C<$count> is the number of items in C<@results>. C<@results> is an
array of references-to-hash; the keys are the items from the
C<marc_breeding> table of the Koha database.
=cut
sub breedingsearch {
my ($title,$isbn) = @_;
my $dbh = C4::Context->dbh;
my $count = 0;
my $query;
my $sth;
my @results;
$query = "Select id,file,isbn,title,author from marc_breeding where ";
if ($title) {
$query .= "title like \"$title%\"";
}
if ($title && $isbn) {
$query .= " and ";
}
if ($isbn) {
$query .= "isbn like \"$isbn%\"";
}
$sth = $dbh->prepare($query);
$sth->execute;
while (my $data = $sth->fetchrow_hashref) {
$results[$count] = $data;
$count++;
} # while
$sth->finish;
return($count, @results);
} # sub breedingsearch
=item isbnsearch
($count, @results) = &isbnsearch($isbn,$title);
Given an isbn and/or a title, returns the biblios having it.
Used in acqui.simple, isbnsearch.pl only
C<$count> is the number of items in C<@results>. C<@results> is an
array of references-to-hash; the keys are the items from the
C<biblioitems> table of the Koha database.
=cut
sub isbnsearch {
my ($isbn,$title) = @_;
my $dbh = C4::Context->dbh;
my $count = 0;
my $query;
my $sth;
my @results;
$query = "Select distinct biblio.* from biblio, biblioitems where
biblio.biblionumber = biblioitems.biblionumber";
if ($isbn) {
$query .= " and isbn=".$dbh->quote($isbn);
}
if ($title) {
$query .= " and title like ".$dbh->quote($title."%");
}
warn $query;
$sth = $dbh->prepare($query);
$sth->execute;
while (my $data = $sth->fetchrow_hashref) {
$results[$count] = $data;
$count++;
} # while
$sth->finish;
return($count, @results);
} # sub isbnsearch
END { } # module clean-up code here (global destructor) END { } # module clean-up code here (global destructor)
1; 1;