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
@ -195,16 +196,15 @@ HTML.
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 { } else {
if ($search->{'subject'} ne ''){ if ($search->{'subject'} ne ''){
($count,@results)=CatSearch($env,'subject',$search,$num,$offset); ($count,@results)=CatSearch($env,'subject',$search,$num,$offset);
@ -860,6 +860,7 @@ not ordered.
#' #'
sub CatSearch { sub CatSearch {
my ($env,$type,$search,$num,$offset)=@_; my ($env,$type,$search,$num,$offset)=@_;
warn "type = $type";
my $dbh = C4::Context->dbh; my $dbh = C4::Context->dbh;
my $query = ''; my $query = '';
my @results; my @results;
@ -870,7 +871,6 @@ sub CatSearch {
$search->{'author'}=~ s/'/\\'/g; $search->{'author'}=~ s/'/\\'/g;
$search->{'illustrator'}=~ s/'/\\'/g; $search->{'illustrator'}=~ s/'/\\'/g;
my $title = lc($search->{'title'}); 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'});
@ -902,10 +902,6 @@ sub CatSearch {
$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]')";
# for ($i=1;$i<$count;$i++){
# $query.=" and (subtitle like '$key[$i]%' or subtitle like '% $key[$i] %' or subtitle like '% $key[$i]')";
# }
$query.=") or ((seriestitle like '$key[0]%' or seriestitle like '% $key[0]%' or seriestitle 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 (seriestitle like '$key[$i]%' or seriestitle like '% $key[$i]%')"; $query.=" and (seriestitle like '$key[$i]%' or seriestitle like '% $key[$i]%')";
@ -924,7 +920,6 @@ sub CatSearch {
if ($search->{'date-before'} ne ''){ if ($search->{'date-before'} ne ''){
$query.= " and (copyrightdate like '%$search->{'date-before'}%')"; $query.= " and (copyrightdate like '%$search->{'date-before'}%')";
} }
$query.=" group by biblio.biblionumber"; $query.=" group by biblio.biblionumber";
} else { } else {
if ($search->{'title'} ne '') { if ($search->{'title'} ne '') {
@ -944,7 +939,7 @@ sub CatSearch {
my @key=split(' ',$search->{'title'}); my @key=split(' ',$search->{'title'});
my $count=@key; my $count=@key;
my $i=1; my $i=1;
$query="select * from biblio $query="select biblio.biblionumber,author,title,unititle,notes,abstract,serial,seriestitle,copyrightdate,timestamp,subtitle from biblio
left join bibliosubtitle on left join bibliosubtitle on
biblio.biblionumber=bibliosubtitle.biblionumber biblio.biblionumber=bibliosubtitle.biblionumber
where where
@ -1001,7 +996,6 @@ sub CatSearch {
=biblioitems.biblionumber and (publishercode like '%$search->{'publisher'}%')"; =biblioitems.biblionumber and (publishercode like '%$search->{'publisher'}%')";
} elsif ($search->{'abstract'} ne ''){ } elsif ($search->{'abstract'} ne ''){
$query.= "Select * from biblio where abstract like '%$search->{'abstract'}%'"; $query.= "Select * from biblio where abstract like '%$search->{'abstract'}%'";
} elsif ($search->{'date-before'} ne ''){ } elsif ($search->{'date-before'} ne ''){
$query.= "Select * from biblio where copyrightdate like '%$search->{'date-before'}%'"; $query.= "Select * from biblio where copyrightdate like '%$search->{'date-before'}%'";
} }
@ -1047,10 +1041,9 @@ sub CatSearch {
} }
} }
if ($type eq 'precise'){ if ($type eq 'precise'){
if ($search->{'itemnumber'} ne ''){
if ($search->{'item'} ne ''){
$query="select * from items,biblio "; $query="select * from items,biblio ";
my $search2=uc $search->{'item'}; my $search2=uc $search->{'itemnumber'};
$query=$query." where $query=$query." where
items.biblionumber=biblio.biblionumber items.biblionumber=biblio.biblionumber
and barcode='$search2'"; and barcode='$search2'";
@ -1060,7 +1053,7 @@ sub CatSearch {
my $search2=uc $search->{'isbn'}; my $search2=uc $search->{'isbn'};
my $query1 = "select * from biblioitems where isbn='$search2'"; my $query1 = "select * from biblioitems where isbn='$search2'";
my $sth1=$dbh->prepare($query1); my $sth1=$dbh->prepare($query1);
# print STDERR "$query1\n"; # print STDERR "$query1\n";
$sth1->execute; $sth1->execute;
my $i2=0; my $i2=0;
while (my $data=$sth1->fetchrow_hashref) { while (my $data=$sth1->fetchrow_hashref) {
@ -1079,32 +1072,30 @@ sub CatSearch {
($dewey) && ($dewey.=" $subclass"); ($dewey) && ($dewey.=" $subclass");
$data->{'dewey'}=$dewey; $data->{'dewey'}=$dewey;
$results[$i2]=$data; $results[$i2]=$data;
# $results[$i2]="$data->{'author'}\t$data->{'title'}\t$data->{'biblionumber'}\t$data->{'copyrightdate'}\t$dewey\t$data->{'isbn'}\t$data->{'itemtype'}"; # $results[$i2]="$data->{'author'}\t$data->{'title'}\t$data->{'biblionumber'}\t$data->{'copyrightdate'}\t$dewey\t$data->{'isbn'}\t$data->{'itemtype'}";
$i2++; $i2++;
$sth->finish; $sth->finish;
} }
$sth1->finish; $sth1->finish;
} }
} }
#print $query; if ($type ne 'precise' && $type ne 'subject'){
if ($type ne 'precise' && $type ne 'subject'){
if ($search->{'author'} ne ''){ if ($search->{'author'} ne ''){
$query .= " order by biblio.author,title"; $query .= " order by biblio.author,title";
} else { } else {
$query .= " order by title"; $query .= " order by title";
} }
} else { } else {
if ($type eq 'subject'){ if ($type eq 'subject'){
$query .= " order by subject"; $query .= " order by subject";
} }
} }
#print STDERR "$query\n"; my $sth=$dbh->prepare($query);
my $sth=$dbh->prepare($query); $sth->execute;
$sth->execute; my $count=1;
my $count=1; my $i=0;
my $i=0; my $limit= $num+$offset;
my $limit= $num+$offset; while (my $data=$sth->fetchrow_hashref){
while (my $data=$sth->fetchrow_hashref){
my $query="select dewey,subclass,publishercode from biblioitems where biblionumber=$data->{'biblionumber'}"; my $query="select dewey,subclass,publishercode from biblioitems where biblionumber=$data->{'biblionumber'}";
if ($search->{'class'} ne ''){ if ($search->{'class'} ne ''){
my @temp=split(/\|/,$search->{'class'}); my @temp=split(/\|/,$search->{'class'});
@ -1124,7 +1115,7 @@ while (my $data=$sth->fetchrow_hashref){
if ($search->{'publisher'} ne ''){ if ($search->{'publisher'} ne ''){
$query.= " and (publishercode like '%$search->{'publisher'}%')"; $query.= " and (publishercode like '%$search->{'publisher'}%')";
} }
warn $query;
my $sti=$dbh->prepare($query); my $sti=$dbh->prepare($query);
$sti->execute; $sti->execute;
my $dewey; my $dewey;
@ -1138,7 +1129,7 @@ while (my $data=$sth->fetchrow_hashref){
$subclass=$bibitemdata->{'subclass'}; $subclass=$bibitemdata->{'subclass'};
$publishercode=$bibitemdata->{'publishercode'}; $publishercode=$bibitemdata->{'publishercode'};
} }
# print STDERR "$dewey $subclass $publishercode\n"; # print STDERR "$dewey $subclass $publishercode\n";
# FIXME - The Dewey code is a string, not a number. # FIXME - The Dewey code is a string, not a number.
$dewey=~s/\.*0*$//; $dewey=~s/\.*0*$//;
($dewey == 0) && ($dewey=''); ($dewey == 0) && ($dewey='');
@ -1153,13 +1144,10 @@ while (my $data=$sth->fetchrow_hashref){
} }
$count++; $count++;
} }
} }
$sth->finish; $sth->finish;
#if ($type ne 'precise'){
$count--; $count--;
#} return($count,@results);
#$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;