[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Koha-cvs] koha/opac opac-zoomsearch.pl [dev_week]
From: |
Joshua Ferraro |
Subject: |
[Koha-cvs] koha/opac opac-zoomsearch.pl [dev_week] |
Date: |
Thu, 08 Jun 2006 07:21:42 +0000 |
CVSROOT: /sources/koha
Module name: koha
Branch: dev_week
Changes by: Joshua Ferraro <kados> 06/06/08 07:21:42
Modified files:
opac : opac-zoomsearch.pl
Log message:
cleaning up formatting of searchResults()
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/opac/opac-zoomsearch.pl?cvsroot=koha&only_with_tag=dev_week&r1=1.1.2.6&r2=1.1.2.7
Patches:
Index: opac-zoomsearch.pl
===================================================================
RCS file: /sources/koha/koha/opac/Attic/opac-zoomsearch.pl,v
retrieving revision 1.1.2.6
retrieving revision 1.1.2.7
diff -u -b -r1.1.2.6 -r1.1.2.7
--- opac-zoomsearch.pl 8 Jun 2006 01:38:30 -0000 1.1.2.6
+++ opac-zoomsearch.pl 8 Jun 2006 07:21:42 -0000 1.1.2.7
@@ -11,6 +11,7 @@
my $query=new CGI;
my $op = $query->param('op'); #show the search form or execute the search
my $cql_query = $query->param('cql_query');
+my @pqf_query_history = $query->param('pqf_query_history');
my @newresults;
my ($template,$borrowernumber,$cookie);
my @forminputs; #this is for the links to navigate among the
results when they are more than the maximum number of results per page
@@ -29,13 +30,14 @@
$number_of_results = 20 unless ($number_of_results); #this could be a
parameter with 20 50 or 100 results per page
my $startfrom = $query->param('startfrom');
($startfrom) || ($startfrom=0);
- # push @forminputs, {field => "results_per_page", value =>
$number_of_results};
## OK, We're searching
# STEP 1. We're a CGI script,so first thing to do is get the
# query into PQF format so we can use the Koha API properly
my ($error,$pqf_sort_by, $pqf_prox_ops, $pqf_bool_ops, $pqf_query) =
cgi2pqf($query);
warn "AFTER CGI: $pqf_sort_by $pqf_prox_ops $pqf_bool_ops $pqf_query";
+ # implement a query history
+ push @pqf_query_history, { field => 'pqf_query', value => $pqf_query};
# lets store the query details in an array for later
push @forminputs, { field => "cql_query" , value => $cql_query} ;
@@ -43,7 +45,7 @@
push @forminputs, { field => 'pqf_prox_ops', value => $pqf_prox_ops};
push @forminputs, { field => 'pqf_bool_ops' , value => $pqf_bool_ops};
push @forminputs, { field => 'pqf_query' , value => $pqf_query };
- $searchdesc=$cql_query.$pqf_query; # FIXME: this should be a more
use-friendly string
+ $searchdesc=$cql_query.$pqf_prox_ops.$pqf_bool_ops.$pqf_query; # FIXME:
this should be a more use-friendly string
# STEP 2. OK, now we have PQF, so we can pass off the query to
# the API
@@ -66,6 +68,7 @@
# the total results searched
$template->param(total => $count);
$template->param(FORMINPUTS => address@hidden);
+ $template->param(PQF_QUERY_HISTORY => address@hidden);
$template->param(searchdesc => $searchdesc );
$template->param(results_per_page => $number_of_results );
$template->param(SEARCH_RESULTS => address@hidden);
@@ -133,8 +136,25 @@
pg => $total_pages};
}
- $template->param(numbers => $numbers);
+ $template->param( pqf_sort_by => $pqf_sort_by,
+ pqf_query => "$pqf_prox_ops
$pqf_bool_ops $pqf_query",
+ numbers => $numbers);
+
+
$template->param('Disable_Dictionary'=>C4::Context->preference("Disable_Dictionary"))
if (C4::Context->preference("Disable_Dictionary"));
+ $template->param(
+ #classlist => $classlist,
+ suggestion => C4::Context->preference("suggestion"),
+ virtualshelves =>
C4::Context->preference("virtualshelves"),
+ LibraryName => C4::Context->preference("LibraryName"),
+ OpacNav => C4::Context->preference("OpacNav"),
+ opaccredits => C4::Context->preference("opaccredits"),
+ AmazonContent => C4::Context->preference("AmazonContent"),
+ opacsmallimage => C4::Context->preference("opacsmallimage"),
+ opaclayoutstylesheet =>
C4::Context->preference("opaclayoutstylesheet"),
+ opaccolorstylesheet =>
C4::Context->preference("opaccolorstylesheet"),
+ );
+## OK, we're not searching, load the search template
} else {
($template, $borrowernumber, $cookie)
@@ -144,6 +164,8 @@
authnotrequired => 1,
});
+ # pass on the query history
+ $template->param(PQF_QUERY_HISTORY => address@hidden);
use C4::Koha;
my $dbh = C4::Context->dbh;
##Itemtypes (Collection Codes)
@@ -206,7 +228,7 @@
my $dbh = C4::Context->dbh;
my $zconn=C4::Context->Zconn("biblioserver");
- warn ($type,$query,$num,$startfrom) ;
+ #warn ($type,$query,$num,$startfrom) ;
if ($zconn eq "error") {
return("error with connection",undef); #FIXME: better error
handling
}
@@ -214,7 +236,7 @@
my $zoom_query_obj;
eval {
if ($type eq 'cql') {
- $zoom_query_obj = new ZOOM::Query::CQL($query,$zconn);
+ $zoom_query_obj = new ZOOM::Query::CQL2RPN($query,$zconn);
} else {
$zoom_query_obj = new ZOOM::Query::PQF($query);
}
@@ -246,7 +268,6 @@
# build a valid PQF query from the CGI form
sub cgi2pqf {
my ($query) = @_;
- warn "CGI 2 PQF conversion";
my @default_attributes = ('sort_by');
# attributes specific to the advanced search - a search_point is
actually a combination of
# several bib1 attributes
@@ -264,6 +285,7 @@
my $cql_query = $query->param('cql_query');
my $pqf_query = $query->param('pqf_query');
+
my @pqf_query_array;
my @counting_pqf_query_array;
@@ -294,7 +316,7 @@
$pqf_sort_by .= " ".$query->param($def_attr);
}
# these are attributes specific to this query_form, set many times per
query
- # First, process the 'operators' and put them in a separate variable
+ # First, process the 'operators' and put them in an array
# proximity and boolean
foreach my $spec_attr (@specific_attributes) {
for (my $i=1;$i<15;$i++) {
@@ -316,9 +338,9 @@
}
}
}
- # by now, we have two variables: $pqf_bool_ops (boolean) and
$pqf_prox_ops (proximity)
+ # by now, we have two operator arrays: @pqf_bool_ops_array (boolean)
and @pqf_prox_ops_array (proximity)
- # Now, process the attributes
+ # Next, we process the attributes (operands)
for (my $i=1;$i<15;$i++) {
foreach my $spec_attr (@specific_attributes) {
if ($query->param("query$i")) {
@@ -334,6 +356,10 @@
}
}
+ # we have to make sure that there # of operators == # of operands-1
+ # because second, third, etc queries, come in with an operator attached
+ # ...but if there is no previous queries, it should be dropped ...
+ # that's what we're doing here
my $count_pqf_query = @counting_pqf_query_array;
my $count_pqf_bool_ops = @pqf_bool_ops_array;
@@ -341,20 +367,18 @@
for (my $i=$count_pqf_query;$i>=0;$i--) {
$pqf_bool_ops.=" ".$pqf_bool_ops_array[$i];
}
- foreach my $que(@pqf_query_array) {
- $pqf_query .=" ".$que;
- }
} else {
- warn "problem example:".$count_pqf_bool_ops."
".$count_pqf_query;
-
for (my $i=$count_pqf_query;$i>=1;$i--) {
$pqf_bool_ops.=" ".$pqf_bool_ops_array[$i];
}
+ }
foreach my $que(@pqf_query_array) {
$pqf_query .=" ".$que;
}
-
+ foreach my $prox(@pqf_prox_ops_array) {
+ $pqf_prox_ops.=" ".$prox;
}
+ # OK, done with that, now lets have a look
warn "Boolean Operators: ".$pqf_bool_ops if $pqf_bool_ops;
warn "Proximigy Operators: ".$pqf_prox_ops if $pqf_prox_ops;
warn "Sort by: ".$pqf_sort_by;
@@ -366,44 +390,41 @@
sub searchResults {
-my ($num,@marcresults)address@hidden;
-use C4::Date;
+ my ($num,@marcresults)address@hidden;
+ use C4::Date;
-my $dbh= C4::Context->dbh;
-my $toggle;
-my $even=1;
-my @newresults;
-#Build brancnames hash
-#find branchname
-#get branch information.....
-my %branches;
+ my $dbh= C4::Context->dbh;
+ my $toggle;
+ my $even=1;
+ my @newresults;
+
+ #Build brancnames hash
+ #find branchname
+ #get branch information.....
+ my %branches;
my $bsth=$dbh->prepare("SELECT branchcode,branchname FROM
branches");
$bsth->execute();
while (my $bdata=$bsth->fetchrow_hashref){
$branches{$bdata->{'branchcode'}}=
$bdata->{'branchname'};
-
}
-
-
-#search item field code
- my $sth =
- $dbh->prepare(
-"select tagfield from marc_subfield_structure where kohafield like
'items.itemnumber'"
+ #search item field code
+ my $sth = $dbh->prepare(
+ "select tagfield from marc_subfield_structure where kohafield
like 'items.itemnumber'"
);
$sth->execute;
my ($itemtag) = $sth->fetchrow;
-## find column names of items related to MARC
-my $sth2=$dbh->prepare("SHOW COLUMNS from items");
+
+ ## find column names of items related to MARC
+ my $sth2=$dbh->prepare("SHOW COLUMNS from items");
$sth2->execute;
-my %subfieldstosearch;
-while ((my $column)=$sth2->fetchrow){
-my ($tagfield,$tagsubfield) =
&MARCfind_marc_from_kohafield($dbh,"items.".$column,"");
-$subfieldstosearch{$column}=$tagsubfield;
-}
+ my %subfieldstosearch;
+ while ((my $column)=$sth2->fetchrow){
+ my ($tagfield,$tagsubfield) =
&MARCfind_marc_from_kohafield($dbh,"items.".$column,"");
+ $subfieldstosearch{$column}=$tagsubfield;
+ }
for ( my $i=0; $i<$num ; $i++){
-
my $marcrecord;
$marcrecord = MARC::File::USMARC::decode($marcresults[$i]);
my $oldbiblio = MARCmarc2koha($dbh,$marcrecord,'');
@@ -413,44 +434,36 @@
$toggle="white";
}
$oldbiblio->{'toggle'}=$toggle;
-
-
-
my @fields = $marcrecord->field($itemtag);
-my @items;
+ my @items;
my $item;
-my %counts;
-$counts{'total'}=0;
+ my %counts;
+ $counts{'total'}=0;
#
##Loop for each item field
foreach my $field (@fields) {
foreach my $code ( keys %subfieldstosearch ) {
-$item->{$code}=$field->subfield($subfieldstosearch{$code});
-}
-
-my $status;
-
-$item->{'branchname'}=$branches{$item->{'holdingbranch'}};
-
-$item->{'date_due'}=$item->{onloan};
-$status="Lost" if ($item->{itemlost});
-$status="Withdrawn" if ($item->{wthdrawn});
+ $item->{$code}=$field->subfield($subfieldstosearch{$code});
+ }
+ my $status;
+ $item->{'branchname'}=$branches{$item->{'holdingbranch'}};
+ $item->{'date_due'}=$item->{onloan};
+ $status="Lost" if ($item->{itemlost});
+ $status="Withdrawn" if ($item->{wthdrawn});
$status="Due:".format_date($item->{onloan}) if ($item->{onloan}>0 );
-
-# $status="On Loan" if ($item->{onloan} );
-if ($item->{'location'}){
+ # $status="On Loan" if ($item->{onloan} );
+ if ($item->{'location'}){
$status = $item->{'branchname'}."[".$item->{'location'}."]" unless defined
$status;
-}else{
+ }else{
$status = $item->{'branchname'} unless defined $status;
-}
+ }
$counts{$status}++;
-$counts{'total'}++;
-push @items,$item;
+ $counts{'total'}++;
+ push @items,$item;
}
-
my $norequests = 1;
my $noitems = 1;
if (@items) {
@@ -463,7 +476,6 @@
$oldbiblio->{'norequests'} = $norequests;
$oldbiblio->{'even'} = $even = not $even;
$oldbiblio->{'itemcount'} = $counts{'total'};
-
my $totalitemcounts = 0;
foreach my $key (keys %counts){
if ($key ne 'total'){
@@ -503,10 +515,8 @@
$oldbiblio->{'location'} = $locationtext;
$oldbiblio->{'location-only'} = $locationtextonly;
$oldbiblio->{'use-location-flags-p'} = 1;
-
-
push (@newresults, $oldbiblio);
}
-return @newresults;
- }
+ return @newresults;
+}
- [Koha-cvs] koha/opac opac-zoomsearch.pl [dev_week], Joshua Ferraro, 2006/06/05
- [Koha-cvs] koha/opac opac-zoomsearch.pl [dev_week], Tumer Garip, 2006/06/07
- [Koha-cvs] koha/opac opac-zoomsearch.pl [dev_week], Tumer Garip, 2006/06/07
- [Koha-cvs] koha/opac opac-zoomsearch.pl [dev_week], Joshua Ferraro, 2006/06/07
- [Koha-cvs] koha/opac opac-zoomsearch.pl [dev_week], Joshua Ferraro, 2006/06/07
- [Koha-cvs] koha/opac opac-zoomsearch.pl [dev_week], Joshua Ferraro, 2006/06/07
- [Koha-cvs] koha/opac opac-zoomsearch.pl [dev_week],
Joshua Ferraro <=
- [Koha-cvs] koha/opac opac-zoomsearch.pl [dev_week], Chris Cormack, 2006/06/09
- [Koha-cvs] koha/opac opac-zoomsearch.pl [dev_week], Joshua Ferraro, 2006/06/10