【问题标题】:Migration from Zend_Lucene to Solr从 Zend_Lucene 迁移到 Solr
【发布时间】:2011-06-11 17:45:51
【问题描述】:

在我们的项目(基于 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 方法?

【问题讨论】:

标签: php zend-framework search solr zend-search-lucene


【解决方案1】:

我建议您使用 Solr 内置的“DataImportHandler”,将数据从数据库导入到 Solr 引擎。

它将为您完成这项工作,您可以配置“full-import”将导入所有数据库和“delta-import”将仅从数据库中导入新数据。您也可以配置“删除”,以删除已删除的数据库数据。

【讨论】:

  • ...或者看看drupal是怎么做到的;)
猜你喜欢
  • 2016-10-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-10-24
  • 2023-04-06
  • 2016-08-05
相关资源
最近更新 更多