zend-frameworklucenezend-search-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;
    }

Every time when i do perform search in my zend website, it is giving me zero results, please tell me someone how to perform reindexing in zend.


Solution

  • I have solved the problem, Its an reindex issue. When we refresh page we have to build indexes. I fixed this by using following code.

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

    Just call this into your controller file. It will build indexes again.