@@ -93,6 +93,9 @@ |
||
93 | 93 | $param->IsValid = $this->password->Text == 'Prado'; |
94 | 94 | } |
95 | 95 | |
96 | + /** |
|
97 | + * @param CommentRecord $record |
|
98 | + */ |
|
96 | 99 | protected function format_message($record) |
97 | 100 | { |
98 | 101 | $username=htmlspecialchars($record->username); |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | |
11 | 11 | class CommentRecord extends TActiveRecord |
12 | 12 | { |
13 | - const TABLE='qs_comments'; |
|
13 | + const TABLE = 'qs_comments'; |
|
14 | 14 | |
15 | 15 | public $id; |
16 | 16 | public $username; |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | public $block_id; |
20 | 20 | public $content; |
21 | 21 | |
22 | - public static function finder($className=__CLASS__) |
|
22 | + public static function finder($className = __CLASS__) |
|
23 | 23 | { |
24 | 24 | return parent::finder($className); |
25 | 25 | } |
@@ -31,18 +31,18 @@ discard block |
||
31 | 31 | |
32 | 32 | function onLoad($param) |
33 | 33 | { |
34 | - if(!$this->Page->IsCallBack) |
|
34 | + if (!$this->Page->IsCallBack) |
|
35 | 35 | { |
36 | 36 | $count = array(); |
37 | 37 | $data = $this->getCommentData(); |
38 | - foreach($data as $r) |
|
38 | + foreach ($data as $r) |
|
39 | 39 | { |
40 | - if(!isset($count[$r->block_id])) |
|
41 | - $count[$r->block_id]=0; |
|
40 | + if (!isset($count[$r->block_id])) |
|
41 | + $count[$r->block_id] = 0; |
|
42 | 42 | $count[$r->block_id]++; |
43 | 43 | } |
44 | - $js = "var comment_count = ".TJavascript::encode($count).";\n"; |
|
45 | - $this->Page->ClientScript->registerBeginScript('count',$js); |
|
44 | + $js = "var comment_count = " . TJavascript::encode($count) . ";\n"; |
|
45 | + $this->Page->ClientScript->registerBeginScript('count', $js); |
|
46 | 46 | $this->comments->dataSource = $data; |
47 | 47 | $this->comments->dataBind(); |
48 | 48 | } |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | |
56 | 56 | function add_comment($sender, $param) |
57 | 57 | { |
58 | - if(!$this->Page->IsValid) |
|
58 | + if (!$this->Page->IsValid) |
|
59 | 59 | return; |
60 | 60 | $record = new CommentRecord; |
61 | 61 | $record->username = $this->username->Text; |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | $cc->appendContent('comment-list', $this->format_message($record)); |
72 | 72 | $cc->callClientFunction('hide_add_comment'); |
73 | 73 | $cc->callClientFunction('increment_count_tag', $record->block_id); |
74 | - if(!$this->Page->IsCallBack) |
|
74 | + if (!$this->Page->IsCallBack) |
|
75 | 75 | { |
76 | 76 | $this->comments->dataSource = $this->getCommentData(); |
77 | 77 | $this->comments->dataBind(); |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | |
81 | 81 | protected function getCurrentPagePath() |
82 | 82 | { |
83 | - if(is_null($this->_page)) |
|
83 | + if (is_null($this->_page)) |
|
84 | 84 | { |
85 | 85 | $page = str_replace($this->Service->BasePath, '', $this->Page->Template->TemplateFile); |
86 | 86 | $this->_page = str_replace('\\', '/', $page); |
@@ -95,8 +95,8 @@ discard block |
||
95 | 95 | |
96 | 96 | protected function format_message($record) |
97 | 97 | { |
98 | - $username=htmlspecialchars($record->username); |
|
99 | - $content=nl2br(htmlspecialchars($record->content)); |
|
98 | + $username = htmlspecialchars($record->username); |
|
99 | + $content = nl2br(htmlspecialchars($record->content)); |
|
100 | 100 | return <<<EOD |
101 | 101 | <div class="comment c-{$record->block_id}"> |
102 | 102 | <span><strong>{$username}</strong> on {$record->date_added}.</span> |
@@ -102,6 +102,6 @@ |
||
102 | 102 | <span><strong>{$username}</strong> on {$record->date_added}.</span> |
103 | 103 | <div>{$content}</div> |
104 | 104 | </div> |
105 | -EOD; |
|
105 | +eod; |
|
106 | 106 | } |
107 | 107 | } |
108 | 108 | \ No newline at end of file |
@@ -268,7 +268,7 @@ discard block |
||
268 | 268 | * Returns a Zend_Search_Lucene_Document object for the document |
269 | 269 | * number $id in this index. |
270 | 270 | * |
271 | - * @param integer|Zend_Search_Lucene_Search_QueryHit $id |
|
271 | + * @param integer $id |
|
272 | 272 | * @return Zend_Search_Lucene_Document |
273 | 273 | */ |
274 | 274 | public function getDocument($id) |
@@ -553,7 +553,6 @@ discard block |
||
553 | 553 | * or the number of the document to delete. |
554 | 554 | * |
555 | 555 | * @todo Implementation |
556 | - * @param mixed $item_to_del |
|
557 | 556 | */ |
558 | 557 | public function delete($doc) |
559 | 558 | {} |
@@ -59,511 +59,511 @@ |
||
59 | 59 | */ |
60 | 60 | class Zend_Search_Lucene |
61 | 61 | { |
62 | - /** |
|
63 | - * File system adapter. |
|
64 | - * |
|
65 | - * @var Zend_Search_Lucene_Storage_Directory |
|
66 | - */ |
|
67 | - private $_directory = null; |
|
68 | - |
|
69 | - /** |
|
70 | - * File system adapter closing option |
|
71 | - * |
|
72 | - * @var boolean |
|
73 | - */ |
|
74 | - private $_closeDirOnExit = true; |
|
75 | - |
|
76 | - /** |
|
77 | - * Writer for this index, not instantiated unless required. |
|
78 | - * |
|
79 | - * @var Zend_Search_Lucene_Index_Writer |
|
80 | - */ |
|
81 | - private $_writer = null; |
|
82 | - |
|
83 | - /** |
|
84 | - * Array of Zend_Search_Lucene_Index_SegmentInfo objects for this index. |
|
85 | - * |
|
86 | - * @var array Zend_Search_Lucene_Index_SegmentInfo |
|
87 | - */ |
|
88 | - private $_segmentInfos = array(); |
|
89 | - |
|
90 | - /** |
|
91 | - * Number of documents in this index. |
|
92 | - * |
|
93 | - * @var integer |
|
94 | - */ |
|
95 | - private $_docCount = 0; |
|
96 | - |
|
97 | - |
|
98 | - /** |
|
99 | - * Opens the index. |
|
100 | - * |
|
101 | - * IndexReader constructor needs Directory as a parameter. It should be |
|
102 | - * a string with a path to the index folder or a Directory object. |
|
103 | - * |
|
104 | - * @param mixed $directory |
|
105 | - * @throws Zend_Search_Lucene_Exception |
|
106 | - */ |
|
107 | - public function __construct($directory = null, $create = false) |
|
108 | - { |
|
109 | - if ($directory === null) { |
|
110 | - throw new Zend_Search_Exception('No index directory specified'); |
|
111 | - } |
|
112 | - |
|
113 | - if ($directory instanceof Zend_Search_Lucene_Storage_Directory_Filesystem) { |
|
114 | - $this->_directory = $directory; |
|
115 | - $this->_closeDirOnExit = false; |
|
116 | - } else { |
|
117 | - $this->_directory = new Zend_Search_Lucene_Storage_Directory_Filesystem($directory); |
|
118 | - $this->_closeDirOnExit = true; |
|
119 | - } |
|
120 | - |
|
121 | - if ($create) { |
|
122 | - $this->_writer = new Zend_Search_Lucene_Index_Writer($this->_directory, true); |
|
123 | - } else { |
|
124 | - $this->_writer = null; |
|
125 | - } |
|
126 | - |
|
127 | - $this->_segmentInfos = array(); |
|
128 | - |
|
129 | - $segmentsFile = $this->_directory->getFileObject('segments'); |
|
130 | - |
|
131 | - $format = $segmentsFile->readInt(); |
|
132 | - |
|
133 | - if ($format != (int)0xFFFFFFFF) { |
|
134 | - throw new Zend_Search_Lucene_Exception('Wrong segments file format'); |
|
135 | - } |
|
136 | - |
|
137 | - // read version |
|
138 | - $segmentsFile->readLong(); |
|
139 | - |
|
140 | - // read counter |
|
141 | - $segmentsFile->readInt(); |
|
142 | - |
|
143 | - $segments = $segmentsFile->readInt(); |
|
144 | - |
|
145 | - $this->_docCount = 0; |
|
146 | - |
|
147 | - // read segmentInfos |
|
148 | - for ($count = 0; $count < $segments; $count++) { |
|
149 | - $segName = $segmentsFile->readString(); |
|
150 | - $segSize = $segmentsFile->readInt(); |
|
151 | - $this->_docCount += $segSize; |
|
152 | - |
|
153 | - $this->_segmentInfos[$count] = |
|
154 | - new Zend_Search_Lucene_Index_SegmentInfo($segName, |
|
155 | - $segSize, |
|
156 | - $this->_directory); |
|
157 | - } |
|
158 | - } |
|
159 | - |
|
160 | - |
|
161 | - /** |
|
162 | - * Object destructor |
|
163 | - */ |
|
164 | - public function __destruct() |
|
165 | - { |
|
166 | - $this->commit(); |
|
167 | - |
|
168 | - if ($this->_closeDirOnExit) { |
|
169 | - $this->_directory->close(); |
|
170 | - } |
|
171 | - } |
|
172 | - |
|
173 | - /** |
|
174 | - * Returns an instance of Zend_Search_Lucene_Index_Writer for the index |
|
175 | - * |
|
176 | - * @return Zend_Search_Lucene_Index_Writer |
|
177 | - */ |
|
178 | - public function getIndexWriter() |
|
179 | - { |
|
180 | - if (!$this->_writer instanceof Zend_Search_Lucene_Index_Writer) { |
|
181 | - $this->_writer = new Zend_Search_Lucene_Index_Writer($this->_directory); |
|
182 | - } |
|
183 | - |
|
184 | - return $this->_writer; |
|
185 | - } |
|
186 | - |
|
187 | - |
|
188 | - /** |
|
189 | - * Returns the Zend_Search_Lucene_Storage_Directory instance for this index. |
|
190 | - * |
|
191 | - * @return Zend_Search_Lucene_Storage_Directory |
|
192 | - */ |
|
193 | - public function getDirectory() |
|
194 | - { |
|
195 | - return $this->_directory; |
|
196 | - } |
|
197 | - |
|
198 | - |
|
199 | - /** |
|
200 | - * Returns the total number of documents in this index. |
|
201 | - * |
|
202 | - * @return integer |
|
203 | - */ |
|
204 | - public function count() |
|
205 | - { |
|
206 | - return $this->_docCount; |
|
207 | - } |
|
208 | - |
|
209 | - |
|
210 | - /** |
|
211 | - * Performs a query against the index and returns an array |
|
212 | - * of Zend_Search_Lucene_Search_QueryHit objects. |
|
213 | - * Input is a string or Zend_Search_Lucene_Search_Query. |
|
214 | - * |
|
215 | - * @param mixed $query |
|
216 | - * @return array ZSearchHit |
|
217 | - */ |
|
218 | - public function find($query) |
|
219 | - { |
|
220 | - if (is_string($query)) { |
|
221 | - $query = Zend_Search_Lucene_Search_QueryParser::parse($query); |
|
222 | - } |
|
223 | - |
|
224 | - if (!$query instanceof Zend_Search_Lucene_Search_Query) { |
|
225 | - throw new Zend_Search_Lucene_Exception('Query must be a string or Zend_Search_Lucene_Search_Query object'); |
|
226 | - } |
|
227 | - |
|
228 | - $this->commit(); |
|
229 | - |
|
230 | - $hits = array(); |
|
231 | - $scores = array(); |
|
232 | - |
|
233 | - $docNum = $this->count(); |
|
234 | - for( $count=0; $count < $docNum; $count++ ) { |
|
235 | - $docScore = $query->score( $count, $this); |
|
236 | - if( $docScore != 0 ) { |
|
237 | - $hit = new Zend_Search_Lucene_Search_QueryHit($this); |
|
238 | - $hit->id = $count; |
|
239 | - $hit->score = $docScore; |
|
240 | - |
|
241 | - $hits[] = $hit; |
|
242 | - $scores[] = $docScore; |
|
243 | - } |
|
244 | - } |
|
245 | - array_multisort($scores, SORT_DESC, SORT_REGULAR, $hits); |
|
246 | - |
|
247 | - return $hits; |
|
248 | - } |
|
249 | - |
|
250 | - |
|
251 | - /** |
|
252 | - * Returns a list of all unique field names that exist in this index. |
|
253 | - * |
|
254 | - * @param boolean $indexed |
|
255 | - * @return array |
|
256 | - */ |
|
257 | - public function getFieldNames($indexed = false) |
|
258 | - { |
|
259 | - $result = array(); |
|
260 | - foreach( $this->_segmentInfos as $segmentInfo ) { |
|
261 | - $result = array_merge($result, $segmentInfo->getFields($indexed)); |
|
262 | - } |
|
263 | - return $result; |
|
264 | - } |
|
265 | - |
|
266 | - |
|
267 | - /** |
|
268 | - * Returns a Zend_Search_Lucene_Document object for the document |
|
269 | - * number $id in this index. |
|
270 | - * |
|
271 | - * @param integer|Zend_Search_Lucene_Search_QueryHit $id |
|
272 | - * @return Zend_Search_Lucene_Document |
|
273 | - */ |
|
274 | - public function getDocument($id) |
|
275 | - { |
|
276 | - if ($id instanceof Zend_Search_Lucene_Search_QueryHit) { |
|
277 | - /* @var $id Zend_Search_Lucene_Search_QueryHit */ |
|
278 | - $id = $id->id; |
|
279 | - } |
|
280 | - |
|
281 | - if ($id >= $this->_docCount) { |
|
282 | - /** |
|
283 | - * @todo exception here? |
|
284 | - */ |
|
285 | - return null; |
|
286 | - } |
|
287 | - |
|
288 | - $segCount = 0; |
|
289 | - $nextSegmentStartId = $this->_segmentInfos[ 0 ]->count(); |
|
290 | - while( $nextSegmentStartId <= $id ) { |
|
291 | - $segCount++; |
|
292 | - $nextSegmentStartId += $this->_segmentInfos[ $segCount ]->count(); |
|
293 | - } |
|
294 | - $segmentStartId = $nextSegmentStartId - $this->_segmentInfos[ $segCount ]->count(); |
|
295 | - |
|
296 | - $fdxFile = $this->_segmentInfos[ $segCount ]->openCompoundFile('.fdx'); |
|
297 | - $fdxFile->seek( ($id-$segmentStartId)*8, SEEK_CUR ); |
|
298 | - $fieldValuesPosition = $fdxFile->readLong(); |
|
299 | - |
|
300 | - $fdtFile = $this->_segmentInfos[ $segCount ]->openCompoundFile('.fdt'); |
|
301 | - $fdtFile->seek( $fieldValuesPosition, SEEK_CUR ); |
|
302 | - $fieldCount = $fdtFile->readVInt(); |
|
303 | - |
|
304 | - $doc = new Zend_Search_Lucene_Document(); |
|
305 | - for( $count = 0; $count < $fieldCount; $count++ ) { |
|
306 | - $fieldNum = $fdtFile->readVInt(); |
|
307 | - $bits = $fdtFile->readByte(); |
|
308 | - |
|
309 | - $fieldInfo = $this->_segmentInfos[ $segCount ]->getField($fieldNum); |
|
310 | - |
|
311 | - if( !($bits & 2) ) { // Text data |
|
312 | - $field = new Zend_Search_Lucene_Field($fieldInfo->name, |
|
313 | - $fdtFile->readString(), |
|
314 | - true, |
|
315 | - $fieldInfo->isIndexed, |
|
316 | - $bits & 1 ); |
|
317 | - } else { |
|
318 | - $field = new Zend_Search_Lucene_Field($fieldInfo->name, |
|
319 | - $fdtFile->readBinary(), |
|
320 | - true, |
|
321 | - $fieldInfo->isIndexed, |
|
322 | - $bits & 1 ); |
|
323 | - } |
|
324 | - |
|
325 | - $doc->addField($field); |
|
326 | - } |
|
327 | - |
|
328 | - return $doc; |
|
329 | - } |
|
330 | - |
|
331 | - |
|
332 | - /** |
|
333 | - * Returns an array of all the documents which contain term. |
|
334 | - * |
|
335 | - * @param Zend_Search_Lucene_Index_Term $term |
|
336 | - * @return array |
|
337 | - */ |
|
338 | - public function termDocs(Zend_Search_Lucene_Index_Term $term) |
|
339 | - { |
|
340 | - $result = array(); |
|
341 | - $segmentStartDocId = 0; |
|
342 | - |
|
343 | - foreach ($this->_segmentInfos as $segInfo) { |
|
344 | - $termInfo = $segInfo->getTermInfo($term); |
|
345 | - |
|
346 | - if (!$termInfo instanceof Zend_Search_Lucene_Index_TermInfo) { |
|
347 | - $segmentStartDocId += $segInfo->count(); |
|
348 | - continue; |
|
349 | - } |
|
350 | - |
|
351 | - $frqFile = $segInfo->openCompoundFile('.frq'); |
|
352 | - $frqFile->seek($termInfo->freqPointer,SEEK_CUR); |
|
353 | - $docId = 0; |
|
354 | - for( $count=0; $count < $termInfo->docFreq; $count++ ) { |
|
355 | - $docDelta = $frqFile->readVInt(); |
|
356 | - if( $docDelta % 2 == 1 ) { |
|
357 | - $docId += ($docDelta-1)/2; |
|
358 | - } else { |
|
359 | - $docId += $docDelta/2; |
|
360 | - // read freq |
|
361 | - $frqFile->readVInt(); |
|
362 | - } |
|
363 | - $result[] = $segmentStartDocId + $docId; |
|
364 | - } |
|
365 | - |
|
366 | - $segmentStartDocId += $segInfo->count(); |
|
367 | - } |
|
368 | - |
|
369 | - return $result; |
|
370 | - } |
|
371 | - |
|
372 | - |
|
373 | - /** |
|
374 | - * Returns an array of all term positions in the documents. |
|
375 | - * Return array structure: array( docId => array( pos1, pos2, ...), ...) |
|
376 | - * |
|
377 | - * @param Zend_Search_Lucene_Index_Term $term |
|
378 | - * @return array |
|
379 | - */ |
|
380 | - public function termPositions(Zend_Search_Lucene_Index_Term $term) |
|
381 | - { |
|
382 | - $result = array(); |
|
383 | - $segmentStartDocId = 0; |
|
384 | - foreach( $this->_segmentInfos as $segInfo ) { |
|
385 | - $termInfo = $segInfo->getTermInfo($term); |
|
386 | - |
|
387 | - if (!$termInfo instanceof Zend_Search_Lucene_Index_TermInfo) { |
|
388 | - $segmentStartDocId += $segInfo->count(); |
|
389 | - continue; |
|
390 | - } |
|
391 | - |
|
392 | - $frqFile = $segInfo->openCompoundFile('.frq'); |
|
393 | - $frqFile->seek($termInfo->freqPointer,SEEK_CUR); |
|
394 | - $freqs = array(); |
|
395 | - $docId = 0; |
|
396 | - |
|
397 | - for( $count = 0; $count < $termInfo->docFreq; $count++ ) { |
|
398 | - $docDelta = $frqFile->readVInt(); |
|
399 | - if( $docDelta % 2 == 1 ) { |
|
400 | - $docId += ($docDelta-1)/2; |
|
401 | - $freqs[ $docId ] = 1; |
|
402 | - } else { |
|
403 | - $docId += $docDelta/2; |
|
404 | - $freqs[ $docId ] = $frqFile->readVInt(); |
|
405 | - } |
|
406 | - } |
|
407 | - |
|
408 | - $prxFile = $segInfo->openCompoundFile('.prx'); |
|
409 | - $prxFile->seek($termInfo->proxPointer,SEEK_CUR); |
|
410 | - foreach ($freqs as $docId => $freq) { |
|
411 | - $termPosition = 0; |
|
412 | - $positions = array(); |
|
413 | - |
|
414 | - for ($count = 0; $count < $freq; $count++ ) { |
|
415 | - $termPosition += $prxFile->readVInt(); |
|
416 | - $positions[] = $termPosition; |
|
417 | - } |
|
418 | - $result[ $segmentStartDocId + $docId ] = $positions; |
|
419 | - } |
|
420 | - |
|
421 | - $segmentStartDocId += $segInfo->count(); |
|
422 | - } |
|
423 | - |
|
424 | - return $result; |
|
425 | - } |
|
426 | - |
|
427 | - |
|
428 | - /** |
|
429 | - * Returns the number of documents in this index containing the $term. |
|
430 | - * |
|
431 | - * @param Zend_Search_Lucene_Index_Term $term |
|
432 | - * @return integer |
|
433 | - */ |
|
434 | - public function docFreq(Zend_Search_Lucene_Index_Term $term) |
|
435 | - { |
|
436 | - $result = 0; |
|
437 | - foreach ($this->_segmentInfos as $segInfo) { |
|
438 | - $termInfo = $segInfo->getTermInfo($term); |
|
439 | - if ($termInfo !== null) { |
|
440 | - $result += $termInfo->docFreq; |
|
441 | - } |
|
442 | - } |
|
443 | - |
|
444 | - return $result; |
|
445 | - } |
|
446 | - |
|
447 | - |
|
448 | - /** |
|
449 | - * Retrive similarity used by index reader |
|
450 | - * |
|
451 | - * @return Zend_Search_Lucene_Search_Similarity |
|
452 | - */ |
|
453 | - public function getSimilarity() |
|
454 | - { |
|
455 | - return Zend_Search_Lucene_Search_Similarity::getDefault(); |
|
456 | - } |
|
457 | - |
|
458 | - |
|
459 | - /** |
|
460 | - * Returns a normalization factor for "field, document" pair. |
|
461 | - * |
|
462 | - * @param integer $id |
|
463 | - * @param string $fieldName |
|
464 | - * @return Zend_Search_Lucene_Document |
|
465 | - */ |
|
466 | - public function norm( $id, $fieldName ) |
|
467 | - { |
|
468 | - if( $id >= $this->_docCount ) |
|
469 | - return null; |
|
470 | - |
|
471 | - $segCount = 0; |
|
472 | - $nextSegmentStartId = $this->_segmentInfos[ 0 ]->count(); |
|
473 | - while( $nextSegmentStartId <= $id ) { |
|
474 | - $segCount++; |
|
475 | - $nextSegmentStartId += $this->_segmentInfos[ $segCount ]->count(); |
|
476 | - } |
|
477 | - |
|
478 | - $segmentStartId = $nextSegmentStartId - $this->_segmentInfos[ $segCount ]->count(); |
|
479 | - |
|
480 | - return $this->_segmentInfos[ $segCount ]->norm($id - $segmentStartId, $fieldName); |
|
481 | - } |
|
482 | - |
|
483 | - |
|
484 | - /** |
|
485 | - * Adds a document to this index. |
|
486 | - * |
|
487 | - * @param Zend_Search_Lucene_Document $document |
|
488 | - */ |
|
489 | - public function addDocument(Zend_Search_Lucene_Document $document) |
|
490 | - { |
|
491 | - if (!$this->_writer instanceof Zend_Search_Lucene_Index_Writer) { |
|
492 | - $this->_writer = new Zend_Search_Lucene_Index_Writer($this->_directory); |
|
493 | - } |
|
494 | - |
|
495 | - $this->_writer->addDocument($document); |
|
496 | - } |
|
497 | - |
|
498 | - |
|
499 | - /** |
|
500 | - * Commit changes resulting from delete() or undeleteAll() operations. |
|
501 | - * |
|
502 | - * @todo delete() and undeleteAll processing. |
|
503 | - */ |
|
504 | - public function commit() |
|
505 | - { |
|
506 | - if ($this->_writer !== null) { |
|
507 | - foreach ($this->_writer->commit() as $segmentName => $segmentInfo) { |
|
508 | - if ($segmentInfo !== null) { |
|
509 | - $this->_segmentInfos[] = $segmentInfo; |
|
510 | - $this->_docCount += $segmentInfo->count(); |
|
511 | - } else { |
|
512 | - foreach ($this->_segmentInfos as $segId => $segInfo) { |
|
513 | - if ($segInfo->getName() == $segmentName) { |
|
514 | - unset($this->_segmentInfos[$segId]); |
|
515 | - } |
|
516 | - } |
|
517 | - } |
|
518 | - } |
|
519 | - } |
|
520 | - } |
|
521 | - |
|
522 | - |
|
523 | - /************************************************************************* |
|
62 | + /** |
|
63 | + * File system adapter. |
|
64 | + * |
|
65 | + * @var Zend_Search_Lucene_Storage_Directory |
|
66 | + */ |
|
67 | + private $_directory = null; |
|
68 | + |
|
69 | + /** |
|
70 | + * File system adapter closing option |
|
71 | + * |
|
72 | + * @var boolean |
|
73 | + */ |
|
74 | + private $_closeDirOnExit = true; |
|
75 | + |
|
76 | + /** |
|
77 | + * Writer for this index, not instantiated unless required. |
|
78 | + * |
|
79 | + * @var Zend_Search_Lucene_Index_Writer |
|
80 | + */ |
|
81 | + private $_writer = null; |
|
82 | + |
|
83 | + /** |
|
84 | + * Array of Zend_Search_Lucene_Index_SegmentInfo objects for this index. |
|
85 | + * |
|
86 | + * @var array Zend_Search_Lucene_Index_SegmentInfo |
|
87 | + */ |
|
88 | + private $_segmentInfos = array(); |
|
89 | + |
|
90 | + /** |
|
91 | + * Number of documents in this index. |
|
92 | + * |
|
93 | + * @var integer |
|
94 | + */ |
|
95 | + private $_docCount = 0; |
|
96 | + |
|
97 | + |
|
98 | + /** |
|
99 | + * Opens the index. |
|
100 | + * |
|
101 | + * IndexReader constructor needs Directory as a parameter. It should be |
|
102 | + * a string with a path to the index folder or a Directory object. |
|
103 | + * |
|
104 | + * @param mixed $directory |
|
105 | + * @throws Zend_Search_Lucene_Exception |
|
106 | + */ |
|
107 | + public function __construct($directory = null, $create = false) |
|
108 | + { |
|
109 | + if ($directory === null) { |
|
110 | + throw new Zend_Search_Exception('No index directory specified'); |
|
111 | + } |
|
112 | + |
|
113 | + if ($directory instanceof Zend_Search_Lucene_Storage_Directory_Filesystem) { |
|
114 | + $this->_directory = $directory; |
|
115 | + $this->_closeDirOnExit = false; |
|
116 | + } else { |
|
117 | + $this->_directory = new Zend_Search_Lucene_Storage_Directory_Filesystem($directory); |
|
118 | + $this->_closeDirOnExit = true; |
|
119 | + } |
|
120 | + |
|
121 | + if ($create) { |
|
122 | + $this->_writer = new Zend_Search_Lucene_Index_Writer($this->_directory, true); |
|
123 | + } else { |
|
124 | + $this->_writer = null; |
|
125 | + } |
|
126 | + |
|
127 | + $this->_segmentInfos = array(); |
|
128 | + |
|
129 | + $segmentsFile = $this->_directory->getFileObject('segments'); |
|
130 | + |
|
131 | + $format = $segmentsFile->readInt(); |
|
132 | + |
|
133 | + if ($format != (int)0xFFFFFFFF) { |
|
134 | + throw new Zend_Search_Lucene_Exception('Wrong segments file format'); |
|
135 | + } |
|
136 | + |
|
137 | + // read version |
|
138 | + $segmentsFile->readLong(); |
|
139 | + |
|
140 | + // read counter |
|
141 | + $segmentsFile->readInt(); |
|
142 | + |
|
143 | + $segments = $segmentsFile->readInt(); |
|
144 | + |
|
145 | + $this->_docCount = 0; |
|
146 | + |
|
147 | + // read segmentInfos |
|
148 | + for ($count = 0; $count < $segments; $count++) { |
|
149 | + $segName = $segmentsFile->readString(); |
|
150 | + $segSize = $segmentsFile->readInt(); |
|
151 | + $this->_docCount += $segSize; |
|
152 | + |
|
153 | + $this->_segmentInfos[$count] = |
|
154 | + new Zend_Search_Lucene_Index_SegmentInfo($segName, |
|
155 | + $segSize, |
|
156 | + $this->_directory); |
|
157 | + } |
|
158 | + } |
|
159 | + |
|
160 | + |
|
161 | + /** |
|
162 | + * Object destructor |
|
163 | + */ |
|
164 | + public function __destruct() |
|
165 | + { |
|
166 | + $this->commit(); |
|
167 | + |
|
168 | + if ($this->_closeDirOnExit) { |
|
169 | + $this->_directory->close(); |
|
170 | + } |
|
171 | + } |
|
172 | + |
|
173 | + /** |
|
174 | + * Returns an instance of Zend_Search_Lucene_Index_Writer for the index |
|
175 | + * |
|
176 | + * @return Zend_Search_Lucene_Index_Writer |
|
177 | + */ |
|
178 | + public function getIndexWriter() |
|
179 | + { |
|
180 | + if (!$this->_writer instanceof Zend_Search_Lucene_Index_Writer) { |
|
181 | + $this->_writer = new Zend_Search_Lucene_Index_Writer($this->_directory); |
|
182 | + } |
|
183 | + |
|
184 | + return $this->_writer; |
|
185 | + } |
|
186 | + |
|
187 | + |
|
188 | + /** |
|
189 | + * Returns the Zend_Search_Lucene_Storage_Directory instance for this index. |
|
190 | + * |
|
191 | + * @return Zend_Search_Lucene_Storage_Directory |
|
192 | + */ |
|
193 | + public function getDirectory() |
|
194 | + { |
|
195 | + return $this->_directory; |
|
196 | + } |
|
197 | + |
|
198 | + |
|
199 | + /** |
|
200 | + * Returns the total number of documents in this index. |
|
201 | + * |
|
202 | + * @return integer |
|
203 | + */ |
|
204 | + public function count() |
|
205 | + { |
|
206 | + return $this->_docCount; |
|
207 | + } |
|
208 | + |
|
209 | + |
|
210 | + /** |
|
211 | + * Performs a query against the index and returns an array |
|
212 | + * of Zend_Search_Lucene_Search_QueryHit objects. |
|
213 | + * Input is a string or Zend_Search_Lucene_Search_Query. |
|
214 | + * |
|
215 | + * @param mixed $query |
|
216 | + * @return array ZSearchHit |
|
217 | + */ |
|
218 | + public function find($query) |
|
219 | + { |
|
220 | + if (is_string($query)) { |
|
221 | + $query = Zend_Search_Lucene_Search_QueryParser::parse($query); |
|
222 | + } |
|
223 | + |
|
224 | + if (!$query instanceof Zend_Search_Lucene_Search_Query) { |
|
225 | + throw new Zend_Search_Lucene_Exception('Query must be a string or Zend_Search_Lucene_Search_Query object'); |
|
226 | + } |
|
227 | + |
|
228 | + $this->commit(); |
|
229 | + |
|
230 | + $hits = array(); |
|
231 | + $scores = array(); |
|
232 | + |
|
233 | + $docNum = $this->count(); |
|
234 | + for( $count=0; $count < $docNum; $count++ ) { |
|
235 | + $docScore = $query->score( $count, $this); |
|
236 | + if( $docScore != 0 ) { |
|
237 | + $hit = new Zend_Search_Lucene_Search_QueryHit($this); |
|
238 | + $hit->id = $count; |
|
239 | + $hit->score = $docScore; |
|
240 | + |
|
241 | + $hits[] = $hit; |
|
242 | + $scores[] = $docScore; |
|
243 | + } |
|
244 | + } |
|
245 | + array_multisort($scores, SORT_DESC, SORT_REGULAR, $hits); |
|
246 | + |
|
247 | + return $hits; |
|
248 | + } |
|
249 | + |
|
250 | + |
|
251 | + /** |
|
252 | + * Returns a list of all unique field names that exist in this index. |
|
253 | + * |
|
254 | + * @param boolean $indexed |
|
255 | + * @return array |
|
256 | + */ |
|
257 | + public function getFieldNames($indexed = false) |
|
258 | + { |
|
259 | + $result = array(); |
|
260 | + foreach( $this->_segmentInfos as $segmentInfo ) { |
|
261 | + $result = array_merge($result, $segmentInfo->getFields($indexed)); |
|
262 | + } |
|
263 | + return $result; |
|
264 | + } |
|
265 | + |
|
266 | + |
|
267 | + /** |
|
268 | + * Returns a Zend_Search_Lucene_Document object for the document |
|
269 | + * number $id in this index. |
|
270 | + * |
|
271 | + * @param integer|Zend_Search_Lucene_Search_QueryHit $id |
|
272 | + * @return Zend_Search_Lucene_Document |
|
273 | + */ |
|
274 | + public function getDocument($id) |
|
275 | + { |
|
276 | + if ($id instanceof Zend_Search_Lucene_Search_QueryHit) { |
|
277 | + /* @var $id Zend_Search_Lucene_Search_QueryHit */ |
|
278 | + $id = $id->id; |
|
279 | + } |
|
280 | + |
|
281 | + if ($id >= $this->_docCount) { |
|
282 | + /** |
|
283 | + * @todo exception here? |
|
284 | + */ |
|
285 | + return null; |
|
286 | + } |
|
287 | + |
|
288 | + $segCount = 0; |
|
289 | + $nextSegmentStartId = $this->_segmentInfos[ 0 ]->count(); |
|
290 | + while( $nextSegmentStartId <= $id ) { |
|
291 | + $segCount++; |
|
292 | + $nextSegmentStartId += $this->_segmentInfos[ $segCount ]->count(); |
|
293 | + } |
|
294 | + $segmentStartId = $nextSegmentStartId - $this->_segmentInfos[ $segCount ]->count(); |
|
295 | + |
|
296 | + $fdxFile = $this->_segmentInfos[ $segCount ]->openCompoundFile('.fdx'); |
|
297 | + $fdxFile->seek( ($id-$segmentStartId)*8, SEEK_CUR ); |
|
298 | + $fieldValuesPosition = $fdxFile->readLong(); |
|
299 | + |
|
300 | + $fdtFile = $this->_segmentInfos[ $segCount ]->openCompoundFile('.fdt'); |
|
301 | + $fdtFile->seek( $fieldValuesPosition, SEEK_CUR ); |
|
302 | + $fieldCount = $fdtFile->readVInt(); |
|
303 | + |
|
304 | + $doc = new Zend_Search_Lucene_Document(); |
|
305 | + for( $count = 0; $count < $fieldCount; $count++ ) { |
|
306 | + $fieldNum = $fdtFile->readVInt(); |
|
307 | + $bits = $fdtFile->readByte(); |
|
308 | + |
|
309 | + $fieldInfo = $this->_segmentInfos[ $segCount ]->getField($fieldNum); |
|
310 | + |
|
311 | + if( !($bits & 2) ) { // Text data |
|
312 | + $field = new Zend_Search_Lucene_Field($fieldInfo->name, |
|
313 | + $fdtFile->readString(), |
|
314 | + true, |
|
315 | + $fieldInfo->isIndexed, |
|
316 | + $bits & 1 ); |
|
317 | + } else { |
|
318 | + $field = new Zend_Search_Lucene_Field($fieldInfo->name, |
|
319 | + $fdtFile->readBinary(), |
|
320 | + true, |
|
321 | + $fieldInfo->isIndexed, |
|
322 | + $bits & 1 ); |
|
323 | + } |
|
324 | + |
|
325 | + $doc->addField($field); |
|
326 | + } |
|
327 | + |
|
328 | + return $doc; |
|
329 | + } |
|
330 | + |
|
331 | + |
|
332 | + /** |
|
333 | + * Returns an array of all the documents which contain term. |
|
334 | + * |
|
335 | + * @param Zend_Search_Lucene_Index_Term $term |
|
336 | + * @return array |
|
337 | + */ |
|
338 | + public function termDocs(Zend_Search_Lucene_Index_Term $term) |
|
339 | + { |
|
340 | + $result = array(); |
|
341 | + $segmentStartDocId = 0; |
|
342 | + |
|
343 | + foreach ($this->_segmentInfos as $segInfo) { |
|
344 | + $termInfo = $segInfo->getTermInfo($term); |
|
345 | + |
|
346 | + if (!$termInfo instanceof Zend_Search_Lucene_Index_TermInfo) { |
|
347 | + $segmentStartDocId += $segInfo->count(); |
|
348 | + continue; |
|
349 | + } |
|
350 | + |
|
351 | + $frqFile = $segInfo->openCompoundFile('.frq'); |
|
352 | + $frqFile->seek($termInfo->freqPointer,SEEK_CUR); |
|
353 | + $docId = 0; |
|
354 | + for( $count=0; $count < $termInfo->docFreq; $count++ ) { |
|
355 | + $docDelta = $frqFile->readVInt(); |
|
356 | + if( $docDelta % 2 == 1 ) { |
|
357 | + $docId += ($docDelta-1)/2; |
|
358 | + } else { |
|
359 | + $docId += $docDelta/2; |
|
360 | + // read freq |
|
361 | + $frqFile->readVInt(); |
|
362 | + } |
|
363 | + $result[] = $segmentStartDocId + $docId; |
|
364 | + } |
|
365 | + |
|
366 | + $segmentStartDocId += $segInfo->count(); |
|
367 | + } |
|
368 | + |
|
369 | + return $result; |
|
370 | + } |
|
371 | + |
|
372 | + |
|
373 | + /** |
|
374 | + * Returns an array of all term positions in the documents. |
|
375 | + * Return array structure: array( docId => array( pos1, pos2, ...), ...) |
|
376 | + * |
|
377 | + * @param Zend_Search_Lucene_Index_Term $term |
|
378 | + * @return array |
|
379 | + */ |
|
380 | + public function termPositions(Zend_Search_Lucene_Index_Term $term) |
|
381 | + { |
|
382 | + $result = array(); |
|
383 | + $segmentStartDocId = 0; |
|
384 | + foreach( $this->_segmentInfos as $segInfo ) { |
|
385 | + $termInfo = $segInfo->getTermInfo($term); |
|
386 | + |
|
387 | + if (!$termInfo instanceof Zend_Search_Lucene_Index_TermInfo) { |
|
388 | + $segmentStartDocId += $segInfo->count(); |
|
389 | + continue; |
|
390 | + } |
|
391 | + |
|
392 | + $frqFile = $segInfo->openCompoundFile('.frq'); |
|
393 | + $frqFile->seek($termInfo->freqPointer,SEEK_CUR); |
|
394 | + $freqs = array(); |
|
395 | + $docId = 0; |
|
396 | + |
|
397 | + for( $count = 0; $count < $termInfo->docFreq; $count++ ) { |
|
398 | + $docDelta = $frqFile->readVInt(); |
|
399 | + if( $docDelta % 2 == 1 ) { |
|
400 | + $docId += ($docDelta-1)/2; |
|
401 | + $freqs[ $docId ] = 1; |
|
402 | + } else { |
|
403 | + $docId += $docDelta/2; |
|
404 | + $freqs[ $docId ] = $frqFile->readVInt(); |
|
405 | + } |
|
406 | + } |
|
407 | + |
|
408 | + $prxFile = $segInfo->openCompoundFile('.prx'); |
|
409 | + $prxFile->seek($termInfo->proxPointer,SEEK_CUR); |
|
410 | + foreach ($freqs as $docId => $freq) { |
|
411 | + $termPosition = 0; |
|
412 | + $positions = array(); |
|
413 | + |
|
414 | + for ($count = 0; $count < $freq; $count++ ) { |
|
415 | + $termPosition += $prxFile->readVInt(); |
|
416 | + $positions[] = $termPosition; |
|
417 | + } |
|
418 | + $result[ $segmentStartDocId + $docId ] = $positions; |
|
419 | + } |
|
420 | + |
|
421 | + $segmentStartDocId += $segInfo->count(); |
|
422 | + } |
|
423 | + |
|
424 | + return $result; |
|
425 | + } |
|
426 | + |
|
427 | + |
|
428 | + /** |
|
429 | + * Returns the number of documents in this index containing the $term. |
|
430 | + * |
|
431 | + * @param Zend_Search_Lucene_Index_Term $term |
|
432 | + * @return integer |
|
433 | + */ |
|
434 | + public function docFreq(Zend_Search_Lucene_Index_Term $term) |
|
435 | + { |
|
436 | + $result = 0; |
|
437 | + foreach ($this->_segmentInfos as $segInfo) { |
|
438 | + $termInfo = $segInfo->getTermInfo($term); |
|
439 | + if ($termInfo !== null) { |
|
440 | + $result += $termInfo->docFreq; |
|
441 | + } |
|
442 | + } |
|
443 | + |
|
444 | + return $result; |
|
445 | + } |
|
446 | + |
|
447 | + |
|
448 | + /** |
|
449 | + * Retrive similarity used by index reader |
|
450 | + * |
|
451 | + * @return Zend_Search_Lucene_Search_Similarity |
|
452 | + */ |
|
453 | + public function getSimilarity() |
|
454 | + { |
|
455 | + return Zend_Search_Lucene_Search_Similarity::getDefault(); |
|
456 | + } |
|
457 | + |
|
458 | + |
|
459 | + /** |
|
460 | + * Returns a normalization factor for "field, document" pair. |
|
461 | + * |
|
462 | + * @param integer $id |
|
463 | + * @param string $fieldName |
|
464 | + * @return Zend_Search_Lucene_Document |
|
465 | + */ |
|
466 | + public function norm( $id, $fieldName ) |
|
467 | + { |
|
468 | + if( $id >= $this->_docCount ) |
|
469 | + return null; |
|
470 | + |
|
471 | + $segCount = 0; |
|
472 | + $nextSegmentStartId = $this->_segmentInfos[ 0 ]->count(); |
|
473 | + while( $nextSegmentStartId <= $id ) { |
|
474 | + $segCount++; |
|
475 | + $nextSegmentStartId += $this->_segmentInfos[ $segCount ]->count(); |
|
476 | + } |
|
477 | + |
|
478 | + $segmentStartId = $nextSegmentStartId - $this->_segmentInfos[ $segCount ]->count(); |
|
479 | + |
|
480 | + return $this->_segmentInfos[ $segCount ]->norm($id - $segmentStartId, $fieldName); |
|
481 | + } |
|
482 | + |
|
483 | + |
|
484 | + /** |
|
485 | + * Adds a document to this index. |
|
486 | + * |
|
487 | + * @param Zend_Search_Lucene_Document $document |
|
488 | + */ |
|
489 | + public function addDocument(Zend_Search_Lucene_Document $document) |
|
490 | + { |
|
491 | + if (!$this->_writer instanceof Zend_Search_Lucene_Index_Writer) { |
|
492 | + $this->_writer = new Zend_Search_Lucene_Index_Writer($this->_directory); |
|
493 | + } |
|
494 | + |
|
495 | + $this->_writer->addDocument($document); |
|
496 | + } |
|
497 | + |
|
498 | + |
|
499 | + /** |
|
500 | + * Commit changes resulting from delete() or undeleteAll() operations. |
|
501 | + * |
|
502 | + * @todo delete() and undeleteAll processing. |
|
503 | + */ |
|
504 | + public function commit() |
|
505 | + { |
|
506 | + if ($this->_writer !== null) { |
|
507 | + foreach ($this->_writer->commit() as $segmentName => $segmentInfo) { |
|
508 | + if ($segmentInfo !== null) { |
|
509 | + $this->_segmentInfos[] = $segmentInfo; |
|
510 | + $this->_docCount += $segmentInfo->count(); |
|
511 | + } else { |
|
512 | + foreach ($this->_segmentInfos as $segId => $segInfo) { |
|
513 | + if ($segInfo->getName() == $segmentName) { |
|
514 | + unset($this->_segmentInfos[$segId]); |
|
515 | + } |
|
516 | + } |
|
517 | + } |
|
518 | + } |
|
519 | + } |
|
520 | + } |
|
521 | + |
|
522 | + |
|
523 | + /************************************************************************* |
|
524 | 524 | @todo UNIMPLEMENTED |
525 | 525 | *************************************************************************/ |
526 | 526 | |
527 | - /** |
|
528 | - * Returns an array of all terms in this index. |
|
529 | - * |
|
530 | - * @todo Implementation |
|
531 | - * @return array |
|
532 | - */ |
|
533 | - public function terms() |
|
534 | - { |
|
535 | - return array(); |
|
536 | - } |
|
537 | - |
|
538 | - |
|
539 | - /** |
|
540 | - * Returns true if any documents have been deleted from this index. |
|
541 | - * |
|
542 | - * @todo Implementation |
|
543 | - * @return boolean |
|
544 | - */ |
|
545 | - public function hasDeletions() |
|
546 | - { |
|
547 | - return false; |
|
548 | - } |
|
549 | - |
|
550 | - |
|
551 | - /** |
|
552 | - * Deletes a document from the index. $doc may contain a Zend_Search_Lucene_Document |
|
553 | - * or the number of the document to delete. |
|
554 | - * |
|
555 | - * @todo Implementation |
|
556 | - * @param mixed $item_to_del |
|
557 | - */ |
|
558 | - public function delete($doc) |
|
559 | - {} |
|
560 | - |
|
561 | - |
|
562 | - /** |
|
563 | - * Undeletes all documents currently marked as deleted in this index. |
|
564 | - * |
|
565 | - * @todo Implementation |
|
566 | - */ |
|
567 | - public function undeleteAll() |
|
568 | - {} |
|
527 | + /** |
|
528 | + * Returns an array of all terms in this index. |
|
529 | + * |
|
530 | + * @todo Implementation |
|
531 | + * @return array |
|
532 | + */ |
|
533 | + public function terms() |
|
534 | + { |
|
535 | + return array(); |
|
536 | + } |
|
537 | + |
|
538 | + |
|
539 | + /** |
|
540 | + * Returns true if any documents have been deleted from this index. |
|
541 | + * |
|
542 | + * @todo Implementation |
|
543 | + * @return boolean |
|
544 | + */ |
|
545 | + public function hasDeletions() |
|
546 | + { |
|
547 | + return false; |
|
548 | + } |
|
549 | + |
|
550 | + |
|
551 | + /** |
|
552 | + * Deletes a document from the index. $doc may contain a Zend_Search_Lucene_Document |
|
553 | + * or the number of the document to delete. |
|
554 | + * |
|
555 | + * @todo Implementation |
|
556 | + * @param mixed $item_to_del |
|
557 | + */ |
|
558 | + public function delete($doc) |
|
559 | + {} |
|
560 | + |
|
561 | + |
|
562 | + /** |
|
563 | + * Undeletes all documents currently marked as deleted in this index. |
|
564 | + * |
|
565 | + * @todo Implementation |
|
566 | + */ |
|
567 | + public function undeleteAll() |
|
568 | + {} |
|
569 | 569 | } |
570 | 570 | \ No newline at end of file |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | |
131 | 131 | $format = $segmentsFile->readInt(); |
132 | 132 | |
133 | - if ($format != (int)0xFFFFFFFF) { |
|
133 | + if ($format != (int) 0xFFFFFFFF) { |
|
134 | 134 | throw new Zend_Search_Lucene_Exception('Wrong segments file format'); |
135 | 135 | } |
136 | 136 | |
@@ -231,9 +231,9 @@ discard block |
||
231 | 231 | $scores = array(); |
232 | 232 | |
233 | 233 | $docNum = $this->count(); |
234 | - for( $count=0; $count < $docNum; $count++ ) { |
|
235 | - $docScore = $query->score( $count, $this); |
|
236 | - if( $docScore != 0 ) { |
|
234 | + for ($count = 0; $count < $docNum; $count++) { |
|
235 | + $docScore = $query->score($count, $this); |
|
236 | + if ($docScore != 0) { |
|
237 | 237 | $hit = new Zend_Search_Lucene_Search_QueryHit($this); |
238 | 238 | $hit->id = $count; |
239 | 239 | $hit->score = $docScore; |
@@ -257,7 +257,7 @@ discard block |
||
257 | 257 | public function getFieldNames($indexed = false) |
258 | 258 | { |
259 | 259 | $result = array(); |
260 | - foreach( $this->_segmentInfos as $segmentInfo ) { |
|
260 | + foreach ($this->_segmentInfos as $segmentInfo) { |
|
261 | 261 | $result = array_merge($result, $segmentInfo->getFields($indexed)); |
262 | 262 | } |
263 | 263 | return $result; |
@@ -286,40 +286,40 @@ discard block |
||
286 | 286 | } |
287 | 287 | |
288 | 288 | $segCount = 0; |
289 | - $nextSegmentStartId = $this->_segmentInfos[ 0 ]->count(); |
|
290 | - while( $nextSegmentStartId <= $id ) { |
|
289 | + $nextSegmentStartId = $this->_segmentInfos[0]->count(); |
|
290 | + while ($nextSegmentStartId <= $id) { |
|
291 | 291 | $segCount++; |
292 | - $nextSegmentStartId += $this->_segmentInfos[ $segCount ]->count(); |
|
292 | + $nextSegmentStartId += $this->_segmentInfos[$segCount]->count(); |
|
293 | 293 | } |
294 | - $segmentStartId = $nextSegmentStartId - $this->_segmentInfos[ $segCount ]->count(); |
|
294 | + $segmentStartId = $nextSegmentStartId - $this->_segmentInfos[$segCount]->count(); |
|
295 | 295 | |
296 | - $fdxFile = $this->_segmentInfos[ $segCount ]->openCompoundFile('.fdx'); |
|
297 | - $fdxFile->seek( ($id-$segmentStartId)*8, SEEK_CUR ); |
|
296 | + $fdxFile = $this->_segmentInfos[$segCount]->openCompoundFile('.fdx'); |
|
297 | + $fdxFile->seek(($id - $segmentStartId) * 8, SEEK_CUR); |
|
298 | 298 | $fieldValuesPosition = $fdxFile->readLong(); |
299 | 299 | |
300 | - $fdtFile = $this->_segmentInfos[ $segCount ]->openCompoundFile('.fdt'); |
|
301 | - $fdtFile->seek( $fieldValuesPosition, SEEK_CUR ); |
|
300 | + $fdtFile = $this->_segmentInfos[$segCount]->openCompoundFile('.fdt'); |
|
301 | + $fdtFile->seek($fieldValuesPosition, SEEK_CUR); |
|
302 | 302 | $fieldCount = $fdtFile->readVInt(); |
303 | 303 | |
304 | 304 | $doc = new Zend_Search_Lucene_Document(); |
305 | - for( $count = 0; $count < $fieldCount; $count++ ) { |
|
305 | + for ($count = 0; $count < $fieldCount; $count++) { |
|
306 | 306 | $fieldNum = $fdtFile->readVInt(); |
307 | 307 | $bits = $fdtFile->readByte(); |
308 | 308 | |
309 | - $fieldInfo = $this->_segmentInfos[ $segCount ]->getField($fieldNum); |
|
309 | + $fieldInfo = $this->_segmentInfos[$segCount]->getField($fieldNum); |
|
310 | 310 | |
311 | - if( !($bits & 2) ) { // Text data |
|
311 | + if (!($bits & 2)) { // Text data |
|
312 | 312 | $field = new Zend_Search_Lucene_Field($fieldInfo->name, |
313 | 313 | $fdtFile->readString(), |
314 | 314 | true, |
315 | 315 | $fieldInfo->isIndexed, |
316 | - $bits & 1 ); |
|
316 | + $bits & 1); |
|
317 | 317 | } else { |
318 | 318 | $field = new Zend_Search_Lucene_Field($fieldInfo->name, |
319 | 319 | $fdtFile->readBinary(), |
320 | 320 | true, |
321 | 321 | $fieldInfo->isIndexed, |
322 | - $bits & 1 ); |
|
322 | + $bits & 1); |
|
323 | 323 | } |
324 | 324 | |
325 | 325 | $doc->addField($field); |
@@ -349,14 +349,14 @@ discard block |
||
349 | 349 | } |
350 | 350 | |
351 | 351 | $frqFile = $segInfo->openCompoundFile('.frq'); |
352 | - $frqFile->seek($termInfo->freqPointer,SEEK_CUR); |
|
352 | + $frqFile->seek($termInfo->freqPointer, SEEK_CUR); |
|
353 | 353 | $docId = 0; |
354 | - for( $count=0; $count < $termInfo->docFreq; $count++ ) { |
|
354 | + for ($count = 0; $count < $termInfo->docFreq; $count++) { |
|
355 | 355 | $docDelta = $frqFile->readVInt(); |
356 | - if( $docDelta % 2 == 1 ) { |
|
357 | - $docId += ($docDelta-1)/2; |
|
356 | + if ($docDelta % 2 == 1) { |
|
357 | + $docId += ($docDelta - 1) / 2; |
|
358 | 358 | } else { |
359 | - $docId += $docDelta/2; |
|
359 | + $docId += $docDelta / 2; |
|
360 | 360 | // read freq |
361 | 361 | $frqFile->readVInt(); |
362 | 362 | } |
@@ -381,7 +381,7 @@ discard block |
||
381 | 381 | { |
382 | 382 | $result = array(); |
383 | 383 | $segmentStartDocId = 0; |
384 | - foreach( $this->_segmentInfos as $segInfo ) { |
|
384 | + foreach ($this->_segmentInfos as $segInfo) { |
|
385 | 385 | $termInfo = $segInfo->getTermInfo($term); |
386 | 386 | |
387 | 387 | if (!$termInfo instanceof Zend_Search_Lucene_Index_TermInfo) { |
@@ -390,32 +390,32 @@ discard block |
||
390 | 390 | } |
391 | 391 | |
392 | 392 | $frqFile = $segInfo->openCompoundFile('.frq'); |
393 | - $frqFile->seek($termInfo->freqPointer,SEEK_CUR); |
|
393 | + $frqFile->seek($termInfo->freqPointer, SEEK_CUR); |
|
394 | 394 | $freqs = array(); |
395 | 395 | $docId = 0; |
396 | 396 | |
397 | - for( $count = 0; $count < $termInfo->docFreq; $count++ ) { |
|
397 | + for ($count = 0; $count < $termInfo->docFreq; $count++) { |
|
398 | 398 | $docDelta = $frqFile->readVInt(); |
399 | - if( $docDelta % 2 == 1 ) { |
|
400 | - $docId += ($docDelta-1)/2; |
|
401 | - $freqs[ $docId ] = 1; |
|
399 | + if ($docDelta % 2 == 1) { |
|
400 | + $docId += ($docDelta - 1) / 2; |
|
401 | + $freqs[$docId] = 1; |
|
402 | 402 | } else { |
403 | - $docId += $docDelta/2; |
|
404 | - $freqs[ $docId ] = $frqFile->readVInt(); |
|
403 | + $docId += $docDelta / 2; |
|
404 | + $freqs[$docId] = $frqFile->readVInt(); |
|
405 | 405 | } |
406 | 406 | } |
407 | 407 | |
408 | 408 | $prxFile = $segInfo->openCompoundFile('.prx'); |
409 | - $prxFile->seek($termInfo->proxPointer,SEEK_CUR); |
|
409 | + $prxFile->seek($termInfo->proxPointer, SEEK_CUR); |
|
410 | 410 | foreach ($freqs as $docId => $freq) { |
411 | 411 | $termPosition = 0; |
412 | 412 | $positions = array(); |
413 | 413 | |
414 | - for ($count = 0; $count < $freq; $count++ ) { |
|
414 | + for ($count = 0; $count < $freq; $count++) { |
|
415 | 415 | $termPosition += $prxFile->readVInt(); |
416 | 416 | $positions[] = $termPosition; |
417 | 417 | } |
418 | - $result[ $segmentStartDocId + $docId ] = $positions; |
|
418 | + $result[$segmentStartDocId + $docId] = $positions; |
|
419 | 419 | } |
420 | 420 | |
421 | 421 | $segmentStartDocId += $segInfo->count(); |
@@ -463,21 +463,21 @@ discard block |
||
463 | 463 | * @param string $fieldName |
464 | 464 | * @return Zend_Search_Lucene_Document |
465 | 465 | */ |
466 | - public function norm( $id, $fieldName ) |
|
466 | + public function norm($id, $fieldName) |
|
467 | 467 | { |
468 | - if( $id >= $this->_docCount ) |
|
468 | + if ($id >= $this->_docCount) |
|
469 | 469 | return null; |
470 | 470 | |
471 | 471 | $segCount = 0; |
472 | - $nextSegmentStartId = $this->_segmentInfos[ 0 ]->count(); |
|
473 | - while( $nextSegmentStartId <= $id ) { |
|
472 | + $nextSegmentStartId = $this->_segmentInfos[0]->count(); |
|
473 | + while ($nextSegmentStartId <= $id) { |
|
474 | 474 | $segCount++; |
475 | - $nextSegmentStartId += $this->_segmentInfos[ $segCount ]->count(); |
|
475 | + $nextSegmentStartId += $this->_segmentInfos[$segCount]->count(); |
|
476 | 476 | } |
477 | 477 | |
478 | - $segmentStartId = $nextSegmentStartId - $this->_segmentInfos[ $segCount ]->count(); |
|
478 | + $segmentStartId = $nextSegmentStartId - $this->_segmentInfos[$segCount]->count(); |
|
479 | 479 | |
480 | - return $this->_segmentInfos[ $segCount ]->norm($id - $segmentStartId, $fieldName); |
|
480 | + return $this->_segmentInfos[$segCount]->norm($id - $segmentStartId, $fieldName); |
|
481 | 481 | } |
482 | 482 | |
483 | 483 |
@@ -68,7 +68,6 @@ |
||
68 | 68 | /** |
69 | 69 | * Set the default Analyzer implementation used by indexing code. |
70 | 70 | * |
71 | - * @param Zend_Search_Lucene_Analysis_Analyzer $similarity |
|
72 | 71 | */ |
73 | 72 | static public function setDefault(Zend_Search_Lucene_Analysis_Analyzer $analyzer) |
74 | 73 | { |
@@ -48,47 +48,47 @@ |
||
48 | 48 | |
49 | 49 | abstract class Zend_Search_Lucene_Analysis_Analyzer |
50 | 50 | { |
51 | - /** |
|
52 | - * The Analyzer implementation used by default. |
|
53 | - * |
|
54 | - * @var Zend_Search_Lucene_Analysis_Analyzer |
|
55 | - */ |
|
56 | - static private $_defaultImpl; |
|
57 | - |
|
58 | - /** |
|
59 | - * Tokenize text to a terms |
|
60 | - * Returns array of Zend_Search_Lucene_Analysis_Token objects |
|
61 | - * |
|
62 | - * @param string $data |
|
63 | - * @return array |
|
64 | - */ |
|
65 | - abstract public function tokenize($data); |
|
66 | - |
|
67 | - |
|
68 | - /** |
|
69 | - * Set the default Analyzer implementation used by indexing code. |
|
70 | - * |
|
71 | - * @param Zend_Search_Lucene_Analysis_Analyzer $similarity |
|
72 | - */ |
|
73 | - static public function setDefault(Zend_Search_Lucene_Analysis_Analyzer $analyzer) |
|
74 | - { |
|
75 | - self::$_defaultImpl = $analyzer; |
|
76 | - } |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * Return the default Analyzer implementation used by indexing code. |
|
81 | - * |
|
82 | - * @return Zend_Search_Lucene_Analysis_Analyzer |
|
83 | - */ |
|
84 | - static public function getDefault() |
|
85 | - { |
|
86 | - if (!self::$_defaultImpl instanceof Zend_Search_Lucene_Analysis_Analyzer) { |
|
87 | - self::$_defaultImpl = new Zend_Search_Lucene_Analysis_Analyzer_Common_Text_CaseInsensitive(); |
|
88 | - } |
|
89 | - |
|
90 | - return self::$_defaultImpl; |
|
91 | - } |
|
51 | + /** |
|
52 | + * The Analyzer implementation used by default. |
|
53 | + * |
|
54 | + * @var Zend_Search_Lucene_Analysis_Analyzer |
|
55 | + */ |
|
56 | + static private $_defaultImpl; |
|
57 | + |
|
58 | + /** |
|
59 | + * Tokenize text to a terms |
|
60 | + * Returns array of Zend_Search_Lucene_Analysis_Token objects |
|
61 | + * |
|
62 | + * @param string $data |
|
63 | + * @return array |
|
64 | + */ |
|
65 | + abstract public function tokenize($data); |
|
66 | + |
|
67 | + |
|
68 | + /** |
|
69 | + * Set the default Analyzer implementation used by indexing code. |
|
70 | + * |
|
71 | + * @param Zend_Search_Lucene_Analysis_Analyzer $similarity |
|
72 | + */ |
|
73 | + static public function setDefault(Zend_Search_Lucene_Analysis_Analyzer $analyzer) |
|
74 | + { |
|
75 | + self::$_defaultImpl = $analyzer; |
|
76 | + } |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * Return the default Analyzer implementation used by indexing code. |
|
81 | + * |
|
82 | + * @return Zend_Search_Lucene_Analysis_Analyzer |
|
83 | + */ |
|
84 | + static public function getDefault() |
|
85 | + { |
|
86 | + if (!self::$_defaultImpl instanceof Zend_Search_Lucene_Analysis_Analyzer) { |
|
87 | + self::$_defaultImpl = new Zend_Search_Lucene_Analysis_Analyzer_Common_Text_CaseInsensitive(); |
|
88 | + } |
|
89 | + |
|
90 | + return self::$_defaultImpl; |
|
91 | + } |
|
92 | 92 | |
93 | 93 | } |
94 | 94 |
@@ -391,7 +391,7 @@ |
||
391 | 391 | * |
392 | 392 | * @param integer $id |
393 | 393 | * @param string $fieldName |
394 | - * @return string |
|
394 | + * @return null|double |
|
395 | 395 | */ |
396 | 396 | public function norm($id, $fieldName) |
397 | 397 | { |
@@ -31,382 +31,382 @@ |
||
31 | 31 | */ |
32 | 32 | class Zend_Search_Lucene_Index_SegmentInfo |
33 | 33 | { |
34 | - /** |
|
35 | - * Number of docs in a segment |
|
36 | - * |
|
37 | - * @var integer |
|
38 | - */ |
|
39 | - private $_docCount; |
|
40 | - |
|
41 | - /** |
|
42 | - * Segment name |
|
43 | - * |
|
44 | - * @var string |
|
45 | - */ |
|
46 | - private $_name; |
|
47 | - |
|
48 | - /** |
|
49 | - * Term Dictionary Index |
|
50 | - * Array of the Zend_Search_Lucene_Index_Term objects |
|
51 | - * Corresponding Zend_Search_Lucene_Index_TermInfo object stored in the $_termDictionaryInfos |
|
52 | - * |
|
53 | - * @var array |
|
54 | - */ |
|
55 | - private $_termDictionary; |
|
56 | - |
|
57 | - /** |
|
58 | - * Term Dictionary Index TermInfos |
|
59 | - * Array of the Zend_Search_Lucene_Index_TermInfo objects |
|
60 | - * |
|
61 | - * @var array |
|
62 | - */ |
|
63 | - private $_termDictionaryInfos; |
|
64 | - |
|
65 | - /** |
|
66 | - * Segment fields. Array of Zend_Search_Lucene_Index_FieldInfo objects for this segment |
|
67 | - * |
|
68 | - * @var array |
|
69 | - */ |
|
70 | - private $_fields; |
|
71 | - |
|
72 | - /** |
|
73 | - * Field positions in a dictionary. |
|
74 | - * (Term dictionary contains filelds ordered by names) |
|
75 | - * |
|
76 | - * @var array |
|
77 | - */ |
|
78 | - private $_fieldsDicPositions; |
|
79 | - |
|
80 | - |
|
81 | - /** |
|
82 | - * Associative array where the key is the file name and the value is data offset |
|
83 | - * in a compound segment file (.csf). |
|
84 | - * |
|
85 | - * @var array |
|
86 | - */ |
|
87 | - private $_segFiles; |
|
88 | - |
|
89 | - /** |
|
90 | - * File system adapter. |
|
91 | - * |
|
92 | - * @var Zend_Search_Lucene_Storage_Directory_Filesystem |
|
93 | - */ |
|
94 | - private $_directory; |
|
95 | - |
|
96 | - /** |
|
97 | - * Normalization factors. |
|
98 | - * An array fieldName => normVector |
|
99 | - * normVector is a binary string. |
|
100 | - * Each byte corresponds to an indexed document in a segment and |
|
101 | - * encodes normalization factor (float value, encoded by |
|
102 | - * Zend_Search_Lucene_Search_Similarity::encodeNorm()) |
|
103 | - * |
|
104 | - * @var array |
|
105 | - */ |
|
106 | - private $_norms = array(); |
|
107 | - |
|
108 | - /** |
|
109 | - * Zend_Search_Lucene_Index_SegmentInfo constructor needs Segmentname, |
|
110 | - * Documents count and Directory as a parameter. |
|
111 | - * |
|
112 | - * @param string $name |
|
113 | - * @param integer $docCount |
|
114 | - * @param Zend_Search_Lucene_Storage_Directory $directory |
|
115 | - */ |
|
116 | - public function __construct($name, $docCount, $directory) |
|
117 | - { |
|
118 | - $this->_name = $name; |
|
119 | - $this->_docCount = $docCount; |
|
120 | - $this->_directory = $directory; |
|
121 | - $this->_termDictionary = null; |
|
122 | - |
|
123 | - $this->_segFiles = array(); |
|
124 | - $cfsFile = $this->_directory->getFileObject($name . '.cfs'); |
|
125 | - $segFilesCount = $cfsFile->readVInt(); |
|
126 | - |
|
127 | - for ($count = 0; $count < $segFilesCount; $count++) { |
|
128 | - $dataOffset = $cfsFile->readLong(); |
|
129 | - $fileName = $cfsFile->readString(); |
|
130 | - $this->_segFiles[$fileName] = $dataOffset; |
|
131 | - } |
|
132 | - |
|
133 | - $fnmFile = $this->openCompoundFile('.fnm'); |
|
134 | - $fieldsCount = $fnmFile->readVInt(); |
|
135 | - $fieldNames = array(); |
|
136 | - $fieldNums = array(); |
|
137 | - $this->_fields = array(); |
|
138 | - for ($count=0; $count < $fieldsCount; $count++) { |
|
139 | - $fieldName = $fnmFile->readString(); |
|
140 | - $fieldBits = $fnmFile->readByte(); |
|
141 | - $this->_fields[$count] = new Zend_Search_Lucene_Index_FieldInfo($fieldName, |
|
142 | - $fieldBits & 1, |
|
143 | - $count, |
|
144 | - $fieldBits & 2 ); |
|
145 | - if ($fieldBits & 0x10) { |
|
146 | - // norms are omitted for the indexed field |
|
147 | - $this->_norms[$count] = str_repeat(chr(Zend_Search_Lucene_Search_Similarity::encodeNorm(1.0)), $docCount); |
|
148 | - } |
|
149 | - |
|
150 | - $fieldNums[$count] = $count; |
|
151 | - $fieldNames[$count] = $fieldName; |
|
152 | - } |
|
153 | - array_multisort($fieldNames, SORT_ASC, SORT_REGULAR, $fieldNums); |
|
154 | - $this->_fieldsDicPositions = array_flip($fieldNums); |
|
155 | - } |
|
156 | - |
|
157 | - /** |
|
158 | - * Opens index file stoted within compound index file |
|
159 | - * |
|
160 | - * @param string $extension |
|
161 | - * @throws Zend_Search_Lucene_Exception |
|
162 | - * @return Zend_Search_Lucene_Storage_File |
|
163 | - */ |
|
164 | - public function openCompoundFile($extension) |
|
165 | - { |
|
166 | - $filename = $this->_name . $extension; |
|
167 | - |
|
168 | - if( !isset($this->_segFiles[ $filename ]) ) { |
|
169 | - throw new Zend_Search_Lucene_Exception('Index compound file doesn\'t contain ' |
|
170 | - . $filename . ' file.' ); |
|
171 | - } |
|
172 | - |
|
173 | - $file = $this->_directory->getFileObject( $this->_name.".cfs" ); |
|
174 | - $file->seek( $this->_segFiles[ $filename ] ); |
|
175 | - return $file; |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * Returns field index or -1 if field is not found |
|
180 | - * |
|
181 | - * @param string $fieldName |
|
182 | - * @return integer |
|
183 | - */ |
|
184 | - public function getFieldNum($fieldName) |
|
185 | - { |
|
186 | - foreach( $this->_fields as $field ) { |
|
187 | - if( $field->name == $fieldName ) { |
|
188 | - return $field->number; |
|
189 | - } |
|
190 | - } |
|
191 | - |
|
192 | - return -1; |
|
193 | - } |
|
194 | - |
|
195 | - /** |
|
196 | - * Returns field info for specified field |
|
197 | - * |
|
198 | - * @param integer $fieldNum |
|
199 | - * @return ZSearchFieldInfo |
|
200 | - */ |
|
201 | - public function getField($fieldNum) |
|
202 | - { |
|
203 | - return $this->_fields[$fieldNum]; |
|
204 | - } |
|
205 | - |
|
206 | - /** |
|
207 | - * Returns array of fields. |
|
208 | - * if $indexed parameter is true, then returns only indexed fields. |
|
209 | - * |
|
210 | - * @param boolean $indexed |
|
211 | - * @return array |
|
212 | - */ |
|
213 | - public function getFields($indexed = false) |
|
214 | - { |
|
215 | - $result = array(); |
|
216 | - foreach( $this->_fields as $field ) { |
|
217 | - if( (!$indexed) || $field->isIndexed ) { |
|
218 | - $result[ $field->name ] = $field->name; |
|
219 | - } |
|
220 | - } |
|
221 | - return $result; |
|
222 | - } |
|
223 | - |
|
224 | - /** |
|
225 | - * Returns the total number of documents in this segment. |
|
226 | - * |
|
227 | - * @return integer |
|
228 | - */ |
|
229 | - public function count() |
|
230 | - { |
|
231 | - return $this->_docCount; |
|
232 | - } |
|
233 | - |
|
234 | - |
|
235 | - /** |
|
236 | - * Loads Term dictionary from TermInfoIndex file |
|
237 | - */ |
|
238 | - protected function _loadDictionary() |
|
239 | - { |
|
240 | - if ($this->_termDictionary !== null) { |
|
241 | - return; |
|
242 | - } |
|
243 | - |
|
244 | - $this->_termDictionary = array(); |
|
245 | - $this->_termDictionaryInfos = array(); |
|
246 | - |
|
247 | - $tiiFile = $this->openCompoundFile('.tii'); |
|
248 | - $tiVersion = $tiiFile->readInt(); |
|
249 | - if ($tiVersion != (int)0xFFFFFFFE) { |
|
250 | - throw new Zend_Search_Lucene_Exception('Wrong TermInfoIndexFile file format'); |
|
251 | - } |
|
252 | - |
|
253 | - $indexTermCount = $tiiFile->readLong(); |
|
254 | - $tiiFile->readInt(); // IndexInterval |
|
255 | - $skipInterval = $tiiFile->readInt(); |
|
256 | - |
|
257 | - $prevTerm = ''; |
|
258 | - $freqPointer = 0; |
|
259 | - $proxPointer = 0; |
|
260 | - $indexPointer = 0; |
|
261 | - for ($count = 0; $count < $indexTermCount; $count++) { |
|
262 | - $termPrefixLength = $tiiFile->readVInt(); |
|
263 | - $termSuffix = $tiiFile->readString(); |
|
264 | - $termValue = substr( $prevTerm, 0, $termPrefixLength ) . $termSuffix; |
|
265 | - |
|
266 | - $termFieldNum = $tiiFile->readVInt(); |
|
267 | - $docFreq = $tiiFile->readVInt(); |
|
268 | - $freqPointer += $tiiFile->readVInt(); |
|
269 | - $proxPointer += $tiiFile->readVInt(); |
|
270 | - if( $docFreq >= $skipInterval ) { |
|
271 | - $skipDelta = $tiiFile->readVInt(); |
|
272 | - } else { |
|
273 | - $skipDelta = 0; |
|
274 | - } |
|
275 | - |
|
276 | - $indexPointer += $tiiFile->readVInt(); |
|
277 | - |
|
278 | - $this->_termDictionary[] = new Zend_Search_Lucene_Index_Term($termValue,$termFieldNum); |
|
279 | - $this->_termDictionaryInfos[] = |
|
280 | - new Zend_Search_Lucene_Index_TermInfo($docFreq, $freqPointer, $proxPointer, $skipDelta, $indexPointer); |
|
281 | - $prevTerm = $termValue; |
|
282 | - } |
|
283 | - } |
|
284 | - |
|
285 | - |
|
286 | - /** |
|
287 | - * Return segment name |
|
288 | - * |
|
289 | - * @return string |
|
290 | - */ |
|
291 | - public function getName() |
|
292 | - { |
|
293 | - return $this->_name; |
|
294 | - } |
|
295 | - |
|
296 | - |
|
297 | - /** |
|
298 | - * Scans terms dictionary and returns term info |
|
299 | - * |
|
300 | - * @param Zend_Search_Lucene_Index_Term $term |
|
301 | - * @return Zend_Search_Lucene_Index_TermInfo |
|
302 | - */ |
|
303 | - public function getTermInfo($term) |
|
304 | - { |
|
305 | - $this->_loadDictionary(); |
|
306 | - |
|
307 | - $searchField = $this->getFieldNum($term->field); |
|
308 | - |
|
309 | - if ($searchField == -1) { |
|
310 | - return null; |
|
311 | - } |
|
312 | - $searchDicField = $this->_fieldsDicPositions[$searchField]; |
|
313 | - |
|
314 | - // search for appropriate value in dictionary |
|
315 | - $lowIndex = 0; |
|
316 | - $highIndex = count($this->_termDictionary)-1; |
|
317 | - while ($highIndex >= $lowIndex) { |
|
318 | - // $mid = ($highIndex - $lowIndex)/2; |
|
319 | - $mid = ($highIndex + $lowIndex) >> 1; |
|
320 | - $midTerm = $this->_termDictionary[$mid]; |
|
321 | - |
|
322 | - $delta = $searchDicField - $this->_fieldsDicPositions[$midTerm->field]; |
|
323 | - if ($delta == 0) { |
|
324 | - $delta = strcmp($term->text, $midTerm->text); |
|
325 | - } |
|
326 | - |
|
327 | - if ($delta < 0) { |
|
328 | - $highIndex = $mid-1; |
|
329 | - } elseif ($delta > 0) { |
|
330 | - $lowIndex = $mid+1; |
|
331 | - } else { |
|
332 | - return $this->_termDictionaryInfos[$mid]; // We got it! |
|
333 | - } |
|
334 | - } |
|
335 | - |
|
336 | - if ($highIndex == -1) { |
|
337 | - // Term is out of the dictionary range |
|
338 | - return null; |
|
339 | - } |
|
340 | - |
|
341 | - $prevPosition = $highIndex; |
|
342 | - $prevTerm = $this->_termDictionary[$prevPosition]; |
|
343 | - $prevTermInfo = $this->_termDictionaryInfos[ $prevPosition ]; |
|
344 | - |
|
345 | - $tisFile = $this->openCompoundFile('.tis'); |
|
346 | - $tiVersion = $tisFile->readInt(); |
|
347 | - if ($tiVersion != (int)0xFFFFFFFE) { |
|
348 | - throw new Zend_Search_Lucene_Exception('Wrong TermInfoFile file format'); |
|
349 | - } |
|
350 | - |
|
351 | - $termCount = $tisFile->readLong(); |
|
352 | - $indexInterval = $tisFile->readInt(); |
|
353 | - $skipInterval = $tisFile->readInt(); |
|
354 | - |
|
355 | - $tisFile->seek($prevTermInfo->indexPointer - 20 /* header size*/, SEEK_CUR); |
|
356 | - |
|
357 | - $termValue = $prevTerm->text; |
|
358 | - $termFieldNum = $prevTerm->field; |
|
359 | - $freqPointer = $prevTermInfo->freqPointer; |
|
360 | - $proxPointer = $prevTermInfo->proxPointer; |
|
361 | - for ($count = $prevPosition*$indexInterval + 1; |
|
362 | - $count < $termCount && |
|
363 | - ( $this->_fieldsDicPositions[ $termFieldNum ] < $searchDicField || |
|
364 | - ($this->_fieldsDicPositions[ $termFieldNum ] == $searchDicField && |
|
365 | - strcmp($termValue, $term->text) < 0) ); |
|
366 | - $count++) { |
|
367 | - $termPrefixLength = $tisFile->readVInt(); |
|
368 | - $termSuffix = $tisFile->readString(); |
|
369 | - $termFieldNum = $tisFile->readVInt(); |
|
370 | - $termValue = substr( $termValue, 0, $termPrefixLength ) . $termSuffix; |
|
371 | - |
|
372 | - $docFreq = $tisFile->readVInt(); |
|
373 | - $freqPointer += $tisFile->readVInt(); |
|
374 | - $proxPointer += $tisFile->readVInt(); |
|
375 | - if( $docFreq >= $skipInterval ) { |
|
376 | - $skipOffset = $tisFile->readVInt(); |
|
377 | - } else { |
|
378 | - $skipOffset = 0; |
|
379 | - } |
|
380 | - } |
|
381 | - |
|
382 | - if ($termFieldNum == $searchField && $termValue == $term->text) { |
|
383 | - return new Zend_Search_Lucene_Index_TermInfo($docFreq, $freqPointer, $proxPointer, $skipOffset); |
|
384 | - } else { |
|
385 | - return null; |
|
386 | - } |
|
387 | - } |
|
388 | - |
|
389 | - /** |
|
390 | - * Returns normalization factor for specified documents |
|
391 | - * |
|
392 | - * @param integer $id |
|
393 | - * @param string $fieldName |
|
394 | - * @return string |
|
395 | - */ |
|
396 | - public function norm($id, $fieldName) |
|
397 | - { |
|
398 | - $fieldNum = $this->getFieldNum($fieldName); |
|
399 | - |
|
400 | - if ( !($this->_fields[$fieldNum]->isIndexed) ) { |
|
401 | - return null; |
|
402 | - } |
|
403 | - |
|
404 | - if ( !isset( $this->_norms[$fieldNum] )) { |
|
405 | - $fFile = $this->openCompoundFile('.f' . $fieldNum); |
|
406 | - $this->_norms[$fieldNum] = $fFile->readBytes($this->_docCount); |
|
407 | - } |
|
408 | - |
|
409 | - return Zend_Search_Lucene_Search_Similarity::decodeNorm( ord($this->_norms[$fieldNum]{$id}) ); |
|
410 | - } |
|
34 | + /** |
|
35 | + * Number of docs in a segment |
|
36 | + * |
|
37 | + * @var integer |
|
38 | + */ |
|
39 | + private $_docCount; |
|
40 | + |
|
41 | + /** |
|
42 | + * Segment name |
|
43 | + * |
|
44 | + * @var string |
|
45 | + */ |
|
46 | + private $_name; |
|
47 | + |
|
48 | + /** |
|
49 | + * Term Dictionary Index |
|
50 | + * Array of the Zend_Search_Lucene_Index_Term objects |
|
51 | + * Corresponding Zend_Search_Lucene_Index_TermInfo object stored in the $_termDictionaryInfos |
|
52 | + * |
|
53 | + * @var array |
|
54 | + */ |
|
55 | + private $_termDictionary; |
|
56 | + |
|
57 | + /** |
|
58 | + * Term Dictionary Index TermInfos |
|
59 | + * Array of the Zend_Search_Lucene_Index_TermInfo objects |
|
60 | + * |
|
61 | + * @var array |
|
62 | + */ |
|
63 | + private $_termDictionaryInfos; |
|
64 | + |
|
65 | + /** |
|
66 | + * Segment fields. Array of Zend_Search_Lucene_Index_FieldInfo objects for this segment |
|
67 | + * |
|
68 | + * @var array |
|
69 | + */ |
|
70 | + private $_fields; |
|
71 | + |
|
72 | + /** |
|
73 | + * Field positions in a dictionary. |
|
74 | + * (Term dictionary contains filelds ordered by names) |
|
75 | + * |
|
76 | + * @var array |
|
77 | + */ |
|
78 | + private $_fieldsDicPositions; |
|
79 | + |
|
80 | + |
|
81 | + /** |
|
82 | + * Associative array where the key is the file name and the value is data offset |
|
83 | + * in a compound segment file (.csf). |
|
84 | + * |
|
85 | + * @var array |
|
86 | + */ |
|
87 | + private $_segFiles; |
|
88 | + |
|
89 | + /** |
|
90 | + * File system adapter. |
|
91 | + * |
|
92 | + * @var Zend_Search_Lucene_Storage_Directory_Filesystem |
|
93 | + */ |
|
94 | + private $_directory; |
|
95 | + |
|
96 | + /** |
|
97 | + * Normalization factors. |
|
98 | + * An array fieldName => normVector |
|
99 | + * normVector is a binary string. |
|
100 | + * Each byte corresponds to an indexed document in a segment and |
|
101 | + * encodes normalization factor (float value, encoded by |
|
102 | + * Zend_Search_Lucene_Search_Similarity::encodeNorm()) |
|
103 | + * |
|
104 | + * @var array |
|
105 | + */ |
|
106 | + private $_norms = array(); |
|
107 | + |
|
108 | + /** |
|
109 | + * Zend_Search_Lucene_Index_SegmentInfo constructor needs Segmentname, |
|
110 | + * Documents count and Directory as a parameter. |
|
111 | + * |
|
112 | + * @param string $name |
|
113 | + * @param integer $docCount |
|
114 | + * @param Zend_Search_Lucene_Storage_Directory $directory |
|
115 | + */ |
|
116 | + public function __construct($name, $docCount, $directory) |
|
117 | + { |
|
118 | + $this->_name = $name; |
|
119 | + $this->_docCount = $docCount; |
|
120 | + $this->_directory = $directory; |
|
121 | + $this->_termDictionary = null; |
|
122 | + |
|
123 | + $this->_segFiles = array(); |
|
124 | + $cfsFile = $this->_directory->getFileObject($name . '.cfs'); |
|
125 | + $segFilesCount = $cfsFile->readVInt(); |
|
126 | + |
|
127 | + for ($count = 0; $count < $segFilesCount; $count++) { |
|
128 | + $dataOffset = $cfsFile->readLong(); |
|
129 | + $fileName = $cfsFile->readString(); |
|
130 | + $this->_segFiles[$fileName] = $dataOffset; |
|
131 | + } |
|
132 | + |
|
133 | + $fnmFile = $this->openCompoundFile('.fnm'); |
|
134 | + $fieldsCount = $fnmFile->readVInt(); |
|
135 | + $fieldNames = array(); |
|
136 | + $fieldNums = array(); |
|
137 | + $this->_fields = array(); |
|
138 | + for ($count=0; $count < $fieldsCount; $count++) { |
|
139 | + $fieldName = $fnmFile->readString(); |
|
140 | + $fieldBits = $fnmFile->readByte(); |
|
141 | + $this->_fields[$count] = new Zend_Search_Lucene_Index_FieldInfo($fieldName, |
|
142 | + $fieldBits & 1, |
|
143 | + $count, |
|
144 | + $fieldBits & 2 ); |
|
145 | + if ($fieldBits & 0x10) { |
|
146 | + // norms are omitted for the indexed field |
|
147 | + $this->_norms[$count] = str_repeat(chr(Zend_Search_Lucene_Search_Similarity::encodeNorm(1.0)), $docCount); |
|
148 | + } |
|
149 | + |
|
150 | + $fieldNums[$count] = $count; |
|
151 | + $fieldNames[$count] = $fieldName; |
|
152 | + } |
|
153 | + array_multisort($fieldNames, SORT_ASC, SORT_REGULAR, $fieldNums); |
|
154 | + $this->_fieldsDicPositions = array_flip($fieldNums); |
|
155 | + } |
|
156 | + |
|
157 | + /** |
|
158 | + * Opens index file stoted within compound index file |
|
159 | + * |
|
160 | + * @param string $extension |
|
161 | + * @throws Zend_Search_Lucene_Exception |
|
162 | + * @return Zend_Search_Lucene_Storage_File |
|
163 | + */ |
|
164 | + public function openCompoundFile($extension) |
|
165 | + { |
|
166 | + $filename = $this->_name . $extension; |
|
167 | + |
|
168 | + if( !isset($this->_segFiles[ $filename ]) ) { |
|
169 | + throw new Zend_Search_Lucene_Exception('Index compound file doesn\'t contain ' |
|
170 | + . $filename . ' file.' ); |
|
171 | + } |
|
172 | + |
|
173 | + $file = $this->_directory->getFileObject( $this->_name.".cfs" ); |
|
174 | + $file->seek( $this->_segFiles[ $filename ] ); |
|
175 | + return $file; |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * Returns field index or -1 if field is not found |
|
180 | + * |
|
181 | + * @param string $fieldName |
|
182 | + * @return integer |
|
183 | + */ |
|
184 | + public function getFieldNum($fieldName) |
|
185 | + { |
|
186 | + foreach( $this->_fields as $field ) { |
|
187 | + if( $field->name == $fieldName ) { |
|
188 | + return $field->number; |
|
189 | + } |
|
190 | + } |
|
191 | + |
|
192 | + return -1; |
|
193 | + } |
|
194 | + |
|
195 | + /** |
|
196 | + * Returns field info for specified field |
|
197 | + * |
|
198 | + * @param integer $fieldNum |
|
199 | + * @return ZSearchFieldInfo |
|
200 | + */ |
|
201 | + public function getField($fieldNum) |
|
202 | + { |
|
203 | + return $this->_fields[$fieldNum]; |
|
204 | + } |
|
205 | + |
|
206 | + /** |
|
207 | + * Returns array of fields. |
|
208 | + * if $indexed parameter is true, then returns only indexed fields. |
|
209 | + * |
|
210 | + * @param boolean $indexed |
|
211 | + * @return array |
|
212 | + */ |
|
213 | + public function getFields($indexed = false) |
|
214 | + { |
|
215 | + $result = array(); |
|
216 | + foreach( $this->_fields as $field ) { |
|
217 | + if( (!$indexed) || $field->isIndexed ) { |
|
218 | + $result[ $field->name ] = $field->name; |
|
219 | + } |
|
220 | + } |
|
221 | + return $result; |
|
222 | + } |
|
223 | + |
|
224 | + /** |
|
225 | + * Returns the total number of documents in this segment. |
|
226 | + * |
|
227 | + * @return integer |
|
228 | + */ |
|
229 | + public function count() |
|
230 | + { |
|
231 | + return $this->_docCount; |
|
232 | + } |
|
233 | + |
|
234 | + |
|
235 | + /** |
|
236 | + * Loads Term dictionary from TermInfoIndex file |
|
237 | + */ |
|
238 | + protected function _loadDictionary() |
|
239 | + { |
|
240 | + if ($this->_termDictionary !== null) { |
|
241 | + return; |
|
242 | + } |
|
243 | + |
|
244 | + $this->_termDictionary = array(); |
|
245 | + $this->_termDictionaryInfos = array(); |
|
246 | + |
|
247 | + $tiiFile = $this->openCompoundFile('.tii'); |
|
248 | + $tiVersion = $tiiFile->readInt(); |
|
249 | + if ($tiVersion != (int)0xFFFFFFFE) { |
|
250 | + throw new Zend_Search_Lucene_Exception('Wrong TermInfoIndexFile file format'); |
|
251 | + } |
|
252 | + |
|
253 | + $indexTermCount = $tiiFile->readLong(); |
|
254 | + $tiiFile->readInt(); // IndexInterval |
|
255 | + $skipInterval = $tiiFile->readInt(); |
|
256 | + |
|
257 | + $prevTerm = ''; |
|
258 | + $freqPointer = 0; |
|
259 | + $proxPointer = 0; |
|
260 | + $indexPointer = 0; |
|
261 | + for ($count = 0; $count < $indexTermCount; $count++) { |
|
262 | + $termPrefixLength = $tiiFile->readVInt(); |
|
263 | + $termSuffix = $tiiFile->readString(); |
|
264 | + $termValue = substr( $prevTerm, 0, $termPrefixLength ) . $termSuffix; |
|
265 | + |
|
266 | + $termFieldNum = $tiiFile->readVInt(); |
|
267 | + $docFreq = $tiiFile->readVInt(); |
|
268 | + $freqPointer += $tiiFile->readVInt(); |
|
269 | + $proxPointer += $tiiFile->readVInt(); |
|
270 | + if( $docFreq >= $skipInterval ) { |
|
271 | + $skipDelta = $tiiFile->readVInt(); |
|
272 | + } else { |
|
273 | + $skipDelta = 0; |
|
274 | + } |
|
275 | + |
|
276 | + $indexPointer += $tiiFile->readVInt(); |
|
277 | + |
|
278 | + $this->_termDictionary[] = new Zend_Search_Lucene_Index_Term($termValue,$termFieldNum); |
|
279 | + $this->_termDictionaryInfos[] = |
|
280 | + new Zend_Search_Lucene_Index_TermInfo($docFreq, $freqPointer, $proxPointer, $skipDelta, $indexPointer); |
|
281 | + $prevTerm = $termValue; |
|
282 | + } |
|
283 | + } |
|
284 | + |
|
285 | + |
|
286 | + /** |
|
287 | + * Return segment name |
|
288 | + * |
|
289 | + * @return string |
|
290 | + */ |
|
291 | + public function getName() |
|
292 | + { |
|
293 | + return $this->_name; |
|
294 | + } |
|
295 | + |
|
296 | + |
|
297 | + /** |
|
298 | + * Scans terms dictionary and returns term info |
|
299 | + * |
|
300 | + * @param Zend_Search_Lucene_Index_Term $term |
|
301 | + * @return Zend_Search_Lucene_Index_TermInfo |
|
302 | + */ |
|
303 | + public function getTermInfo($term) |
|
304 | + { |
|
305 | + $this->_loadDictionary(); |
|
306 | + |
|
307 | + $searchField = $this->getFieldNum($term->field); |
|
308 | + |
|
309 | + if ($searchField == -1) { |
|
310 | + return null; |
|
311 | + } |
|
312 | + $searchDicField = $this->_fieldsDicPositions[$searchField]; |
|
313 | + |
|
314 | + // search for appropriate value in dictionary |
|
315 | + $lowIndex = 0; |
|
316 | + $highIndex = count($this->_termDictionary)-1; |
|
317 | + while ($highIndex >= $lowIndex) { |
|
318 | + // $mid = ($highIndex - $lowIndex)/2; |
|
319 | + $mid = ($highIndex + $lowIndex) >> 1; |
|
320 | + $midTerm = $this->_termDictionary[$mid]; |
|
321 | + |
|
322 | + $delta = $searchDicField - $this->_fieldsDicPositions[$midTerm->field]; |
|
323 | + if ($delta == 0) { |
|
324 | + $delta = strcmp($term->text, $midTerm->text); |
|
325 | + } |
|
326 | + |
|
327 | + if ($delta < 0) { |
|
328 | + $highIndex = $mid-1; |
|
329 | + } elseif ($delta > 0) { |
|
330 | + $lowIndex = $mid+1; |
|
331 | + } else { |
|
332 | + return $this->_termDictionaryInfos[$mid]; // We got it! |
|
333 | + } |
|
334 | + } |
|
335 | + |
|
336 | + if ($highIndex == -1) { |
|
337 | + // Term is out of the dictionary range |
|
338 | + return null; |
|
339 | + } |
|
340 | + |
|
341 | + $prevPosition = $highIndex; |
|
342 | + $prevTerm = $this->_termDictionary[$prevPosition]; |
|
343 | + $prevTermInfo = $this->_termDictionaryInfos[ $prevPosition ]; |
|
344 | + |
|
345 | + $tisFile = $this->openCompoundFile('.tis'); |
|
346 | + $tiVersion = $tisFile->readInt(); |
|
347 | + if ($tiVersion != (int)0xFFFFFFFE) { |
|
348 | + throw new Zend_Search_Lucene_Exception('Wrong TermInfoFile file format'); |
|
349 | + } |
|
350 | + |
|
351 | + $termCount = $tisFile->readLong(); |
|
352 | + $indexInterval = $tisFile->readInt(); |
|
353 | + $skipInterval = $tisFile->readInt(); |
|
354 | + |
|
355 | + $tisFile->seek($prevTermInfo->indexPointer - 20 /* header size*/, SEEK_CUR); |
|
356 | + |
|
357 | + $termValue = $prevTerm->text; |
|
358 | + $termFieldNum = $prevTerm->field; |
|
359 | + $freqPointer = $prevTermInfo->freqPointer; |
|
360 | + $proxPointer = $prevTermInfo->proxPointer; |
|
361 | + for ($count = $prevPosition*$indexInterval + 1; |
|
362 | + $count < $termCount && |
|
363 | + ( $this->_fieldsDicPositions[ $termFieldNum ] < $searchDicField || |
|
364 | + ($this->_fieldsDicPositions[ $termFieldNum ] == $searchDicField && |
|
365 | + strcmp($termValue, $term->text) < 0) ); |
|
366 | + $count++) { |
|
367 | + $termPrefixLength = $tisFile->readVInt(); |
|
368 | + $termSuffix = $tisFile->readString(); |
|
369 | + $termFieldNum = $tisFile->readVInt(); |
|
370 | + $termValue = substr( $termValue, 0, $termPrefixLength ) . $termSuffix; |
|
371 | + |
|
372 | + $docFreq = $tisFile->readVInt(); |
|
373 | + $freqPointer += $tisFile->readVInt(); |
|
374 | + $proxPointer += $tisFile->readVInt(); |
|
375 | + if( $docFreq >= $skipInterval ) { |
|
376 | + $skipOffset = $tisFile->readVInt(); |
|
377 | + } else { |
|
378 | + $skipOffset = 0; |
|
379 | + } |
|
380 | + } |
|
381 | + |
|
382 | + if ($termFieldNum == $searchField && $termValue == $term->text) { |
|
383 | + return new Zend_Search_Lucene_Index_TermInfo($docFreq, $freqPointer, $proxPointer, $skipOffset); |
|
384 | + } else { |
|
385 | + return null; |
|
386 | + } |
|
387 | + } |
|
388 | + |
|
389 | + /** |
|
390 | + * Returns normalization factor for specified documents |
|
391 | + * |
|
392 | + * @param integer $id |
|
393 | + * @param string $fieldName |
|
394 | + * @return string |
|
395 | + */ |
|
396 | + public function norm($id, $fieldName) |
|
397 | + { |
|
398 | + $fieldNum = $this->getFieldNum($fieldName); |
|
399 | + |
|
400 | + if ( !($this->_fields[$fieldNum]->isIndexed) ) { |
|
401 | + return null; |
|
402 | + } |
|
403 | + |
|
404 | + if ( !isset( $this->_norms[$fieldNum] )) { |
|
405 | + $fFile = $this->openCompoundFile('.f' . $fieldNum); |
|
406 | + $this->_norms[$fieldNum] = $fFile->readBytes($this->_docCount); |
|
407 | + } |
|
408 | + |
|
409 | + return Zend_Search_Lucene_Search_Similarity::decodeNorm( ord($this->_norms[$fieldNum]{$id}) ); |
|
410 | + } |
|
411 | 411 | } |
412 | 412 |
@@ -135,13 +135,13 @@ discard block |
||
135 | 135 | $fieldNames = array(); |
136 | 136 | $fieldNums = array(); |
137 | 137 | $this->_fields = array(); |
138 | - for ($count=0; $count < $fieldsCount; $count++) { |
|
138 | + for ($count = 0; $count < $fieldsCount; $count++) { |
|
139 | 139 | $fieldName = $fnmFile->readString(); |
140 | 140 | $fieldBits = $fnmFile->readByte(); |
141 | 141 | $this->_fields[$count] = new Zend_Search_Lucene_Index_FieldInfo($fieldName, |
142 | 142 | $fieldBits & 1, |
143 | 143 | $count, |
144 | - $fieldBits & 2 ); |
|
144 | + $fieldBits & 2); |
|
145 | 145 | if ($fieldBits & 0x10) { |
146 | 146 | // norms are omitted for the indexed field |
147 | 147 | $this->_norms[$count] = str_repeat(chr(Zend_Search_Lucene_Search_Similarity::encodeNorm(1.0)), $docCount); |
@@ -165,13 +165,13 @@ discard block |
||
165 | 165 | { |
166 | 166 | $filename = $this->_name . $extension; |
167 | 167 | |
168 | - if( !isset($this->_segFiles[ $filename ]) ) { |
|
168 | + if (!isset($this->_segFiles[$filename])) { |
|
169 | 169 | throw new Zend_Search_Lucene_Exception('Index compound file doesn\'t contain ' |
170 | - . $filename . ' file.' ); |
|
170 | + . $filename . ' file.'); |
|
171 | 171 | } |
172 | 172 | |
173 | - $file = $this->_directory->getFileObject( $this->_name.".cfs" ); |
|
174 | - $file->seek( $this->_segFiles[ $filename ] ); |
|
173 | + $file = $this->_directory->getFileObject($this->_name . ".cfs"); |
|
174 | + $file->seek($this->_segFiles[$filename]); |
|
175 | 175 | return $file; |
176 | 176 | } |
177 | 177 | |
@@ -183,8 +183,8 @@ discard block |
||
183 | 183 | */ |
184 | 184 | public function getFieldNum($fieldName) |
185 | 185 | { |
186 | - foreach( $this->_fields as $field ) { |
|
187 | - if( $field->name == $fieldName ) { |
|
186 | + foreach ($this->_fields as $field) { |
|
187 | + if ($field->name == $fieldName) { |
|
188 | 188 | return $field->number; |
189 | 189 | } |
190 | 190 | } |
@@ -213,9 +213,9 @@ discard block |
||
213 | 213 | public function getFields($indexed = false) |
214 | 214 | { |
215 | 215 | $result = array(); |
216 | - foreach( $this->_fields as $field ) { |
|
217 | - if( (!$indexed) || $field->isIndexed ) { |
|
218 | - $result[ $field->name ] = $field->name; |
|
216 | + foreach ($this->_fields as $field) { |
|
217 | + if ((!$indexed) || $field->isIndexed) { |
|
218 | + $result[$field->name] = $field->name; |
|
219 | 219 | } |
220 | 220 | } |
221 | 221 | return $result; |
@@ -246,28 +246,28 @@ discard block |
||
246 | 246 | |
247 | 247 | $tiiFile = $this->openCompoundFile('.tii'); |
248 | 248 | $tiVersion = $tiiFile->readInt(); |
249 | - if ($tiVersion != (int)0xFFFFFFFE) { |
|
249 | + if ($tiVersion != (int) 0xFFFFFFFE) { |
|
250 | 250 | throw new Zend_Search_Lucene_Exception('Wrong TermInfoIndexFile file format'); |
251 | 251 | } |
252 | 252 | |
253 | 253 | $indexTermCount = $tiiFile->readLong(); |
254 | - $tiiFile->readInt(); // IndexInterval |
|
254 | + $tiiFile->readInt(); // IndexInterval |
|
255 | 255 | $skipInterval = $tiiFile->readInt(); |
256 | 256 | |
257 | 257 | $prevTerm = ''; |
258 | - $freqPointer = 0; |
|
259 | - $proxPointer = 0; |
|
260 | - $indexPointer = 0; |
|
258 | + $freqPointer = 0; |
|
259 | + $proxPointer = 0; |
|
260 | + $indexPointer = 0; |
|
261 | 261 | for ($count = 0; $count < $indexTermCount; $count++) { |
262 | 262 | $termPrefixLength = $tiiFile->readVInt(); |
263 | 263 | $termSuffix = $tiiFile->readString(); |
264 | - $termValue = substr( $prevTerm, 0, $termPrefixLength ) . $termSuffix; |
|
264 | + $termValue = substr($prevTerm, 0, $termPrefixLength) . $termSuffix; |
|
265 | 265 | |
266 | 266 | $termFieldNum = $tiiFile->readVInt(); |
267 | 267 | $docFreq = $tiiFile->readVInt(); |
268 | 268 | $freqPointer += $tiiFile->readVInt(); |
269 | 269 | $proxPointer += $tiiFile->readVInt(); |
270 | - if( $docFreq >= $skipInterval ) { |
|
270 | + if ($docFreq >= $skipInterval) { |
|
271 | 271 | $skipDelta = $tiiFile->readVInt(); |
272 | 272 | } else { |
273 | 273 | $skipDelta = 0; |
@@ -275,7 +275,7 @@ discard block |
||
275 | 275 | |
276 | 276 | $indexPointer += $tiiFile->readVInt(); |
277 | 277 | |
278 | - $this->_termDictionary[] = new Zend_Search_Lucene_Index_Term($termValue,$termFieldNum); |
|
278 | + $this->_termDictionary[] = new Zend_Search_Lucene_Index_Term($termValue, $termFieldNum); |
|
279 | 279 | $this->_termDictionaryInfos[] = |
280 | 280 | new Zend_Search_Lucene_Index_TermInfo($docFreq, $freqPointer, $proxPointer, $skipDelta, $indexPointer); |
281 | 281 | $prevTerm = $termValue; |
@@ -313,7 +313,7 @@ discard block |
||
313 | 313 | |
314 | 314 | // search for appropriate value in dictionary |
315 | 315 | $lowIndex = 0; |
316 | - $highIndex = count($this->_termDictionary)-1; |
|
316 | + $highIndex = count($this->_termDictionary) - 1; |
|
317 | 317 | while ($highIndex >= $lowIndex) { |
318 | 318 | // $mid = ($highIndex - $lowIndex)/2; |
319 | 319 | $mid = ($highIndex + $lowIndex) >> 1; |
@@ -325,9 +325,9 @@ discard block |
||
325 | 325 | } |
326 | 326 | |
327 | 327 | if ($delta < 0) { |
328 | - $highIndex = $mid-1; |
|
328 | + $highIndex = $mid - 1; |
|
329 | 329 | } elseif ($delta > 0) { |
330 | - $lowIndex = $mid+1; |
|
330 | + $lowIndex = $mid + 1; |
|
331 | 331 | } else { |
332 | 332 | return $this->_termDictionaryInfos[$mid]; // We got it! |
333 | 333 | } |
@@ -340,11 +340,11 @@ discard block |
||
340 | 340 | |
341 | 341 | $prevPosition = $highIndex; |
342 | 342 | $prevTerm = $this->_termDictionary[$prevPosition]; |
343 | - $prevTermInfo = $this->_termDictionaryInfos[ $prevPosition ]; |
|
343 | + $prevTermInfo = $this->_termDictionaryInfos[$prevPosition]; |
|
344 | 344 | |
345 | 345 | $tisFile = $this->openCompoundFile('.tis'); |
346 | 346 | $tiVersion = $tisFile->readInt(); |
347 | - if ($tiVersion != (int)0xFFFFFFFE) { |
|
347 | + if ($tiVersion != (int) 0xFFFFFFFE) { |
|
348 | 348 | throw new Zend_Search_Lucene_Exception('Wrong TermInfoFile file format'); |
349 | 349 | } |
350 | 350 | |
@@ -358,21 +358,21 @@ discard block |
||
358 | 358 | $termFieldNum = $prevTerm->field; |
359 | 359 | $freqPointer = $prevTermInfo->freqPointer; |
360 | 360 | $proxPointer = $prevTermInfo->proxPointer; |
361 | - for ($count = $prevPosition*$indexInterval + 1; |
|
361 | + for ($count = $prevPosition * $indexInterval + 1; |
|
362 | 362 | $count < $termCount && |
363 | - ( $this->_fieldsDicPositions[ $termFieldNum ] < $searchDicField || |
|
364 | - ($this->_fieldsDicPositions[ $termFieldNum ] == $searchDicField && |
|
365 | - strcmp($termValue, $term->text) < 0) ); |
|
363 | + ($this->_fieldsDicPositions[$termFieldNum] < $searchDicField || |
|
364 | + ($this->_fieldsDicPositions[$termFieldNum] == $searchDicField && |
|
365 | + strcmp($termValue, $term->text) < 0)); |
|
366 | 366 | $count++) { |
367 | 367 | $termPrefixLength = $tisFile->readVInt(); |
368 | 368 | $termSuffix = $tisFile->readString(); |
369 | 369 | $termFieldNum = $tisFile->readVInt(); |
370 | - $termValue = substr( $termValue, 0, $termPrefixLength ) . $termSuffix; |
|
370 | + $termValue = substr($termValue, 0, $termPrefixLength) . $termSuffix; |
|
371 | 371 | |
372 | 372 | $docFreq = $tisFile->readVInt(); |
373 | 373 | $freqPointer += $tisFile->readVInt(); |
374 | 374 | $proxPointer += $tisFile->readVInt(); |
375 | - if( $docFreq >= $skipInterval ) { |
|
375 | + if ($docFreq >= $skipInterval) { |
|
376 | 376 | $skipOffset = $tisFile->readVInt(); |
377 | 377 | } else { |
378 | 378 | $skipOffset = 0; |
@@ -397,16 +397,16 @@ discard block |
||
397 | 397 | { |
398 | 398 | $fieldNum = $this->getFieldNum($fieldName); |
399 | 399 | |
400 | - if ( !($this->_fields[$fieldNum]->isIndexed) ) { |
|
400 | + if (!($this->_fields[$fieldNum]->isIndexed)) { |
|
401 | 401 | return null; |
402 | 402 | } |
403 | 403 | |
404 | - if ( !isset( $this->_norms[$fieldNum] )) { |
|
404 | + if (!isset($this->_norms[$fieldNum])) { |
|
405 | 405 | $fFile = $this->openCompoundFile('.f' . $fieldNum); |
406 | 406 | $this->_norms[$fieldNum] = $fFile->readBytes($this->_docCount); |
407 | 407 | } |
408 | 408 | |
409 | - return Zend_Search_Lucene_Search_Similarity::decodeNorm( ord($this->_norms[$fieldNum]{$id}) ); |
|
409 | + return Zend_Search_Lucene_Search_Similarity::decodeNorm(ord($this->_norms[$fieldNum]{$id})); |
|
410 | 410 | } |
411 | 411 | } |
412 | 412 |
@@ -258,7 +258,7 @@ |
||
258 | 258 | * Score calculator for exact phrase queries (terms sequence is fixed) |
259 | 259 | * |
260 | 260 | * @param integer $docId |
261 | - * @return float |
|
261 | + * @return integer |
|
262 | 262 | */ |
263 | 263 | public function _exactPhraseFreq($docId) |
264 | 264 | { |
@@ -40,385 +40,385 @@ |
||
40 | 40 | */ |
41 | 41 | class Zend_Search_Lucene_Search_Query_Phrase extends Zend_Search_Lucene_Search_Query |
42 | 42 | { |
43 | - /** |
|
44 | - * Terms to find. |
|
45 | - * Array of Zend_Search_Lucene_Index_Term objects. |
|
46 | - * |
|
47 | - * @var array |
|
48 | - */ |
|
49 | - private $_terms; |
|
50 | - |
|
51 | - /** |
|
52 | - * Term positions (relative positions of terms within the phrase). |
|
53 | - * Array of integers |
|
54 | - * |
|
55 | - * @var array |
|
56 | - */ |
|
57 | - private $_offsets; |
|
58 | - |
|
59 | - /** |
|
60 | - * Sets the number of other words permitted between words in query phrase. |
|
61 | - * If zero, then this is an exact phrase search. For larger values this works |
|
62 | - * like a WITHIN or NEAR operator. |
|
63 | - * |
|
64 | - * The slop is in fact an edit-distance, where the units correspond to |
|
65 | - * moves of terms in the query phrase out of position. For example, to switch |
|
66 | - * the order of two words requires two moves (the first move places the words |
|
67 | - * atop one another), so to permit re-orderings of phrases, the slop must be |
|
68 | - * at least two. |
|
69 | - * More exact matches are scored higher than sloppier matches, thus search |
|
70 | - * results are sorted by exactness. |
|
71 | - * |
|
72 | - * The slop is zero by default, requiring exact matches. |
|
73 | - * |
|
74 | - * @var unknown_type |
|
75 | - */ |
|
76 | - private $_slop; |
|
77 | - |
|
78 | - /** |
|
79 | - * Result vector. |
|
80 | - * Bitset or array of document IDs |
|
81 | - * (depending from Bitset extension availability). |
|
82 | - * |
|
83 | - * @var mixed |
|
84 | - */ |
|
85 | - private $_resVector = null; |
|
86 | - |
|
87 | - /** |
|
88 | - * Terms positions vectors. |
|
89 | - * Array of Arrays: |
|
90 | - * term1Id => (docId => array( pos1, pos2, ... ), ...) |
|
91 | - * term2Id => (docId => array( pos1, pos2, ... ), ...) |
|
92 | - * |
|
93 | - * @var array |
|
94 | - */ |
|
95 | - private $_termsPositions = array(); |
|
96 | - |
|
97 | - /** |
|
98 | - * Class constructor. Create a new prase query. |
|
99 | - * |
|
100 | - * @param string $field Field to search. |
|
101 | - * @param array $terms Terms to search Array of strings. |
|
102 | - * @param array $offsets Relative term positions. Array of integers. |
|
103 | - * @throws Zend_Search_Lucene_Exception |
|
104 | - */ |
|
105 | - public function __construct($terms = null, $offsets = null, $field = null) |
|
106 | - { |
|
107 | - $this->_slop = 0; |
|
108 | - |
|
109 | - if (is_array($terms)) { |
|
110 | - $this->_terms = array(); |
|
111 | - foreach ($terms as $termId => $termText) { |
|
112 | - $this->_terms[$termId] = ($field !== null)? new Zend_Search_Lucene_Index_Term($termText, $field): |
|
113 | - new Zend_Search_Lucene_Index_Term($termText); |
|
114 | - } |
|
115 | - } else if ($terms === null) { |
|
116 | - $this->_terms = array(); |
|
117 | - } else { |
|
118 | - throw new Zend_Search_Lucene_Exception('terms argument must be array of strings or null'); |
|
119 | - } |
|
120 | - |
|
121 | - if (is_array($offsets)) { |
|
122 | - if (count($this->_terms) != count($offsets)) { |
|
123 | - throw new Zend_Search_Lucene_Exception('terms and offsets arguments must have the same size.'); |
|
124 | - } |
|
125 | - $this->_offsets = $offsets; |
|
126 | - } else if ($offsets === null) { |
|
127 | - $this->_offsets = array(); |
|
128 | - foreach ($this->_terms as $termId => $term) { |
|
129 | - $position = count($this->_offsets); |
|
130 | - $this->_offsets[$termId] = $position; |
|
131 | - } |
|
132 | - } else { |
|
133 | - throw new Zend_Search_Lucene_Exception('offsets argument must be array of strings or null'); |
|
134 | - } |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * Set slop |
|
139 | - * |
|
140 | - * @param integer $slop |
|
141 | - */ |
|
142 | - public function setSlop($slop) |
|
143 | - { |
|
144 | - $this->_slop = $slop; |
|
145 | - } |
|
146 | - |
|
147 | - |
|
148 | - /** |
|
149 | - * Get slop |
|
150 | - * |
|
151 | - * @return integer |
|
152 | - */ |
|
153 | - public function getSlop() |
|
154 | - { |
|
155 | - return $this->_slop; |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - /** |
|
160 | - * Adds a term to the end of the query phrase. |
|
161 | - * The relative position of the term is specified explicitly or the one immediately |
|
162 | - * after the last term added. |
|
163 | - * |
|
164 | - * @param Zend_Search_Lucene_Index_Term $term |
|
165 | - * @param integer $position |
|
166 | - */ |
|
167 | - public function addTerm(Zend_Search_Lucene_Index_Term $term, $position = null) { |
|
168 | - if ((count($this->_terms) != 0)&&(end($this->_terms)->field != $term->field)) { |
|
169 | - throw new Zend_Search_Lucene_Exception('All phrase terms must be in the same field: ' . |
|
170 | - $term->field . ':' . $term->text); |
|
171 | - } |
|
172 | - |
|
173 | - $this->_terms[] = $term; |
|
174 | - if ($position !== null) { |
|
175 | - $this->_offsets[] = $position; |
|
176 | - } else if (count($this->_offsets) != 0) { |
|
177 | - $this->_offsets[] = end($this->_offsets) + 1; |
|
178 | - } else { |
|
179 | - $this->_offsets[] = 0; |
|
180 | - } |
|
181 | - } |
|
182 | - |
|
183 | - |
|
184 | - /** |
|
185 | - * Returns query term |
|
186 | - * |
|
187 | - * @return array |
|
188 | - */ |
|
189 | - public function getTerms() |
|
190 | - { |
|
191 | - return $this->_terms; |
|
192 | - } |
|
193 | - |
|
194 | - |
|
195 | - /** |
|
196 | - * Set weight for specified term |
|
197 | - * |
|
198 | - * @param integer $num |
|
199 | - * @param Zend_Search_Lucene_Search_Weight_Term $weight |
|
200 | - */ |
|
201 | - public function setWeight($num, $weight) |
|
202 | - { |
|
203 | - $this->_weights[$num] = $weight; |
|
204 | - } |
|
205 | - |
|
206 | - |
|
207 | - /** |
|
208 | - * Constructs an appropriate Weight implementation for this query. |
|
209 | - * |
|
210 | - * @param Zend_Search_Lucene $reader |
|
211 | - * @return Zend_Search_Lucene_Search_Weight |
|
212 | - */ |
|
213 | - protected function _createWeight($reader) |
|
214 | - { |
|
215 | - return new Zend_Search_Lucene_Search_Weight_Phrase($this, $reader); |
|
216 | - } |
|
217 | - |
|
218 | - |
|
219 | - /** |
|
220 | - * Calculate result vector |
|
221 | - * |
|
222 | - * @param Zend_Search_Lucene $reader |
|
223 | - */ |
|
224 | - private function _calculateResult($reader) |
|
225 | - { |
|
226 | - if (extension_loaded('bitset')) { |
|
227 | - foreach( $this->_terms as $termId=>$term ) { |
|
228 | - if($this->_resVector === null) { |
|
229 | - $this->_resVector = bitset_from_array($reader->termDocs($term)); |
|
230 | - } else { |
|
231 | - $this->_resVector = bitset_intersection( |
|
232 | - $this->_resVector, |
|
233 | - bitset_from_array($reader->termDocs($term)) ); |
|
234 | - } |
|
235 | - |
|
236 | - $this->_termsPositions[$termId] = $reader->termPositions($term); |
|
237 | - } |
|
238 | - } else { |
|
239 | - foreach( $this->_terms as $termId=>$term ) { |
|
240 | - if($this->_resVector === null) { |
|
241 | - $this->_resVector = array_flip($reader->termDocs($term)); |
|
242 | - } else { |
|
243 | - $termDocs = array_flip($reader->termDocs($term)); |
|
244 | - foreach($this->_resVector as $key=>$value) { |
|
245 | - if (!isset( $termDocs[$key] )) { |
|
246 | - unset( $this->_resVector[$key] ); |
|
247 | - } |
|
248 | - } |
|
249 | - } |
|
250 | - |
|
251 | - $this->_termsPositions[$termId] = $reader->termPositions($term); |
|
252 | - } |
|
253 | - } |
|
254 | - } |
|
255 | - |
|
256 | - |
|
257 | - /** |
|
258 | - * Score calculator for exact phrase queries (terms sequence is fixed) |
|
259 | - * |
|
260 | - * @param integer $docId |
|
261 | - * @return float |
|
262 | - */ |
|
263 | - public function _exactPhraseFreq($docId) |
|
264 | - { |
|
265 | - $freq = 0; |
|
266 | - |
|
267 | - // Term Id with lowest cardinality |
|
268 | - $lowCardTermId = null; |
|
269 | - |
|
270 | - // Calculate $lowCardTermId |
|
271 | - foreach ($this->_terms as $termId => $term) { |
|
272 | - if ($lowCardTermId === null || |
|
273 | - count($this->_termsPositions[$termId][$docId]) < |
|
274 | - count($this->_termsPositions[$lowCardTermId][$docId]) ) { |
|
275 | - $lowCardTermId = $termId; |
|
276 | - } |
|
277 | - } |
|
278 | - |
|
279 | - // Walk through positions of the term with lowest cardinality |
|
280 | - foreach ($this->_termsPositions[$lowCardTermId][$docId] as $lowCardPos) { |
|
281 | - // We expect phrase to be found |
|
282 | - $freq++; |
|
283 | - |
|
284 | - // Walk through other terms |
|
285 | - foreach ($this->_terms as $termId => $term) { |
|
286 | - if ($termId != $lowCardTermId) { |
|
287 | - $expectedPosition = $lowCardPos + |
|
288 | - ($this->_offsets[$termId] - |
|
289 | - $this->_offsets[$lowCardTermId]); |
|
290 | - |
|
291 | - if (!in_array($expectedPosition, $this->_termsPositions[$termId][$docId])) { |
|
292 | - $freq--; // Phrase wasn't found. |
|
293 | - break; |
|
294 | - } |
|
295 | - } |
|
296 | - } |
|
297 | - } |
|
298 | - |
|
299 | - return $freq; |
|
300 | - } |
|
301 | - |
|
302 | - /** |
|
303 | - * Score calculator for sloppy phrase queries (terms sequence is fixed) |
|
304 | - * |
|
305 | - * @param integer $docId |
|
306 | - * @param Zend_Search_Lucene $reader |
|
307 | - * @return float |
|
308 | - */ |
|
309 | - public function _sloppyPhraseFreq($docId, Zend_Search_Lucene $reader) |
|
310 | - { |
|
311 | - $freq = 0; |
|
312 | - |
|
313 | - $phraseQueue = array(); |
|
314 | - $phraseQueue[0] = array(); // empty phrase |
|
315 | - $lastTerm = null; |
|
316 | - |
|
317 | - // Walk through the terms to create phrases. |
|
318 | - foreach ($this->_terms as $termId => $term) { |
|
319 | - $queueSize = count($phraseQueue); |
|
320 | - $firstPass = true; |
|
321 | - |
|
322 | - // Walk through the term positions. |
|
323 | - // Each term position produces a set of phrases. |
|
324 | - foreach ($this->_termsPositions[$termId][$docId] as $termPosition ) { |
|
325 | - if ($firstPass) { |
|
326 | - for ($count = 0; $count < $queueSize; $count++) { |
|
327 | - $phraseQueue[$count][$termId] = $termPosition; |
|
328 | - } |
|
329 | - } else { |
|
330 | - for ($count = 0; $count < $queueSize; $count++) { |
|
331 | - if ($lastTerm !== null && |
|
332 | - abs( $termPosition - $phraseQueue[$count][$lastTerm] - |
|
333 | - ($this->_offsets[$termId] - $this->_offsets[$lastTerm])) > $this->_slop) { |
|
334 | - continue; |
|
335 | - } |
|
336 | - |
|
337 | - $newPhraseId = count($phraseQueue); |
|
338 | - $phraseQueue[$newPhraseId] = $phraseQueue[$count]; |
|
339 | - $phraseQueue[$newPhraseId][$termId] = $termPosition; |
|
340 | - } |
|
341 | - |
|
342 | - } |
|
343 | - |
|
344 | - $firstPass = false; |
|
345 | - } |
|
346 | - $lastTerm = $termId; |
|
347 | - } |
|
348 | - |
|
349 | - |
|
350 | - foreach ($phraseQueue as $phrasePos) { |
|
351 | - $minDistance = null; |
|
352 | - |
|
353 | - for ($shift = -$this->_slop; $shift <= $this->_slop; $shift++) { |
|
354 | - $distance = 0; |
|
355 | - $start = reset($phrasePos) - reset($this->_offsets) + $shift; |
|
356 | - |
|
357 | - foreach ($this->_terms as $termId => $term) { |
|
358 | - $distance += abs($phrasePos[$termId] - $this->_offsets[$termId] - $start); |
|
359 | - |
|
360 | - if($distance > $this->_slop) { |
|
361 | - break; |
|
362 | - } |
|
363 | - } |
|
364 | - |
|
365 | - if ($minDistance === null || $distance < $minDistance) { |
|
366 | - $minDistance = $distance; |
|
367 | - } |
|
368 | - } |
|
369 | - |
|
370 | - if ($minDistance <= $this->_slop) { |
|
371 | - $freq += $reader->getSimilarity()->sloppyFreq($minDistance); |
|
372 | - } |
|
373 | - } |
|
374 | - |
|
375 | - return $freq; |
|
376 | - } |
|
377 | - |
|
378 | - |
|
379 | - /** |
|
380 | - * Score specified document |
|
381 | - * |
|
382 | - * @param integer $docId |
|
383 | - * @param Zend_Search_Lucene $reader |
|
384 | - * @return float |
|
385 | - */ |
|
386 | - public function score($docId, $reader) |
|
387 | - { |
|
388 | - // optimize zero-term case |
|
389 | - if (count($this->_terms) == 0) { |
|
390 | - return 0; |
|
391 | - } |
|
392 | - |
|
393 | - if($this->_resVector === null) { |
|
394 | - $this->_calculateResult($reader); |
|
395 | - $this->_initWeight($reader); |
|
396 | - } |
|
397 | - |
|
398 | - if ( (extension_loaded('bitset')) ? |
|
399 | - bitset_in($this->_resVector, $docId) : |
|
400 | - isset($this->_resVector[$docId]) ) { |
|
401 | - if ($this->_slop == 0) { |
|
402 | - $freq = $this->_exactPhraseFreq($docId); |
|
403 | - } else { |
|
404 | - $freq = $this->_sloppyPhraseFreq($docId, $reader); |
|
405 | - } |
|
43 | + /** |
|
44 | + * Terms to find. |
|
45 | + * Array of Zend_Search_Lucene_Index_Term objects. |
|
46 | + * |
|
47 | + * @var array |
|
48 | + */ |
|
49 | + private $_terms; |
|
50 | + |
|
51 | + /** |
|
52 | + * Term positions (relative positions of terms within the phrase). |
|
53 | + * Array of integers |
|
54 | + * |
|
55 | + * @var array |
|
56 | + */ |
|
57 | + private $_offsets; |
|
58 | + |
|
59 | + /** |
|
60 | + * Sets the number of other words permitted between words in query phrase. |
|
61 | + * If zero, then this is an exact phrase search. For larger values this works |
|
62 | + * like a WITHIN or NEAR operator. |
|
63 | + * |
|
64 | + * The slop is in fact an edit-distance, where the units correspond to |
|
65 | + * moves of terms in the query phrase out of position. For example, to switch |
|
66 | + * the order of two words requires two moves (the first move places the words |
|
67 | + * atop one another), so to permit re-orderings of phrases, the slop must be |
|
68 | + * at least two. |
|
69 | + * More exact matches are scored higher than sloppier matches, thus search |
|
70 | + * results are sorted by exactness. |
|
71 | + * |
|
72 | + * The slop is zero by default, requiring exact matches. |
|
73 | + * |
|
74 | + * @var unknown_type |
|
75 | + */ |
|
76 | + private $_slop; |
|
77 | + |
|
78 | + /** |
|
79 | + * Result vector. |
|
80 | + * Bitset or array of document IDs |
|
81 | + * (depending from Bitset extension availability). |
|
82 | + * |
|
83 | + * @var mixed |
|
84 | + */ |
|
85 | + private $_resVector = null; |
|
86 | + |
|
87 | + /** |
|
88 | + * Terms positions vectors. |
|
89 | + * Array of Arrays: |
|
90 | + * term1Id => (docId => array( pos1, pos2, ... ), ...) |
|
91 | + * term2Id => (docId => array( pos1, pos2, ... ), ...) |
|
92 | + * |
|
93 | + * @var array |
|
94 | + */ |
|
95 | + private $_termsPositions = array(); |
|
96 | + |
|
97 | + /** |
|
98 | + * Class constructor. Create a new prase query. |
|
99 | + * |
|
100 | + * @param string $field Field to search. |
|
101 | + * @param array $terms Terms to search Array of strings. |
|
102 | + * @param array $offsets Relative term positions. Array of integers. |
|
103 | + * @throws Zend_Search_Lucene_Exception |
|
104 | + */ |
|
105 | + public function __construct($terms = null, $offsets = null, $field = null) |
|
106 | + { |
|
107 | + $this->_slop = 0; |
|
108 | + |
|
109 | + if (is_array($terms)) { |
|
110 | + $this->_terms = array(); |
|
111 | + foreach ($terms as $termId => $termText) { |
|
112 | + $this->_terms[$termId] = ($field !== null)? new Zend_Search_Lucene_Index_Term($termText, $field): |
|
113 | + new Zend_Search_Lucene_Index_Term($termText); |
|
114 | + } |
|
115 | + } else if ($terms === null) { |
|
116 | + $this->_terms = array(); |
|
117 | + } else { |
|
118 | + throw new Zend_Search_Lucene_Exception('terms argument must be array of strings or null'); |
|
119 | + } |
|
120 | + |
|
121 | + if (is_array($offsets)) { |
|
122 | + if (count($this->_terms) != count($offsets)) { |
|
123 | + throw new Zend_Search_Lucene_Exception('terms and offsets arguments must have the same size.'); |
|
124 | + } |
|
125 | + $this->_offsets = $offsets; |
|
126 | + } else if ($offsets === null) { |
|
127 | + $this->_offsets = array(); |
|
128 | + foreach ($this->_terms as $termId => $term) { |
|
129 | + $position = count($this->_offsets); |
|
130 | + $this->_offsets[$termId] = $position; |
|
131 | + } |
|
132 | + } else { |
|
133 | + throw new Zend_Search_Lucene_Exception('offsets argument must be array of strings or null'); |
|
134 | + } |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * Set slop |
|
139 | + * |
|
140 | + * @param integer $slop |
|
141 | + */ |
|
142 | + public function setSlop($slop) |
|
143 | + { |
|
144 | + $this->_slop = $slop; |
|
145 | + } |
|
146 | + |
|
147 | + |
|
148 | + /** |
|
149 | + * Get slop |
|
150 | + * |
|
151 | + * @return integer |
|
152 | + */ |
|
153 | + public function getSlop() |
|
154 | + { |
|
155 | + return $this->_slop; |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + /** |
|
160 | + * Adds a term to the end of the query phrase. |
|
161 | + * The relative position of the term is specified explicitly or the one immediately |
|
162 | + * after the last term added. |
|
163 | + * |
|
164 | + * @param Zend_Search_Lucene_Index_Term $term |
|
165 | + * @param integer $position |
|
166 | + */ |
|
167 | + public function addTerm(Zend_Search_Lucene_Index_Term $term, $position = null) { |
|
168 | + if ((count($this->_terms) != 0)&&(end($this->_terms)->field != $term->field)) { |
|
169 | + throw new Zend_Search_Lucene_Exception('All phrase terms must be in the same field: ' . |
|
170 | + $term->field . ':' . $term->text); |
|
171 | + } |
|
172 | + |
|
173 | + $this->_terms[] = $term; |
|
174 | + if ($position !== null) { |
|
175 | + $this->_offsets[] = $position; |
|
176 | + } else if (count($this->_offsets) != 0) { |
|
177 | + $this->_offsets[] = end($this->_offsets) + 1; |
|
178 | + } else { |
|
179 | + $this->_offsets[] = 0; |
|
180 | + } |
|
181 | + } |
|
182 | + |
|
183 | + |
|
184 | + /** |
|
185 | + * Returns query term |
|
186 | + * |
|
187 | + * @return array |
|
188 | + */ |
|
189 | + public function getTerms() |
|
190 | + { |
|
191 | + return $this->_terms; |
|
192 | + } |
|
193 | + |
|
194 | + |
|
195 | + /** |
|
196 | + * Set weight for specified term |
|
197 | + * |
|
198 | + * @param integer $num |
|
199 | + * @param Zend_Search_Lucene_Search_Weight_Term $weight |
|
200 | + */ |
|
201 | + public function setWeight($num, $weight) |
|
202 | + { |
|
203 | + $this->_weights[$num] = $weight; |
|
204 | + } |
|
205 | + |
|
206 | + |
|
207 | + /** |
|
208 | + * Constructs an appropriate Weight implementation for this query. |
|
209 | + * |
|
210 | + * @param Zend_Search_Lucene $reader |
|
211 | + * @return Zend_Search_Lucene_Search_Weight |
|
212 | + */ |
|
213 | + protected function _createWeight($reader) |
|
214 | + { |
|
215 | + return new Zend_Search_Lucene_Search_Weight_Phrase($this, $reader); |
|
216 | + } |
|
217 | + |
|
218 | + |
|
219 | + /** |
|
220 | + * Calculate result vector |
|
221 | + * |
|
222 | + * @param Zend_Search_Lucene $reader |
|
223 | + */ |
|
224 | + private function _calculateResult($reader) |
|
225 | + { |
|
226 | + if (extension_loaded('bitset')) { |
|
227 | + foreach( $this->_terms as $termId=>$term ) { |
|
228 | + if($this->_resVector === null) { |
|
229 | + $this->_resVector = bitset_from_array($reader->termDocs($term)); |
|
230 | + } else { |
|
231 | + $this->_resVector = bitset_intersection( |
|
232 | + $this->_resVector, |
|
233 | + bitset_from_array($reader->termDocs($term)) ); |
|
234 | + } |
|
235 | + |
|
236 | + $this->_termsPositions[$termId] = $reader->termPositions($term); |
|
237 | + } |
|
238 | + } else { |
|
239 | + foreach( $this->_terms as $termId=>$term ) { |
|
240 | + if($this->_resVector === null) { |
|
241 | + $this->_resVector = array_flip($reader->termDocs($term)); |
|
242 | + } else { |
|
243 | + $termDocs = array_flip($reader->termDocs($term)); |
|
244 | + foreach($this->_resVector as $key=>$value) { |
|
245 | + if (!isset( $termDocs[$key] )) { |
|
246 | + unset( $this->_resVector[$key] ); |
|
247 | + } |
|
248 | + } |
|
249 | + } |
|
250 | + |
|
251 | + $this->_termsPositions[$termId] = $reader->termPositions($term); |
|
252 | + } |
|
253 | + } |
|
254 | + } |
|
255 | + |
|
256 | + |
|
257 | + /** |
|
258 | + * Score calculator for exact phrase queries (terms sequence is fixed) |
|
259 | + * |
|
260 | + * @param integer $docId |
|
261 | + * @return float |
|
262 | + */ |
|
263 | + public function _exactPhraseFreq($docId) |
|
264 | + { |
|
265 | + $freq = 0; |
|
266 | + |
|
267 | + // Term Id with lowest cardinality |
|
268 | + $lowCardTermId = null; |
|
269 | + |
|
270 | + // Calculate $lowCardTermId |
|
271 | + foreach ($this->_terms as $termId => $term) { |
|
272 | + if ($lowCardTermId === null || |
|
273 | + count($this->_termsPositions[$termId][$docId]) < |
|
274 | + count($this->_termsPositions[$lowCardTermId][$docId]) ) { |
|
275 | + $lowCardTermId = $termId; |
|
276 | + } |
|
277 | + } |
|
278 | + |
|
279 | + // Walk through positions of the term with lowest cardinality |
|
280 | + foreach ($this->_termsPositions[$lowCardTermId][$docId] as $lowCardPos) { |
|
281 | + // We expect phrase to be found |
|
282 | + $freq++; |
|
283 | + |
|
284 | + // Walk through other terms |
|
285 | + foreach ($this->_terms as $termId => $term) { |
|
286 | + if ($termId != $lowCardTermId) { |
|
287 | + $expectedPosition = $lowCardPos + |
|
288 | + ($this->_offsets[$termId] - |
|
289 | + $this->_offsets[$lowCardTermId]); |
|
290 | + |
|
291 | + if (!in_array($expectedPosition, $this->_termsPositions[$termId][$docId])) { |
|
292 | + $freq--; // Phrase wasn't found. |
|
293 | + break; |
|
294 | + } |
|
295 | + } |
|
296 | + } |
|
297 | + } |
|
298 | + |
|
299 | + return $freq; |
|
300 | + } |
|
301 | + |
|
302 | + /** |
|
303 | + * Score calculator for sloppy phrase queries (terms sequence is fixed) |
|
304 | + * |
|
305 | + * @param integer $docId |
|
306 | + * @param Zend_Search_Lucene $reader |
|
307 | + * @return float |
|
308 | + */ |
|
309 | + public function _sloppyPhraseFreq($docId, Zend_Search_Lucene $reader) |
|
310 | + { |
|
311 | + $freq = 0; |
|
312 | + |
|
313 | + $phraseQueue = array(); |
|
314 | + $phraseQueue[0] = array(); // empty phrase |
|
315 | + $lastTerm = null; |
|
316 | + |
|
317 | + // Walk through the terms to create phrases. |
|
318 | + foreach ($this->_terms as $termId => $term) { |
|
319 | + $queueSize = count($phraseQueue); |
|
320 | + $firstPass = true; |
|
321 | + |
|
322 | + // Walk through the term positions. |
|
323 | + // Each term position produces a set of phrases. |
|
324 | + foreach ($this->_termsPositions[$termId][$docId] as $termPosition ) { |
|
325 | + if ($firstPass) { |
|
326 | + for ($count = 0; $count < $queueSize; $count++) { |
|
327 | + $phraseQueue[$count][$termId] = $termPosition; |
|
328 | + } |
|
329 | + } else { |
|
330 | + for ($count = 0; $count < $queueSize; $count++) { |
|
331 | + if ($lastTerm !== null && |
|
332 | + abs( $termPosition - $phraseQueue[$count][$lastTerm] - |
|
333 | + ($this->_offsets[$termId] - $this->_offsets[$lastTerm])) > $this->_slop) { |
|
334 | + continue; |
|
335 | + } |
|
336 | + |
|
337 | + $newPhraseId = count($phraseQueue); |
|
338 | + $phraseQueue[$newPhraseId] = $phraseQueue[$count]; |
|
339 | + $phraseQueue[$newPhraseId][$termId] = $termPosition; |
|
340 | + } |
|
341 | + |
|
342 | + } |
|
343 | + |
|
344 | + $firstPass = false; |
|
345 | + } |
|
346 | + $lastTerm = $termId; |
|
347 | + } |
|
348 | + |
|
349 | + |
|
350 | + foreach ($phraseQueue as $phrasePos) { |
|
351 | + $minDistance = null; |
|
352 | + |
|
353 | + for ($shift = -$this->_slop; $shift <= $this->_slop; $shift++) { |
|
354 | + $distance = 0; |
|
355 | + $start = reset($phrasePos) - reset($this->_offsets) + $shift; |
|
356 | + |
|
357 | + foreach ($this->_terms as $termId => $term) { |
|
358 | + $distance += abs($phrasePos[$termId] - $this->_offsets[$termId] - $start); |
|
359 | + |
|
360 | + if($distance > $this->_slop) { |
|
361 | + break; |
|
362 | + } |
|
363 | + } |
|
364 | + |
|
365 | + if ($minDistance === null || $distance < $minDistance) { |
|
366 | + $minDistance = $distance; |
|
367 | + } |
|
368 | + } |
|
369 | + |
|
370 | + if ($minDistance <= $this->_slop) { |
|
371 | + $freq += $reader->getSimilarity()->sloppyFreq($minDistance); |
|
372 | + } |
|
373 | + } |
|
374 | + |
|
375 | + return $freq; |
|
376 | + } |
|
377 | + |
|
378 | + |
|
379 | + /** |
|
380 | + * Score specified document |
|
381 | + * |
|
382 | + * @param integer $docId |
|
383 | + * @param Zend_Search_Lucene $reader |
|
384 | + * @return float |
|
385 | + */ |
|
386 | + public function score($docId, $reader) |
|
387 | + { |
|
388 | + // optimize zero-term case |
|
389 | + if (count($this->_terms) == 0) { |
|
390 | + return 0; |
|
391 | + } |
|
392 | + |
|
393 | + if($this->_resVector === null) { |
|
394 | + $this->_calculateResult($reader); |
|
395 | + $this->_initWeight($reader); |
|
396 | + } |
|
397 | + |
|
398 | + if ( (extension_loaded('bitset')) ? |
|
399 | + bitset_in($this->_resVector, $docId) : |
|
400 | + isset($this->_resVector[$docId]) ) { |
|
401 | + if ($this->_slop == 0) { |
|
402 | + $freq = $this->_exactPhraseFreq($docId); |
|
403 | + } else { |
|
404 | + $freq = $this->_sloppyPhraseFreq($docId, $reader); |
|
405 | + } |
|
406 | 406 | |
407 | 407 | /* |
408 | 408 | return $reader->getSimilarity()->tf($freq) * |
409 | 409 | $this->_weight->getValue() * |
410 | 410 | $reader->norm($docId, reset($this->_terms)->field); |
411 | 411 | */ |
412 | - if ($freq != 0) { |
|
413 | - $tf = $reader->getSimilarity()->tf($freq); |
|
414 | - $weight = $this->_weight->getValue(); |
|
415 | - $norm = $reader->norm($docId, reset($this->_terms)->field); |
|
416 | - |
|
417 | - return $tf*$weight*$norm; |
|
418 | - } |
|
419 | - } else { |
|
420 | - return 0; |
|
421 | - } |
|
422 | - } |
|
412 | + if ($freq != 0) { |
|
413 | + $tf = $reader->getSimilarity()->tf($freq); |
|
414 | + $weight = $this->_weight->getValue(); |
|
415 | + $norm = $reader->norm($docId, reset($this->_terms)->field); |
|
416 | + |
|
417 | + return $tf*$weight*$norm; |
|
418 | + } |
|
419 | + } else { |
|
420 | + return 0; |
|
421 | + } |
|
422 | + } |
|
423 | 423 | } |
424 | 424 |
@@ -109,8 +109,7 @@ discard block |
||
109 | 109 | if (is_array($terms)) { |
110 | 110 | $this->_terms = array(); |
111 | 111 | foreach ($terms as $termId => $termText) { |
112 | - $this->_terms[$termId] = ($field !== null)? new Zend_Search_Lucene_Index_Term($termText, $field): |
|
113 | - new Zend_Search_Lucene_Index_Term($termText); |
|
112 | + $this->_terms[$termId] = ($field !== null) ? new Zend_Search_Lucene_Index_Term($termText, $field) : new Zend_Search_Lucene_Index_Term($termText); |
|
114 | 113 | } |
115 | 114 | } else if ($terms === null) { |
116 | 115 | $this->_terms = array(); |
@@ -165,7 +164,7 @@ discard block |
||
165 | 164 | * @param integer $position |
166 | 165 | */ |
167 | 166 | public function addTerm(Zend_Search_Lucene_Index_Term $term, $position = null) { |
168 | - if ((count($this->_terms) != 0)&&(end($this->_terms)->field != $term->field)) { |
|
167 | + if ((count($this->_terms) != 0) && (end($this->_terms)->field != $term->field)) { |
|
169 | 168 | throw new Zend_Search_Lucene_Exception('All phrase terms must be in the same field: ' . |
170 | 169 | $term->field . ':' . $term->text); |
171 | 170 | } |
@@ -224,8 +223,8 @@ discard block |
||
224 | 223 | private function _calculateResult($reader) |
225 | 224 | { |
226 | 225 | if (extension_loaded('bitset')) { |
227 | - foreach( $this->_terms as $termId=>$term ) { |
|
228 | - if($this->_resVector === null) { |
|
226 | + foreach ($this->_terms as $termId=>$term) { |
|
227 | + if ($this->_resVector === null) { |
|
229 | 228 | $this->_resVector = bitset_from_array($reader->termDocs($term)); |
230 | 229 | } else { |
231 | 230 | $this->_resVector = bitset_intersection( |
@@ -236,14 +235,14 @@ discard block |
||
236 | 235 | $this->_termsPositions[$termId] = $reader->termPositions($term); |
237 | 236 | } |
238 | 237 | } else { |
239 | - foreach( $this->_terms as $termId=>$term ) { |
|
240 | - if($this->_resVector === null) { |
|
238 | + foreach ($this->_terms as $termId=>$term) { |
|
239 | + if ($this->_resVector === null) { |
|
241 | 240 | $this->_resVector = array_flip($reader->termDocs($term)); |
242 | 241 | } else { |
243 | 242 | $termDocs = array_flip($reader->termDocs($term)); |
244 | - foreach($this->_resVector as $key=>$value) { |
|
245 | - if (!isset( $termDocs[$key] )) { |
|
246 | - unset( $this->_resVector[$key] ); |
|
243 | + foreach ($this->_resVector as $key=>$value) { |
|
244 | + if (!isset($termDocs[$key])) { |
|
245 | + unset($this->_resVector[$key]); |
|
247 | 246 | } |
248 | 247 | } |
249 | 248 | } |
@@ -271,7 +270,7 @@ discard block |
||
271 | 270 | foreach ($this->_terms as $termId => $term) { |
272 | 271 | if ($lowCardTermId === null || |
273 | 272 | count($this->_termsPositions[$termId][$docId]) < |
274 | - count($this->_termsPositions[$lowCardTermId][$docId]) ) { |
|
273 | + count($this->_termsPositions[$lowCardTermId][$docId])) { |
|
275 | 274 | $lowCardTermId = $termId; |
276 | 275 | } |
277 | 276 | } |
@@ -289,7 +288,7 @@ discard block |
||
289 | 288 | $this->_offsets[$lowCardTermId]); |
290 | 289 | |
291 | 290 | if (!in_array($expectedPosition, $this->_termsPositions[$termId][$docId])) { |
292 | - $freq--; // Phrase wasn't found. |
|
291 | + $freq--; // Phrase wasn't found. |
|
293 | 292 | break; |
294 | 293 | } |
295 | 294 | } |
@@ -321,7 +320,7 @@ discard block |
||
321 | 320 | |
322 | 321 | // Walk through the term positions. |
323 | 322 | // Each term position produces a set of phrases. |
324 | - foreach ($this->_termsPositions[$termId][$docId] as $termPosition ) { |
|
323 | + foreach ($this->_termsPositions[$termId][$docId] as $termPosition) { |
|
325 | 324 | if ($firstPass) { |
326 | 325 | for ($count = 0; $count < $queueSize; $count++) { |
327 | 326 | $phraseQueue[$count][$termId] = $termPosition; |
@@ -329,7 +328,7 @@ discard block |
||
329 | 328 | } else { |
330 | 329 | for ($count = 0; $count < $queueSize; $count++) { |
331 | 330 | if ($lastTerm !== null && |
332 | - abs( $termPosition - $phraseQueue[$count][$lastTerm] - |
|
331 | + abs($termPosition - $phraseQueue[$count][$lastTerm] - |
|
333 | 332 | ($this->_offsets[$termId] - $this->_offsets[$lastTerm])) > $this->_slop) { |
334 | 333 | continue; |
335 | 334 | } |
@@ -357,7 +356,7 @@ discard block |
||
357 | 356 | foreach ($this->_terms as $termId => $term) { |
358 | 357 | $distance += abs($phrasePos[$termId] - $this->_offsets[$termId] - $start); |
359 | 358 | |
360 | - if($distance > $this->_slop) { |
|
359 | + if ($distance > $this->_slop) { |
|
361 | 360 | break; |
362 | 361 | } |
363 | 362 | } |
@@ -390,14 +389,13 @@ discard block |
||
390 | 389 | return 0; |
391 | 390 | } |
392 | 391 | |
393 | - if($this->_resVector === null) { |
|
392 | + if ($this->_resVector === null) { |
|
394 | 393 | $this->_calculateResult($reader); |
395 | 394 | $this->_initWeight($reader); |
396 | 395 | } |
397 | 396 | |
398 | - if ( (extension_loaded('bitset')) ? |
|
399 | - bitset_in($this->_resVector, $docId) : |
|
400 | - isset($this->_resVector[$docId]) ) { |
|
397 | + if ((extension_loaded('bitset')) ? |
|
398 | + bitset_in($this->_resVector, $docId) : isset($this->_resVector[$docId])) { |
|
401 | 399 | if ($this->_slop == 0) { |
402 | 400 | $freq = $this->_exactPhraseFreq($docId); |
403 | 401 | } else { |
@@ -414,7 +412,7 @@ discard block |
||
414 | 412 | $weight = $this->_weight->getValue(); |
415 | 413 | $norm = $reader->norm($docId, reset($this->_terms)->field); |
416 | 414 | |
417 | - return $tf*$weight*$norm; |
|
415 | + return $tf * $weight * $norm; |
|
418 | 416 | } |
419 | 417 | } else { |
420 | 418 | return 0; |
@@ -407,8 +407,8 @@ discard block |
||
407 | 407 | /** |
408 | 408 | * Float to byte conversion |
409 | 409 | * |
410 | - * @param integer $b |
|
411 | - * @return float |
|
410 | + * @param double $f |
|
411 | + * @return integer |
|
412 | 412 | */ |
413 | 413 | static private function _floatToByte($f) |
414 | 414 | { |
@@ -494,7 +494,7 @@ discard block |
||
494 | 494 | * |
495 | 495 | * @param mixed $input |
496 | 496 | * @param Zend_Search_Lucene $reader |
497 | - * @return a score factor for the term |
|
497 | + * @return double score factor for the term |
|
498 | 498 | */ |
499 | 499 | public function idf($input, $reader) |
500 | 500 | { |
@@ -31,521 +31,521 @@ |
||
31 | 31 | */ |
32 | 32 | abstract class Zend_Search_Lucene_Search_Similarity |
33 | 33 | { |
34 | - /** |
|
35 | - * The Similarity implementation used by default. |
|
36 | - * |
|
37 | - * @var Zend_Search_Lucene_Search_Similarity |
|
38 | - */ |
|
39 | - static private $_defaultImpl; |
|
34 | + /** |
|
35 | + * The Similarity implementation used by default. |
|
36 | + * |
|
37 | + * @var Zend_Search_Lucene_Search_Similarity |
|
38 | + */ |
|
39 | + static private $_defaultImpl; |
|
40 | 40 | |
41 | - /** |
|
42 | - * Cache of decoded bytes. |
|
43 | - * Array of floats |
|
44 | - * |
|
45 | - * @var array |
|
46 | - */ |
|
47 | - static private $_normTable = array( 0 => 0.0, |
|
48 | - 1 => 5.820766E-10, |
|
49 | - 2 => 6.9849193E-10, |
|
50 | - 3 => 8.1490725E-10, |
|
51 | - 4 => 9.313226E-10, |
|
52 | - 5 => 1.1641532E-9, |
|
53 | - 6 => 1.3969839E-9, |
|
54 | - 7 => 1.6298145E-9, |
|
55 | - 8 => 1.8626451E-9, |
|
56 | - 9 => 2.3283064E-9, |
|
57 | - 10 => 2.7939677E-9, |
|
58 | - 11 => 3.259629E-9, |
|
59 | - 12 => 3.7252903E-9, |
|
60 | - 13 => 4.656613E-9, |
|
61 | - 14 => 5.5879354E-9, |
|
62 | - 15 => 6.519258E-9, |
|
63 | - 16 => 7.4505806E-9, |
|
64 | - 17 => 9.313226E-9, |
|
65 | - 18 => 1.1175871E-8, |
|
66 | - 19 => 1.3038516E-8, |
|
67 | - 20 => 1.4901161E-8, |
|
68 | - 21 => 1.8626451E-8, |
|
69 | - 22 => 2.2351742E-8, |
|
70 | - 23 => 2.6077032E-8, |
|
71 | - 24 => 2.9802322E-8, |
|
72 | - 25 => 3.7252903E-8, |
|
73 | - 26 => 4.4703484E-8, |
|
74 | - 27 => 5.2154064E-8, |
|
75 | - 28 => 5.9604645E-8, |
|
76 | - 29 => 7.4505806E-8, |
|
77 | - 30 => 8.940697E-8, |
|
78 | - 31 => 1.0430813E-7, |
|
79 | - 32 => 1.1920929E-7, |
|
80 | - 33 => 1.4901161E-7, |
|
81 | - 34 => 1.7881393E-7, |
|
82 | - 35 => 2.0861626E-7, |
|
83 | - 36 => 2.3841858E-7, |
|
84 | - 37 => 2.9802322E-7, |
|
85 | - 38 => 3.5762787E-7, |
|
86 | - 39 => 4.172325E-7, |
|
87 | - 40 => 4.7683716E-7, |
|
88 | - 41 => 5.9604645E-7, |
|
89 | - 42 => 7.1525574E-7, |
|
90 | - 43 => 8.34465E-7, |
|
91 | - 44 => 9.536743E-7, |
|
92 | - 45 => 1.1920929E-6, |
|
93 | - 46 => 1.4305115E-6, |
|
94 | - 47 => 1.66893E-6, |
|
95 | - 48 => 1.9073486E-6, |
|
96 | - 49 => 2.3841858E-6, |
|
97 | - 50 => 2.861023E-6, |
|
98 | - 51 => 3.33786E-6, |
|
99 | - 52 => 3.8146973E-6, |
|
100 | - 53 => 4.7683716E-6, |
|
101 | - 54 => 5.722046E-6, |
|
102 | - 55 => 6.67572E-6, |
|
103 | - 56 => 7.6293945E-6, |
|
104 | - 57 => 9.536743E-6, |
|
105 | - 58 => 1.1444092E-5, |
|
106 | - 59 => 1.335144E-5, |
|
107 | - 60 => 1.5258789E-5, |
|
108 | - 61 => 1.9073486E-5, |
|
109 | - 62 => 2.2888184E-5, |
|
110 | - 63 => 2.670288E-5, |
|
111 | - 64 => 3.0517578E-5, |
|
112 | - 65 => 3.8146973E-5, |
|
113 | - 66 => 4.5776367E-5, |
|
114 | - 67 => 5.340576E-5, |
|
115 | - 68 => 6.1035156E-5, |
|
116 | - 69 => 7.6293945E-5, |
|
117 | - 70 => 9.1552734E-5, |
|
118 | - 71 => 1.0681152E-4, |
|
119 | - 72 => 1.2207031E-4, |
|
120 | - 73 => 1.5258789E-4, |
|
121 | - 74 => 1.8310547E-4, |
|
122 | - 75 => 2.1362305E-4, |
|
123 | - 76 => 2.4414062E-4, |
|
124 | - 77 => 3.0517578E-4, |
|
125 | - 78 => 3.6621094E-4, |
|
126 | - 79 => 4.272461E-4, |
|
127 | - 80 => 4.8828125E-4, |
|
128 | - 81 => 6.1035156E-4, |
|
129 | - 82 => 7.324219E-4, |
|
130 | - 83 => 8.544922E-4, |
|
131 | - 84 => 9.765625E-4, |
|
132 | - 85 => 0.0012207031, |
|
133 | - 86 => 0.0014648438, |
|
134 | - 87 => 0.0017089844, |
|
135 | - 88 => 0.001953125, |
|
136 | - 89 => 0.0024414062, |
|
137 | - 90 => 0.0029296875, |
|
138 | - 91 => 0.0034179688, |
|
139 | - 92 => 0.00390625, |
|
140 | - 93 => 0.0048828125, |
|
141 | - 94 => 0.005859375, |
|
142 | - 95 => 0.0068359375, |
|
143 | - 96 => 0.0078125, |
|
144 | - 97 => 0.009765625, |
|
145 | - 98 => 0.01171875, |
|
146 | - 99 => 0.013671875, |
|
147 | - 100 => 0.015625, |
|
148 | - 101 => 0.01953125, |
|
149 | - 102 => 0.0234375, |
|
150 | - 103 => 0.02734375, |
|
151 | - 104 => 0.03125, |
|
152 | - 105 => 0.0390625, |
|
153 | - 106 => 0.046875, |
|
154 | - 107 => 0.0546875, |
|
155 | - 108 => 0.0625, |
|
156 | - 109 => 0.078125, |
|
157 | - 110 => 0.09375, |
|
158 | - 111 => 0.109375, |
|
159 | - 112 => 0.125, |
|
160 | - 113 => 0.15625, |
|
161 | - 114 => 0.1875, |
|
162 | - 115 => 0.21875, |
|
163 | - 116 => 0.25, |
|
164 | - 117 => 0.3125, |
|
165 | - 118 => 0.375, |
|
166 | - 119 => 0.4375, |
|
167 | - 120 => 0.5, |
|
168 | - 121 => 0.625, |
|
169 | - 122 => 0.75, |
|
170 | - 123 => 0.875, |
|
171 | - 124 => 1.0, |
|
172 | - 125 => 1.25, |
|
173 | - 126 => 1.5, |
|
174 | - 127 => 1.75, |
|
175 | - 128 => 2.0, |
|
176 | - 129 => 2.5, |
|
177 | - 130 => 3.0, |
|
178 | - 131 => 3.5, |
|
179 | - 132 => 4.0, |
|
180 | - 133 => 5.0, |
|
181 | - 134 => 6.0, |
|
182 | - 135 => 7.0, |
|
183 | - 136 => 8.0, |
|
184 | - 137 => 10.0, |
|
185 | - 138 => 12.0, |
|
186 | - 139 => 14.0, |
|
187 | - 140 => 16.0, |
|
188 | - 141 => 20.0, |
|
189 | - 142 => 24.0, |
|
190 | - 143 => 28.0, |
|
191 | - 144 => 32.0, |
|
192 | - 145 => 40.0, |
|
193 | - 146 => 48.0, |
|
194 | - 147 => 56.0, |
|
195 | - 148 => 64.0, |
|
196 | - 149 => 80.0, |
|
197 | - 150 => 96.0, |
|
198 | - 151 => 112.0, |
|
199 | - 152 => 128.0, |
|
200 | - 153 => 160.0, |
|
201 | - 154 => 192.0, |
|
202 | - 155 => 224.0, |
|
203 | - 156 => 256.0, |
|
204 | - 157 => 320.0, |
|
205 | - 158 => 384.0, |
|
206 | - 159 => 448.0, |
|
207 | - 160 => 512.0, |
|
208 | - 161 => 640.0, |
|
209 | - 162 => 768.0, |
|
210 | - 163 => 896.0, |
|
211 | - 164 => 1024.0, |
|
212 | - 165 => 1280.0, |
|
213 | - 166 => 1536.0, |
|
214 | - 167 => 1792.0, |
|
215 | - 168 => 2048.0, |
|
216 | - 169 => 2560.0, |
|
217 | - 170 => 3072.0, |
|
218 | - 171 => 3584.0, |
|
219 | - 172 => 4096.0, |
|
220 | - 173 => 5120.0, |
|
221 | - 174 => 6144.0, |
|
222 | - 175 => 7168.0, |
|
223 | - 176 => 8192.0, |
|
224 | - 177 => 10240.0, |
|
225 | - 178 => 12288.0, |
|
226 | - 179 => 14336.0, |
|
227 | - 180 => 16384.0, |
|
228 | - 181 => 20480.0, |
|
229 | - 182 => 24576.0, |
|
230 | - 183 => 28672.0, |
|
231 | - 184 => 32768.0, |
|
232 | - 185 => 40960.0, |
|
233 | - 186 => 49152.0, |
|
234 | - 187 => 57344.0, |
|
235 | - 188 => 65536.0, |
|
236 | - 189 => 81920.0, |
|
237 | - 190 => 98304.0, |
|
238 | - 191 => 114688.0, |
|
239 | - 192 => 131072.0, |
|
240 | - 193 => 163840.0, |
|
241 | - 194 => 196608.0, |
|
242 | - 195 => 229376.0, |
|
243 | - 196 => 262144.0, |
|
244 | - 197 => 327680.0, |
|
245 | - 198 => 393216.0, |
|
246 | - 199 => 458752.0, |
|
247 | - 200 => 524288.0, |
|
248 | - 201 => 655360.0, |
|
249 | - 202 => 786432.0, |
|
250 | - 203 => 917504.0, |
|
251 | - 204 => 1048576.0, |
|
252 | - 205 => 1310720.0, |
|
253 | - 206 => 1572864.0, |
|
254 | - 207 => 1835008.0, |
|
255 | - 208 => 2097152.0, |
|
256 | - 209 => 2621440.0, |
|
257 | - 210 => 3145728.0, |
|
258 | - 211 => 3670016.0, |
|
259 | - 212 => 4194304.0, |
|
260 | - 213 => 5242880.0, |
|
261 | - 214 => 6291456.0, |
|
262 | - 215 => 7340032.0, |
|
263 | - 216 => 8388608.0, |
|
264 | - 217 => 1.048576E7, |
|
265 | - 218 => 1.2582912E7, |
|
266 | - 219 => 1.4680064E7, |
|
267 | - 220 => 1.6777216E7, |
|
268 | - 221 => 2.097152E7, |
|
269 | - 222 => 2.5165824E7, |
|
270 | - 223 => 2.9360128E7, |
|
271 | - 224 => 3.3554432E7, |
|
272 | - 225 => 4.194304E7, |
|
273 | - 226 => 5.0331648E7, |
|
274 | - 227 => 5.8720256E7, |
|
275 | - 228 => 6.7108864E7, |
|
276 | - 229 => 8.388608E7, |
|
277 | - 230 => 1.00663296E8, |
|
278 | - 231 => 1.17440512E8, |
|
279 | - 232 => 1.34217728E8, |
|
280 | - 233 => 1.6777216E8, |
|
281 | - 234 => 2.01326592E8, |
|
282 | - 235 => 2.34881024E8, |
|
283 | - 236 => 2.68435456E8, |
|
284 | - 237 => 3.3554432E8, |
|
285 | - 238 => 4.02653184E8, |
|
286 | - 239 => 4.69762048E8, |
|
287 | - 240 => 5.3687091E8, |
|
288 | - 241 => 6.7108864E8, |
|
289 | - 242 => 8.0530637E8, |
|
290 | - 243 => 9.395241E8, |
|
291 | - 244 => 1.07374182E9, |
|
292 | - 245 => 1.34217728E9, |
|
293 | - 246 => 1.61061274E9, |
|
294 | - 247 => 1.87904819E9, |
|
295 | - 248 => 2.14748365E9, |
|
296 | - 249 => 2.68435456E9, |
|
297 | - 250 => 3.22122547E9, |
|
298 | - 251 => 3.75809638E9, |
|
299 | - 252 => 4.2949673E9, |
|
300 | - 253 => 5.3687091E9, |
|
301 | - 254 => 6.4424509E9, |
|
302 | - 255 => 7.5161928E9 ); |
|
41 | + /** |
|
42 | + * Cache of decoded bytes. |
|
43 | + * Array of floats |
|
44 | + * |
|
45 | + * @var array |
|
46 | + */ |
|
47 | + static private $_normTable = array( 0 => 0.0, |
|
48 | + 1 => 5.820766E-10, |
|
49 | + 2 => 6.9849193E-10, |
|
50 | + 3 => 8.1490725E-10, |
|
51 | + 4 => 9.313226E-10, |
|
52 | + 5 => 1.1641532E-9, |
|
53 | + 6 => 1.3969839E-9, |
|
54 | + 7 => 1.6298145E-9, |
|
55 | + 8 => 1.8626451E-9, |
|
56 | + 9 => 2.3283064E-9, |
|
57 | + 10 => 2.7939677E-9, |
|
58 | + 11 => 3.259629E-9, |
|
59 | + 12 => 3.7252903E-9, |
|
60 | + 13 => 4.656613E-9, |
|
61 | + 14 => 5.5879354E-9, |
|
62 | + 15 => 6.519258E-9, |
|
63 | + 16 => 7.4505806E-9, |
|
64 | + 17 => 9.313226E-9, |
|
65 | + 18 => 1.1175871E-8, |
|
66 | + 19 => 1.3038516E-8, |
|
67 | + 20 => 1.4901161E-8, |
|
68 | + 21 => 1.8626451E-8, |
|
69 | + 22 => 2.2351742E-8, |
|
70 | + 23 => 2.6077032E-8, |
|
71 | + 24 => 2.9802322E-8, |
|
72 | + 25 => 3.7252903E-8, |
|
73 | + 26 => 4.4703484E-8, |
|
74 | + 27 => 5.2154064E-8, |
|
75 | + 28 => 5.9604645E-8, |
|
76 | + 29 => 7.4505806E-8, |
|
77 | + 30 => 8.940697E-8, |
|
78 | + 31 => 1.0430813E-7, |
|
79 | + 32 => 1.1920929E-7, |
|
80 | + 33 => 1.4901161E-7, |
|
81 | + 34 => 1.7881393E-7, |
|
82 | + 35 => 2.0861626E-7, |
|
83 | + 36 => 2.3841858E-7, |
|
84 | + 37 => 2.9802322E-7, |
|
85 | + 38 => 3.5762787E-7, |
|
86 | + 39 => 4.172325E-7, |
|
87 | + 40 => 4.7683716E-7, |
|
88 | + 41 => 5.9604645E-7, |
|
89 | + 42 => 7.1525574E-7, |
|
90 | + 43 => 8.34465E-7, |
|
91 | + 44 => 9.536743E-7, |
|
92 | + 45 => 1.1920929E-6, |
|
93 | + 46 => 1.4305115E-6, |
|
94 | + 47 => 1.66893E-6, |
|
95 | + 48 => 1.9073486E-6, |
|
96 | + 49 => 2.3841858E-6, |
|
97 | + 50 => 2.861023E-6, |
|
98 | + 51 => 3.33786E-6, |
|
99 | + 52 => 3.8146973E-6, |
|
100 | + 53 => 4.7683716E-6, |
|
101 | + 54 => 5.722046E-6, |
|
102 | + 55 => 6.67572E-6, |
|
103 | + 56 => 7.6293945E-6, |
|
104 | + 57 => 9.536743E-6, |
|
105 | + 58 => 1.1444092E-5, |
|
106 | + 59 => 1.335144E-5, |
|
107 | + 60 => 1.5258789E-5, |
|
108 | + 61 => 1.9073486E-5, |
|
109 | + 62 => 2.2888184E-5, |
|
110 | + 63 => 2.670288E-5, |
|
111 | + 64 => 3.0517578E-5, |
|
112 | + 65 => 3.8146973E-5, |
|
113 | + 66 => 4.5776367E-5, |
|
114 | + 67 => 5.340576E-5, |
|
115 | + 68 => 6.1035156E-5, |
|
116 | + 69 => 7.6293945E-5, |
|
117 | + 70 => 9.1552734E-5, |
|
118 | + 71 => 1.0681152E-4, |
|
119 | + 72 => 1.2207031E-4, |
|
120 | + 73 => 1.5258789E-4, |
|
121 | + 74 => 1.8310547E-4, |
|
122 | + 75 => 2.1362305E-4, |
|
123 | + 76 => 2.4414062E-4, |
|
124 | + 77 => 3.0517578E-4, |
|
125 | + 78 => 3.6621094E-4, |
|
126 | + 79 => 4.272461E-4, |
|
127 | + 80 => 4.8828125E-4, |
|
128 | + 81 => 6.1035156E-4, |
|
129 | + 82 => 7.324219E-4, |
|
130 | + 83 => 8.544922E-4, |
|
131 | + 84 => 9.765625E-4, |
|
132 | + 85 => 0.0012207031, |
|
133 | + 86 => 0.0014648438, |
|
134 | + 87 => 0.0017089844, |
|
135 | + 88 => 0.001953125, |
|
136 | + 89 => 0.0024414062, |
|
137 | + 90 => 0.0029296875, |
|
138 | + 91 => 0.0034179688, |
|
139 | + 92 => 0.00390625, |
|
140 | + 93 => 0.0048828125, |
|
141 | + 94 => 0.005859375, |
|
142 | + 95 => 0.0068359375, |
|
143 | + 96 => 0.0078125, |
|
144 | + 97 => 0.009765625, |
|
145 | + 98 => 0.01171875, |
|
146 | + 99 => 0.013671875, |
|
147 | + 100 => 0.015625, |
|
148 | + 101 => 0.01953125, |
|
149 | + 102 => 0.0234375, |
|
150 | + 103 => 0.02734375, |
|
151 | + 104 => 0.03125, |
|
152 | + 105 => 0.0390625, |
|
153 | + 106 => 0.046875, |
|
154 | + 107 => 0.0546875, |
|
155 | + 108 => 0.0625, |
|
156 | + 109 => 0.078125, |
|
157 | + 110 => 0.09375, |
|
158 | + 111 => 0.109375, |
|
159 | + 112 => 0.125, |
|
160 | + 113 => 0.15625, |
|
161 | + 114 => 0.1875, |
|
162 | + 115 => 0.21875, |
|
163 | + 116 => 0.25, |
|
164 | + 117 => 0.3125, |
|
165 | + 118 => 0.375, |
|
166 | + 119 => 0.4375, |
|
167 | + 120 => 0.5, |
|
168 | + 121 => 0.625, |
|
169 | + 122 => 0.75, |
|
170 | + 123 => 0.875, |
|
171 | + 124 => 1.0, |
|
172 | + 125 => 1.25, |
|
173 | + 126 => 1.5, |
|
174 | + 127 => 1.75, |
|
175 | + 128 => 2.0, |
|
176 | + 129 => 2.5, |
|
177 | + 130 => 3.0, |
|
178 | + 131 => 3.5, |
|
179 | + 132 => 4.0, |
|
180 | + 133 => 5.0, |
|
181 | + 134 => 6.0, |
|
182 | + 135 => 7.0, |
|
183 | + 136 => 8.0, |
|
184 | + 137 => 10.0, |
|
185 | + 138 => 12.0, |
|
186 | + 139 => 14.0, |
|
187 | + 140 => 16.0, |
|
188 | + 141 => 20.0, |
|
189 | + 142 => 24.0, |
|
190 | + 143 => 28.0, |
|
191 | + 144 => 32.0, |
|
192 | + 145 => 40.0, |
|
193 | + 146 => 48.0, |
|
194 | + 147 => 56.0, |
|
195 | + 148 => 64.0, |
|
196 | + 149 => 80.0, |
|
197 | + 150 => 96.0, |
|
198 | + 151 => 112.0, |
|
199 | + 152 => 128.0, |
|
200 | + 153 => 160.0, |
|
201 | + 154 => 192.0, |
|
202 | + 155 => 224.0, |
|
203 | + 156 => 256.0, |
|
204 | + 157 => 320.0, |
|
205 | + 158 => 384.0, |
|
206 | + 159 => 448.0, |
|
207 | + 160 => 512.0, |
|
208 | + 161 => 640.0, |
|
209 | + 162 => 768.0, |
|
210 | + 163 => 896.0, |
|
211 | + 164 => 1024.0, |
|
212 | + 165 => 1280.0, |
|
213 | + 166 => 1536.0, |
|
214 | + 167 => 1792.0, |
|
215 | + 168 => 2048.0, |
|
216 | + 169 => 2560.0, |
|
217 | + 170 => 3072.0, |
|
218 | + 171 => 3584.0, |
|
219 | + 172 => 4096.0, |
|
220 | + 173 => 5120.0, |
|
221 | + 174 => 6144.0, |
|
222 | + 175 => 7168.0, |
|
223 | + 176 => 8192.0, |
|
224 | + 177 => 10240.0, |
|
225 | + 178 => 12288.0, |
|
226 | + 179 => 14336.0, |
|
227 | + 180 => 16384.0, |
|
228 | + 181 => 20480.0, |
|
229 | + 182 => 24576.0, |
|
230 | + 183 => 28672.0, |
|
231 | + 184 => 32768.0, |
|
232 | + 185 => 40960.0, |
|
233 | + 186 => 49152.0, |
|
234 | + 187 => 57344.0, |
|
235 | + 188 => 65536.0, |
|
236 | + 189 => 81920.0, |
|
237 | + 190 => 98304.0, |
|
238 | + 191 => 114688.0, |
|
239 | + 192 => 131072.0, |
|
240 | + 193 => 163840.0, |
|
241 | + 194 => 196608.0, |
|
242 | + 195 => 229376.0, |
|
243 | + 196 => 262144.0, |
|
244 | + 197 => 327680.0, |
|
245 | + 198 => 393216.0, |
|
246 | + 199 => 458752.0, |
|
247 | + 200 => 524288.0, |
|
248 | + 201 => 655360.0, |
|
249 | + 202 => 786432.0, |
|
250 | + 203 => 917504.0, |
|
251 | + 204 => 1048576.0, |
|
252 | + 205 => 1310720.0, |
|
253 | + 206 => 1572864.0, |
|
254 | + 207 => 1835008.0, |
|
255 | + 208 => 2097152.0, |
|
256 | + 209 => 2621440.0, |
|
257 | + 210 => 3145728.0, |
|
258 | + 211 => 3670016.0, |
|
259 | + 212 => 4194304.0, |
|
260 | + 213 => 5242880.0, |
|
261 | + 214 => 6291456.0, |
|
262 | + 215 => 7340032.0, |
|
263 | + 216 => 8388608.0, |
|
264 | + 217 => 1.048576E7, |
|
265 | + 218 => 1.2582912E7, |
|
266 | + 219 => 1.4680064E7, |
|
267 | + 220 => 1.6777216E7, |
|
268 | + 221 => 2.097152E7, |
|
269 | + 222 => 2.5165824E7, |
|
270 | + 223 => 2.9360128E7, |
|
271 | + 224 => 3.3554432E7, |
|
272 | + 225 => 4.194304E7, |
|
273 | + 226 => 5.0331648E7, |
|
274 | + 227 => 5.8720256E7, |
|
275 | + 228 => 6.7108864E7, |
|
276 | + 229 => 8.388608E7, |
|
277 | + 230 => 1.00663296E8, |
|
278 | + 231 => 1.17440512E8, |
|
279 | + 232 => 1.34217728E8, |
|
280 | + 233 => 1.6777216E8, |
|
281 | + 234 => 2.01326592E8, |
|
282 | + 235 => 2.34881024E8, |
|
283 | + 236 => 2.68435456E8, |
|
284 | + 237 => 3.3554432E8, |
|
285 | + 238 => 4.02653184E8, |
|
286 | + 239 => 4.69762048E8, |
|
287 | + 240 => 5.3687091E8, |
|
288 | + 241 => 6.7108864E8, |
|
289 | + 242 => 8.0530637E8, |
|
290 | + 243 => 9.395241E8, |
|
291 | + 244 => 1.07374182E9, |
|
292 | + 245 => 1.34217728E9, |
|
293 | + 246 => 1.61061274E9, |
|
294 | + 247 => 1.87904819E9, |
|
295 | + 248 => 2.14748365E9, |
|
296 | + 249 => 2.68435456E9, |
|
297 | + 250 => 3.22122547E9, |
|
298 | + 251 => 3.75809638E9, |
|
299 | + 252 => 4.2949673E9, |
|
300 | + 253 => 5.3687091E9, |
|
301 | + 254 => 6.4424509E9, |
|
302 | + 255 => 7.5161928E9 ); |
|
303 | 303 | |
304 | 304 | |
305 | - /** |
|
306 | - * Set the default Similarity implementation used by indexing and search |
|
307 | - * code. |
|
308 | - * |
|
309 | - * @param Zend_Search_Lucene_Search_Similarity $similarity |
|
310 | - */ |
|
311 | - static public function setDefault(Zend_Search_Lucene_Search_Similarity $similarity) |
|
312 | - { |
|
313 | - self::$_defaultImpl = $similarity; |
|
314 | - } |
|
305 | + /** |
|
306 | + * Set the default Similarity implementation used by indexing and search |
|
307 | + * code. |
|
308 | + * |
|
309 | + * @param Zend_Search_Lucene_Search_Similarity $similarity |
|
310 | + */ |
|
311 | + static public function setDefault(Zend_Search_Lucene_Search_Similarity $similarity) |
|
312 | + { |
|
313 | + self::$_defaultImpl = $similarity; |
|
314 | + } |
|
315 | 315 | |
316 | 316 | |
317 | - /** |
|
318 | - * Return the default Similarity implementation used by indexing and search |
|
319 | - * code. |
|
320 | - * |
|
321 | - * @return Zend_Search_Lucene_Search_Similarity |
|
322 | - */ |
|
323 | - static public function getDefault() |
|
324 | - { |
|
325 | - if (!self::$_defaultImpl instanceof Zend_Search_Lucene_Search_Similarity) { |
|
326 | - self::$_defaultImpl = new Zend_Search_Lucene_Search_Similarity_Default(); |
|
327 | - } |
|
317 | + /** |
|
318 | + * Return the default Similarity implementation used by indexing and search |
|
319 | + * code. |
|
320 | + * |
|
321 | + * @return Zend_Search_Lucene_Search_Similarity |
|
322 | + */ |
|
323 | + static public function getDefault() |
|
324 | + { |
|
325 | + if (!self::$_defaultImpl instanceof Zend_Search_Lucene_Search_Similarity) { |
|
326 | + self::$_defaultImpl = new Zend_Search_Lucene_Search_Similarity_Default(); |
|
327 | + } |
|
328 | 328 | |
329 | - return self::$_defaultImpl; |
|
330 | - } |
|
329 | + return self::$_defaultImpl; |
|
330 | + } |
|
331 | 331 | |
332 | 332 | |
333 | - /** |
|
334 | - * Computes the normalization value for a field given the total number of |
|
335 | - * terms contained in a field. These values, together with field boosts, are |
|
336 | - * stored in an index and multipled into scores for hits on each field by the |
|
337 | - * search code. |
|
338 | - * |
|
339 | - * Matches in longer fields are less precise, so implemenations of this |
|
340 | - * method usually return smaller values when 'numTokens' is large, |
|
341 | - * and larger values when 'numTokens' is small. |
|
342 | - * |
|
343 | - * That these values are computed under |
|
344 | - * IndexWriter::addDocument(Document) and stored then using |
|
345 | - * encodeNorm(float). Thus they have limited precision, and documents |
|
346 | - * must be re-indexed if this method is altered. |
|
347 | - * |
|
348 | - * fieldName - name of field |
|
349 | - * numTokens - the total number of tokens contained in fields named |
|
350 | - * 'fieldName' of 'doc'. |
|
351 | - * Returns a normalization factor for hits on this field of this document |
|
352 | - * |
|
353 | - * @param string $fieldName |
|
354 | - * @param integer $numTokens |
|
355 | - * @return float |
|
356 | - */ |
|
357 | - abstract public function lengthNorm($fieldName, $numTokens); |
|
333 | + /** |
|
334 | + * Computes the normalization value for a field given the total number of |
|
335 | + * terms contained in a field. These values, together with field boosts, are |
|
336 | + * stored in an index and multipled into scores for hits on each field by the |
|
337 | + * search code. |
|
338 | + * |
|
339 | + * Matches in longer fields are less precise, so implemenations of this |
|
340 | + * method usually return smaller values when 'numTokens' is large, |
|
341 | + * and larger values when 'numTokens' is small. |
|
342 | + * |
|
343 | + * That these values are computed under |
|
344 | + * IndexWriter::addDocument(Document) and stored then using |
|
345 | + * encodeNorm(float). Thus they have limited precision, and documents |
|
346 | + * must be re-indexed if this method is altered. |
|
347 | + * |
|
348 | + * fieldName - name of field |
|
349 | + * numTokens - the total number of tokens contained in fields named |
|
350 | + * 'fieldName' of 'doc'. |
|
351 | + * Returns a normalization factor for hits on this field of this document |
|
352 | + * |
|
353 | + * @param string $fieldName |
|
354 | + * @param integer $numTokens |
|
355 | + * @return float |
|
356 | + */ |
|
357 | + abstract public function lengthNorm($fieldName, $numTokens); |
|
358 | 358 | |
359 | - /** |
|
360 | - * Computes the normalization value for a query given the sum of the squared |
|
361 | - * weights of each of the query terms. This value is then multipled into the |
|
362 | - * weight of each query term. |
|
363 | - * |
|
364 | - * This does not affect ranking, but rather just attempts to make scores |
|
365 | - * from different queries comparable. |
|
366 | - * |
|
367 | - * sumOfSquaredWeights - the sum of the squares of query term weights |
|
368 | - * Returns a normalization factor for query weights |
|
369 | - * |
|
370 | - * @param float $sumOfSquaredWeights |
|
371 | - * @return float |
|
372 | - */ |
|
373 | - abstract public function queryNorm($sumOfSquaredWeights); |
|
359 | + /** |
|
360 | + * Computes the normalization value for a query given the sum of the squared |
|
361 | + * weights of each of the query terms. This value is then multipled into the |
|
362 | + * weight of each query term. |
|
363 | + * |
|
364 | + * This does not affect ranking, but rather just attempts to make scores |
|
365 | + * from different queries comparable. |
|
366 | + * |
|
367 | + * sumOfSquaredWeights - the sum of the squares of query term weights |
|
368 | + * Returns a normalization factor for query weights |
|
369 | + * |
|
370 | + * @param float $sumOfSquaredWeights |
|
371 | + * @return float |
|
372 | + */ |
|
373 | + abstract public function queryNorm($sumOfSquaredWeights); |
|
374 | 374 | |
375 | 375 | |
376 | - /** |
|
377 | - * Decodes a normalization factor stored in an index. |
|
378 | - * |
|
379 | - * @param integer $byte |
|
380 | - * @return float |
|
381 | - */ |
|
382 | - static public function decodeNorm($byte) |
|
383 | - { |
|
384 | - return self::$_normTable[$byte & 0xFF]; |
|
385 | - } |
|
376 | + /** |
|
377 | + * Decodes a normalization factor stored in an index. |
|
378 | + * |
|
379 | + * @param integer $byte |
|
380 | + * @return float |
|
381 | + */ |
|
382 | + static public function decodeNorm($byte) |
|
383 | + { |
|
384 | + return self::$_normTable[$byte & 0xFF]; |
|
385 | + } |
|
386 | 386 | |
387 | 387 | |
388 | - /** |
|
389 | - * Encodes a normalization factor for storage in an index. |
|
390 | - * |
|
391 | - * The encoding uses a five-bit exponent and three-bit mantissa, thus |
|
392 | - * representing values from around 7x10^9 to 2x10^-9 with about one |
|
393 | - * significant decimal digit of accuracy. Zero is also represented. |
|
394 | - * Negative numbers are rounded up to zero. Values too large to represent |
|
395 | - * are rounded down to the largest representable value. Positive values too |
|
396 | - * small to represent are rounded up to the smallest positive representable |
|
397 | - * value. |
|
398 | - * |
|
399 | - * @param float $f |
|
400 | - * @return integer |
|
401 | - */ |
|
402 | - static function encodeNorm($f) |
|
403 | - { |
|
404 | - return self::_floatToByte($f); |
|
405 | - } |
|
388 | + /** |
|
389 | + * Encodes a normalization factor for storage in an index. |
|
390 | + * |
|
391 | + * The encoding uses a five-bit exponent and three-bit mantissa, thus |
|
392 | + * representing values from around 7x10^9 to 2x10^-9 with about one |
|
393 | + * significant decimal digit of accuracy. Zero is also represented. |
|
394 | + * Negative numbers are rounded up to zero. Values too large to represent |
|
395 | + * are rounded down to the largest representable value. Positive values too |
|
396 | + * small to represent are rounded up to the smallest positive representable |
|
397 | + * value. |
|
398 | + * |
|
399 | + * @param float $f |
|
400 | + * @return integer |
|
401 | + */ |
|
402 | + static function encodeNorm($f) |
|
403 | + { |
|
404 | + return self::_floatToByte($f); |
|
405 | + } |
|
406 | 406 | |
407 | - /** |
|
408 | - * Float to byte conversion |
|
409 | - * |
|
410 | - * @param integer $b |
|
411 | - * @return float |
|
412 | - */ |
|
413 | - static private function _floatToByte($f) |
|
414 | - { |
|
415 | - // round negatives up to zero |
|
416 | - if ($f <= 0.0) { |
|
417 | - return 0; |
|
418 | - } |
|
407 | + /** |
|
408 | + * Float to byte conversion |
|
409 | + * |
|
410 | + * @param integer $b |
|
411 | + * @return float |
|
412 | + */ |
|
413 | + static private function _floatToByte($f) |
|
414 | + { |
|
415 | + // round negatives up to zero |
|
416 | + if ($f <= 0.0) { |
|
417 | + return 0; |
|
418 | + } |
|
419 | 419 | |
420 | - // search for appropriate value |
|
421 | - $lowIndex = 0; |
|
422 | - $highIndex = 255; |
|
423 | - while ($highIndex >= $lowIndex) { |
|
424 | - // $mid = ($highIndex - $lowIndex)/2; |
|
425 | - $mid = ($highIndex + $lowIndex) >> 1; |
|
426 | - $delta = $f - self::$_normTable[$mid]; |
|
420 | + // search for appropriate value |
|
421 | + $lowIndex = 0; |
|
422 | + $highIndex = 255; |
|
423 | + while ($highIndex >= $lowIndex) { |
|
424 | + // $mid = ($highIndex - $lowIndex)/2; |
|
425 | + $mid = ($highIndex + $lowIndex) >> 1; |
|
426 | + $delta = $f - self::$_normTable[$mid]; |
|
427 | 427 | |
428 | - if ($delta < 0) { |
|
429 | - $highIndex = $mid-1; |
|
430 | - } elseif ($delta > 0) { |
|
431 | - $lowIndex = $mid+1; |
|
432 | - } else { |
|
433 | - return $mid; // We got it! |
|
434 | - } |
|
435 | - } |
|
428 | + if ($delta < 0) { |
|
429 | + $highIndex = $mid-1; |
|
430 | + } elseif ($delta > 0) { |
|
431 | + $lowIndex = $mid+1; |
|
432 | + } else { |
|
433 | + return $mid; // We got it! |
|
434 | + } |
|
435 | + } |
|
436 | 436 | |
437 | - // round to closest value |
|
438 | - if ($highIndex != 255 && |
|
439 | - $f - self::$_normTable[$highIndex] > self::$_normTable[$highIndex+1] - $f ) { |
|
440 | - return $highIndex + 1; |
|
441 | - } else { |
|
442 | - return $highIndex; |
|
443 | - } |
|
444 | - } |
|
437 | + // round to closest value |
|
438 | + if ($highIndex != 255 && |
|
439 | + $f - self::$_normTable[$highIndex] > self::$_normTable[$highIndex+1] - $f ) { |
|
440 | + return $highIndex + 1; |
|
441 | + } else { |
|
442 | + return $highIndex; |
|
443 | + } |
|
444 | + } |
|
445 | 445 | |
446 | 446 | |
447 | - /** |
|
448 | - * Computes a score factor based on a term or phrase's frequency in a |
|
449 | - * document. This value is multiplied by the idf(Term, Searcher) |
|
450 | - * factor for each term in the query and these products are then summed to |
|
451 | - * form the initial score for a document. |
|
452 | - * |
|
453 | - * Terms and phrases repeated in a document indicate the topic of the |
|
454 | - * document, so implementations of this method usually return larger values |
|
455 | - * when 'freq' is large, and smaller values when 'freq' |
|
456 | - * is small. |
|
457 | - * |
|
458 | - * freq - the frequency of a term within a document |
|
459 | - * Returns a score factor based on a term's within-document frequency |
|
460 | - * |
|
461 | - * @param float $freq |
|
462 | - * @return float |
|
463 | - */ |
|
464 | - abstract public function tf($freq); |
|
447 | + /** |
|
448 | + * Computes a score factor based on a term or phrase's frequency in a |
|
449 | + * document. This value is multiplied by the idf(Term, Searcher) |
|
450 | + * factor for each term in the query and these products are then summed to |
|
451 | + * form the initial score for a document. |
|
452 | + * |
|
453 | + * Terms and phrases repeated in a document indicate the topic of the |
|
454 | + * document, so implementations of this method usually return larger values |
|
455 | + * when 'freq' is large, and smaller values when 'freq' |
|
456 | + * is small. |
|
457 | + * |
|
458 | + * freq - the frequency of a term within a document |
|
459 | + * Returns a score factor based on a term's within-document frequency |
|
460 | + * |
|
461 | + * @param float $freq |
|
462 | + * @return float |
|
463 | + */ |
|
464 | + abstract public function tf($freq); |
|
465 | 465 | |
466 | - /** |
|
467 | - * Computes the amount of a sloppy phrase match, based on an edit distance. |
|
468 | - * This value is summed for each sloppy phrase match in a document to form |
|
469 | - * the frequency that is passed to tf(float). |
|
470 | - * |
|
471 | - * A phrase match with a small edit distance to a document passage more |
|
472 | - * closely matches the document, so implementations of this method usually |
|
473 | - * return larger values when the edit distance is small and smaller values |
|
474 | - * when it is large. |
|
475 | - * |
|
476 | - * distance - the edit distance of this sloppy phrase match |
|
477 | - * Returns the frequency increment for this match |
|
478 | - * |
|
479 | - * @param integer $distance |
|
480 | - * @return float |
|
481 | - */ |
|
482 | - abstract public function sloppyFreq($distance); |
|
466 | + /** |
|
467 | + * Computes the amount of a sloppy phrase match, based on an edit distance. |
|
468 | + * This value is summed for each sloppy phrase match in a document to form |
|
469 | + * the frequency that is passed to tf(float). |
|
470 | + * |
|
471 | + * A phrase match with a small edit distance to a document passage more |
|
472 | + * closely matches the document, so implementations of this method usually |
|
473 | + * return larger values when the edit distance is small and smaller values |
|
474 | + * when it is large. |
|
475 | + * |
|
476 | + * distance - the edit distance of this sloppy phrase match |
|
477 | + * Returns the frequency increment for this match |
|
478 | + * |
|
479 | + * @param integer $distance |
|
480 | + * @return float |
|
481 | + */ |
|
482 | + abstract public function sloppyFreq($distance); |
|
483 | 483 | |
484 | 484 | |
485 | - /** |
|
486 | - * Computes a score factor for a simple term or a phrase. |
|
487 | - * |
|
488 | - * The default implementation is: |
|
489 | - * return idfFreq(searcher.docFreq(term), searcher.maxDoc()); |
|
490 | - * |
|
491 | - * input - the term in question or array of terms |
|
492 | - * reader - reader the document collection being searched |
|
493 | - * Returns a score factor for the term |
|
494 | - * |
|
495 | - * @param mixed $input |
|
496 | - * @param Zend_Search_Lucene $reader |
|
497 | - * @return a score factor for the term |
|
498 | - */ |
|
499 | - public function idf($input, $reader) |
|
500 | - { |
|
501 | - if (!is_array($input)) { |
|
502 | - return $this->idfFreq($reader->docFreq($input), $reader->count()); |
|
503 | - } else { |
|
504 | - $idf = 0.0; |
|
505 | - foreach ($input as $term) { |
|
506 | - $idf += $this->idfFreq($reader->docFreq($term), $reader->count()); |
|
507 | - } |
|
508 | - return $idf; |
|
509 | - } |
|
510 | - } |
|
485 | + /** |
|
486 | + * Computes a score factor for a simple term or a phrase. |
|
487 | + * |
|
488 | + * The default implementation is: |
|
489 | + * return idfFreq(searcher.docFreq(term), searcher.maxDoc()); |
|
490 | + * |
|
491 | + * input - the term in question or array of terms |
|
492 | + * reader - reader the document collection being searched |
|
493 | + * Returns a score factor for the term |
|
494 | + * |
|
495 | + * @param mixed $input |
|
496 | + * @param Zend_Search_Lucene $reader |
|
497 | + * @return a score factor for the term |
|
498 | + */ |
|
499 | + public function idf($input, $reader) |
|
500 | + { |
|
501 | + if (!is_array($input)) { |
|
502 | + return $this->idfFreq($reader->docFreq($input), $reader->count()); |
|
503 | + } else { |
|
504 | + $idf = 0.0; |
|
505 | + foreach ($input as $term) { |
|
506 | + $idf += $this->idfFreq($reader->docFreq($term), $reader->count()); |
|
507 | + } |
|
508 | + return $idf; |
|
509 | + } |
|
510 | + } |
|
511 | 511 | |
512 | - /** |
|
513 | - * Computes a score factor based on a term's document frequency (the number |
|
514 | - * of documents which contain the term). This value is multiplied by the |
|
515 | - * tf(int) factor for each term in the query and these products are |
|
516 | - * then summed to form the initial score for a document. |
|
517 | - * |
|
518 | - * Terms that occur in fewer documents are better indicators of topic, so |
|
519 | - * implemenations of this method usually return larger values for rare terms, |
|
520 | - * and smaller values for common terms. |
|
521 | - * |
|
522 | - * docFreq - the number of documents which contain the term |
|
523 | - * numDocs - the total number of documents in the collection |
|
524 | - * Returns a score factor based on the term's document frequency |
|
525 | - * |
|
526 | - * @param integer $docFreq |
|
527 | - * @param integer $numDocs |
|
528 | - * @return float |
|
529 | - */ |
|
530 | - abstract public function idfFreq($docFreq, $numDocs); |
|
512 | + /** |
|
513 | + * Computes a score factor based on a term's document frequency (the number |
|
514 | + * of documents which contain the term). This value is multiplied by the |
|
515 | + * tf(int) factor for each term in the query and these products are |
|
516 | + * then summed to form the initial score for a document. |
|
517 | + * |
|
518 | + * Terms that occur in fewer documents are better indicators of topic, so |
|
519 | + * implemenations of this method usually return larger values for rare terms, |
|
520 | + * and smaller values for common terms. |
|
521 | + * |
|
522 | + * docFreq - the number of documents which contain the term |
|
523 | + * numDocs - the total number of documents in the collection |
|
524 | + * Returns a score factor based on the term's document frequency |
|
525 | + * |
|
526 | + * @param integer $docFreq |
|
527 | + * @param integer $numDocs |
|
528 | + * @return float |
|
529 | + */ |
|
530 | + abstract public function idfFreq($docFreq, $numDocs); |
|
531 | 531 | |
532 | - /** |
|
533 | - * Computes a score factor based on the fraction of all query terms that a |
|
534 | - * document contains. This value is multiplied into scores. |
|
535 | - * |
|
536 | - * The presence of a large portion of the query terms indicates a better |
|
537 | - * match with the query, so implemenations of this method usually return |
|
538 | - * larger values when the ratio between these parameters is large and smaller |
|
539 | - * values when the ratio between them is small. |
|
540 | - * |
|
541 | - * overlap - the number of query terms matched in the document |
|
542 | - * maxOverlap - the total number of terms in the query |
|
543 | - * Returns a score factor based on term overlap with the query |
|
544 | - * |
|
545 | - * @param integer $overlap |
|
546 | - * @param integer $maxOverlap |
|
547 | - * @return float |
|
548 | - */ |
|
549 | - abstract public function coord($overlap, $maxOverlap); |
|
532 | + /** |
|
533 | + * Computes a score factor based on the fraction of all query terms that a |
|
534 | + * document contains. This value is multiplied into scores. |
|
535 | + * |
|
536 | + * The presence of a large portion of the query terms indicates a better |
|
537 | + * match with the query, so implemenations of this method usually return |
|
538 | + * larger values when the ratio between these parameters is large and smaller |
|
539 | + * values when the ratio between them is small. |
|
540 | + * |
|
541 | + * overlap - the number of query terms matched in the document |
|
542 | + * maxOverlap - the total number of terms in the query |
|
543 | + * Returns a score factor based on term overlap with the query |
|
544 | + * |
|
545 | + * @param integer $overlap |
|
546 | + * @param integer $maxOverlap |
|
547 | + * @return float |
|
548 | + */ |
|
549 | + abstract public function coord($overlap, $maxOverlap); |
|
550 | 550 | } |
551 | 551 |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | * |
45 | 45 | * @var array |
46 | 46 | */ |
47 | - static private $_normTable = array( 0 => 0.0, |
|
47 | + static private $_normTable = array(0 => 0.0, |
|
48 | 48 | 1 => 5.820766E-10, |
49 | 49 | 2 => 6.9849193E-10, |
50 | 50 | 3 => 8.1490725E-10, |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | 252 => 4.2949673E9, |
300 | 300 | 253 => 5.3687091E9, |
301 | 301 | 254 => 6.4424509E9, |
302 | - 255 => 7.5161928E9 ); |
|
302 | + 255 => 7.5161928E9); |
|
303 | 303 | |
304 | 304 | |
305 | 305 | /** |
@@ -426,9 +426,9 @@ discard block |
||
426 | 426 | $delta = $f - self::$_normTable[$mid]; |
427 | 427 | |
428 | 428 | if ($delta < 0) { |
429 | - $highIndex = $mid-1; |
|
429 | + $highIndex = $mid - 1; |
|
430 | 430 | } elseif ($delta > 0) { |
431 | - $lowIndex = $mid+1; |
|
431 | + $lowIndex = $mid + 1; |
|
432 | 432 | } else { |
433 | 433 | return $mid; // We got it! |
434 | 434 | } |
@@ -436,7 +436,7 @@ discard block |
||
436 | 436 | |
437 | 437 | // round to closest value |
438 | 438 | if ($highIndex != 255 && |
439 | - $f - self::$_normTable[$highIndex] > self::$_normTable[$highIndex+1] - $f ) { |
|
439 | + $f - self::$_normTable[$highIndex] > self::$_normTable[$highIndex + 1] - $f) { |
|
440 | 440 | return $highIndex + 1; |
441 | 441 | } else { |
442 | 442 | return $highIndex; |
@@ -241,7 +241,7 @@ |
||
241 | 241 | * Sets the modified time of $filename to now. |
242 | 242 | * |
243 | 243 | * @param string $filename |
244 | - * @return void |
|
244 | + * @return boolean |
|
245 | 245 | */ |
246 | 246 | public function touchFile($filename) |
247 | 247 | { |
@@ -36,234 +36,234 @@ |
||
36 | 36 | */ |
37 | 37 | class Zend_Search_Lucene_Storage_Directory_Filesystem extends Zend_Search_Lucene_Storage_Directory |
38 | 38 | { |
39 | - /** |
|
40 | - * Filesystem path to the directory |
|
41 | - * |
|
42 | - * @var string |
|
43 | - */ |
|
44 | - private $_dirPath = null; |
|
45 | - |
|
46 | - /** |
|
47 | - * Cache for Zend_Search_Lucene_Storage_File_Filesystem objects |
|
48 | - * Array: filename => Zend_Search_Lucene_Storage_File object |
|
49 | - * |
|
50 | - * @var array |
|
51 | - * @throws Zend_Search_Lucene_Exception |
|
52 | - */ |
|
53 | - private $_fileHandlers; |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * Utility function to recursive directory creation |
|
58 | - * |
|
59 | - * @param string $dir |
|
60 | - * @param integer $mode |
|
61 | - * @param boolean $recursive |
|
62 | - * @return boolean |
|
63 | - */ |
|
64 | - |
|
65 | - static public function mkdirs($dir, $mode = 0777, $recursive = true) |
|
66 | - { |
|
67 | - if (is_null($dir) || $dir === '') { |
|
68 | - return false; |
|
69 | - } |
|
70 | - if (is_dir($dir) || $dir === '/') { |
|
71 | - return true; |
|
72 | - } |
|
73 | - if (self::mkdirs(dirname($dir), $mode, $recursive)) { |
|
74 | - return mkdir($dir, $mode); |
|
75 | - } |
|
76 | - return false; |
|
77 | - } |
|
78 | - |
|
79 | - |
|
80 | - /** |
|
81 | - * Object constructor |
|
82 | - * Checks if $path is a directory or tries to create it. |
|
83 | - * |
|
84 | - * @param string $path |
|
85 | - * @throws Zend_Search_Lucene_Exception |
|
86 | - */ |
|
87 | - public function __construct($path) |
|
88 | - { |
|
89 | - if (!is_dir($path)) { |
|
90 | - if (file_exists($path)) { |
|
91 | - throw new Zend_Search_Lucene_Exception('Path exists, but it\'s not a directory'); |
|
92 | - } else { |
|
93 | - if (!self::mkdirs($path)) { |
|
94 | - throw new Zend_Search_Lucene_Exception("Can't create directory '$path'."); |
|
95 | - } |
|
96 | - } |
|
97 | - } |
|
98 | - $this->_dirPath = $path; |
|
99 | - $this->_fileHandlers = array(); |
|
100 | - } |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * Closes the store. |
|
105 | - * |
|
106 | - * @return void |
|
107 | - */ |
|
108 | - public function close() |
|
109 | - { |
|
110 | - foreach ($this->_fileHandlers as $fileObject) { |
|
111 | - $fileObject->close(); |
|
112 | - } |
|
113 | - |
|
114 | - unset($this->_fileHandlers); |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * Returns an array of strings, one for each file in the directory. |
|
120 | - * |
|
121 | - * @return array |
|
122 | - */ |
|
123 | - public function fileList() |
|
124 | - { |
|
125 | - $result = array(); |
|
126 | - |
|
127 | - $dirContent = opendir( $this->_dirPath ); |
|
128 | - while ($file = readdir($dirContent)) { |
|
129 | - if (($file == '..')||($file == '.')) continue; |
|
130 | - |
|
131 | - $fullName = $this->_dirPath . '/' . $file; |
|
132 | - |
|
133 | - if( !is_dir($this->_dirPath . '/' . $file) ) { |
|
134 | - $result[] = $file; |
|
135 | - } |
|
136 | - } |
|
137 | - |
|
138 | - return $result; |
|
139 | - } |
|
140 | - |
|
141 | - /** |
|
142 | - * Creates a new, empty file in the directory with the given $filename. |
|
143 | - * |
|
144 | - * @param string $filename |
|
145 | - * @return Zend_Search_Lucene_Storage_File |
|
146 | - */ |
|
147 | - public function createFile($filename) |
|
148 | - { |
|
149 | - if (isset($this->_fileHandlers[$filename])) { |
|
150 | - $this->_fileHandlers[$filename]->close(); |
|
151 | - } |
|
152 | - unset($this->_fileHandlers[$filename]); |
|
153 | - $this->_fileHandlers[$filename] = new Zend_Search_Lucene_Storage_File_Filesystem($this->_dirPath . '/' . $filename, 'w+b'); |
|
154 | - return $this->_fileHandlers[$filename]; |
|
155 | - } |
|
156 | - |
|
157 | - |
|
158 | - /** |
|
159 | - * Removes an existing $filename in the directory. |
|
160 | - * |
|
161 | - * @param string $filename |
|
162 | - * @return void |
|
163 | - */ |
|
164 | - public function deleteFile($filename) |
|
165 | - { |
|
166 | - if (isset($this->_fileHandlers[$filename])) { |
|
167 | - $this->_fileHandlers[$filename]->close(); |
|
168 | - } |
|
169 | - unset($this->_fileHandlers[$filename]); |
|
170 | - unlink($this->_dirPath .'/'. $filename); |
|
171 | - } |
|
172 | - |
|
173 | - |
|
174 | - /** |
|
175 | - * Returns true if a file with the given $filename exists. |
|
176 | - * |
|
177 | - * @param string $filename |
|
178 | - * @return boolean |
|
179 | - */ |
|
180 | - public function fileExists($filename) |
|
181 | - { |
|
182 | - return file_exists($this->_dirPath .'/'. $filename); |
|
183 | - } |
|
184 | - |
|
185 | - |
|
186 | - /** |
|
187 | - * Returns the length of a $filename in the directory. |
|
188 | - * |
|
189 | - * @param string $filename |
|
190 | - * @return integer |
|
191 | - */ |
|
192 | - public function fileLength($filename) |
|
193 | - { |
|
194 | - if (isset( $this->_fileHandlers[$filename] )) { |
|
195 | - return $this->_fileHandlers[$filename]->size(); |
|
196 | - } |
|
197 | - return filesize($this->_dirPath .'/'. $filename); |
|
198 | - } |
|
199 | - |
|
200 | - |
|
201 | - /** |
|
202 | - * Returns the UNIX timestamp $filename was last modified. |
|
203 | - * |
|
204 | - * @param string $filename |
|
205 | - * @return integer |
|
206 | - */ |
|
207 | - public function fileModified($filename) |
|
208 | - { |
|
209 | - return filemtime($this->_dirPath .'/'. $filename); |
|
210 | - } |
|
211 | - |
|
212 | - |
|
213 | - /** |
|
214 | - * Renames an existing file in the directory. |
|
215 | - * |
|
216 | - * @param string $from |
|
217 | - * @param string $to |
|
218 | - * @return void |
|
219 | - */ |
|
220 | - public function renameFile($from, $to) |
|
221 | - { |
|
222 | - if ($this->_fileHandlers[$from] !== null) { |
|
223 | - $this->_fileHandlers[$from]->close(); |
|
224 | - } |
|
225 | - unset($this->_fileHandlers[$from]); |
|
226 | - |
|
227 | - if ($this->_fileHandlers[$to] !== null) { |
|
228 | - $this->_fileHandlers[$to]->close(); |
|
229 | - } |
|
230 | - unset($this->_fileHandlers[$to]); |
|
231 | - |
|
232 | - if (file_exists($this->_dirPath . '/' . $to)) { |
|
233 | - unlink($this->_dirPath . '/' . $to); |
|
234 | - } |
|
235 | - |
|
236 | - return @rename($this->_dirPath . '/' . $from, $this->_dirPath . '/' . $to); |
|
237 | - } |
|
238 | - |
|
239 | - |
|
240 | - /** |
|
241 | - * Sets the modified time of $filename to now. |
|
242 | - * |
|
243 | - * @param string $filename |
|
244 | - * @return void |
|
245 | - */ |
|
246 | - public function touchFile($filename) |
|
247 | - { |
|
248 | - return touch($this->_dirPath .'/'. $filename); |
|
249 | - } |
|
250 | - |
|
251 | - |
|
252 | - /** |
|
253 | - * Returns a Zend_Search_Lucene_Storage_File object for a given $filename in the directory. |
|
254 | - * |
|
255 | - * @param string $filename |
|
256 | - * @return Zend_Search_Lucene_Storage_File |
|
257 | - */ |
|
258 | - public function getFileObject($filename) |
|
259 | - { |
|
260 | - if (isset( $this->_fileHandlers[$filename] )) { |
|
261 | - $this->_fileHandlers[$filename]->seek(0); |
|
262 | - return $this->_fileHandlers[$filename]; |
|
263 | - } |
|
264 | - |
|
265 | - $this->_fileHandlers[$filename] = new Zend_Search_Lucene_Storage_File_Filesystem($this->_dirPath . '/' . $filename, 'rb'); |
|
266 | - return $this->_fileHandlers[$filename]; |
|
267 | - } |
|
39 | + /** |
|
40 | + * Filesystem path to the directory |
|
41 | + * |
|
42 | + * @var string |
|
43 | + */ |
|
44 | + private $_dirPath = null; |
|
45 | + |
|
46 | + /** |
|
47 | + * Cache for Zend_Search_Lucene_Storage_File_Filesystem objects |
|
48 | + * Array: filename => Zend_Search_Lucene_Storage_File object |
|
49 | + * |
|
50 | + * @var array |
|
51 | + * @throws Zend_Search_Lucene_Exception |
|
52 | + */ |
|
53 | + private $_fileHandlers; |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * Utility function to recursive directory creation |
|
58 | + * |
|
59 | + * @param string $dir |
|
60 | + * @param integer $mode |
|
61 | + * @param boolean $recursive |
|
62 | + * @return boolean |
|
63 | + */ |
|
64 | + |
|
65 | + static public function mkdirs($dir, $mode = 0777, $recursive = true) |
|
66 | + { |
|
67 | + if (is_null($dir) || $dir === '') { |
|
68 | + return false; |
|
69 | + } |
|
70 | + if (is_dir($dir) || $dir === '/') { |
|
71 | + return true; |
|
72 | + } |
|
73 | + if (self::mkdirs(dirname($dir), $mode, $recursive)) { |
|
74 | + return mkdir($dir, $mode); |
|
75 | + } |
|
76 | + return false; |
|
77 | + } |
|
78 | + |
|
79 | + |
|
80 | + /** |
|
81 | + * Object constructor |
|
82 | + * Checks if $path is a directory or tries to create it. |
|
83 | + * |
|
84 | + * @param string $path |
|
85 | + * @throws Zend_Search_Lucene_Exception |
|
86 | + */ |
|
87 | + public function __construct($path) |
|
88 | + { |
|
89 | + if (!is_dir($path)) { |
|
90 | + if (file_exists($path)) { |
|
91 | + throw new Zend_Search_Lucene_Exception('Path exists, but it\'s not a directory'); |
|
92 | + } else { |
|
93 | + if (!self::mkdirs($path)) { |
|
94 | + throw new Zend_Search_Lucene_Exception("Can't create directory '$path'."); |
|
95 | + } |
|
96 | + } |
|
97 | + } |
|
98 | + $this->_dirPath = $path; |
|
99 | + $this->_fileHandlers = array(); |
|
100 | + } |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * Closes the store. |
|
105 | + * |
|
106 | + * @return void |
|
107 | + */ |
|
108 | + public function close() |
|
109 | + { |
|
110 | + foreach ($this->_fileHandlers as $fileObject) { |
|
111 | + $fileObject->close(); |
|
112 | + } |
|
113 | + |
|
114 | + unset($this->_fileHandlers); |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * Returns an array of strings, one for each file in the directory. |
|
120 | + * |
|
121 | + * @return array |
|
122 | + */ |
|
123 | + public function fileList() |
|
124 | + { |
|
125 | + $result = array(); |
|
126 | + |
|
127 | + $dirContent = opendir( $this->_dirPath ); |
|
128 | + while ($file = readdir($dirContent)) { |
|
129 | + if (($file == '..')||($file == '.')) continue; |
|
130 | + |
|
131 | + $fullName = $this->_dirPath . '/' . $file; |
|
132 | + |
|
133 | + if( !is_dir($this->_dirPath . '/' . $file) ) { |
|
134 | + $result[] = $file; |
|
135 | + } |
|
136 | + } |
|
137 | + |
|
138 | + return $result; |
|
139 | + } |
|
140 | + |
|
141 | + /** |
|
142 | + * Creates a new, empty file in the directory with the given $filename. |
|
143 | + * |
|
144 | + * @param string $filename |
|
145 | + * @return Zend_Search_Lucene_Storage_File |
|
146 | + */ |
|
147 | + public function createFile($filename) |
|
148 | + { |
|
149 | + if (isset($this->_fileHandlers[$filename])) { |
|
150 | + $this->_fileHandlers[$filename]->close(); |
|
151 | + } |
|
152 | + unset($this->_fileHandlers[$filename]); |
|
153 | + $this->_fileHandlers[$filename] = new Zend_Search_Lucene_Storage_File_Filesystem($this->_dirPath . '/' . $filename, 'w+b'); |
|
154 | + return $this->_fileHandlers[$filename]; |
|
155 | + } |
|
156 | + |
|
157 | + |
|
158 | + /** |
|
159 | + * Removes an existing $filename in the directory. |
|
160 | + * |
|
161 | + * @param string $filename |
|
162 | + * @return void |
|
163 | + */ |
|
164 | + public function deleteFile($filename) |
|
165 | + { |
|
166 | + if (isset($this->_fileHandlers[$filename])) { |
|
167 | + $this->_fileHandlers[$filename]->close(); |
|
168 | + } |
|
169 | + unset($this->_fileHandlers[$filename]); |
|
170 | + unlink($this->_dirPath .'/'. $filename); |
|
171 | + } |
|
172 | + |
|
173 | + |
|
174 | + /** |
|
175 | + * Returns true if a file with the given $filename exists. |
|
176 | + * |
|
177 | + * @param string $filename |
|
178 | + * @return boolean |
|
179 | + */ |
|
180 | + public function fileExists($filename) |
|
181 | + { |
|
182 | + return file_exists($this->_dirPath .'/'. $filename); |
|
183 | + } |
|
184 | + |
|
185 | + |
|
186 | + /** |
|
187 | + * Returns the length of a $filename in the directory. |
|
188 | + * |
|
189 | + * @param string $filename |
|
190 | + * @return integer |
|
191 | + */ |
|
192 | + public function fileLength($filename) |
|
193 | + { |
|
194 | + if (isset( $this->_fileHandlers[$filename] )) { |
|
195 | + return $this->_fileHandlers[$filename]->size(); |
|
196 | + } |
|
197 | + return filesize($this->_dirPath .'/'. $filename); |
|
198 | + } |
|
199 | + |
|
200 | + |
|
201 | + /** |
|
202 | + * Returns the UNIX timestamp $filename was last modified. |
|
203 | + * |
|
204 | + * @param string $filename |
|
205 | + * @return integer |
|
206 | + */ |
|
207 | + public function fileModified($filename) |
|
208 | + { |
|
209 | + return filemtime($this->_dirPath .'/'. $filename); |
|
210 | + } |
|
211 | + |
|
212 | + |
|
213 | + /** |
|
214 | + * Renames an existing file in the directory. |
|
215 | + * |
|
216 | + * @param string $from |
|
217 | + * @param string $to |
|
218 | + * @return void |
|
219 | + */ |
|
220 | + public function renameFile($from, $to) |
|
221 | + { |
|
222 | + if ($this->_fileHandlers[$from] !== null) { |
|
223 | + $this->_fileHandlers[$from]->close(); |
|
224 | + } |
|
225 | + unset($this->_fileHandlers[$from]); |
|
226 | + |
|
227 | + if ($this->_fileHandlers[$to] !== null) { |
|
228 | + $this->_fileHandlers[$to]->close(); |
|
229 | + } |
|
230 | + unset($this->_fileHandlers[$to]); |
|
231 | + |
|
232 | + if (file_exists($this->_dirPath . '/' . $to)) { |
|
233 | + unlink($this->_dirPath . '/' . $to); |
|
234 | + } |
|
235 | + |
|
236 | + return @rename($this->_dirPath . '/' . $from, $this->_dirPath . '/' . $to); |
|
237 | + } |
|
238 | + |
|
239 | + |
|
240 | + /** |
|
241 | + * Sets the modified time of $filename to now. |
|
242 | + * |
|
243 | + * @param string $filename |
|
244 | + * @return void |
|
245 | + */ |
|
246 | + public function touchFile($filename) |
|
247 | + { |
|
248 | + return touch($this->_dirPath .'/'. $filename); |
|
249 | + } |
|
250 | + |
|
251 | + |
|
252 | + /** |
|
253 | + * Returns a Zend_Search_Lucene_Storage_File object for a given $filename in the directory. |
|
254 | + * |
|
255 | + * @param string $filename |
|
256 | + * @return Zend_Search_Lucene_Storage_File |
|
257 | + */ |
|
258 | + public function getFileObject($filename) |
|
259 | + { |
|
260 | + if (isset( $this->_fileHandlers[$filename] )) { |
|
261 | + $this->_fileHandlers[$filename]->seek(0); |
|
262 | + return $this->_fileHandlers[$filename]; |
|
263 | + } |
|
264 | + |
|
265 | + $this->_fileHandlers[$filename] = new Zend_Search_Lucene_Storage_File_Filesystem($this->_dirPath . '/' . $filename, 'rb'); |
|
266 | + return $this->_fileHandlers[$filename]; |
|
267 | + } |
|
268 | 268 | } |
269 | 269 |
@@ -124,13 +124,13 @@ discard block |
||
124 | 124 | { |
125 | 125 | $result = array(); |
126 | 126 | |
127 | - $dirContent = opendir( $this->_dirPath ); |
|
127 | + $dirContent = opendir($this->_dirPath); |
|
128 | 128 | while ($file = readdir($dirContent)) { |
129 | - if (($file == '..')||($file == '.')) continue; |
|
129 | + if (($file == '..') || ($file == '.')) continue; |
|
130 | 130 | |
131 | 131 | $fullName = $this->_dirPath . '/' . $file; |
132 | 132 | |
133 | - if( !is_dir($this->_dirPath . '/' . $file) ) { |
|
133 | + if (!is_dir($this->_dirPath . '/' . $file)) { |
|
134 | 134 | $result[] = $file; |
135 | 135 | } |
136 | 136 | } |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | $this->_fileHandlers[$filename]->close(); |
168 | 168 | } |
169 | 169 | unset($this->_fileHandlers[$filename]); |
170 | - unlink($this->_dirPath .'/'. $filename); |
|
170 | + unlink($this->_dirPath . '/' . $filename); |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | */ |
180 | 180 | public function fileExists($filename) |
181 | 181 | { |
182 | - return file_exists($this->_dirPath .'/'. $filename); |
|
182 | + return file_exists($this->_dirPath . '/' . $filename); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | |
@@ -191,10 +191,10 @@ discard block |
||
191 | 191 | */ |
192 | 192 | public function fileLength($filename) |
193 | 193 | { |
194 | - if (isset( $this->_fileHandlers[$filename] )) { |
|
194 | + if (isset($this->_fileHandlers[$filename])) { |
|
195 | 195 | return $this->_fileHandlers[$filename]->size(); |
196 | 196 | } |
197 | - return filesize($this->_dirPath .'/'. $filename); |
|
197 | + return filesize($this->_dirPath . '/' . $filename); |
|
198 | 198 | } |
199 | 199 | |
200 | 200 | |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | */ |
207 | 207 | public function fileModified($filename) |
208 | 208 | { |
209 | - return filemtime($this->_dirPath .'/'. $filename); |
|
209 | + return filemtime($this->_dirPath . '/' . $filename); |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | */ |
246 | 246 | public function touchFile($filename) |
247 | 247 | { |
248 | - return touch($this->_dirPath .'/'. $filename); |
|
248 | + return touch($this->_dirPath . '/' . $filename); |
|
249 | 249 | } |
250 | 250 | |
251 | 251 | |
@@ -257,7 +257,7 @@ discard block |
||
257 | 257 | */ |
258 | 258 | public function getFileObject($filename) |
259 | 259 | { |
260 | - if (isset( $this->_fileHandlers[$filename] )) { |
|
260 | + if (isset($this->_fileHandlers[$filename])) { |
|
261 | 261 | $this->_fileHandlers[$filename]->seek(0); |
262 | 262 | return $this->_fileHandlers[$filename]; |
263 | 263 | } |
@@ -42,6 +42,9 @@ |
||
42 | 42 | return $prefix.implode(' ', $subtext).$suffix; |
43 | 43 | } |
44 | 44 | |
45 | + /** |
|
46 | + * @param string $word |
|
47 | + */ |
|
45 | 48 | protected function containsKeys($word, $keys) |
46 | 49 | { |
47 | 50 | foreach($keys as $key) |
@@ -7,10 +7,10 @@ discard block |
||
7 | 7 | { |
8 | 8 | public function onLoad($param) |
9 | 9 | { |
10 | - if(!$this->IsPostBack && strlen($text = $this->search->getText()) > 0) |
|
10 | + if (!$this->IsPostBack && strlen($text = $this->search->getText()) > 0) |
|
11 | 11 | { |
12 | 12 | $quickstart = $this->getApplication()->getModule("quickstart_search"); |
13 | - $hits_1 = $quickstart->find($text); |
|
13 | + $hits_1 = $quickstart->find($text); |
|
14 | 14 | $this->quickstart_results->setDataSource($hits_1); |
15 | 15 | $this->quickstart_results->dataBind(); |
16 | 16 | |
@@ -21,32 +21,32 @@ discard block |
||
21 | 21 | public function highlightSearch($text) |
22 | 22 | { |
23 | 23 | $words = str_word_count($text, 1); |
24 | - $keys = str_word_count(strtolower($this->search->getText()),1); |
|
24 | + $keys = str_word_count(strtolower($this->search->getText()), 1); |
|
25 | 25 | $where = 0; |
26 | 26 | $t = count($words); |
27 | - for($i = 0; $i<$t; $i++) |
|
27 | + for ($i = 0; $i < $t; $i++) |
|
28 | 28 | { |
29 | - if($this->containsKeys(strtolower($words[$i]), $keys)) |
|
29 | + if ($this->containsKeys(strtolower($words[$i]), $keys)) |
|
30 | 30 | { |
31 | - $words[$i] = '<span class="searchterm">'.$words[$i].'</span>'; |
|
31 | + $words[$i] = '<span class="searchterm">' . $words[$i] . '</span>'; |
|
32 | 32 | $where = $i; |
33 | 33 | break; |
34 | 34 | } |
35 | 35 | } |
36 | 36 | |
37 | - $min = $where - 15 < 0 ? 0 : $where - 15; |
|
38 | - $max = $where + 15 > $t ? $t : $where + 15; |
|
39 | - $subtext = array_splice($words, $min, $max-$min); |
|
37 | + $min = $where - 15 < 0 ? 0 : $where - 15; |
|
38 | + $max = $where + 15 > $t ? $t : $where + 15; |
|
39 | + $subtext = array_splice($words, $min, $max - $min); |
|
40 | 40 | $prefix = $min == 0 ? '' : '...'; |
41 | 41 | $suffix = $max == $t ? '' : '...'; |
42 | - return $prefix.implode(' ', $subtext).$suffix; |
|
42 | + return $prefix . implode(' ', $subtext) . $suffix; |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | protected function containsKeys($word, $keys) |
46 | 46 | { |
47 | - foreach($keys as $key) |
|
47 | + foreach ($keys as $key) |
|
48 | 48 | { |
49 | - if(is_int(strpos($word, $key))) |
|
49 | + if (is_int(strpos($word, $key))) |
|
50 | 50 | return true; |
51 | 51 | } |
52 | 52 | return false; |
@@ -69,11 +69,17 @@ discard block |
||
69 | 69 | return $list; |
70 | 70 | } |
71 | 71 | |
72 | + /** |
|
73 | + * @param string $extension |
|
74 | + */ |
|
72 | 75 | protected function isFileTypeAllowed($extension) |
73 | 76 | { |
74 | 77 | return in_array($extension,array('tpl','page','php','html')); |
75 | 78 | } |
76 | 79 | |
80 | + /** |
|
81 | + * @param string $fileName |
|
82 | + */ |
|
77 | 83 | protected function getFileExtension($fileName) |
78 | 84 | { |
79 | 85 | if(($pos=strrpos($fileName,'.'))===false) |
@@ -82,6 +88,9 @@ discard block |
||
82 | 88 | return substr($fileName,$pos+1); |
83 | 89 | } |
84 | 90 | |
91 | + /** |
|
92 | + * @param string $extension |
|
93 | + */ |
|
85 | 94 | protected function getFileType($extension) |
86 | 95 | { |
87 | 96 | if($extension==='tpl' || $extension==='page') |
@@ -90,6 +99,9 @@ discard block |
||
90 | 99 | return 'Class file'; |
91 | 100 | } |
92 | 101 | |
102 | + /** |
|
103 | + * @param string $extension |
|
104 | + */ |
|
93 | 105 | protected function getFileLanguage($extension) |
94 | 106 | { |
95 | 107 | switch($extension) |
@@ -2,34 +2,34 @@ discard block |
||
2 | 2 | |
3 | 3 | class ViewSource extends TPage |
4 | 4 | { |
5 | - private $_path=null; |
|
6 | - private $_fullPath=null; |
|
7 | - private $_fileType=null; |
|
5 | + private $_path = null; |
|
6 | + private $_fullPath = null; |
|
7 | + private $_fileType = null; |
|
8 | 8 | |
9 | 9 | public function onLoad($param) |
10 | 10 | { |
11 | 11 | parent::onLoad($param); |
12 | - $path=$this->Request['path']; |
|
13 | - $fullPath=realpath($this->Service->BasePath.'/'.$path); |
|
14 | - $fileExt=$this->getFileExtension($fullPath); |
|
15 | - if($fullPath!==false && is_file($fullPath) && strpos($fullPath,$this->Service->BasePath)!==false) |
|
12 | + $path = $this->Request['path']; |
|
13 | + $fullPath = realpath($this->Service->BasePath . '/' . $path); |
|
14 | + $fileExt = $this->getFileExtension($fullPath); |
|
15 | + if ($fullPath !== false && is_file($fullPath) && strpos($fullPath, $this->Service->BasePath) !== false) |
|
16 | 16 | { |
17 | - if($this->isFileTypeAllowed($fileExt)) |
|
17 | + if ($this->isFileTypeAllowed($fileExt)) |
|
18 | 18 | { |
19 | - $this->_fullPath=strtr($fullPath,'\\','/'); |
|
20 | - $this->_path=strtr(substr($fullPath,strlen($this->Service->BasePath)),'\\','/'); |
|
19 | + $this->_fullPath = strtr($fullPath, '\\', '/'); |
|
20 | + $this->_path = strtr(substr($fullPath, strlen($this->Service->BasePath)), '\\', '/'); |
|
21 | 21 | } |
22 | 22 | } |
23 | - if($this->_fullPath===null) |
|
24 | - throw new THttpException(500,'File Not Found: %s',$path); |
|
23 | + if ($this->_fullPath === null) |
|
24 | + throw new THttpException(500, 'File Not Found: %s', $path); |
|
25 | 25 | |
26 | - $this->SourceList->DataSource=$this->SourceFiles; |
|
26 | + $this->SourceList->DataSource = $this->SourceFiles; |
|
27 | 27 | $this->SourceList->dataBind(); |
28 | 28 | |
29 | - $this->Highlighter->Language=$this->getFileLanguage($fileExt); |
|
30 | - if($this->Request['lines']==='false') |
|
31 | - $this->Highlighter->ShowLineNumbers=false; |
|
32 | - $this->SourceView->Text=file_get_contents($this->_fullPath); |
|
29 | + $this->Highlighter->Language = $this->getFileLanguage($fileExt); |
|
30 | + if ($this->Request['lines'] === 'false') |
|
31 | + $this->Highlighter->ShowLineNumbers = false; |
|
32 | + $this->SourceView->Text = file_get_contents($this->_fullPath); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | public function getFilePath() |
@@ -39,23 +39,23 @@ discard block |
||
39 | 39 | |
40 | 40 | protected function getSourceFiles() |
41 | 41 | { |
42 | - $list=array(); |
|
43 | - $basePath=dirname($this->_fullPath); |
|
44 | - if($dh=opendir($basePath)) |
|
42 | + $list = array(); |
|
43 | + $basePath = dirname($this->_fullPath); |
|
44 | + if ($dh = opendir($basePath)) |
|
45 | 45 | { |
46 | - while(($file=readdir($dh))!==false) |
|
46 | + while (($file = readdir($dh)) !== false) |
|
47 | 47 | { |
48 | - if(is_file($basePath.'/'.$file)) |
|
48 | + if (is_file($basePath . '/' . $file)) |
|
49 | 49 | { |
50 | - $extension=$this->getFileExtension($basePath.'/'.$file); |
|
51 | - if($this->isFileTypeAllowed($extension)) |
|
50 | + $extension = $this->getFileExtension($basePath . '/' . $file); |
|
51 | + if ($this->isFileTypeAllowed($extension)) |
|
52 | 52 | { |
53 | - $fileType=$this->getFileType($extension); |
|
54 | - $list[]=array( |
|
53 | + $fileType = $this->getFileType($extension); |
|
54 | + $list[] = array( |
|
55 | 55 | 'name'=>$file, |
56 | 56 | 'type'=>$fileType, |
57 | - 'active'=>basename($this->_fullPath)===$file, |
|
58 | - 'url'=>'?page=ViewSource&path=/'.ltrim(strtr(dirname($this->_path),'\\','/').'/'.$file,'/') |
|
57 | + 'active'=>basename($this->_fullPath) === $file, |
|
58 | + 'url'=>'?page=ViewSource&path=/' . ltrim(strtr(dirname($this->_path), '\\', '/') . '/' . $file, '/') |
|
59 | 59 | ); |
60 | 60 | } |
61 | 61 | } |
@@ -63,28 +63,28 @@ discard block |
||
63 | 63 | } |
64 | 64 | closedir($dh); |
65 | 65 | } |
66 | - foreach($list as $item) |
|
67 | - $aux[]=$item['name']; |
|
66 | + foreach ($list as $item) |
|
67 | + $aux[] = $item['name']; |
|
68 | 68 | array_multisort($aux, SORT_ASC, $list); |
69 | 69 | return $list; |
70 | 70 | } |
71 | 71 | |
72 | 72 | protected function isFileTypeAllowed($extension) |
73 | 73 | { |
74 | - return in_array($extension,array('tpl','page','php','html')); |
|
74 | + return in_array($extension, array('tpl', 'page', 'php', 'html')); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | protected function getFileExtension($fileName) |
78 | 78 | { |
79 | - if(($pos=strrpos($fileName,'.'))===false) |
|
79 | + if (($pos = strrpos($fileName, '.')) === false) |
|
80 | 80 | return ''; |
81 | 81 | else |
82 | - return substr($fileName,$pos+1); |
|
82 | + return substr($fileName, $pos + 1); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | protected function getFileType($extension) |
86 | 86 | { |
87 | - if($extension==='tpl' || $extension==='page') |
|
87 | + if ($extension === 'tpl' || $extension === 'page') |
|
88 | 88 | return 'Template file'; |
89 | 89 | else |
90 | 90 | return 'Class file'; |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | |
93 | 93 | protected function getFileLanguage($extension) |
94 | 94 | { |
95 | - switch($extension) |
|
95 | + switch ($extension) |
|
96 | 96 | { |
97 | 97 | case 'page' : |
98 | 98 | case 'tpl' : |
@@ -63,8 +63,9 @@ |
||
63 | 63 | } |
64 | 64 | closedir($dh); |
65 | 65 | } |
66 | - foreach($list as $item) |
|
67 | - $aux[]=$item['name']; |
|
66 | + foreach($list as $item) { |
|
67 | + $aux[]=$item['name']; |
|
68 | + } |
|
68 | 69 | array_multisort($aux, SORT_ASC, $list); |
69 | 70 | return $list; |
70 | 71 | } |