使用 Zend_Search_Lucene_Search_QueryParser 的 highlightMatches 函数时出现异常
Exception when using highlightMatches function of Zend_Search_Lucene_Search_QueryParser
我控制器的这段代码:
$index = new Zend_Search_Lucene(Yii::getPathOfAlias('application.' . $this->_indexFiles));
$results = $index->find($term);
$query = Zend_Search_Lucene_Search_QueryParser::parse($term,'utf-8');
然后我尝试在视图文件中突出显示我的结果:
echo $query->highlightMatches($result->method, 'utf-8');
但我在 ZendSearch/Lucene/Analysis/Analyzer/Common/Utf8.php(77)
中遇到异常
iconv(): Detected an illegal character in input string
问题是我能做些什么来解决这个问题。
我做了一些研究。问题出在 ZendSearch/Lucene/Document/Html.php highlightExtended 函数中。
$analyzer->tokenize($wordString);
Tokenize 函数接受编码作为第二个参数,但在上面的行中我认为它被遗漏了。
代码:
public function tokenize($data, $encoding = '')
{
$this->setInput($data, $encoding);
$tokenList = array();
while (($nextToken = $this->nextToken()) !== null) {
$tokenList[] = $nextToken;
}
return $tokenList;
}
因此使用空字符串作为编码参数调用了 iconv。为了解决我的问题,我刚刚做了
public function tokenize($data, $encoding = 'UTF-8')
一切都变好了。
我控制器的这段代码:
$index = new Zend_Search_Lucene(Yii::getPathOfAlias('application.' . $this->_indexFiles));
$results = $index->find($term);
$query = Zend_Search_Lucene_Search_QueryParser::parse($term,'utf-8');
然后我尝试在视图文件中突出显示我的结果:
echo $query->highlightMatches($result->method, 'utf-8');
但我在 ZendSearch/Lucene/Analysis/Analyzer/Common/Utf8.php(77)
中遇到异常iconv(): Detected an illegal character in input string
问题是我能做些什么来解决这个问题。
我做了一些研究。问题出在 ZendSearch/Lucene/Document/Html.php highlightExtended 函数中。
$analyzer->tokenize($wordString);
Tokenize 函数接受编码作为第二个参数,但在上面的行中我认为它被遗漏了。
代码:
public function tokenize($data, $encoding = '')
{
$this->setInput($data, $encoding);
$tokenList = array();
while (($nextToken = $this->nextToken()) !== null) {
$tokenList[] = $nextToken;
}
return $tokenList;
}
因此使用空字符串作为编码参数调用了 iconv。为了解决我的问题,我刚刚做了
public function tokenize($data, $encoding = 'UTF-8')
一切都变好了。