开发者

How to call a Zend lucene search function?

I inherited a Zend project devoid of comments and I didn't get to talk to the previous developer. Since I have no Zend experience I'm having some issues :)

I'd like to print out some variables inside an function that indexes items from the site using Zend_Search_Lucene because I think something is going wrong here.

From what I've read, ::create creates a new index and ::open updates it. So it's in this ::open function I'd like to print out some variables.

The name and params of the function are below. Does anyone have any idea how this function can be called so I can run some tests?

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

EDIT: OR, is there a 开发者_开发百科way I can nuke the existing index and force it to be rebuilt completely, for example by deleting the index files on the FS and then performing some searches?


Here's some code to create an index from scratch:

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();

... don't remember where i got the standard analyzer from...


good examples - ZendFramework-1.9.6/demos/Zend/Search/Lucene

ZF full distro

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜