2012-04-30 226 views
1

我有3個字段,其中兩個是數組,另一個是名字字段。如何從zend lucene索引中搜索這些記錄。如何在zend lucene中搜索多個查詢?

code: 

$name = $_POST ['name']; 

$emails = $_POST ['email']; // this is a array 

$xId = $_POST ['xId']; // this also an array 

$index = new Zend_Search_Lucene ('test-index'); 
+0

也許你可以添加多一點的,你嘗試了什麼至今。代碼示例沒有給出太多方向。您可以構建相當複雜的查詢來搜索索引,這本質上是布爾查詢。 –

回答

2

試試這個

$name = $_POST ['name']; 

$emails = $_POST ['email']; // this is a array 

$xIds = $_POST ['xId']; // this also an array 

// Making array as string 
$emailIds = ''; 
foreach($emails as $email) { 
    $emailIds .= $email . " "; 
} 

// Making array as string 
$xIdsString = ''; 
foreach ($xIds as $xId) { 
    $xIdsString .= $xId . " "; 
} 

// Create a new index object 
$index = new Zend_Search_Lucene ('test-index'); 

// Here we are going to search over multiple fields. 
// we are just creating the string for right now 
$name_query  = "name:($lastName)"; 
$emails_query = "emails:($emailIds)"; 
$xIds_query  = "xIds:($xIdsString)"; 

// Parse the query 
$query = Zend_Search_Lucene_Search_QueryParser::parse("$name_query $emails_query $xIds_query"); 

$hits = $index->find($query); 
print_r($hits);