In our project (based on Zend Framework) we have to find a replacement for default Zend_Lucene. Now I'm trying to implement Solr with PHP Solr Client in it. We have 2 tables, where we take the data: categories and offers.
In Zend_Lucene addition data to index go that way:
/*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*/
The same methods we have for categories/
In Solr and PHP Solr Client, I've changed that code (using default example schema.xml):
$to_index = "{$category["name"]}";
$doc = new Apache_Solr_Document();
$doc->text = $to_index;
$doc->type = "category";
$do开发者_高级运维c->id = $category["id"];
$doc->created = time();
try {
$this->solr->addDocuments($doc);
$this->solr->commit();
$this->solr->optimize();
}
catch ( Exception $e ) {
echo $e->getMessage();
}
But search in index gives me 0! I have a suspicion, that Solr doesn't make proper index. (But there are no bug messages or exeptions during index creation). Also I'd try to give Solr only text and id poles in methods. But result was the same!
What I'm doing wrong? Did I change the Zend_Lucene methods correctly?
I would recommend you to use the "DataImportHandler" built in Solr, to import data from a DataBase to the Solr engine.
It will do the job for you, and you can configure "full-import" which will import all the database and "delta-import" which will just import the new data from the database. You can configure "delete" too, to remove deleted database data.
精彩评论