【问题标题】:How to call a Zend lucene search function?如何调用 Zend lucene 搜索函数?
【发布时间】:2010-12-23 05:10:48
【问题描述】:

我继承了一个没有 cmets 的 Zend 项目,但我没有机会与之前的开发人员交谈。由于我没有 Zend 经验,我遇到了一些问题 :)

我想在一个函数中打印出一些变量,该函数使用 Zend_Search_Lucene 对站点中的项目进行索引,因为我认为这里出了点问题。

根据我的阅读, ::create 创建一个新索引并 ::open 更新它。所以我想在这个 ::open 函数中打印出一些变量。

函数的名称和参数如下。有谁知道如何调用这个函数以便我可以运行一些测试?

private function search($category,$string,$page = 1,$itemsByPage = 5)

编辑:或者,有没有办法可以删除现有索引并强制它完全重建,例如通过删除 FS 上的索引文件然后执行一些搜索?

【问题讨论】:

  • ::create 如果存在则删除索引

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


【解决方案1】:

下面是一些从头开始创建索引的代码:

Zend_Search_Lucene_Analysis_Analyzer::setDefault(new StandardAnalyzer_Analyzer_Standard_English());

$tmpIndexDir = '/your/index/dir/'
$index = Zend_Search_Lucene::create($tmpIndexDir);

foreach($myObjects as $myObject){

    $doc = new Zend_Search_Lucene_Document();
    $doc->addField(Zend_Search_Lucene_Field::UnIndexed('objectId', $myObject->getId()));
    $contents = $myObject->toString();
    $contentsField = Zend_Search_Lucene_Field::Text('contents', $contents);
    $doc->addField($contentsField);
    $index->addDocument($doc);
}

$index->optimize();

...不记得我从哪里得到标准分析仪...

【讨论】:

    【解决方案2】:

    很好的例子 - ZendFramework-1.9.6/demos/Zend/Search/Lucene

    ZF full distro

    【讨论】:

      猜你喜欢
      • 2010-11-06
      • 1970-01-01
      • 1970-01-01
      • 2011-12-09
      • 1970-01-01
      • 1970-01-01
      • 2012-02-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多