Joomla! 1.5中文搜索BUG修正

在 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!那么低效率的数据库查询,这也不算什么啦。

Joomla! 1.5中文搜索BUG修正.

Rating: 0.0/10 (0 votes cast)

Related posts:

  1. wordpress similar posts error fix if you get an error like this when you turn...
  2. wpmu array_merge() error for array when you twist wpmu, sometime plugin does not work well...

Leave a Reply

Preview:

Tags:
Separate individual tags by commas