2012-04-30 19 views
1

私は3つのフィールドを持っており、そのうちの2つは配列であり、1つは名前フィールドです。これらのレコードを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); 
関連する問題