在我们的项目中(基于 Zend 框架),我们必须找到默认 Zend_Lucene 的替代品。现在我正在尝试在其中使用 PHP Solr Client 来实现 Solr。我们有 2 个表格,我们在其中获取数据:类别和优惠。
在 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 Client 中,我更改了该代码(使用默认示例 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 方法?