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-2009 Zend Technologies USA Inc. (http://www.zend.com)
19 * @license http://framework.zend.com/license/new-bsd New BSD License
20 * @version $Id: Document.php 16543 2009-07-07 09:44:56Z yoshida@zend.co.jp $
24 /** Zend_Search_Lucene_Field */
25 require_once 'Zend/Search/Lucene/Field.php';
29 * A Document is a set of fields. Each field has a name and a textual value.
32 * @package Zend_Search_Lucene
33 * @subpackage Document
34 * @copyright Copyright (c) 2005-2009 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_Document
41 * Associative array Zend_Search_Lucene_Field objects where the keys to the
42 * array are the names of the fields.
46 protected $_fields = array();
50 * It's not stored directly in the index, but affects on normalization factor
57 * Proxy method for getFieldValue(), provides more convenient access to
58 * the string value of a field.
63 public function __get($offset)
65 return $this->getFieldValue($offset);
70 * Add a field object to this document.
72 * @param Zend_Search_Lucene_Field $field
73 * @return Zend_Search_Lucene_Document
75 public function addField(Zend_Search_Lucene_Field $field)
77 $this->_fields[$field->name] = $field;
84 * Return an array with the names of the fields in this document.
88 public function getFieldNames()
90 return array_keys($this->_fields);
95 * Returns Zend_Search_Lucene_Field object for a named field in this document.
97 * @param string $fieldName
98 * @return Zend_Search_Lucene_Field
100 public function getField($fieldName)
102 if (!array_key_exists($fieldName, $this->_fields)) {
103 require_once 'Zend/Search/Lucene/Exception.php';
104 throw new Zend_Search_Lucene_Exception("Field name \"$fieldName\" not found in document.");
106 return $this->_fields[$fieldName];
111 * Returns the string value of a named field in this document.
116 public function getFieldValue($fieldName)
118 return $this->getField($fieldName)->value;
122 * Returns the string value of a named field in UTF-8 encoding.
127 public function getFieldUtf8Value($fieldName)
129 return $this->getField($fieldName)->getUtf8Value();