在这里或其他任何地方都找不到解决方案,所以我要问另一个关于 Zend Lucene 的问题。每个人都讲述了一些 Lucene 的编码。我应该在哪里切换这种编码?
当我使用搜索(PL 语言)时,我得到了
oprĂłcz wystÄ...pi reprezentacja Rosji。Mistrzowie olimpijscy z Londynu powalczÄ...</p>
这个 Ăł 在波兰语中应该是“ó”,Ä...(变音符号?)是“ą”等等......当然它适用于英语。
再次 searchController.php(操作创建 + 搜索):
public function actionCreate()
{
$_indexFiles = 'runtime.search';
$index = Zend_Search_Lucene::create($_indexFiles);
$index = new Zend_Search_Lucene(Yii::getPathOfAlias('application.' . $this->_indexFiles), true);
$posts = News::model()->with('comment')->findAll();
foreach($posts as $news){
$doc = new Zend_Search_Lucene_Document();
$doc->addField(Zend_Search_Lucene_Field::Text('title',CHtml::encode($news->name), 'utf-8'));
$doc->addField(Zend_Search_Lucene_Field::Text('link',CHtml::encode($news->url), 'utf-8'));
$doc->addField(Zend_Search_Lucene_Field::Text('content',CHtml::encode($news->description), ' utf-8 '));
$index->addDocument($doc);
}
setlocale(LC_CTYPE, 'pl_PL.utf-8');
$index->commit();
echo 'Lucene index created';
}
public function actionSearch()
{
Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding('utf-8');
Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8_CaseInsensitive ());
$this->layout='column2';
if (($term = Yii::app()->getRequest()->getParam('q', null)) !== null) {
$index = new Zend_Search_Lucene(Yii::getPathOfAlias('application.' . $this->_indexFiles));
$results = $index->find($term);
$query = Zend_Search_Lucene_Search_QueryParser::parse($term);
$this->render('search', compact('results', 'term', 'query'));
}
}