我们如何才能对lucene搜索进行整个站点重建索引

时间:2015-03-23 11:46:18

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

public function searchIndex($entity)
    {
        //http://framework.zend.com/manual/2.0/en/modules/zendsearch.lucene.searching.html#
        //http://stackoverflow.com/questions/7805996/zend-search-lucene-matches
        //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中执行重建索引。

1 个答案:

答案 0 :(得分:0)

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

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

        return $this->searchService;
    }

只需将其调入您的控制器文件即可。它将再次构建索引。

相关问题