import
[web.mtrack] / inc / lib / Zend / Search / Lucene / Analysis / TokenFilter / ShortWords.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: ShortWords.php 16971 2009-07-22 18:05:45Z mikaelkael $
21  */
22
23
24 /** Zend_Search_Lucene_Analysis_TokenFilter */
25 require_once 'Zend/Search/Lucene/Analysis/TokenFilter.php';
26
27
28 /**
29  * Token filter that removes short words. What is short word can be configured with constructor.
30  *
31  * @category   Zend
32  * @package    Zend_Search_Lucene
33  * @subpackage Analysis
34  * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
35  * @license    http://framework.zend.com/license/new-bsd     New BSD License
36  */
37
38 class Zend_Search_Lucene_Analysis_TokenFilter_ShortWords extends Zend_Search_Lucene_Analysis_TokenFilter
39 {
40     /**
41      * Minimum allowed term length
42      * @var integer
43      */
44     private $length;
45
46     /**
47      * Constructs new instance of this filter.
48      *
49      * @param integer $short  minimum allowed length of term which passes this filter (default 2)
50      */
51     public function __construct($length = 2) {
52         $this->length = $length;
53     }
54
55     /**
56      * Normalize Token or remove it (if null is returned)
57      *
58      * @param Zend_Search_Lucene_Analysis_Token $srcToken
59      * @return Zend_Search_Lucene_Analysis_Token
60      */
61     public function normalize(Zend_Search_Lucene_Analysis_Token $srcToken) {
62         if (strlen($srcToken->getTermText()) < $this->length) {
63             return null;
64         } else {
65             return $srcToken;
66         }
67     }
68 }
69