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 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 /** Zend_Search_Lucene_Field */
24 require_once $CFG->dirroot
.'/search/Zend/Search/Lucene/Field.php';
28 * A Document is a set of fields. Each field has a name and a textual value.
31 * @package Zend_Search_Lucene
32 * @subpackage Document
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
36 class Zend_Search_Lucene_Document
40 * Associative array Zend_Search_Lucene_Field objects where the keys to the
41 * array are the names of the fields.
45 protected $_fields = array();
51 * Proxy method for getFieldValue(), provides more convenient access to
52 * the string value of a field.
57 public function __get($offset)
59 return $this->getFieldValue($offset);
64 * Add a field object to this document.
66 * @param Zend_Search_Lucene_Field $field
68 public function addField(Zend_Search_Lucene_Field
$field)
70 $this->_fields
[$field->name
] = $field;
75 * Return an array with the names of the fields in this document.
79 public function getFieldNames()
81 return array_keys($this->_fields
);
86 * Returns Zend_Search_Lucene_Field object for a named field in this document.
88 * @param string $fieldName
89 * @return Zend_Search_Lucene_Field
91 public function getField($fieldName)
93 if (!array_key_exists($fieldName, $this->_fields
)) {
94 throw new Zend_Search_Lucene_Exception("Field name \"$fieldName\" not found in document.");
96 return $this->_fields
[$fieldName];
101 * Returns the string value of a named field in this document.
106 public function getFieldValue($fieldName)
108 return $this->getField($fieldName)->value
;
112 * Returns the string value of a named field in UTF-8 encoding.
117 public function getFieldUtf8Value($fieldName)
119 return $this->getField($fieldName)->getUtf8Value();