2011-03-02 65 views
1

我創建索引的功能是作爲波紋管Zend的Lucene的 - 如何做查詢

function create() 
{ 
    Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8_CaseInsensitive()); 
    $index = Zend_Search_Lucene::create('data/index');  
    $doc = new Zend_Search_Lucene_Document(); 

    $doc->addField(Zend_Search_Lucene_Field::Text('title', 'a cheap car in town milage under 3000','utf-8')); 
    $doc->addField(Zend_Search_Lucene_Field::Text('detail','a cheap car in town milage under 3000','utf-8')); 
    $doc->addField(Zend_Search_Lucene_Field::Text('category', 'milage under 3000','utf-8')); 

    $index->addDocument($doc); 
} 

當「在3000下鎮milage一輛廉價汽車」用戶搜索,我將查詢拆分成3個部分

$query1 = "a cheap car"; 
$query2 = "in town"; 
$query3 = " milage under 3000"; 

我要搜索

$query1 in field "title", $query2 in field "detail", $query3 in field "category". 

我也想搜索數量不區分大小寫和文本不區分大小寫。我該怎麼做?我需要實際的代碼,因爲我完全被Zend的Lucene的文檔迷茫,我不知道用哪個代碼或查詢。

回答

2

您的查詢將是:

$query = Zend_Search_Lucene_Search_QueryParser::parse("title:($query1) detail:($query2) category:($query3)"; 
$hits = $index->find($query); 

指數是不區分大小寫的,除非明確設置爲區分在創建敏感。