File indexing completed on 2025-01-19 05:21:27
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_Search_Lucene 0017 * @subpackage Document 0018 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0019 * @license http://framework.zend.com/license/new-bsd New BSD License 0020 * @version $Id$ 0021 */ 0022 0023 0024 /** Zend_Search_Lucene_Field */ 0025 // require_once 'Zend/Search/Lucene/Field.php'; 0026 0027 0028 /** 0029 * A Document is a set of fields. Each field has a name and a textual value. 0030 * 0031 * @category Zend 0032 * @package Zend_Search_Lucene 0033 * @subpackage Document 0034 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0035 * @license http://framework.zend.com/license/new-bsd New BSD License 0036 */ 0037 class Zend_Search_Lucene_Document 0038 { 0039 0040 /** 0041 * Associative array Zend_Search_Lucene_Field objects where the keys to the 0042 * array are the names of the fields. 0043 * 0044 * @var array 0045 */ 0046 protected $_fields = array(); 0047 0048 /** 0049 * Field boost factor 0050 * It's not stored directly in the index, but affects on normalization factor 0051 * 0052 * @var float 0053 */ 0054 public $boost = 1.0; 0055 0056 /** 0057 * Proxy method for getFieldValue(), provides more convenient access to 0058 * the string value of a field. 0059 * 0060 * @param string $offset 0061 * @return string 0062 */ 0063 public function __get($offset) 0064 { 0065 return $this->getFieldValue($offset); 0066 } 0067 0068 0069 /** 0070 * Add a field object to this document. 0071 * 0072 * @param Zend_Search_Lucene_Field $field 0073 * @return Zend_Search_Lucene_Document 0074 */ 0075 public function addField(Zend_Search_Lucene_Field $field) 0076 { 0077 $this->_fields[$field->name] = $field; 0078 0079 return $this; 0080 } 0081 0082 0083 /** 0084 * Return an array with the names of the fields in this document. 0085 * 0086 * @return array 0087 */ 0088 public function getFieldNames() 0089 { 0090 return array_keys($this->_fields); 0091 } 0092 0093 0094 /** 0095 * Returns Zend_Search_Lucene_Field object for a named field in this document. 0096 * 0097 * @param string $fieldName 0098 * @return Zend_Search_Lucene_Field 0099 */ 0100 public function getField($fieldName) 0101 { 0102 if (!array_key_exists($fieldName, $this->_fields)) { 0103 // require_once 'Zend/Search/Lucene/Exception.php'; 0104 throw new Zend_Search_Lucene_Exception("Field name \"$fieldName\" not found in document."); 0105 } 0106 return $this->_fields[$fieldName]; 0107 } 0108 0109 0110 /** 0111 * Returns the string value of a named field in this document. 0112 * 0113 * @see __get() 0114 * @return string 0115 */ 0116 public function getFieldValue($fieldName) 0117 { 0118 return $this->getField($fieldName)->value; 0119 } 0120 0121 /** 0122 * Returns the string value of a named field in UTF-8 encoding. 0123 * 0124 * @see __get() 0125 * @return string 0126 */ 0127 public function getFieldUtf8Value($fieldName) 0128 { 0129 return $this->getField($fieldName)->getUtf8Value(); 0130 } 0131 }