import
[web.mtrack] / inc / lib / Zend / Search / Lucene / Interface.php
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-2009 Zend Technologies USA Inc. (http://www.zend.com)
18  * @license    http://framework.zend.com/license/new-bsd     New BSD License
19  * @version    $Id: Interface.php 16971 2009-07-22 18:05:45Z mikaelkael $
20  */
21
22 /** Zend_Search_Lucene_Index_TermsStream_Interface */
23 require_once 'Zend/Search/Lucene/Index/TermsStream/Interface.php';
24
25
26 /**
27  * @category   Zend
28  * @package    Zend_Search_Lucene
29  * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
30  * @license    http://framework.zend.com/license/new-bsd     New BSD License
31  */
32 interface Zend_Search_Lucene_Interface extends Zend_Search_Lucene_Index_TermsStream_Interface
33 {
34     /**
35      * Get current generation number
36      *
37      * Returns generation number
38      * 0 means pre-2.1 index format
39      * -1 means there are no segments files.
40      *
41      * @param Zend_Search_Lucene_Storage_Directory $directory
42      * @return integer
43      * @throws Zend_Search_Lucene_Exception
44      */
45     public static function getActualGeneration(Zend_Search_Lucene_Storage_Directory $directory);
46
47     /**
48      * Get segments file name
49      *
50      * @param integer $generation
51      * @return string
52      */
53     public static function getSegmentFileName($generation);
54
55     /**
56      * Get index format version
57      *
58      * @return integer
59      */
60     public function getFormatVersion();
61
62     /**
63      * Set index format version.
64      * Index is converted to this format at the nearest upfdate time
65      *
66      * @param int $formatVersion
67      * @throws Zend_Search_Lucene_Exception
68      */
69     public function setFormatVersion($formatVersion);
70
71     /**
72      * Returns the Zend_Search_Lucene_Storage_Directory instance for this index.
73      *
74      * @return Zend_Search_Lucene_Storage_Directory
75      */
76     public function getDirectory();
77
78     /**
79      * Returns the total number of documents in this index (including deleted documents).
80      *
81      * @return integer
82      */
83     public function count();
84
85     /**
86      * Returns one greater than the largest possible document number.
87      * This may be used to, e.g., determine how big to allocate a structure which will have
88      * an element for every document number in an index.
89      *
90      * @return integer
91      */
92     public function maxDoc();
93
94     /**
95      * Returns the total number of non-deleted documents in this index.
96      *
97      * @return integer
98      */
99     public function numDocs();
100
101     /**
102      * Checks, that document is deleted
103      *
104      * @param integer $id
105      * @return boolean
106      * @throws Zend_Search_Lucene_Exception    Exception is thrown if $id is out of the range
107      */
108     public function isDeleted($id);
109
110     /**
111      * Set default search field.
112      *
113      * Null means, that search is performed through all fields by default
114      *
115      * Default value is null
116      *
117      * @param string $fieldName
118      */
119     public static function setDefaultSearchField($fieldName);
120
121     /**
122      * Get default search field.
123      *
124      * Null means, that search is performed through all fields by default
125      *
126      * @return string
127      */
128     public static function getDefaultSearchField();
129
130     /**
131      * Set result set limit.
132      *
133      * 0 (default) means no limit
134      *
135      * @param integer $limit
136      */
137     public static function setResultSetLimit($limit);
138
139     /**
140      * Set result set limit.
141      *
142      * 0 means no limit
143      *
144      * @return integer
145      */
146     public static function getResultSetLimit();
147
148     /**
149      * Retrieve index maxBufferedDocs option
150      *
151      * maxBufferedDocs is a minimal number of documents required before
152      * the buffered in-memory documents are written into a new Segment
153      *
154      * Default value is 10
155      *
156      * @return integer
157      */
158     public function getMaxBufferedDocs();
159
160     /**
161      * Set index maxBufferedDocs option
162      *
163      * maxBufferedDocs is a minimal number of documents required before
164      * the buffered in-memory documents are written into a new Segment
165      *
166      * Default value is 10
167      *
168      * @param integer $maxBufferedDocs
169      */
170     public function setMaxBufferedDocs($maxBufferedDocs);
171
172     /**
173      * Retrieve index maxMergeDocs option
174      *
175      * maxMergeDocs is a largest number of documents ever merged by addDocument().
176      * Small values (e.g., less than 10,000) are best for interactive indexing,
177      * as this limits the length of pauses while indexing to a few seconds.
178      * Larger values are best for batched indexing and speedier searches.
179      *
180      * Default value is PHP_INT_MAX
181      *
182      * @return integer
183      */
184     public function getMaxMergeDocs();
185
186     /**
187      * Set index maxMergeDocs option
188      *
189      * maxMergeDocs is a largest number of documents ever merged by addDocument().
190      * Small values (e.g., less than 10,000) are best for interactive indexing,
191      * as this limits the length of pauses while indexing to a few seconds.
192      * Larger values are best for batched indexing and speedier searches.
193      *
194      * Default value is PHP_INT_MAX
195      *
196      * @param integer $maxMergeDocs
197      */
198     public function setMaxMergeDocs($maxMergeDocs);
199
200     /**
201      * Retrieve index mergeFactor option
202      *
203      * mergeFactor determines how often segment indices are merged by addDocument().
204      * With smaller values, less RAM is used while indexing,
205      * and searches on unoptimized indices are faster,
206      * but indexing speed is slower.
207      * With larger values, more RAM is used during indexing,
208      * and while searches on unoptimized indices are slower,
209      * indexing is faster.
210      * Thus larger values (> 10) are best for batch index creation,
211      * and smaller values (< 10) for indices that are interactively maintained.
212      *
213      * Default value is 10
214      *
215      * @return integer
216      */
217     public function getMergeFactor();
218
219     /**
220      * Set index mergeFactor option
221      *
222      * mergeFactor determines how often segment indices are merged by addDocument().
223      * With smaller values, less RAM is used while indexing,
224      * and searches on unoptimized indices are faster,
225      * but indexing speed is slower.
226      * With larger values, more RAM is used during indexing,
227      * and while searches on unoptimized indices are slower,
228      * indexing is faster.
229      * Thus larger values (> 10) are best for batch index creation,
230      * and smaller values (< 10) for indices that are interactively maintained.
231      *
232      * Default value is 10
233      *
234      * @param integer $maxMergeDocs
235      */
236     public function setMergeFactor($mergeFactor);
237
238     /**
239      * Performs a query against the index and returns an array
240      * of Zend_Search_Lucene_Search_QueryHit objects.
241      * Input is a string or Zend_Search_Lucene_Search_Query.
242      *
243      * @param mixed $query
244      * @return array Zend_Search_Lucene_Search_QueryHit
245      * @throws Zend_Search_Lucene_Exception
246      */
247     public function find($query);
248
249     /**
250      * Returns a list of all unique field names that exist in this index.
251      *
252      * @param boolean $indexed
253      * @return array
254      */
255     public function getFieldNames($indexed = false);
256
257     /**
258      * Returns a Zend_Search_Lucene_Document object for the document
259      * number $id in this index.
260      *
261      * @param integer|Zend_Search_Lucene_Search_QueryHit $id
262      * @return Zend_Search_Lucene_Document
263      */
264     public function getDocument($id);
265
266     /**
267      * Returns true if index contain documents with specified term.
268      *
269      * Is used for query optimization.
270      *
271      * @param Zend_Search_Lucene_Index_Term $term
272      * @return boolean
273      */
274     public function hasTerm(Zend_Search_Lucene_Index_Term $term);
275
276     /**
277      * Returns IDs of all the documents containing term.
278      *
279      * @param Zend_Search_Lucene_Index_Term $term
280      * @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter
281      * @return array
282      */
283     public function termDocs(Zend_Search_Lucene_Index_Term $term, $docsFilter = null);
284
285     /**
286      * Returns documents filter for all documents containing term.
287      *
288      * It performs the same operation as termDocs, but return result as
289      * Zend_Search_Lucene_Index_DocsFilter object
290      *
291      * @param Zend_Search_Lucene_Index_Term $term
292      * @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter
293      * @return Zend_Search_Lucene_Index_DocsFilter
294      */
295     public function termDocsFilter(Zend_Search_Lucene_Index_Term $term, $docsFilter = null);
296
297     /**
298      * Returns an array of all term freqs.
299      * Return array structure: array( docId => freq, ...)
300      *
301      * @param Zend_Search_Lucene_Index_Term $term
302      * @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter
303      * @return integer
304      */
305     public function termFreqs(Zend_Search_Lucene_Index_Term $term, $docsFilter = null);
306
307     /**
308      * Returns an array of all term positions in the documents.
309      * Return array structure: array( docId => array( pos1, pos2, ...), ...)
310      *
311      * @param Zend_Search_Lucene_Index_Term $term
312      * @param Zend_Search_Lucene_Index_DocsFilter|null $docsFilter
313      * @return array
314      */
315     public function termPositions(Zend_Search_Lucene_Index_Term $term, $docsFilter = null);
316
317     /**
318      * Returns the number of documents in this index containing the $term.
319      *
320      * @param Zend_Search_Lucene_Index_Term $term
321      * @return integer
322      */
323     public function docFreq(Zend_Search_Lucene_Index_Term $term);
324
325     /**
326      * Retrive similarity used by index reader
327      *
328      * @return Zend_Search_Lucene_Search_Similarity
329      */
330     public function getSimilarity();
331
332     /**
333      * Returns a normalization factor for "field, document" pair.
334      *
335      * @param integer $id
336      * @param string $fieldName
337      * @return float
338      */
339     public function norm($id, $fieldName);
340
341     /**
342      * Returns true if any documents have been deleted from this index.
343      *
344      * @return boolean
345      */
346     public function hasDeletions();
347
348     /**
349      * Deletes a document from the index.
350      * $id is an internal document id
351      *
352      * @param integer|Zend_Search_Lucene_Search_QueryHit $id
353      * @throws Zend_Search_Lucene_Exception
354      */
355     public function delete($id);
356
357     /**
358      * Adds a document to this index.
359      *
360      * @param Zend_Search_Lucene_Document $document
361      */
362     public function addDocument(Zend_Search_Lucene_Document $document);
363
364     /**
365      * Commit changes resulting from delete() or undeleteAll() operations.
366      */
367     public function commit();
368
369     /**
370      * Optimize index.
371      *
372      * Merges all segments into one
373      */
374     public function optimize();
375
376     /**
377      * Returns an array of all terms in this index.
378      *
379      * @return array
380      */
381     public function terms();
382
383     /**
384      * Undeletes all documents currently marked as deleted in this index.
385      */
386     public function undeleteAll();
387
388
389     /**
390      * Add reference to the index object
391      *
392      * @internal
393      */
394     public function addReference();
395
396     /**
397      * Remove reference from the index object
398      *
399      * When reference count becomes zero, index is closed and resources are cleaned up
400      *
401      * @internal
402      */
403     public function removeReference();
404 }