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.
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: Analyzer.php 16541 2009-07-07 06:59:03Z bkarwin $
24 /** Zend_Search_Lucene_Analysis_Token */
25 require_once 'Zend/Search/Lucene/Analysis/Token.php';
27 /** Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8 */
28 require_once 'Zend/Search/Lucene/Analysis/Analyzer/Common/Utf8.php';
30 /** Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8_CaseInsensitive */
31 require_once 'Zend/Search/Lucene/Analysis/Analyzer/Common/Utf8/CaseInsensitive.php';
33 /** Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num */
34 require_once 'Zend/Search/Lucene/Analysis/Analyzer/Common/Utf8Num.php';
36 /** Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8Num_CaseInsensitive */
37 require_once 'Zend/Search/Lucene/Analysis/Analyzer/Common/Utf8Num/CaseInsensitive.php';
39 /** Zend_Search_Lucene_Analysis_Analyzer_Common_Text */
40 require_once 'Zend/Search/Lucene/Analysis/Analyzer/Common/Text.php';
42 /** Zend_Search_Lucene_Analysis_Analyzer_Common_Text_CaseInsensitive */
43 require_once 'Zend/Search/Lucene/Analysis/Analyzer/Common/Text/CaseInsensitive.php';
45 /** Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum */
46 require_once 'Zend/Search/Lucene/Analysis/Analyzer/Common/TextNum.php';
48 /** Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum_CaseInsensitive */
49 require_once 'Zend/Search/Lucene/Analysis/Analyzer/Common/TextNum/CaseInsensitive.php';
51 /** Zend_Search_Lucene_Analysis_TokenFilter_StopWords */
52 require_once 'Zend/Search/Lucene/Analysis/TokenFilter/StopWords.php';
54 /** Zend_Search_Lucene_Analysis_TokenFilter_ShortWords */
55 require_once 'Zend/Search/Lucene/Analysis/TokenFilter/ShortWords.php';
59 * An Analyzer is used to analyze text.
60 * It thus represents a policy for extracting index terms from text.
63 * Lucene Java implementation is oriented to streams. It provides effective work
64 * with a huge documents (more then 20Mb).
65 * But engine itself is not oriented such documents.
66 * Thus Zend_Search_Lucene analysis API works with data strings and sets (arrays).
69 * @package Zend_Search_Lucene
70 * @subpackage Analysis
71 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
72 * @license http://framework.zend.com/license/new-bsd New BSD License
75 abstract class Zend_Search_Lucene_Analysis_Analyzer
78 * The Analyzer implementation used by default.
80 * @var Zend_Search_Lucene_Analysis_Analyzer
82 private static $_defaultImpl;
89 protected $_input = null;
92 * Input string encoding
96 protected $_encoding = '';
99 * Tokenize text to a terms
100 * Returns array of Zend_Search_Lucene_Analysis_Token objects
102 * Tokens are returned in UTF-8 (internal Zend_Search_Lucene encoding)
104 * @param string $data
107 public function tokenize($data, $encoding = '')
109 $this->setInput($data, $encoding);
111 $tokenList = array();
112 while (($nextToken = $this->nextToken()) !== null) {
113 $tokenList[] = $nextToken;
121 * Tokenization stream API
124 * @param string $data
126 public function setInput($data, $encoding = '')
128 $this->_input = $data;
129 $this->_encoding = $encoding;
136 abstract public function reset();
139 * Tokenization stream API
141 * Returns null at the end of stream
143 * Tokens are returned in UTF-8 (internal Zend_Search_Lucene encoding)
145 * @return Zend_Search_Lucene_Analysis_Token|null
147 abstract public function nextToken();
153 * Set the default Analyzer implementation used by indexing code.
155 * @param Zend_Search_Lucene_Analysis_Analyzer $similarity
157 public static function setDefault(Zend_Search_Lucene_Analysis_Analyzer $analyzer)
159 self::$_defaultImpl = $analyzer;
164 * Return the default Analyzer implementation used by indexing code.
166 * @return Zend_Search_Lucene_Analysis_Analyzer
168 public static function getDefault()
170 if (!self::$_defaultImpl instanceof Zend_Search_Lucene_Analysis_Analyzer) {
171 self::$_defaultImpl = new Zend_Search_Lucene_Analysis_Analyzer_Common_Text_CaseInsensitive();
174 return self::$_defaultImpl;