我有这段代码:
$query = '"ala ma"';
try {
$index = Zend_Search_Lucene::open(ROOT_PATH.'/data');
}catch(Zend_Search_Lucene_Exception $e){
$index = Zend_Search_Lucene::create(ROOT_PATH.'/data');
}
Zend_Search_Lucene_Search_QueryParser::setDefaultEncoding('utf-8');
Zend_Search_Lucene_Analysis_Analyzer::setDefault(
new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num_CaseInsensitive()
);
$doc = new Zend_Search_Lucene_Document();
$doc->addField(Zend_Search_Lucene_Field::text('title', 'ala ma kota ala ma kota ala', 'utf-8'));
$index->addDocument($doc);
$index->commit();
$query = Zend_Search_Lucene_Search_QueryParser::parse($query);
$results = $index->find($query);
foreach ($results as $result){
echo $query->htmlFragmentHighlightMatches($result->title, 'utf-8') . '<br></br>';
}
我只需要标记找到的短语和荧光笔也选择单个单词,在这种情况下:
我只需要标记:&#34; ala ma&#34;,但荧光笔也选择最后一个字符串:ala
有人知道这个的答案吗?