adding some strings
[moodle-linuxchix.git] / search / Zend / Search / Lucene / Index / Term.php
blob465b4ef41baff902e7616315cb085a48b1df2a53
1 <?php
2 /**
3 * Zend Framework
5 * LICENSE
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.
15 * @category Zend
16 * @package Zend_Search_Lucene
17 * @subpackage Index
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
23 /**
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.
31 * @category Zend
32 * @package Zend_Search_Lucene
33 * @subpackage Index
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
39 /**
40 * Field name or field number (depending from context)
42 * @var mixed
44 public $field;
46 /**
47 * Term value
49 * @var string
51 public $text;
54 /**
55 * Object constructor
57 public function __construct($text, $field = null)
59 $this->field = ($field === null)? Zend_Search_Lucene::getDefaultSearchField() : $field;
60 $this->text = $text;
64 /**
65 * Returns term key
67 * @return string
69 public function key()
71 return $this->field . chr(0) . $this->text;
74 /**
75 * Get term prefix
77 * @param integer $length
78 * @return string
80 public static function getPrefix($str, $length)
82 $prefixBytes = 0;
83 $prefixChars = 0;
84 while ($prefixBytes < strlen($str) && $prefixChars < $length) {
85 $charBytes = 1;
86 if ((ord($str[$prefixBytes]) & 0xC0) == 0xC0) {
87 $charBytes++;
88 if (ord($str[$prefixBytes]) & 0x20 ) {
89 $charBytes++;
90 if (ord($str[$prefixBytes]) & 0x10 ) {
91 $charBytes++;
96 if ($prefixBytes + $charBytes > strlen($str)) {
97 // wrong character
98 break;
101 $prefixChars++;
102 $prefixBytes += $charBytes;
105 return substr($str, 0, $prefixBytes);