Initial commit
[moodle.git] / search / Zend / Search / Lucene / Document.php
CommitLineData
682d4032 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) 2006 Zend Technologies USA Inc. (http://www.zend.com)
19 * @license http://framework.zend.com/license/new-bsd New BSD License
20 */
21
22
23/** Zend_Search_Lucene_Field */
24require_once 'Zend/Search/Lucene/Field.php';
25
26
27/**
28 * A Document is a set of fields. Each field has a name and a textual value.
29 *
30 * @category Zend
31 * @package Zend_Search_Lucene
32 * @subpackage Document
33 * @copyright Copyright (c) 2006 Zend Technologies USA Inc. (http://www.zend.com)
34 * @license http://framework.zend.com/license/new-bsd New BSD License
35 */
36class Zend_Search_Lucene_Document
37{
38
39 /**
40 * Associative array Zend_Search_Lucene_Field objects where the keys to the
41 * array are the names of the fields.
42 *
43 * @var array
44 */
45 protected $_fields = array();
46
47 public $boost = 1.0;
48
49
50 /**
51 * Proxy method for getFieldValue(), provides more convenient access to
52 * the string value of a field.
53 *
54 * @param $offset
55 * @return string
56 */
57 public function __get($offset)
58 {
59 return $this->getFieldValue($offset);
60 }
61
62
63 /**
64 * Add a field object to this document.
65 *
66 * @param Zend_Search_Lucene_Field $field
67 */
68 public function addField(Zend_Search_Lucene_Field $field)
69 {
70 $this->_fields[$field->name] = $field;
71 }
72
73
74 /**
75 * Return an array with the names of the fields in this document.
76 *
77 * @return array
78 */
79 public function getFieldNames()
80 {
81 return array_keys($this->_fields);
82 }
83
84
85 /**
86 * Returns Zend_Search_Lucene_Field object for a named field in this document.
87 *
88 * @param string $fieldName
89 * @return Zend_Search_Lucene_Field
90 */
91 public function getField($fieldName)
92 {
93 if (!array_key_exists($fieldName, $this->_fields)) {
94 throw new Zend_Search_Lucene_Exception("Field name \"$fieldName\" not found in document.");
95 }
96 return $this->_fields[$fieldName];
97 }
98
99
100 /**
101 * Returns the string value of a named field in this document.
102 *
103 * @see __get()
104 * @return string
105 */
106 public function getFieldValue($fieldName)
107 {
108 return $this->getField($fieldName)->stringValue;
109 }
110
111}