From 2eabddf5e93e777c2051adb741a3a9cd5c025fee Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Fri, 17 Jul 2020 11:53:00 +0200 Subject: [PATCH] fix(form): prevent SQL errors, remove natural language search - natural language search is not efficient, boolean mode with wilcard worls well; see the KB search engine Signed-off-by: Thierry Bugier --- inc/form.class.php | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/inc/form.class.php b/inc/form.class.php index 6047d0a4b..5fd288ae8 100644 --- a/inc/form.class.php +++ b/inc/form.class.php @@ -859,24 +859,15 @@ public function showFormList($rootCategory = 0, $keywords = '', $helpdeskHome = } // Find forms accessible by the current user + $keywords = trim($keywords); if (!empty($keywords)) { - // Determine the optimal search mode - $searchMode = "BOOLEAN MODE"; - $formCount = $dbUtils->countElementsInTable($table_form); - if ($formCount > 20) { - $searchMode = "NATURAL LANGUAGE MODE"; - } else { - $keywords = PluginFormcreatorCommon::prepareBooleanKeywords($keywords); - } - $keywords = $DB->escape($keywords); - $highWeightedMatch = " MATCH($table_form.`name`, $table_form.`description`) - AGAINST('$keywords' IN $searchMode)"; - $lowWeightedMatch = " MATCH($table_question.`name`, $table_question.`description`) - AGAINST('$keywords' IN $searchMode)"; + $keywordsWithWilcards = $DB->escape(PluginFormcreatorCommon::prepareBooleanKeywords($keywords)); $where_form['AND'][] = [ 'OR' => [ - new QueryExpression("$highWeightedMatch"), - new QueryExpression("$lowWeightedMatch"), + new QueryExpression("MATCH($table_form.`name`, $table_form.`description`) + AGAINST('$keywordsWithWilcards' IN BOOLEAN MODE)"), + new QueryExpression("MATCH($table_question.`name`, $table_question.`description`) + AGAINST('$keywordsWithWilcards' IN BOOLEAN MODE)"), ] ]; }