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