Hallo good people,

I have been having an error of "Index doesn't exists in the specified directory" in my zend application. i have a controller called search and it looks like this

class SearchController extends Zend_Controller_Action {

    protected $_indexPath = 'C:/xampp/htdocs/tbSurveillance/application/data/search';

    public function init() {
        /* Initialize action controller here */
    }

    public function indexAction() {
        // action body
    }

    public function buildindexAction() {
//        protected $_indexPath = APPLICATION_PATH.('\data\search');
        Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num());
        /*
         * create index
         */
        $index = Zend_Search_Lucene::create($this->_indexPath);
        /*
         * get all users for trial first
         * original was $mapper = new User_Mapper();
         * $users = $mapper->fetchall();
         */
        $mapper = new Application_Model_DbTable_Hospital();
        $hospital = $mapper->fetchAll();
        /*
         * Create a document for each user and add it to the index
         */
        foreach ($hospital as $hospital) {
            $doc = new Zend_Search_Lucene_Document();
            /*
             * Fill document with data
             */
//            $doc->addField(Zend_Search_Lucene_Field::keyword('hospitalId', $hospital->getId(), 'UTF-8'));
            $doc->addField(Zend_Search_Lucene_Field::keyword('hospitalName', $hospital->HospitalName(), 'UTF-8'));
            $doc->addField(Zend_Search_Lucene_Field::keyword('location', $hospital->getLocation(), 'UTF-8'));
            $doc->addField(Zend_Search_Lucene_Field::keyword('hospitalType', $hospitalType->get(), 'UTF-8'));
            /*
             * Add document
             */
            $index->addDocument($doc);

            echo 'Added to index.<br />';
        }
        $index = Zend_Search_Lucene::open($this->_indexPath);
        $index->optimize();
        /*
         * Now you can call http://yourdomain.com/search/buildindex to create the index or configure 
         * a cron job that creates the index every day. You could also put the functionality in a class 
         * and build the index only if something changes in the user data.
         */
    }

    public function searchAction() {
        if ($this->getRequest()->isPost()) {
            $post = $this->getRequest()->getPost('s');
            /*
             * open index
             */
            $index = Zend_Search_Lucene::open($this->_indexPath);
            Zend_Search_Lucene_Search_Query_Wildcard::setMinPrefixLength(0);
            $query = 'hospitalName:"' . $post['hospitalName'] . '" OR location:"' . $post['location'] . '"';
//            $data['results'] = $index->find($this->input->post('search_query'));
            $this->view->result = $index->find($query);
        } else {
            $this->view->form = new Search_Form();
        }
    }
}

while my view looks like

<?php foreach($this->result as $hospital): ?>
    <?php echo $hospital->hospitalName ?><br/>
<?php endforeach; ?>

But every time i run it, it displays the error (Index doesn't exists in the specified directory). i dont know what am not doing. any help will be appreciated.

Member Avatar for LastMitch

I have been having an error of "Index doesn't exists in the specified directory" in my zend application. i have a controller called search and it looks like this.

Read this link and it will explain why "Index doesn't exists in the specified directory":

https://github.com/egeloen/IvoryLuceneSearchBundle/issues/1

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.