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
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
24 * A Term represents a word from text. This is the unit of search. It is
25 * composed of two elements, the text of the word, as a string, and the name of
26 * the field that the text occured in, an interned string.
28 * Note that terms may represent more than words from text fields, but also
29 * things like dates, email addresses, urls, etc.
32 * @package Zend_Search_Lucene
34 * @copyright Copyright (c) 2005-2007 Zend Technologies USA Inc. (http://www.zend.com)
35 * @license http://framework.zend.com/license/new-bsd New BSD License
37 class Zend_Search_Lucene_Index_Term
40 * Field name or field number (depending from context)
57 public function __construct($text, $field = null)
59 $this->field
= ($field === null)? Zend_Search_Lucene
::getDefaultSearchField() : $field;
71 return $this->field
. chr(0) . $this->text
;
77 * @param integer $length
80 public static function getPrefix($str, $length)
84 while ($prefixBytes < strlen($str) && $prefixChars < $length) {
86 if ((ord($str[$prefixBytes]) & 0xC0) == 0xC0) {
88 if (ord($str[$prefixBytes]) & 0x20 ) {
90 if (ord($str[$prefixBytes]) & 0x10 ) {
96 if ($prefixBytes +
$charBytes > strlen($str)) {
102 $prefixBytes +
= $charBytes;
105 return substr($str, 0, $prefixBytes);