搜索字符串是:“警察丹佛”。
我需要的结果就是这样,丹佛的警察。现在我得到了丹佛的所有警察和一切。
这就是我所拥有的,这是指定搜索应该是 EXACT 还是 ANY 的部分。但它并没有像我想要的那样工作。“警察丹佛”结果一无所获,警察丹佛结果芝加哥警察,丹佛消防员等等......
(代码来自k2 joomla扩展,开源)
$sql .= " AND MATCH(i.title, i.introtext, i.`fulltext`,i.image_caption,i.image_credits,i.video_caption,i.video_credits,i.extra_fields_search,i.metadesc,i.metakey) ";
if ($type == 'exact')
{
$text = JString::trim($search, '"');
$escaped = K2_JVERSION == '15' ? $db->getEscaped($text, true) : $db->escape($text, true);
$text = $db->Quote('"'.$db->getEscaped($text, true).'"', false);
}
else //this is search for any of the words
{
$search = JString::str_ireplace('*', '', $search);
$words = explode(' ', $search);
for ($i = 0; $i < count($words); $i++)
{
$words[$i] .= '*';
}
$search = implode(' ', $words);
$escaped = K2_JVERSION == '15' ? $db->getEscaped($search, true) : $db->escape($search, true);
$text = $db->Quote($escaped, false);
}
$sql .= " AGAINST ({$text} IN BOOLEAN MODE)";
}
return $sql;