Initial commit
[moodle.git] / search / Zend / Search / Lucene / Field.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/**
24 * A field is a section of a Document. Each field has two parts,
25 * a name and a value. Values may be free text or they may be atomic
26 * keywords, which are not further processed. Such keywords may
27 * be used to represent dates, urls, etc. Fields are optionally
28 * stored in the index, so that they may be returned with hits
29 * on the document.
30 *
31 * @category Zend
32 * @package Zend_Search_Lucene
33 * @subpackage Document
34 * @copyright Copyright (c) 2006 Zend Technologies USA Inc. (http://www.zend.com)
35 * @license http://framework.zend.com/license/new-bsd New BSD License
36 */
37//require_once('EncodingConverter.php');
38
39class Zend_Search_Lucene_Field
40{
41 public $kind;
42
43 public $name = 'body';
44 public $stringValue = null;
45 public $isStored = false;
46 public $isIndexed = true;
47 public $isTokenized = true;
48 public $isBinary = false;
49
50 public $storeTermVector = false;
51
52 public $boost = 1.0;
53
54 public function __construct($name, $stringValue, $isStored, $isIndexed, $isTokenized, $isBinary = false)
55 {
56 $this->name = $name;
57
58 if (!$isBinary) {
59 /*
60 $econv = new EncodingConverter(mb_detect_encoding($stringValue), 'ASCII//TRANSLIT');
61 $this->stringValue = $econv->convert($stringValue);
62
63 if ($econv->getLastError()) {
64 echo "Error: ".$econv->getLastError();
65 echo "<br>";
66 echo "x".$stringValue."x";
67 exit();
68 } else {
69 }*/
70
71 /**
72 * @todo Correct UTF-8 string should be required in future
73 * Until full UTF-8 support is not completed, string should be normalized to ANSII encoding
74 */
75
76 $this->stringValue = iconv('ISO-8859-1', 'ASCII//TRANSLIT', $stringValue);
77 //$this->stringValue = iconv(mb_detect_encoding($stringValue), 'ASCII//TRANSLIT', $stringValue);
78 } else {
79 $this->stringValue = $stringValue;
80 }
81 $this->isStored = $isStored;
82 $this->isIndexed = $isIndexed;
83 $this->isTokenized = $isTokenized;
84 $this->isBinary = $isBinary;
85
86 $this->storeTermVector = false;
87 $this->boost = 1.0;
88 }
89
90
91 /**
92 * Constructs a String-valued Field that is not tokenized, but is indexed
93 * and stored. Useful for non-text fields, e.g. date or url.
94 *
95 * @param string $name
96 * @param string $value
97 * @return Zend_Search_Lucene_Field
98 */
99 static public function Keyword($name, $value)
100 {
101 return new self($name, $value, true, true, false);
102 }
103
104
105 /**
106 * Constructs a String-valued Field that is not tokenized nor indexed,
107 * but is stored in the index, for return with hits.
108 *
109 * @param string $name
110 * @param string $value
111 * @return Zend_Search_Lucene_Field
112 */
113 static public function UnIndexed($name, $value)
114 {
115 return new self($name, $value, true, false, false);
116 }
117
118
119 /**
120 * Constructs a Binary String valued Field that is not tokenized nor indexed,
121 * but is stored in the index, for return with hits.
122 *
123 * @param string $name
124 * @param string $value
125 * @return Zend_Search_Lucene_Field
126 */
127 static public function Binary($name, $value)
128 {
129 return new self($name, $value, true, false, false, true);
130 }
131
132 /**
133 * Constructs a String-valued Field that is tokenized and indexed,
134 * and is stored in the index, for return with hits. Useful for short text
135 * fields, like "title" or "subject". Term vector will not be stored for this field.
136 *
137 * @param string $name
138 * @param string $value
139 * @return Zend_Search_Lucene_Field
140 */
141 static public function Text($name, $value)
142 {
143 return new self($name, $value, true, true, true);
144 }
145
146
147 /**
148 * Constructs a String-valued Field that is tokenized and indexed,
149 * but that is not stored in the index.
150 *
151 * @param string $name
152 * @param string $value
153 * @return Zend_Search_Lucene_Field
154 */
155 static public function UnStored($name, $value)
156 {
157 return new self($name, $value, false, true, true);
158 }
159
160}
161