【问题标题】:How can we do whole site reindexing of lucene search我们如何对 lucene 搜索进行整个站点重新索引
【发布时间】:2015-03-23 11:46:18
【问题描述】:
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 中执行重新索引。

【问题讨论】:

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


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-04
      • 2011-06-15
      • 1970-01-01
      • 2011-12-14
      • 2012-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多