From 895660f8e3a84b7fd99016581a87ff877e2826e9 Mon Sep 17 00:00:00 2001
From: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Date: Wed, 12 Mar 2014 17:43:20 +0000
Subject: [PATCH] Bug 10542: Fix QueryParser with OpacSupression

OpacSupressions manipulates the query string after the buildQuery
call and so breaks with queryParser enabled.  This patch adds
checks for queryParser and manipulates the query before passing it
to buildQuery if it is enabled, but leaves the post buildQuery
manipultation when queryParser is disabled

Signed-off-by: Jesse Maseto <jesse@bywatersolutions.com>
---
 opac/opac-search.pl |   28 ++++++++++++++++++++++++++--
 1 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/opac/opac-search.pl b/opac/opac-search.pl
index 617d67e..8620128 100755
--- a/opac/opac-search.pl
+++ b/opac/opac-search.pl
@@ -445,6 +445,26 @@ my ($error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_
 
 my @results;
 
+# Add OPAC suppression - requires at least one item indexed with Suppress
+if (C4::Context->preference('OpacSuppression')) {
+    # OPAC suppression by IP address
+    if (C4::Context->preference('OpacSuppressionByIPRange')) {
+        my $IPAddress = $ENV{'REMOTE_ADDR'};
+        my $IPRange = C4::Context->preference('OpacSuppressionByIPRange');
+        if ($IPAddress !~ /^$IPRange/)  {
+	    if ( C4::Context->preference('UseQueryParser') ) {
+                $query = "$query -suppress:1";
+	    }
+        }
+    }
+    else {
+	if ( C4::Context->preference('UseQueryParser') ) {
+            $query = "$query -suppress:1";
+        }
+    }
+}
+
+
 ## I. BUILD THE QUERY
 ( $error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$stopwords_removed,$query_type) = buildQuery(\@operators,\@operands,\@indexes,\@limits,\@sort_by, 0, $lang);
 
@@ -478,11 +498,15 @@ if (C4::Context->preference('OpacSuppression')) {
         my $IPAddress = $ENV{'REMOTE_ADDR'};
         my $IPRange = C4::Context->preference('OpacSuppressionByIPRange');
         if ($IPAddress !~ /^$IPRange/)  {
-            $query = "($query) not Suppress=1";
+	    unless ( C4::Context->preference('UseQueryParser') ) {
+                $query = "($query) not Suppress=1";
+	    }
         }
     }
     else {
-        $query = "($query) not Suppress=1";
+	unless ( C4::Context->preference('UseQueryParser') ) {
+            $query = "($query) not Suppress=1";
+        }
     }
 }
 
-- 
1.7.2.5