[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Koha-cvs] koha/C4 Search.pm [dev_week]
From: |
Joshua Ferraro |
Subject: |
[Koha-cvs] koha/C4 Search.pm [dev_week] |
Date: |
Wed, 15 Nov 2006 19:18:48 +0000 |
CVSROOT: /sources/koha
Module name: koha
Branch: dev_week
Changes by: Joshua Ferraro <kados> 06/11/15 19:18:48
Modified files:
C4 : Search.pm
Log message:
adding catalogsearch back to Search.pm. Back up your Search.pm before
updating
as there may be some NPL-specific stuff in this ...
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/C4/Search.pm?cvsroot=koha&only_with_tag=dev_week&r1=1.99.2.11.2.31&r2=1.99.2.11.2.32
Patches:
Index: Search.pm
===================================================================
RCS file: /sources/koha/koha/C4/Search.pm,v
retrieving revision 1.99.2.11.2.31
retrieving revision 1.99.2.11.2.32
diff -u -b -r1.99.2.11.2.31 -r1.99.2.11.2.32
--- Search.pm 9 Oct 2006 14:56:30 -0000 1.99.2.11.2.31
+++ Search.pm 15 Nov 2006 19:18:48 -0000 1.99.2.11.2.32
@@ -39,7 +39,7 @@
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
# set the version for version checking
-$VERSION = do { my @v = '$Revision: 1.99.2.11.2.31 $' =~ /\d+/g;
+$VERSION = do { my @v = '$Revision: 1.99.2.11.2.32 $' =~ /\d+/g;
shift(@v) . "." . join("_", map {sprintf "%03d", $_ } @v); };
=head1 NAME
@@ -1264,9 +1264,23 @@
if ($datedue eq ''){
# $datedue="Available";
my
($restype,$reserves)=C4::Reserves2::CheckReserves($data->{'itemnumber'});
+ #use Data::Dumper;
+ #warn "restype: $restype,$reserves";
+ #warn Dumper($reserves);
+ #FIXME: Templatize this
if ($restype) {
# $datedue=$restype;
- $count_reserves = $restype;
+ #warn "RESERVE:".$reserves->{'itemnumber'}.":
".$reserves->{'found'};
+ if ($reserves->{'found'} eq "W") {
+ if ($reserves->{'branchcode'} eq
$data->{'holdingbranch'}) {
+ $count_reserves = "Waiting";
#$reserves->{'found'}; #stype;
+ } else {
+ $count_reserves = "In Transit
from ".$data->{'holdingbranch'}." to ".$reserves->{'branchcode'};
+ }
+ }
+ else {
+ $count_reserves = "Reserved";
+ }
}
}
$isth->finish;
@@ -1289,7 +1303,7 @@
$sthnflstatus = $dbh->prepare("select lib from
authorised_values where category=? and authorised_value=?");
$sthnflstatus->execute($authorised_valuecode,$data->{notforloan});
my ($lib) = $sthnflstatus->fetchrow;
- #warn "lib: $lib from
$authorised_valuecode,$data->{notforloan}";
+ # warn "lib: $lib from
$authorised_valuecode,$data->{notforloan}";
$data->{notforloan} = $lib;
}
@@ -1738,35 +1752,68 @@
my $query = ""; my $count; my @data;
my @bind=();
+ ### ADDED by JF: Special check for follett barcodes of length == 10
(strictly numeric)
+ #
+ # Remove leading spaces from the searchstring
+ $searchstring =~s/^ //g;
+ if (length($searchstring)==10 and ($searchstring =~ m/^\d+$/)) {
+ $searchstring = substr($searchstring,0, -3);
+ }
+
if($type eq "simple") # simple search for one letter only
{
- $query="Select * from borrowers where surname like
'$searchstring%' order by $orderby";
-# @bind=("$searchstring%");
+ $query="Select * from borrowers where surname like ? order by
$orderby";
+ @bind=("$searchstring%");
}
+
+ else
+ {
+ @data=split(' ',$searchstring);
+ address@hidden;
+ $query="SELECT * FROM borrowers
+ WHERE ((surname LIKE ? OR surname LIKE ?
+ OR firstname LIKE ? OR firstname LIKE ?
+ OR othernames LIKE ? OR othernames LIKE ?)
+ ";
+ @bind=("$data[0]%","% $data[0]%","$data[0]%","%
$data[0]%","$data[0]%","% $data[0]%");
+ for (my $i=1;$i<$count;$i++){
+ $query=$query." AND (".
+ " surname LIKE ? OR surname LIKE ?
+ OR firstname LIKE ? OR firstname LIKE ?
+ OR othernames LIKE ? OR othernames LIKE ?)";
+ push(@bind,"$data[$i]%","% $data[$i]%","$data[$i]%","%
$data[$i]%","$data[$i]%","% $data[$i]%");
+ # FIXME - .= <<EOT;
+ }
+ $query=$query.") OR cardnumber = ?";
+ $query=$query." ORDER BY $orderby" if $orderby;
+ #surname,firstname";
+ push(@bind,$searchstring);
+ }
+
+=head
else # advanced search looking in surname, firstname and othernames
{
-### Try to determine whether numeric like cardnumber
+ ### Try to determine whether numeric like cardnumber
if ($searchstring+1>1) {
$query="Select * from borrowers where cardnumber like
'$searchstring%' ";
-
}else{
my @words=split / /,$searchstring;
foreach my $word(@words){
- $word="+".$word;
-
+ # + means mandatory, * is wildcard
+ $word="+".$word; #."*";
}
$searchstring=join " ",@words;
-
- $query="Select * from borrowers where
MATCH(surname,firstname,othernames) AGAINST('$searchstring' in boolean mode)";
-
+ $query="SELECT * FROM borrowers WHERE
MATCH(surname,firstname,othernames) AGAINST('$searchstring' IN BOOLEAN MODE)";
+ #OR WHERE MATCH(surname,firstname,othernames)
AGAINST('$searchstring)' IN BOOLEAN MODE";
}
$query=$query." order by $orderby";
}
+=cut
my $sth=$dbh->prepare($query);
# warn "Q $orderby : $query";
- $sth->execute();
+ $sth->execute(@bind);
my @results;
my $cnt=$sth->rows;
while (my $data=$sth->fetchrow_hashref){
@@ -3021,6 +3068,35 @@
return (undef, $results_hashref, address@hidden);
}
+sub stringifyLimit {
+ my ($query,@limits) = @_;
+ my ($limit_query, $limit_search_desc);
+ foreach my $limit (@limits) {
+ # FIXME: not quite right yet ... will work on this soon -- JF
+ if ($limit =~ /available/) {
+ $limit_query.=" (($query and datedue=0000-00-00) or ($query and
datedue=0000-00-00 not lost=1) or ($query and datedue=0000-00-00 not lost=2))";
+ #$limit_search_desc.=" and available";
+ }
+ # these queries are treated as OR
+ elsif (($limit_query) && ($limit =~/mc/)) {
+ $limit_query.=" or $limit" if $limit;
+ $limit_search_desc.=" or $limit" if $limit;
+ }
+
+ # these are treated as AND
+ elsif ($limit_query) {
+ $limit_query.=" and $limit" if $limit;
+ $limit_search_desc.=" and $limit" if $limit;
+ }
+ # otherwise, there is nothing but the limit
+ else {
+ $limit_query.="$limit" if $limit;
+ $limit_search_desc.="$limit" if $limit;
+ }
+ $query.=" and ".$limit_query;
+ }
+ return ($query,$limit_query,$limit_search_desc);
+}
# build the query itself
sub buildQuery {
my ($query,$operators,$operands,$indexes,$limits,$sort_by) = @_;
@@ -3053,23 +3129,35 @@
if ($query =~/^pqf=/) {
return (undef,$',$',$','pqf');
}
- if ($query =~/(\(|\))/ ) { # sorry, too complex
- return (undef,$query,$query,$query,'ccl');
+
+ # what follows I consider to be a hack ... the idea is that
+ # if the incoming query has parentheses already, without a proper query
+ # parser (recursive, etc.), we can't parse it properly, so we just
assume
+ # it's CCL and pass it off to zebra directly
+ if ($query =~/(\(|\))/ ) { # sorry, too complex, just concatenate all
the queries and pass off to zebra
+
+ # add limits and sort_by
+ my $oldquery; my $newquery;
+ ($newquery,$oldquery,$query) = stringifyLimit($query,@limits);
+ return (undef,$newquery,$newquery,$newquery,'ccl');
}
- # form-based queries are limited to non-nested a specific depth, so we
can easily
+
+ # However, if there are no parentheses, parsing it is much easier
because
+ # queries are limited to non-nested and to a specific depth, so we can
easily
# modify the incoming query operands and indexes to do stemming and
field weighting
# Once we do so, we'll end up with a value in $query, just like if we
had an
# incoming $query from the user
else {
- $query = ""; # clear it out so we can populate properly with
field-weighted stemmed query
+ # FIXME: these should be sysprefs
+ my $stemming = 1;
+ my $weight_fields = 1;
+ $query = "" if $weight_fields; # clear it out so we can
populate properly with field-weighted stemmed query
my $previous_operand; # a flag used to keep track if there
was a previous query
# if there was,
we can apply the current operator
for (my $i=0; $i<address@hidden; $i++) {
my $operand = $operands[$i];
my $index = $indexes[$i];
my $stemmed_operand;
- # FIXME: these should be sysprefs
- my $stemming = 1; my $weight_fields = 1;
if ($operands[$i]) {
@@ -3159,8 +3247,13 @@
# the default operator is and
else {
$query.=" and $operand";
+ if ($index) {
$human_search_desc.=" and
$index: $operands[$i]";
}
+ else {
+ $human_search_desc.="
and $operands[$i]";
+ }
+ }
}
else {
$query.=" $operand";
@@ -3236,7 +3329,7 @@
# building the HTML output for the template
sub searchResults {
my
($searchdesc,$hits,$results_per_page,$offset,@marcresults)address@hidden;
-
+ warn "HITS:$hits\n";
my $dbh= C4::Context->dbh;
my $toggle;
my $even=1;
@@ -3289,14 +3382,14 @@
if (length($term) > 3) {
$term =~ s/(.*=|\)|\(|\+|\.)//g;
#FIXME: is there a better way to do this?
- $oldbiblio->{'title'} =~ s/$term/<span
class=term>$&<\/span>/gi;
- $oldbiblio->{'subtitle'} =~ s/$term/<span
class=term>$&<\/span>/gi;
+ $oldbiblio->{'title'} =~ s/$term/<span
class=\"term\">$&<\/span>/gi;
+ $oldbiblio->{'subtitle'} =~ s/$term/<span
class=\"term\">$&<\/span>/gi;
#$oldbiblio->{'author'} =~ s/$term/<span
class=term>$&<\/span>/gi; #FIXME: add back later
- $oldbiblio->{'publishercode'} =~ s/$term/<span
class=term>$&<\/span>/gi;
- $oldbiblio->{'place'} =~ s/$term/<span
class=term>$&<\/span>/gi;
- $oldbiblio->{'pages'} =~ s/$term/<span
class=term>$&<\/span>/gi;
- $oldbiblio->{'notes'} =~ s/$term/<span
class=term>$&<\/span>/gi;
- $oldbiblio->{'size'} =~ s/$term/<span
class=term>$&<\/span>/gi;
+ $oldbiblio->{'publishercode'} =~ s/$term/<span
class=\"term\">$&<\/span>/gi;
+ $oldbiblio->{'place'} =~ s/$term/<span
class=\"term\">$&<\/span>/gi;
+ $oldbiblio->{'pages'} =~ s/$term/<span
class=\"term\">$&<\/span>/gi;
+ $oldbiblio->{'notes'} =~ s/$term/<span
class=\"term\">$&<\/span>/gi;
+ $oldbiblio->{'size'} =~ s/$term/<span
class=\"term\">$&<\/span>/gi;
}
}
@@ -3323,10 +3416,15 @@
if ($item->{wthdrawn}) {
$wthdrawn_count++;
}
- elsif ($item->{notforloan} == -1) {
+ if ($item->{notforloan} == "-1") {
$ordered_count++;
$norequests = 0;
}
+ elsif (($item->{notforloan}) ||
($item->{itemnotforloan})) {
+ if ($item->{'homebranch'}) {
+
$items->{$item->{'homebranch'}}->{count}++;
+ }
+ }
elsif ($item->{itemlost}) {
$itemlost_count++;
}
@@ -3337,6 +3435,8 @@
$onloan_count++;
$norequests = 0;
}
+ # homebranch first, then holdingbranch:q
+ #
else {
$norequests = 0;
if ($item->{'homebranch'}) {
@@ -3348,7 +3448,20 @@
}
}
} # notforloan, item level and biblioitem level
- #
+
+ # Now check itemtype for not for loan info
+ my $itemtype_sth = $dbh->prepare("SELECT notforloan FROM
itemtypes WHERE itemtype=?");
+ $itemtype_sth->execute($oldbiblio->{itemtype});
+ my $itemtype_notforloan = $itemtype_sth->fetchrow();
+ $norequests = 1 if $itemtype_notforloan;
+
+ #my @koha_items = &ItemInfo(undef, $biblionumber, 'opac');
+ #for my $koha_item (@koha_items) {
+ # if ($koha_item->{'itemnotforloan'}) {
+ # warn "not for loan\n";
+# }
+# }
+
for my $key (keys %$items) {
#warn "key: $key";
my $this_item = { branchname => $branches{$key},
branchcode => $key, count => $items->{$key}->{count} };
- [Koha-cvs] koha/C4 Search.pm [dev_week],
Joshua Ferraro <=