import
[web.mtrack] / inc / lib / Zend / Search / Lucene / Index / SegmentWriter / StreamWriter.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  * @subpackage Index
18  * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
20  * @version    $Id: StreamWriter.php 16541 2009-07-07 06:59:03Z bkarwin $
21  */
22
23 /** Zend_Search_Lucene_Index_SegmentInfo */
24 require_once 'Zend/Search/Lucene/Index/SegmentInfo.php';
25
26 /** Zend_Search_Lucene_Index_SegmentWriter */
27 require_once 'Zend/Search/Lucene/Index/SegmentWriter.php';
28
29 /**
30  * @category   Zend
31  * @package    Zend_Search_Lucene
32  * @subpackage Index
33  * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
34  * @license    http://framework.zend.com/license/new-bsd     New BSD License
35  */
36 class Zend_Search_Lucene_Index_SegmentWriter_StreamWriter extends Zend_Search_Lucene_Index_SegmentWriter
37 {
38     /**
39      * Object constructor.
40      *
41      * @param Zend_Search_Lucene_Storage_Directory $directory
42      * @param string $name
43      */
44     public function __construct(Zend_Search_Lucene_Storage_Directory $directory, $name)
45     {
46         parent::__construct($directory, $name);
47     }
48
49
50     /**
51      * Create stored fields files and open them for write
52      */
53     public function createStoredFieldsFiles()
54     {
55         $this->_fdxFile = $this->_directory->createFile($this->_name . '.fdx');
56         $this->_fdtFile = $this->_directory->createFile($this->_name . '.fdt');
57
58         $this->_files[] = $this->_name . '.fdx';
59         $this->_files[] = $this->_name . '.fdt';
60     }
61
62     public function addNorm($fieldName, $normVector)
63     {
64         if (isset($this->_norms[$fieldName])) {
65             $this->_norms[$fieldName] .= $normVector;
66         } else {
67             $this->_norms[$fieldName] = $normVector;
68         }
69     }
70
71     /**
72      * Close segment, write it to disk and return segment info
73      *
74      * @return Zend_Search_Lucene_Index_SegmentInfo
75      */
76     public function close()
77     {
78         if ($this->_docCount == 0) {
79             return null;
80         }
81
82         $this->_dumpFNM();
83         $this->_generateCFS();
84
85         return new Zend_Search_Lucene_Index_SegmentInfo($this->_directory,
86                                                         $this->_name,
87                                                         $this->_docCount,
88                                                         -1,
89                                                         null,
90                                                         true,
91                                                         true);
92     }
93 }
94