web/lib/Zend/Search/Lucene/Analysis/Analyzer/Common.php
changeset 64 162c1de6545a
parent 19 1c2f13fd785c
child 68 ecaf28ffe26e
equal deleted inserted replaced
63:5b37998e522e 64:162c1de6545a
       
     1 <?php
       
     2 /**
       
     3  * Zend Framework
       
     4  *
       
     5  * LICENSE
       
     6  *
       
     7  * This source file is subject to the new BSD license that is bundled
       
     8  * with this package in the file LICENSE.txt.
       
     9  * It is also available through the world-wide-web at this URL:
       
    10  * http://framework.zend.com/license/new-bsd
       
    11  * If you did not receive a copy of the license and are unable to
       
    12  * obtain it through the world-wide-web, please send an email
       
    13  * to license@zend.com so we can send you a copy immediately.
       
    14  *
       
    15  * @category   Zend
       
    16  * @package    Zend_Search_Lucene
       
    17  * @subpackage Analysis
       
    18  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    20  * @version    $Id: Common.php 20096 2010-01-06 02:05:09Z bkarwin $
       
    21  */
       
    22 
       
    23 
       
    24 /** Define constant used to provide correct file processing order    */
       
    25 /** @todo Section should be removed with ZF 2.0 release as obsolete  */
       
    26 define('ZEND_SEARCH_LUCENE_COMMON_ANALYZER_PROCESSED', true);
       
    27 
       
    28 
       
    29 /** Zend_Search_Lucene_Analysis_Analyzer */
       
    30 require_once 'Zend/Search/Lucene/Analysis/Analyzer.php';
       
    31 
       
    32 /** Zend_Search_Lucene_Analysis_Token */
       
    33 require_once 'Zend/Search/Lucene/Analysis/Token.php';
       
    34 
       
    35 /** Zend_Search_Lucene_Analysis_TokenFilter */
       
    36 require_once 'Zend/Search/Lucene/Analysis/TokenFilter.php';
       
    37 
       
    38 
       
    39 /**
       
    40  * Common implementation of the Zend_Search_Lucene_Analysis_Analyzer interface.
       
    41  * There are several standard standard subclasses provided by Zend_Search_Lucene/Analysis
       
    42  * subpackage: Zend_Search_Lucene_Analysis_Analyzer_Common_Text, ZSearchHTMLAnalyzer, ZSearchXMLAnalyzer.
       
    43  *
       
    44  * @todo ZSearchHTMLAnalyzer and ZSearchXMLAnalyzer implementation
       
    45  *
       
    46  * @category   Zend
       
    47  * @package    Zend_Search_Lucene
       
    48  * @subpackage Analysis
       
    49  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    50  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    51  */
       
    52 abstract class Zend_Search_Lucene_Analysis_Analyzer_Common extends Zend_Search_Lucene_Analysis_Analyzer
       
    53 {
       
    54     /**
       
    55      * The set of Token filters applied to the Token stream.
       
    56      * Array of Zend_Search_Lucene_Analysis_TokenFilter objects.
       
    57      *
       
    58      * @var array
       
    59      */
       
    60     private $_filters = array();
       
    61 
       
    62     /**
       
    63      * Add Token filter to the Analyzer
       
    64      *
       
    65      * @param Zend_Search_Lucene_Analysis_TokenFilter $filter
       
    66      */
       
    67     public function addFilter(Zend_Search_Lucene_Analysis_TokenFilter $filter)
       
    68     {
       
    69         $this->_filters[] = $filter;
       
    70     }
       
    71 
       
    72     /**
       
    73      * Apply filters to the token. Can return null when the token was removed.
       
    74      *
       
    75      * @param Zend_Search_Lucene_Analysis_Token $token
       
    76      * @return Zend_Search_Lucene_Analysis_Token
       
    77      */
       
    78     public function normalize(Zend_Search_Lucene_Analysis_Token $token)
       
    79     {
       
    80         foreach ($this->_filters as $filter) {
       
    81             $token = $filter->normalize($token);
       
    82 
       
    83             // resulting token can be null if the filter removes it
       
    84             if ($token === null) {
       
    85                 return null;
       
    86             }
       
    87         }
       
    88 
       
    89         return $token;
       
    90     }
       
    91 }
       
    92