2011-01-19 5 views
1

私たちのプロジェクト(Zend Frameworkに基づいています)では、デフォルトのZend_Luceneを置き換える必要があります。今、私はそれにPHP Solr Clientを使ってSolrを実装しようとしています。 私たちはデータを取る2つのテーブルを持っています:カテゴリーとオファー。インデックスにZend_Lucene付加データでZend_LuceneからSolrへの移行

は、その道を行く:

/*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が適切な指数を作っていないという疑いがあります。 (ただし、索引作成中にバグ・メッセージや例外はありません)。また、私はSolrにメソッドのテキストとid極のみを与えようとします。しかし結果は同じでした!

私は間違っていますか? Zend_Luceneメソッドを正しく変更しましたか?

+0

私の問題の解決方法は次のとおりです: http://groups.google.com/group/php-solr-client/browse_thread/thread/204261f54411628b?pli=1 –

答えて

2

DataBaseからSolrエンジンにデータをインポートするには、「DataImportHandler」を使用することをお勧めします。

それはあなたのための仕事を行い、すべてのデータベースをインポートする「フルインポート」とデータベースから新しいデータをインポートする「デルタインポート」を設定することができます。削除したデータベースのデータを削除するには、「削除」も設定できます。

+0

...またはdrupalのやり方を見てくださいそれ ;) – Karussell