* [highgo] Fix search sql

This commit is contained in:
朱金勇
2025-10-11 09:12:54 +08:00
committed by Gitfox
parent e655f8ec36
commit 84875bd342
+22 -2
View File
@@ -399,18 +399,38 @@ class searchTao extends searchModel
$words = explode(' ', $this->unify($keywords, ' '));
$against = '';
$againstCond = '';
$againstCond = array();
foreach($words as $word)
{
/* 将 utf-8 字符串拆分为单词,为每个单词计算 unicode. */
$splitedWords = $spliter->utf8Split($word);
$trimmedWord = trim($splitedWords['words']);
$against .= '"' . $trimmedWord . '" ';
$againstCond .= '(+"' . $trimmedWord . '") ';
if(in_array($this->config->db->driver, $this->config->pgsqlDriverList))
{
$splitWords = preg_split('/\s+/', trim($trimmedWord));
$quotedWords = array_map(function($word) { return "''" . $word . "''"; }, $splitWords);
$againstCond[] = implode(' <-> ', $quotedWords);
}
else
{
$againstCond[] = '(+"' . $trimmedWord . '")';
}
if(is_numeric($word) && strpos($word, '.') === false && strlen($word) == 5) $againstCond .= "(-\" $word \") ";
}
if(in_array($this->config->db->driver, $this->config->pgsqlDriverList))
{
$againstCond = implode(' | ', $againstCond);
}
else
{
$againstCond = implode(' ', $againstCond);
}
$likeCondition = trim($keywords) ? 'OR title LIKE ' . $this->dbh->quote("%{$keywords}%") . ' OR content LIKE ' . $this->dbh->quote("%{$keywords}%") : '';
$words = str_replace('"', '', $against);