Skip to content

Commit

Permalink
fix(form): prevent SQL errors, remove natural language search
Browse files Browse the repository at this point in the history
- natural language search is not efficient, boolean mode with wilcard worls well; see the KB search engine

Signed-off-by: Thierry Bugier <tbugier@teclib.com>
  • Loading branch information
btry committed Jul 21, 2020
1 parent 21cb43b commit 2eabddf
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions inc/form.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)"),
]
];
}
Expand Down

0 comments on commit 2eabddf

Please sign in to comment.