From 4169f6d5e89d60df87eb69b5cd50278518a4047c Mon Sep 17 00:00:00 2001 From: Joshua Ferraro Date: Wed, 21 Nov 2007 17:57:16 -0600 Subject: [PATCH] adding query_inputs to build the query as a set of hidden inputs Signed-off-by: Chris Cormack Signed-off-by: Joshua Ferraro --- C4/Search.pm | 14 +++++++--- catalogue/search.pl | 27 +++++++++++++++++-- .../prog/en/modules/catalogue/results.tmpl | 9 ++++++- 3 files changed, 43 insertions(+), 7 deletions(-) diff --git a/C4/Search.pm b/C4/Search.pm index ad7a9b7cf8..b84a528b94 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -702,7 +702,7 @@ sub buildQuery { } # FIXME: this is bound to be broken now - if ( $query =~ /(\(|\)|:|=)/ ) { # sorry, too complex, assume CCL + if ( $query =~ /(\(|\))/ ) { # sorry, too complex, assume CCL return ( undef, $query, $query_cgi, $query_search_desc, $limit, $limit_cgi, $limit_desc, 'ccl' ); } @@ -719,7 +719,13 @@ sub buildQuery { # COMBINE OPERANDS, INDEXES AND OPERATORS if ( $operands[$i] ) { + + $weight_fields = 0 if $operands[$i] =~ /(:|=)/; my $operand = $operands[$i]; + + my $sanatized_operand = $operands[$i]; + $sanatized_operand =~ s/://g; + my $index = $indexes[$i]; # if there's no index, don't use one, it will throw a CCL error @@ -788,7 +794,7 @@ sub buildQuery { $query .= " $operand"; $query_cgi .="&op=$operators[$i-1]"; $query_cgi .="&idx=$index" if $index; - $query_cgi .="&q=$operands[$i]" if $operand; + $query_cgi .="&q=$sanatized_operand" if $sanatized_operand; $query_search_desc .=" $operators[$i-1] $index_plus $operands[$i]"; } @@ -798,7 +804,7 @@ sub buildQuery { $query .= "$index_plus " unless $indexes_set; $query .= "$operand"; $query_cgi .="&op=and&idx=$index" if $index; - $query_cgi .="&q=$operands[$i]" if $operand; + $query_cgi .="&q=$sanatized_operand" if $sanatized_operand; $query_search_desc .= " and $index_plus $operands[$i]"; } } @@ -809,7 +815,7 @@ sub buildQuery { $query .= $operand; $query_search_desc .= " $index_plus $operands[$i]"; $query_cgi.="&idx=$index" if $index; - $query_cgi.="&q=$operands[$i]" if $operand; + $query_cgi.="&q=$sanatized_operand" if $sanatized_operand; $previous_operand = 1; } diff --git a/catalogue/search.pl b/catalogue/search.pl index 6fa3d8ac6e..9329f99f1b 100755 --- a/catalogue/search.pl +++ b/catalogue/search.pl @@ -335,10 +335,9 @@ my $params = $cgi->Vars; # Params that can have more than one value # sort by is used to sort the query +# in theory can have more than one but generally there's just one my @sort_by; @sort_by = split("\0",$params->{'sort_by'}) if $params->{'sort_by'}; - -# FIXME: this is a quick hack foreach my $sort (@sort_by) { $template->param($sort => 1); } @@ -402,6 +401,30 @@ my @results; ## I. BUILD THE QUERY ( $error,$query,$simple_query,$query_cgi,$query_search_desc,$limit,$limit_cgi,$limit_desc,$query_type) = buildQuery(\@operators,\@operands,\@indexes,\@limits,\@sort_by); +## parse the query_cgi string and put it into a form suitable for s +my @query_inputs; +for my $this_cgi ( split('&',$query_cgi) ) { + next unless $this_cgi; + $this_cgi =~ m/(.*=)(.*)/; + my $input_name = $1; + my $input_value = $2; + $input_name =~ s/=$//; + push @query_inputs, { input_name => $input_name, input_value => $input_value }; +} +$template->param ( QUERY_INPUTS => \@query_inputs ); + +## parse the limit_cgi string and put it into a form suitable for s +my @limit_inputs; +for my $this_cgi ( split('&',$limit_cgi) ) { + next unless $this_cgi; + $this_cgi =~ m/(.*=)(.*)/; + my $input_name = $1; + my $input_value = $2; + $input_name =~ s/=$//; + push @limit_inputs, { input_name => $input_name, input_value => $input_value }; +} +$template->param ( LIMIT_INPUTS => \@limit_inputs ); + ## II. DO THE SEARCH AND GET THE RESULTS my $total; # the total results for the whole set my $facets; # this object stores the faceted results that display on the left-hand of the results page diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tmpl index 66c5f8ab97..4060533098 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tmpl @@ -184,7 +184,14 @@
- " /> + + " value=""/> + + + " value=""/> + + +

-- 2.39.5