Merge commit 'catalyst/MOODLE_19_STABLE' into mdl19-linuxchix
[moodle-linuxchix.git] / search / Zend / Search / Lucene / Field.php
blob86cd22ccea1797f456cb1da120abaa036498f432
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 Document
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 field is a section of a Document. Each field has two parts,
25 * a name and a value. Values may be free text or they may be atomic
26 * keywords, which are not further processed. Such keywords may
27 * be used to represent dates, urls, etc. Fields are optionally
28 * stored in the index, so that they may be returned with hits
29 * on the document.
31 * @category Zend
32 * @package Zend_Search_Lucene
33 * @subpackage Document
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_Field
39 /**
40 * Field name
42 * @var string
44 public $name;
47 public $value;
48 public $isStored = false;
49 public $isIndexed = true;
50 public $isTokenized = true;
51 public $isBinary = false;
53 public $storeTermVector = false;
55 /**
56 * Field boos factor
57 * It's not stored directly in the index, but affects on normalizetion factor
59 * @var float
61 public $boost = 1.0;
63 /**
64 * Field value encoding.
66 * @var string
68 public $encoding;
70 /**
71 * Object constructor
73 * @param string $name
74 * @param string $value
75 * @param string $encoding
76 * @param boolean $isStored
77 * @param boolean $isIndexed
78 * @param boolean $isTokenized
79 * @param boolean $isBinary
81 public function __construct($name, $value, $encoding, $isStored, $isIndexed, $isTokenized, $isBinary = false)
83 $this->name = $name;
84 $this->value = $value;
86 if (!$isBinary) {
87 $this->encoding = $encoding;
88 $this->isTokenized = $isTokenized;
89 } else {
90 $this->encoding = '';
91 $this->isTokenized = false;
94 $this->isStored = $isStored;
95 $this->isIndexed = $isIndexed;
96 $this->isBinary = $isBinary;
98 $this->storeTermVector = false;
99 $this->boost = 1.0;
104 * Constructs a String-valued Field that is not tokenized, but is indexed
105 * and stored. Useful for non-text fields, e.g. date or url.
107 * @param string $name
108 * @param string $value
109 * @param string $encoding
110 * @return Zend_Search_Lucene_Field
112 public static function Keyword($name, $value, $encoding = '')
114 return new self($name, $value, $encoding, true, true, false);
119 * Constructs a String-valued Field that is not tokenized nor indexed,
120 * but is stored in the index, for return with hits.
122 * @param string $name
123 * @param string $value
124 * @param string $encoding
125 * @return Zend_Search_Lucene_Field
127 public static function UnIndexed($name, $value, $encoding = '')
129 return new self($name, $value, $encoding, true, false, false);
134 * Constructs a Binary String valued Field that is not tokenized nor indexed,
135 * but is stored in the index, for return with hits.
137 * @param string $name
138 * @param string $value
139 * @param string $encoding
140 * @return Zend_Search_Lucene_Field
142 public static function Binary($name, $value)
144 return new self($name, $value, '', true, false, false, true);
148 * Constructs a String-valued Field that is tokenized and indexed,
149 * and is stored in the index, for return with hits. Useful for short text
150 * fields, like "title" or "subject". Term vector will not be stored for this field.
152 * @param string $name
153 * @param string $value
154 * @param string $encoding
155 * @return Zend_Search_Lucene_Field
157 public static function Text($name, $value, $encoding = '')
159 return new self($name, $value, $encoding, true, true, true);
164 * Constructs a String-valued Field that is tokenized and indexed,
165 * but that is not stored in the index.
167 * @param string $name
168 * @param string $value
169 * @param string $encoding
170 * @return Zend_Search_Lucene_Field
172 public static function UnStored($name, $value, $encoding = '')
174 return new self($name, $value, $encoding, false, true, true);
178 * Get field value in UTF-8 encoding
180 * @return string
182 public function getUtf8Value()
184 if (strcasecmp($this->encoding, 'utf8' ) == 0 ||
185 strcasecmp($this->encoding, 'utf-8') == 0 ) {
186 return $this->value;
187 } else {
188 return iconv($this->encoding, 'UTF-8', $this->value);