在我們的項目(基於Zend Framework)中,我們必須找到默認Zend_Lucene的替代品。現在我試圖用PHP Solr Client實現Solr。 我們有2個表格,我們在這裏獲取數據:類別和優惠。從Zend_Lucene遷移到Solr
在Zend_Lucene除了數據指標走那條路:
/*Code above we create new index and take data from mysql
And here are the old methods:
offer - is array with query results
*/
$to_index = "{$offer["name"]} {$offer["type"]} {$offer["description"]}";
$doc = new Zend_Search_Lucene_Document();
$doc->addField(Zend_Search_Lucene_Field::Text('text', $to_index, "utf-8"));
$doc->addField(Zend_Search_Lucene_Field::Keyword('cat_id', $offer["cat_id"]));
$doc->addField(Zend_Search_Lucene_Field::Keyword('type', "offer"));
$doc->addField(Zend_Search_Lucene_Field::Keyword('id', $offer["id"]));
$doc->addField(Zend_Search_Lucene_Field::UnIndexed('created', time()));
$this->index->addDocument($doc);
/*End of old code*/
我們有類別相同的方法/
Solr中和PHP Solr的客戶,我已經改變了代碼(使用默認實例schema.xml):
$to_index = "{$category["name"]}";
$doc = new Apache_Solr_Document();
$doc->text = $to_index;
$doc->type = "category";
$doc->id = $category["id"];
$doc->created = time();
try {
$this->solr->addDocuments($doc);
$this->solr->commit();
$this->solr->optimize();
}
catch (Exception $e) {
echo $e->getMessage();
}
但是,在索引中搜索給我0!我有一個懷疑,索爾沒有適當的索引。 (但是在創建索引期間沒有錯誤消息或豁免)。此外,我會嘗試給方法只Solr文本和id杆。但結果是一樣的!
我在做什麼錯了?我是否正確更改了Zend_Lucene方法?
我的問題的解決方案,您可以在這裏找到: http://groups.google.com/group/php-solr-client/browse_thread/thread/204261f54411628b?pli=1 – 2011-01-20 13:03:56