Class 'Zend_Search_Lucene' not found-Collection of common programming errors

A big beginner of Zend-framework on PHP calls, I could include it on Netbeans IDE. Now I’m trying to use it to achieve a Lucene indexer and searcher using Zend_Lucene, I followed the getting started of the official site, unfortunately they explain the whole thing with just few words. Anyway, I copied pasted this $index = Zend_Search_Lucene::create($indexPath);, but I got a message onto this line saying: Fatal error: Class ‘Zend_Search_Lucene’ not found in C:\wamp\www\witswork\luceneTry.php means that the function still unknown, maybe, some files need to be copied on my project folder but really I’m running out of ideas right now. Accept my regards, dany90.

  1. You need to load the php file which contains the Zend_Search_Lucene class first. One option is to load your/path/to/library/Zend/Search/Lucene.php:

    require_once 'my/path/to/library/Zend/Search/Lucene.php';
    $index = new Zend_Search_Lucene::create($indexPath);
    

    This class loads all its dependencies, so you don’t need to worry about that.

    Another option is to use the autoloader of Zend, Zend_Loader_Autoloader. This class is a singleton and registers itself with spl_autoload() when you retrieve it for the first time:

    $autoloader = Zend_Loader_Autoloader::getInstance();
    $index      = new Zend_Search_Lucene::create($indexPath);
    

    After the autoloader is loaded, you just can use Zend_Search_Lucene without the require_once() call. In the manual of Zend Framework you can find more information about the autoloader.

Originally posted 2013-11-09 23:22:24.