|
1 <?php |
|
2 /** |
|
3 * Zend Framework |
|
4 * |
|
5 * LICENSE |
|
6 * |
|
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. |
|
14 * |
|
15 * @category Zend |
|
16 * @package Zend_Search_Lucene |
|
17 * @subpackage Document |
|
18 * @copyright Copyright (c) 2005-2010 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 20096 2010-01-06 02:05:09Z bkarwin $ |
|
21 */ |
|
22 |
|
23 |
|
24 /** Zend_Search_Lucene_Field */ |
|
25 require_once 'Zend/Search/Lucene/Field.php'; |
|
26 |
|
27 |
|
28 /** |
|
29 * A Document is a set of fields. Each field has a name and a textual value. |
|
30 * |
|
31 * @category Zend |
|
32 * @package Zend_Search_Lucene |
|
33 * @subpackage Document |
|
34 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
35 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
36 */ |
|
37 class Zend_Search_Lucene_Document |
|
38 { |
|
39 |
|
40 /** |
|
41 * Associative array Zend_Search_Lucene_Field objects where the keys to the |
|
42 * array are the names of the fields. |
|
43 * |
|
44 * @var array |
|
45 */ |
|
46 protected $_fields = array(); |
|
47 |
|
48 /** |
|
49 * Field boost factor |
|
50 * It's not stored directly in the index, but affects on normalization factor |
|
51 * |
|
52 * @var float |
|
53 */ |
|
54 public $boost = 1.0; |
|
55 |
|
56 /** |
|
57 * Proxy method for getFieldValue(), provides more convenient access to |
|
58 * the string value of a field. |
|
59 * |
|
60 * @param $offset |
|
61 * @return string |
|
62 */ |
|
63 public function __get($offset) |
|
64 { |
|
65 return $this->getFieldValue($offset); |
|
66 } |
|
67 |
|
68 |
|
69 /** |
|
70 * Add a field object to this document. |
|
71 * |
|
72 * @param Zend_Search_Lucene_Field $field |
|
73 * @return Zend_Search_Lucene_Document |
|
74 */ |
|
75 public function addField(Zend_Search_Lucene_Field $field) |
|
76 { |
|
77 $this->_fields[$field->name] = $field; |
|
78 |
|
79 return $this; |
|
80 } |
|
81 |
|
82 |
|
83 /** |
|
84 * Return an array with the names of the fields in this document. |
|
85 * |
|
86 * @return array |
|
87 */ |
|
88 public function getFieldNames() |
|
89 { |
|
90 return array_keys($this->_fields); |
|
91 } |
|
92 |
|
93 |
|
94 /** |
|
95 * Returns Zend_Search_Lucene_Field object for a named field in this document. |
|
96 * |
|
97 * @param string $fieldName |
|
98 * @return Zend_Search_Lucene_Field |
|
99 */ |
|
100 public function getField($fieldName) |
|
101 { |
|
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."); |
|
105 } |
|
106 return $this->_fields[$fieldName]; |
|
107 } |
|
108 |
|
109 |
|
110 /** |
|
111 * Returns the string value of a named field in this document. |
|
112 * |
|
113 * @see __get() |
|
114 * @return string |
|
115 */ |
|
116 public function getFieldValue($fieldName) |
|
117 { |
|
118 return $this->getField($fieldName)->value; |
|
119 } |
|
120 |
|
121 /** |
|
122 * Returns the string value of a named field in UTF-8 encoding. |
|
123 * |
|
124 * @see __get() |
|
125 * @return string |
|
126 */ |
|
127 public function getFieldUtf8Value($fieldName) |
|
128 { |
|
129 return $this->getField($fieldName)->getUtf8Value(); |
|
130 } |
|
131 } |