~chroot64bit/zivios/gentoo-experimental

« back to all changes in this revision

Viewing changes to application/library/Zend/Search/Lucene/Proxy.php

  • Committer: Mustafa A. Hashmi
  • Date: 2008-12-04 13:32:21 UTC
  • Revision ID: mhashmi@zivios.org-20081204133221-0nd1trunwevijj38
Inclusion of new installation framework with ties to zend layout and dojo layout

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * Zend Framework
 
4
 *
 
5
 * LICENSE
 
6
 *
 
7
 * This source file is subject to the new BSD license that is bundled
 
8
 * with this package in the file LICENSE.txt.
 
9
 * It is also available through the world-wide-web at this URL:
 
10
 * http://framework.zend.com/license/new-bsd
 
11
 * If you did not receive a copy of the license and are unable to
 
12
 * obtain it through the world-wide-web, please send an email
 
13
 * to license@zend.com so we can send you a copy immediately.
 
14
 *
 
15
 * @category   Zend
 
16
 * @package    Zend_Search_Lucene
 
17
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 
18
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 
19
 */
 
20
 
 
21
/** Zend_Search_Lucene_Interface */
 
22
require_once 'Zend/Search/Lucene/Interface.php';
 
23
 
 
24
 
 
25
/**
 
26
 * Proxy class intended to be used in userland.
 
27
 *
 
28
 * It tracks, when index object goes out of scope and forces ndex closing
 
29
 *
 
30
 * @category   Zend
 
31
 * @package    Zend_Search_Lucene
 
32
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 
33
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 
34
 */
 
35
class Zend_Search_Lucene_Proxy implements Zend_Search_Lucene_Interface
 
36
{
 
37
    /**
 
38
     * Index object
 
39
     *
 
40
     * @var Zend_Search_Lucene_Interface
 
41
     */
 
42
    private $_index;
 
43
 
 
44
    /**
 
45
     * Object constructor
 
46
     *
 
47
     * @param Zend_Search_Lucene_Interface $index
 
48
     */
 
49
    public function __construct(Zend_Search_Lucene_Interface $index)
 
50
    {
 
51
        $this->_index = $index;
 
52
        $this->_index->addReference();
 
53
    }
 
54
 
 
55
    /**
 
56
     * Object destructor
 
57
     */
 
58
    public function __destruct()
 
59
    {
 
60
        if ($this->_index !== null) {
 
61
            // This code is invoked if Zend_Search_Lucene_Interface object constructor throws an exception
 
62
            $this->_index->removeReference();
 
63
        }
 
64
        $this->_index = null;
 
65
    }
 
66
 
 
67
    /**
 
68
     * Get current generation number
 
69
     *
 
70
     * Returns generation number
 
71
     * 0 means pre-2.1 index format
 
72
     * -1 means there are no segments files.
 
73
     *
 
74
     * @param Zend_Search_Lucene_Storage_Directory $directory
 
75
     * @return integer
 
76
     * @throws Zend_Search_Lucene_Exception
 
77
     */
 
78
    public static function getActualGeneration(Zend_Search_Lucene_Storage_Directory $directory)
 
79
    {
 
80
        Zend_Search_Lucene::getActualGeneration($directory);
 
81
    }
 
82
 
 
83
    /**
 
84
     * Get segments file name
 
85
     *
 
86
     * @param integer $generation
 
87
     * @return string
 
88
     */
 
89
    public static function getSegmentFileName($generation)
 
90
    {
 
91
        Zend_Search_Lucene::getSegmentFileName($generation);
 
92
    }
 
93
 
 
94
    /**
 
95
     * Get index format version
 
96
     *
 
97
     * @return integer
 
98
     */
 
99
    public function getFormatVersion()
 
100
    {
 
101
        return $this->_index->getFormatVersion();
 
102
    }
 
103
 
 
104
    /**
 
105
     * Set index format version.
 
106
     * Index is converted to this format at the nearest upfdate time
 
107
     *
 
108
     * @param int $formatVersion
 
109
     * @throws Zend_Search_Lucene_Exception
 
110
     */
 
111
    public function setFormatVersion($formatVersion)
 
112
    {
 
113
        $this->_index->setFormatVersion($formatVersion);
 
114
    }
 
115
 
 
116
    /**
 
117
     * Returns the Zend_Search_Lucene_Storage_Directory instance for this index.
 
118
     *
 
119
     * @return Zend_Search_Lucene_Storage_Directory
 
120
     */
 
121
    public function getDirectory()
 
122
    {
 
123
        return $this->_index->getDirectory();
 
124
    }
 
125
 
 
126
    /**
 
127
     * Returns the total number of documents in this index (including deleted documents).
 
128
     *
 
129
     * @return integer
 
130
     */
 
131
    public function count()
 
132
    {
 
133
        return $this->_index->count();
 
134
    }
 
135
 
 
136
    /**
 
137
     * Returns one greater than the largest possible document number.
 
138
     * This may be used to, e.g., determine how big to allocate a structure which will have
 
139
     * an element for every document number in an index.
 
140
     *
 
141
     * @return integer
 
142
     */
 
143
    public function maxDoc()
 
144
    {
 
145
        return $this->_index->maxDoc();
 
146
    }
 
147
 
 
148
    /**
 
149
     * Returns the total number of non-deleted documents in this index.
 
150
     *
 
151
     * @return integer
 
152
     */
 
153
    public function numDocs()
 
154
    {
 
155
        return $this->_index->numDocs();
 
156
    }
 
157
 
 
158
    /**
 
159
     * Checks, that document is deleted
 
160
     *
 
161
     * @param integer $id
 
162
     * @return boolean
 
163
     * @throws Zend_Search_Lucene_Exception    Exception is thrown if $id is out of the range
 
164
     */
 
165
    public function isDeleted($id)
 
166
    {
 
167
        return $this->_index->isDeleted($id);
 
168
    }
 
169
 
 
170
    /**
 
171
     * Set default search field.
 
172
     *
 
173
     * Null means, that search is performed through all fields by default
 
174
     *
 
175
     * Default value is null
 
176
     *
 
177
     * @param string $fieldName
 
178
     */
 
179
    public static function setDefaultSearchField($fieldName)
 
180
    {
 
181
        Zend_Search_Lucene::setDefaultSearchField($fieldName);
 
182
    }
 
183
 
 
184
    /**
 
185
     * Get default search field.
 
186
     *
 
187
     * Null means, that search is performed through all fields by default
 
188
     *
 
189
     * @return string
 
190
     */
 
191
    public static function getDefaultSearchField()
 
192
    {
 
193
        return Zend_Search_Lucene::getDefaultSearchField();
 
194
    }
 
195
 
 
196
    /**
 
197
     * Set result set limit.
 
198
     *
 
199
     * 0 (default) means no limit
 
200
     *
 
201
     * @param integer $limit
 
202
     */
 
203
    public static function setResultSetLimit($limit)
 
204
    {
 
205
        Zend_Search_Lucene::setResultSetLimit($limit);
 
206
    }
 
207
 
 
208
    /**
 
209
     * Set result set limit.
 
210
     *
 
211
     * 0 means no limit
 
212
     *
 
213
     * @return integer
 
214
     */
 
215
    public static function getResultSetLimit()
 
216
    {
 
217
        return Zend_Search_Lucene::getResultSetLimit();
 
218
    }
 
219
 
 
220
    /**
 
221
     * Retrieve index maxBufferedDocs option
 
222
     *
 
223
     * maxBufferedDocs is a minimal number of documents required before
 
224
     * the buffered in-memory documents are written into a new Segment
 
225
     *
 
226
     * Default value is 10
 
227
     *
 
228
     * @return integer
 
229
     */
 
230
    public function getMaxBufferedDocs()
 
231
    {
 
232
        return $this->_index->getMaxBufferedDocs();
 
233
    }
 
234
 
 
235
    /**
 
236
     * Set index maxBufferedDocs option
 
237
     *
 
238
     * maxBufferedDocs is a minimal number of documents required before
 
239
     * the buffered in-memory documents are written into a new Segment
 
240
     *
 
241
     * Default value is 10
 
242
     *
 
243
     * @param integer $maxBufferedDocs
 
244
     */
 
245
    public function setMaxBufferedDocs($maxBufferedDocs)
 
246
    {
 
247
        $this->_index->setMaxBufferedDocs($maxBufferedDocs);
 
248
    }
 
249
 
 
250
 
 
251
    /**
 
252
     * Retrieve index maxMergeDocs option
 
253
     *
 
254
     * maxMergeDocs is a largest number of documents ever merged by addDocument().
 
255
     * Small values (e.g., less than 10,000) are best for interactive indexing,
 
256
     * as this limits the length of pauses while indexing to a few seconds.
 
257
     * Larger values are best for batched indexing and speedier searches.
 
258
     *
 
259
     * Default value is PHP_INT_MAX
 
260
     *
 
261
     * @return integer
 
262
     */
 
263
    public function getMaxMergeDocs()
 
264
    {
 
265
        return $this->_index->getMaxMergeDocs();
 
266
    }
 
267
 
 
268
    /**
 
269
     * Set index maxMergeDocs option
 
270
     *
 
271
     * maxMergeDocs is a largest number of documents ever merged by addDocument().
 
272
     * Small values (e.g., less than 10,000) are best for interactive indexing,
 
273
     * as this limits the length of pauses while indexing to a few seconds.
 
274
     * Larger values are best for batched indexing and speedier searches.
 
275
     *
 
276
     * Default value is PHP_INT_MAX
 
277
     *
 
278
     * @param integer $maxMergeDocs
 
279
     */
 
280
    public function setMaxMergeDocs($maxMergeDocs)
 
281
    {
 
282
        $this->_index->setMaxMergeDocs($maxMergeDocs);
 
283
    }
 
284
 
 
285
 
 
286
    /**
 
287
     * Retrieve index mergeFactor option
 
288
     *
 
289
     * mergeFactor determines how often segment indices are merged by addDocument().
 
290
     * With smaller values, less RAM is used while indexing,
 
291
     * and searches on unoptimized indices are faster,
 
292
     * but indexing speed is slower.
 
293
     * With larger values, more RAM is used during indexing,
 
294
     * and while searches on unoptimized indices are slower,
 
295
     * indexing is faster.
 
296
     * Thus larger values (> 10) are best for batch index creation,
 
297
     * and smaller values (< 10) for indices that are interactively maintained.
 
298
     *
 
299
     * Default value is 10
 
300
     *
 
301
     * @return integer
 
302
     */
 
303
    public function getMergeFactor()
 
304
    {
 
305
        return $this->_index->getMergeFactor();
 
306
    }
 
307
 
 
308
    /**
 
309
     * Set index mergeFactor option
 
310
     *
 
311
     * mergeFactor determines how often segment indices are merged by addDocument().
 
312
     * With smaller values, less RAM is used while indexing,
 
313
     * and searches on unoptimized indices are faster,
 
314
     * but indexing speed is slower.
 
315
     * With larger values, more RAM is used during indexing,
 
316
     * and while searches on unoptimized indices are slower,
 
317
     * indexing is faster.
 
318
     * Thus larger values (> 10) are best for batch index creation,
 
319
     * and smaller values (< 10) for indices that are interactively maintained.
 
320
     *
 
321
     * Default value is 10
 
322
     *
 
323
     * @param integer $maxMergeDocs
 
324
     */
 
325
    public function setMergeFactor($mergeFactor)
 
326
    {
 
327
        $this->_index->setMergeFactor($mergeFactor);
 
328
    }
 
329
 
 
330
    /**
 
331
     * Performs a query against the index and returns an array
 
332
     * of Zend_Search_Lucene_Search_QueryHit objects.
 
333
     * Input is a string or Zend_Search_Lucene_Search_Query.
 
334
     *
 
335
     * @param mixed $query
 
336
     * @return array Zend_Search_Lucene_Search_QueryHit
 
337
     * @throws Zend_Search_Lucene_Exception
 
338
     */
 
339
    public function find($query)
 
340
    {
 
341
        // actual parameter list
 
342
        $parameters = func_get_args();
 
343
 
 
344
        // invoke $this->_index->find() method with specified parameters
 
345
        return call_user_func_array(array(&$this->_index, 'find'), $parameters);
 
346
    }
 
347
 
 
348
    /**
 
349
     * Returns a list of all unique field names that exist in this index.
 
350
     *
 
351
     * @param boolean $indexed
 
352
     * @return array
 
353
     */
 
354
    public function getFieldNames($indexed = false)
 
355
    {
 
356
        return $this->_index->getFieldNames($indexed);
 
357
    }
 
358
 
 
359
    /**
 
360
     * Returns a Zend_Search_Lucene_Document object for the document
 
361
     * number $id in this index.
 
362
     *
 
363
     * @param integer|Zend_Search_Lucene_Search_QueryHit $id
 
364
     * @return Zend_Search_Lucene_Document
 
365
     */
 
366
    public function getDocument($id)
 
367
    {
 
368
        return $this->_index->getDocument($id);
 
369
    }
 
370
 
 
371
    /**
 
372
     * Returns true if index contain documents with specified term.
 
373
     *
 
374
     * Is used for query optimization.
 
375
     *
 
376
     * @param Zend_Search_Lucene_Index_Term $term
 
377
     * @return boolean
 
378
     */
 
379
    public function hasTerm(Zend_Search_Lucene_Index_Term $term)
 
380
    {
 
381
        return $this->_index->hasTerm($term);
 
382
    }
 
383
 
 
384
    /**
 
385
     * Returns IDs of all the documents containing term.
 
386
     *
 
387
     * @param Zend_Search_Lucene_Index_Term $term
 
388
     * @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter
 
389
     * @return array
 
390
     */
 
391
    public function termDocs(Zend_Search_Lucene_Index_Term $term, $docsFilter = null)
 
392
    {
 
393
        return $this->_index->termDocs($term, $docsFilter);
 
394
    }
 
395
 
 
396
    /**
 
397
     * Returns documents filter for all documents containing term.
 
398
     *
 
399
     * It performs the same operation as termDocs, but return result as
 
400
     * Zend_Search_Lucene_Index_DocsFilter object
 
401
     *
 
402
     * @param Zend_Search_Lucene_Index_Term $term
 
403
     * @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter
 
404
     * @return Zend_Search_Lucene_Index_DocsFilter
 
405
     */
 
406
    public function termDocsFilter(Zend_Search_Lucene_Index_Term $term, $docsFilter = null)
 
407
    {
 
408
        return $this->_index->termDocsFilter($term, $docsFilter);
 
409
    }
 
410
 
 
411
    /**
 
412
     * Returns an array of all term freqs.
 
413
     * Return array structure: array( docId => freq, ...)
 
414
     *
 
415
     * @param Zend_Search_Lucene_Index_Term $term
 
416
     * @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter
 
417
     * @return integer
 
418
     */
 
419
    public function termFreqs(Zend_Search_Lucene_Index_Term $term, $docsFilter = null)
 
420
    {
 
421
        return $this->_index->termFreqs($term, $docsFilter);
 
422
    }
 
423
 
 
424
    /**
 
425
     * Returns an array of all term positions in the documents.
 
426
     * Return array structure: array( docId => array( pos1, pos2, ...), ...)
 
427
     *
 
428
     * @param Zend_Search_Lucene_Index_Term $term
 
429
     * @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter
 
430
     * @return array
 
431
     */
 
432
    public function termPositions(Zend_Search_Lucene_Index_Term $term, $docsFilter = null)
 
433
    {
 
434
        return $this->_index->termPositions($term, $docsFilter);
 
435
    }
 
436
 
 
437
    /**
 
438
     * Returns the number of documents in this index containing the $term.
 
439
     *
 
440
     * @param Zend_Search_Lucene_Index_Term $term
 
441
     * @return integer
 
442
     */
 
443
    public function docFreq(Zend_Search_Lucene_Index_Term $term)
 
444
    {
 
445
        return $this->_index->docFreq($term);
 
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 $this->_index->getSimilarity();
 
456
    }
 
457
 
 
458
    /**
 
459
     * Returns a normalization factor for "field, document" pair.
 
460
     *
 
461
     * @param integer $id
 
462
     * @param string $fieldName
 
463
     * @return float
 
464
     */
 
465
    public function norm($id, $fieldName)
 
466
    {
 
467
        return $this->_index->norm($id, $fieldName);
 
468
    }
 
469
 
 
470
    /**
 
471
     * Returns true if any documents have been deleted from this index.
 
472
     *
 
473
     * @return boolean
 
474
     */
 
475
    public function hasDeletions()
 
476
    {
 
477
        return $this->_index->hasDeletions();
 
478
    }
 
479
 
 
480
    /**
 
481
     * Deletes a document from the index.
 
482
     * $id is an internal document id
 
483
     *
 
484
     * @param integer|Zend_Search_Lucene_Search_QueryHit $id
 
485
     * @throws Zend_Search_Lucene_Exception
 
486
     */
 
487
    public function delete($id)
 
488
    {
 
489
        return $this->_index->delete($id);
 
490
    }
 
491
 
 
492
    /**
 
493
     * Adds a document to this index.
 
494
     *
 
495
     * @param Zend_Search_Lucene_Document $document
 
496
     */
 
497
    public function addDocument(Zend_Search_Lucene_Document $document)
 
498
    {
 
499
        $this->_index->addDocument($document);
 
500
    }
 
501
 
 
502
    /**
 
503
     * Commit changes resulting from delete() or undeleteAll() operations.
 
504
     */
 
505
    public function commit()
 
506
    {
 
507
        $this->_index->commit();
 
508
    }
 
509
 
 
510
    /**
 
511
     * Optimize index.
 
512
     *
 
513
     * Merges all segments into one
 
514
     */
 
515
    public function optimize()
 
516
    {
 
517
        $this->_index->optimize();
 
518
    }
 
519
 
 
520
    /**
 
521
     * Returns an array of all terms in this index.
 
522
     *
 
523
     * @return array
 
524
     */
 
525
    public function terms()
 
526
    {
 
527
        return $this->_index->terms();
 
528
    }
 
529
 
 
530
 
 
531
    /**
 
532
     * Reset terms stream.
 
533
     */
 
534
    public function resetTermsStream()
 
535
    {
 
536
        $this->_index->resetTermsStream();
 
537
    }
 
538
 
 
539
    /**
 
540
     * Skip terms stream up to specified term preffix.
 
541
     *
 
542
     * Prefix contains fully specified field info and portion of searched term
 
543
     *
 
544
     * @param Zend_Search_Lucene_Index_Term $prefix
 
545
     */
 
546
    public function skipTo(Zend_Search_Lucene_Index_Term $prefix)
 
547
    {
 
548
        return $this->_index->skipTo($prefix);
 
549
    }
 
550
 
 
551
    /**
 
552
     * Scans terms dictionary and returns next term
 
553
     *
 
554
     * @return Zend_Search_Lucene_Index_Term|null
 
555
     */
 
556
    public function nextTerm()
 
557
    {
 
558
        return $this->_index->nextTerm();
 
559
    }
 
560
 
 
561
    /**
 
562
     * Returns term in current position
 
563
     *
 
564
     * @return Zend_Search_Lucene_Index_Term|null
 
565
     */
 
566
    public function currentTerm()
 
567
    {
 
568
        return $this->_index->currentTerm();
 
569
    }
 
570
 
 
571
    /**
 
572
     * Close terms stream
 
573
     *
 
574
     * Should be used for resources clean up if stream is not read up to the end
 
575
     */
 
576
    public function closeTermsStream()
 
577
    {
 
578
        $this->_index->closeTermsStream();
 
579
    }
 
580
 
 
581
 
 
582
    /**
 
583
     * Undeletes all documents currently marked as deleted in this index.
 
584
     */
 
585
    public function undeleteAll()
 
586
    {
 
587
        return $this->_index->undeleteAll();
 
588
    }
 
589
 
 
590
    /**
 
591
     * Add reference to the index object
 
592
     *
 
593
     * @internal
 
594
     */
 
595
    public function addReference()
 
596
    {
 
597
        return $this->_index->addReference();
 
598
    }
 
599
 
 
600
    /**
 
601
     * Remove reference from the index object
 
602
     *
 
603
     * When reference count becomes zero, index is closed and resources are cleaned up
 
604
     *
 
605
     * @internal
 
606
     */
 
607
    public function removeReference()
 
608
    {
 
609
        return $this->_index->removeReference();
 
610
    }
 
611
}