import
[web.mtrack] / inc / lib / Zend / Search / Lucene / Analysis / Analyzer / Common.php
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-2009 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 16541 2009-07-07 06:59:03Z bkarwin $
21  */
22
23
24 /** Zend_Search_Lucene_Analysis_Analyzer */
25 require_once 'Zend/Search/Lucene/Analysis/Analyzer.php';
26
27
28 /**
29  * Common implementation of the Zend_Search_Lucene_Analysis_Analyzer interface.
30  * There are several standard standard subclasses provided by Zend_Search_Lucene/Analysis
31  * subpackage: Zend_Search_Lucene_Analysis_Analyzer_Common_Text, ZSearchHTMLAnalyzer, ZSearchXMLAnalyzer.
32  *
33  * @todo ZSearchHTMLAnalyzer and ZSearchXMLAnalyzer implementation
34  *
35  * @category   Zend
36  * @package    Zend_Search_Lucene
37  * @subpackage Analysis
38  * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
39  * @license    http://framework.zend.com/license/new-bsd     New BSD License
40  */
41 abstract class Zend_Search_Lucene_Analysis_Analyzer_Common extends Zend_Search_Lucene_Analysis_Analyzer
42 {
43     /**
44      * The set of Token filters applied to the Token stream.
45      * Array of Zend_Search_Lucene_Analysis_TokenFilter objects.
46      *
47      * @var array
48      */
49     private $_filters = array();
50
51     /**
52      * Add Token filter to the Analyzer
53      *
54      * @param Zend_Search_Lucene_Analysis_TokenFilter $filter
55      */
56     public function addFilter(Zend_Search_Lucene_Analysis_TokenFilter $filter)
57     {
58         $this->_filters[] = $filter;
59     }
60
61     /**
62      * Apply filters to the token. Can return null when the token was removed.
63      *
64      * @param Zend_Search_Lucene_Analysis_Token $token
65      * @return Zend_Search_Lucene_Analysis_Token
66      */
67     public function normalize(Zend_Search_Lucene_Analysis_Token $token)
68     {
69         foreach ($this->_filters as $filter) {
70             $token = $filter->normalize($token);
71
72             // resulting token can be null if the filter removes it
73             if ($token === null) {
74                 return null;
75             }
76         }
77
78         return $token;
79     }
80 }
81