Merge commit 'catalyst/MOODLE_19_STABLE' into mdl19-linuxchix
[moodle-linuxchix.git] / search / Zend / Search / Lucene / Document.php
blob6309719568d44a6be6b1381a734931e84db0256a
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 /** Zend_Search_Lucene_Field */
24 require_once $CFG->dirroot.'/search/Zend/Search/Lucene/Field.php';
27 /**
28 * A Document is a set of fields. Each field has a name and a textual value.
30 * @category Zend
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
39 /**
40 * Associative array Zend_Search_Lucene_Field objects where the keys to the
41 * array are the names of the fields.
43 * @var array
45 protected $_fields = array();
47 public $boost = 1.0;
50 /**
51 * Proxy method for getFieldValue(), provides more convenient access to
52 * the string value of a field.
54 * @param $offset
55 * @return string
57 public function __get($offset)
59 return $this->getFieldValue($offset);
63 /**
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;
74 /**
75 * Return an array with the names of the fields in this document.
77 * @return array
79 public function getFieldNames()
81 return array_keys($this->_fields);
85 /**
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.
103 * @see __get()
104 * @return string
106 public function getFieldValue($fieldName)
108 return $this->getField($fieldName)->value;
112 * Returns the string value of a named field in UTF-8 encoding.
114 * @see __get()
115 * @return string
117 public function getFieldUtf8Value($fieldName)
119 return $this->getField($fieldName)->getUtf8Value();