Browse Source

ordering of search results

master
chris 22 years ago
parent
commit
54fcb2c357
  1. 28
      C4/Search.pm
  2. 2
      opac-search.pl

28
C4/Search.pm

@ -54,10 +54,24 @@ my $priv_func = sub {
sub KeywordSearch {
my ($env,$type,$search,$num,$offset)=@_;
my $dbh = &C4Connect;
my $query ="Select count(*) from biblio where author like
'%$search->{'keyword'}%' or
title like '%$search->{'keyword'}%'";
my @key=split(' ',$search->{'keyword'});
my $count=@key;
my $i=1;
my $query ="Select count(*) from biblio where
(author like
'%$key[0]%' ";
while ($i < $count){
$query=$query." and author like '%$key[$i]%'";
$i++;
}
$i=1;
$query=$query.") or
(title like '%$key[0]%'";
while ($i < $count){
$query=$query." and title like '%$key[$i]%'";
$i++;
}
$query=$query.")";
my $sth=$dbh->prepare($query);
$sth->execute;
my $count2=$sth->fetchrow_arrayref;
@ -66,7 +80,11 @@ sub KeywordSearch {
my $count=$count2->[0];
my @results;
$query=~ s/count\(\*\)/\*/;
$query=$query." order by title limit $offset,$num";
if ($type ne 'intra'){
$query=$query." order by title limit $offset,$num";
} else {
$query=$query." order by author limit $offset,$num";
}
$sth=$dbh->prepare($query);
# print $query;
$sth->execute;

2
opac-search.pl

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

Loading…
Cancel
Save