簡體   English   中英

我們如何進行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://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('SearchEntity\Service\Indexer') );
        }

        return $this->searchService;
    }

只需將其調用到控制器文件中即可。 它將再次建立索引。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM