From cd4ba226787c19d3a0a3d256a7b1b2cbfb47936c Mon Sep 17 00:00:00 2001
From: JediKev <kevin@enhancesoft.com>
Date: Mon, 4 Mar 2019 10:46:50 -0600
Subject: [PATCH] issue: FAQ Search Results

This addresses an issue reported on the forum where searching for a keyword
in FAQ search brings back more results than it should. This is due to the
format of the query selecting the results, essentially, the `WHERE NOT`
statement is not properly formatted so the `OR` statements take precedence
over the `WHERE NOT` causing non-public results to be shown to the client.
The `WHERE NOT` statement contains the bit to select from only public faqs
and since the `OR` takes precedence it will return the non-public results
too.
---
 include/client/knowledgebase.inc.php | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/include/client/knowledgebase.inc.php b/include/client/knowledgebase.inc.php
index ac4a82f69..c3895e162 100644
--- a/include/client/knowledgebase.inc.php
+++ b/include/client/knowledgebase.inc.php
@@ -18,12 +18,14 @@ if($_REQUEST['q'] || $_REQUEST['cid'] || $_REQUEST['topicId']) { //Search
         $faqs->filter(array('topics__topic_id'=>$_REQUEST['topicId']));
 
     if ($_REQUEST['q'])
-        $faqs->filter(Q::ANY(array(
-            'question__contains'=>$_REQUEST['q'],
-            'answer__contains'=>$_REQUEST['q'],
-            'keywords__contains'=>$_REQUEST['q'],
-            'category__name__contains'=>$_REQUEST['q'],
-            'category__description__contains'=>$_REQUEST['q'],
+        $faqs->filter(Q::all(array(
+            Q::ANY(array(
+                'question__contains'=>$_REQUEST['q'],
+                'answer__contains'=>$_REQUEST['q'],
+                'keywords__contains'=>$_REQUEST['q'],
+                'category__name__contains'=>$_REQUEST['q'],
+                'category__description__contains'=>$_REQUEST['q'],
+            ))
         )));
 
     include CLIENTINC_DIR . 'kb-search.inc.php';
-- 
GitLab