【发布时间】:2016-06-29 09:46:08
【问题描述】:
我在 MySQL 中的 ft_min_word_len 设置为 4。当我尝试对包含 2 或 3 个字母的内容进行全文搜索时,我没有得到任何结果。所以我使用这段代码来获取这些短词的全文搜索:
$table = $this->db->shop_products();
$where = '';
preg_match_all("~[\\pL\\pN_]+('[\\pL\\pN_]+)*~u", stripslashes($find), $matches);
foreach($matches[0] as $part) {
$isFirst = empty($where);
$regexp = "REGEXP '" . addslashes($part) . "'";
if(!$isFirst) $where .= " AND (";
$where .= "name {$regexp} OR content {$regexp}";
if(!$isFirst) $where .= ")";
}
return $table->where($where)->limit(5)->fetchAll();
这段代码可以正常工作,但它的变音符号有问题,比如č, á, é, í...。例如,我有一个名为 bé 的产品,当我只想查找 be 时,它不会显示该产品,因为它没有相同的字母。
注意:我使用 NotORM 进行 MySQL 查询,但我希望您知道 $table->where(... 是如何工作的。
【问题讨论】:
-
为什么不将
ft_min_word_len设置为2? -
在我的网站托管上我不能做这样的事情。