我们如何对 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中执行重新索引。

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

public function getbuild()
    {
        if (!$this->searchService) {
            $this->setSearchService( $this->getServiceLocator()->get('SearchEntityServiceIndexer') );
        }
        return $this->searchService;
    }

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

最新更新