speeding up searches ... well trying to

This commit is contained in:
chris 1999-12-15 21:52:51 +00:00
parent 1c691d272f
commit 65a02afae3
3 changed files with 26 additions and 70 deletions

View file

@ -7,7 +7,7 @@ use strict;
require Exporter; require Exporter;
use DBI; use DBI;
use C4::Database; use C4::Database;
use C4::InterfaceCDK; #use C4::InterfaceCDK;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
# set the version for version checking # set the version for version checking
@ -54,37 +54,25 @@ my $priv_func = sub {
sub KeywordSearch { sub KeywordSearch {
my ($env,$type,$search,$num,$offset)=@_; my ($env,$type,$search,$num,$offset)=@_;
my $dbh = &C4Connect; my $dbh = &C4Connect;
my $query="(Select * from biblio,catalogueentry my $query ="Select count(*) from biblio where author ~* '$search->{'keyword'}' or
where (catalogueentry.catalogueentry=biblio.author and title ~* '$search->{'keyword'}'";
catalogueentry.entrytype='a' and catalogueentry.catalogueentry ~* # print $query;
'$search->{'keyword'}') union select * from biblio,catalogueentry where
(catalogueentry.catalogueentry=biblio.title and
catalogueentry.entrytype='t' and catalogueentry.catalogueentry ~*
'$search->{'keyword'}')) order by biblio.title";
my $query ="Select * from biblio where author ~* '$search->{'keyword'}' or
title ~* '$search->{'keyword'}'";
my $sth=$dbh->prepare($query); my $sth=$dbh->prepare($query);
# print $query; # $sth->execute;
$sth->execute; my $count2=$sth->fetchrow_hashref;
$sth->finish;
my $i=0; my $i=0;
my $i2=0; my $count=$count2->{'count'};
my $limit=$num+$offset;
my $count=0;
my @results; my @results;
while (my $data=$sth->fetchrow_hashref){ $query=~ s/count\(\*\)/\*/;
$count++; $query=$query." order by title limit $num,$offset";
}
$sth->finish;
# $query=$query." limit $num,$offset";
$sth=$dbh->prepare($query); $sth=$dbh->prepare($query);
$sth->execute; $sth->execute;
# print $query; #
while ((my $data=$sth->fetchrow_hashref) && $i < $limit){ while (my $data=$sth->fetchrow_hashref){
if ($i >= $offset){
$results[$i2]="$data->{'biblionumber'}\t$data->{'title'}\t$data->{'author'}"; $results[$i]="$data->{'biblionumber'}\t$data->{'title'}\t$data->{'author'}";
$i2++; $i++;
}
$i++;
} }
$sth->finish; $sth->finish;
$dbh->disconnect; $dbh->disconnect;
@ -97,46 +85,17 @@ sub CatSearch {
my $query = ''; my $query = '';
my $title = lc($search->{'title'}); my $title = lc($search->{'title'});
if ($type eq 'loose') { if ($type eq 'loose') {
# $query="Select count(*) from biblio,catalogueentry";
if ($search->{'author'} ne ''){ if ($search->{'author'} ne ''){
$query="select biblio.biblionumber,title,author from $query="select biblio.biblionumber,title,author from
biblio,catalogueentry biblio
where (catalogueentry.entrytype='a' and where biblio.author ~* '$search->{'author'}'";
(catalogueentry.catalogueentry = biblio.author) if ($search->{'title'} ne ''){
and (lower(catalogueentry.catalogueentry) ~* lower('$search->{'author'}'))) union $query=$query. " and title ~* '$search->{'title'}'";
select biblio.biblionumber,title,author from biblio,biblioanalysis }
where biblioanalysis.analyticalauthor ~* '$search->{'author'}'
and biblioanalysis.biblionumber=
biblio.biblionumber";
# if ($search->{'title'} ne ''){
# }
} else { } else {
if ($search->{'title'} ne ''){ if ($search->{'title'} ne ''){
$query="select biblio.biblionumber,title,author $query="select biblionumber,title,author from biblio
from biblio,catalogueentry where where title ~* '$search->{'title'}'";
(lower(catalogueentry.catalogueentry) = '$title'
and entrytype = 't')
and
(catalogueentry.catalogueentry = biblio.title)"
#union select
#biblio.biblionumber,title,author from
#biblioanalysis,biblio where analyticaltitle ~*
#'^$search->{'title'}' and
#biblio.biblionumber=biblioanalysis.biblionumber
#union select biblio.biblionumber,title,author from
#biblio,bibliosubtitle where subtitle ~* '^$search->{'title'}' and
#biblio.biblionumber=bibliosubtitle.biblionumber";
#$query="select biblio.biblionumber,title,author from biblio,catalogueentry where ((catalogueentry.catalogueentry = biblio.title)
#and (lower(catalogueentry.catalogueentry) ~* lower('^$search->{'title'}'))
#and (entrytype = 't')) union select
#biblio.biblionumber,title,author from
#biblioanalysis,biblio where analyticaltitle ~*
#'^$search->{'title'}' and
#biblio.biblionumber=biblioanalysis.biblionumber
#union select biblio.biblionumber,title,author from
#biblio,bibliosubtitle where subtitle ~* '^$search->{'title'}' and
#biblio.biblionumber=bibliosubtitle.biblionumber";
} }
} }
} }

View file

@ -51,9 +51,11 @@ if ($itemnumber ne '' || $isbn ne ''){
($count,@results)=&CatSearch(\$blah,'subject',\%search,$num,$offset); ($count,@results)=&CatSearch(\$blah,'subject',\%search,$num,$offset);
} else { } else {
if ($keyword ne ''){ if ($keyword ne ''){
# print "hey";
($count,@results)=&KeywordSearch(\$blah,'intra',\%search,$num,$offset); ($count,@results)=&KeywordSearch(\$blah,'intra',\%search,$num,$offset);
} else { } else {
($count,@results)=&CatSearch(\$blah,'loose',\%search,$num,$offset); ($count,@results)=&CatSearch(\$blah,'loose',\%search,$num,$offset);
print "hey";
} }
} }
} }

View file

@ -2,11 +2,6 @@
use strict; use strict;
#use DBI; #use DBI;
use C4::Interface2; use C4::Search;
print "hello";
startint("Circulation");
my $data=dialog("Borrower");
print $data;
endint();