在 Joomla!系统自带搜索对于中文关键词两个问题的解决 文章中说明了如何解决Joomla!中文搜索的两个BUG,
1、对于中文关键词我们通常是两个字,比如"插件",这样的关键词的长度是2,而Joomla!查询的关键词限制长度是3以上。
2、对于一些中文关键词,如果开启了sef,就会导致搜索不到结果。
除了这两个问题外,还有一个棘手的问题,就是如果查询关键词为中文,涉及到翻页的情况下(SEF开启,没测试过未开启状态),是无法翻页的,你可以看到关键词都成了乱码,实际上中文字中的丢掉了一些字节。经过努力,才定位错误原来发生在 /libraries/joomla/eviroments/uri.php 的_PARSEURL函数中,函数的代码如下:
function _parseURL($uri)
{
$parts = array();
if (version_compare( phpversion(), '4.4' ) < 0)
{
$regex = "<^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?>";
$matches = array();
preg_match($regex, $uri, $matches, PREG_OFFSET_CAPTURE);
$authority = @$matches[4][0];
if (strpos($authority, '@') !== false) {
$authority = explode('@', $authority);
@list($parts['user'], $parts['pass']) = explode(':', $authority[0]);
$authority = $authority[1];
}
if (strpos($authority, ':') !== false) {
$authority = explode(':', $authority);
$parts['host'] = $authority[0];
$parts['port'] = $authority[1];
} else {
$parts['host'] = $authority;
}
$parts['scheme'] = @$matches[2][0];
$parts['path'] = @$matches[5][0];
$parts['query'] = @$matches[7][0];
$parts['fragment'] = @$matches[9][0];
}
else
{
$parts = @parse_url($uri);
}
return $parts;
}
这个函数,对于我的php版本,显然会走这个分支 @parse_url($uri) ,查了一下parse_url函数的源码,的确是会吃掉中文utf-8中的字节,即使经过urlencode以后也不行。没办法,只好直接采用低版本分支,将php版本判断部分去掉。
function _parseURL($uri)
{
$parts = array();
//if (version_compare( phpversion(), '4.4' ) < 0)
//{
$regex = "<^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?>";
$matches = array();
preg_match($regex, $uri, $matches, PREG_OFFSET_CAPTURE);
$authority = @$matches[4][0];
if (strpos($authority, '@') !== false) {
$authority = explode('@', $authority);
@list($parts['user'], $parts['pass']) = explode(':', $authority[0]);
$authority = $authority[1];
}
if (strpos($authority, ':') !== false) {
$authority = explode(':', $authority);
$parts['host'] = $authority[0];
$parts['port'] = $authority[1];
} else {
$parts['host'] = $authority;
}
$parts['scheme'] = @$matches[2][0];
$parts['path'] = @$matches[5][0];
$parts['query'] = @$matches[7][0];
$parts['fragment'] = @$matches[9][0];
//}
//else
//{
// $parts = @parse_url($uri);
//}
return $parts;
}
这样就好啦!目前我还没发现带来的其他问题,也就是效率稍低一点吧。不过相对于Joomla!那么低效率的数据库查询,这也不算什么啦。
作者:purity 星期五, 21 十一月 2008 02:54 |
老大,你真有耐心! |
作者:wboys 星期五, 21 十一月 2008 05:54 |
即是!怎用的.....是否安裝了這個. 本站的\"tags\"組件及模組!搜索\"tag\"後就可以解决中文seo友好翻页部分 |
作者:admin 星期六, 22 十一月 2008 03:44 |
是的,目前看来问题不大。能解决翻页问题。周末整整分词模块,打个完整的包。 |
作者:wboys 星期六, 22 十一月 2008 11:37 |
呵!呵!好呀.等很久了..^^.. |