我们怎样才能对整个站点重新索引 lucene 搜索

How can we do whole site reindexing of lucene search

public function searchIndex($entity)
    {
        //http://framework.zend.com/manual/2.0/en/modules/zendsearch.lucene.searching.html#
        //
        //http://framework.zend.com/manual/2.0/en/modules/zendsearch.lucene.index-creation.html
        try {
            $index = Lucene::open( $this->getOptions()->getIndexDir() );
            $index->optimize();

            echo '<p>Index optimized.</p>';
        } catch (Exception $e) {
            throw new Exception("Search index not configured", 1);
        }

        $query = QueryParser::parse( $entity->getTerm() );

        $hits = $index->find($query);

        //print_r($hits);
        $entity->setCount( count( $hits ) );

        //save the search for reference
        $this->create($entity);

        return $hits;
    }

每次我在我的 zend 网站上执行搜索时,结果都是零,请告诉我如何在 zend 中执行重建索引。

我已经解决了这个问题,它是一个重建索引问题。当我们刷新页面时,我们必须建立索引。我使用以下代码解决了这个问题。

public function getbuild()
    {
        if (!$this->searchService) {
            $this->setSearchService( $this->getServiceLocator()->get('SearchEntity\Service\Indexer') );
        }

        return $this->searchService;
    }

只需将其调用到您的控制器文件中即可。它将再次建立索引。