2011-05-03 176 views
0

保存我fieldes與此代碼:Lucene的搜索沒有找到關鍵字索引字段

class Places_Search_Document extends Zend_Search_Lucene_Document{ 
public function __construct($class, $key, $title,$contents, $summary, $createdBy, $dateCreated) 
    { 
     $this->addField(Zend_Search_Lucene_Field::Keyword('docRef', "$class:$key")); 
     $this->addField(Zend_Search_Lucene_Field::UnIndexed('class', $class)); 
     $this->addField(Zend_Search_Lucene_Field::UnIndexed('key', $key)); 
     $this->addField(Zend_Search_Lucene_Field::Keyword('title', $title ,'UTF-8')); 
     $this->addField(Zend_Search_Lucene_Field::unStored('contents', $contents , 'UTF-8')); 
     $this->addField(Zend_Search_Lucene_Field::text('summary', $summary , 'UTF-8')); 
     //$this->addField(Zend_Search_Lucene_Field::UnIndexed('createdBy', $createdBy)); 
     $this->addField(Zend_Search_Lucene_Field::Keyword('dateCreated', $dateCreated)); 
    } 

}

我搜索這個碼字:

$index = Places_Search_Lucene::open(SearchIndexer::getIndexDirectory()); 
     $term = new Zend_Search_Lucene_Index_Term($q); 
     $query = new Zend_Search_Lucene_Search_Query_Wildcard($term); 
     $results = $index->find($query); 

現在它的工作完美的未排序和文本字段,但它不會搜索關鍵字!

回答

1

您確定您確實希望對這些字段進行關鍵字分析嗎?關鍵字分析器將字段的整個文本作爲一個令牌,這是您很少需要的。

+0

thanx很多你的注意:)我發現我的錯誤;) – afsane 2011-05-05 06:29:49