ZF-2456: Fatal error: Class 'Zend_Search_Lucene_Analysis_Analyzer_Common' not found

Description

When I'm using Zend_Search_Lucene with the stopwords filter, I did run on a fatal error that the Zend_Search_Lucene_Analysis_Analyzer_Common couldn't be found.

When I was looking to this error, it seemed that Zend_Search_Lucene_Analysis_Analyzer_Common requires some other classes that require Zend_Search_Lucene_Analysis_Analyzer_Common before it was declared.

I am using the last version from trunk (r7513). I will also build a patch to fix this problem.

Comments

This patch fixes the problem, and removes the unnecessary require statements from Zend/Search/Lucene/Analysis/Analyzer.php, so there will be no fatal error.

This bug does also affect version 1.0.3.

Just include 'Zend/Search/Lucene.php' or 'Zend/Search/Lucene/Analysis/Analyzer.php' into your php file which implements your own analyzer (instead of 'Zend/Search/Lucene/Analysis/Analyzer/Common.php').

Zend_Search_Lucene_Analyzer package has some cyclic references between files and needs them to be included in a special order. This order is defined in the 'Analyzer.php'. There are no other files which are intended to be included directly into your code.

Use the example:


<?php
require_once 'Zend/Search/Lucene/Analysis/Analyzer.php';

class MyAnalyzer extends Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum_CaseInsensitive
{
    public function __construct()
    {
        parent::__construct();
        
        $stopWords = array('a', 'the', 'this', 'in', 'is', 'from');
        $this->addFilter(new Zend_Search_Lucene_Analysis_TokenFilter_StopWords($stopWords));
    }
}

Zend_Search_Lucene_Analysis_Analyzer::setDefault(new MyAnalyzer);


var_dump(Zend_Search_Lucene_Analysis_Analyzer::getDefault()->tokenize('This is the test of stop-words analyzer'));

Bookkeeping. Closing and assigning all old unassigned issues. The only unassigned issues should be new and unreviewed.