@@ -32,6 +32,9 @@ |
||
32 | 32 | return $limit; |
33 | 33 | } |
34 | 34 | |
35 | + /** |
|
36 | + * @param integer $newOffset |
|
37 | + */ |
|
35 | 38 | private function formUrl($newOffset) |
36 | 39 | { |
37 | 40 | $gets=array(); |
@@ -7,60 +7,60 @@ |
||
7 | 7 | public function onInit($param) |
8 | 8 | { |
9 | 9 | parent::onInit($param); |
10 | - $this->_posts=$this->DataAccess->queryPostsSearch( |
|
10 | + $this->_posts = $this->DataAccess->queryPostsSearch( |
|
11 | 11 | $this->getPostKeywords(), |
12 | 12 | 'ORDER BY create_time DESC', |
13 | - 'LIMIT '.$this->getPageOffset().','.$this->getPageSize()); |
|
13 | + 'LIMIT ' . $this->getPageOffset() . ',' . $this->getPageSize()); |
|
14 | 14 | } |
15 | 15 | |
16 | 16 | private function getPostKeywords() |
17 | 17 | { |
18 | - return explode(' ',$this->Request['keyword']); |
|
18 | + return explode(' ', $this->Request['keyword']); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | private function getPageOffset() |
22 | 22 | { |
23 | - if(($offset=TPropertyValue::ensureInteger($this->Request['offset']))<=0) |
|
24 | - $offset=0; |
|
23 | + if (($offset = TPropertyValue::ensureInteger($this->Request['offset'])) <= 0) |
|
24 | + $offset = 0; |
|
25 | 25 | return $offset; |
26 | 26 | } |
27 | 27 | |
28 | 28 | private function getPageSize() |
29 | 29 | { |
30 | - if(($limit=TPropertyValue::ensureInteger($this->Request['limit']))<=0) |
|
31 | - $limit=TPropertyValue::ensureInteger($this->Application->Parameters['PostPerPage']); |
|
30 | + if (($limit = TPropertyValue::ensureInteger($this->Request['limit'])) <= 0) |
|
31 | + $limit = TPropertyValue::ensureInteger($this->Application->Parameters['PostPerPage']); |
|
32 | 32 | return $limit; |
33 | 33 | } |
34 | 34 | |
35 | 35 | private function formUrl($newOffset) |
36 | 36 | { |
37 | - $gets=array(); |
|
38 | - $gets['offset']=$newOffset; |
|
39 | - if($this->Request['limit']!==null) |
|
40 | - $gets['limit']=$this->Request['limit']; |
|
41 | - if($this->Request['time']!==null) |
|
42 | - $gets['time']=$this->Request['time']; |
|
43 | - if($this->Request['cat']!==null) |
|
44 | - $gets['cat']=$this->Request['cat']; |
|
45 | - return $this->Service->constructUrl('Posts.ListPost',$gets); |
|
37 | + $gets = array(); |
|
38 | + $gets['offset'] = $newOffset; |
|
39 | + if ($this->Request['limit'] !== null) |
|
40 | + $gets['limit'] = $this->Request['limit']; |
|
41 | + if ($this->Request['time'] !== null) |
|
42 | + $gets['time'] = $this->Request['time']; |
|
43 | + if ($this->Request['cat'] !== null) |
|
44 | + $gets['cat'] = $this->Request['cat']; |
|
45 | + return $this->Service->constructUrl('Posts.ListPost', $gets); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | public function onLoad($param) |
49 | 49 | { |
50 | 50 | parent::onLoad($param); |
51 | - $this->PostList->DataSource=$this->_posts; |
|
51 | + $this->PostList->DataSource = $this->_posts; |
|
52 | 52 | $this->PostList->dataBind(); |
53 | - if($this->getPageOffset()>0) |
|
53 | + if ($this->getPageOffset() > 0) |
|
54 | 54 | { |
55 | - if(($offset=$this->getPageOffset()-$this->getPageSize())<0) |
|
56 | - $offset=0; |
|
57 | - $this->PrevPage->NavigateUrl=$this->formUrl($offset); |
|
58 | - $this->PrevPage->Visible=true; |
|
55 | + if (($offset = $this->getPageOffset() - $this->getPageSize()) < 0) |
|
56 | + $offset = 0; |
|
57 | + $this->PrevPage->NavigateUrl = $this->formUrl($offset); |
|
58 | + $this->PrevPage->Visible = true; |
|
59 | 59 | } |
60 | - if(count($this->_posts)===$this->getPageSize()) |
|
60 | + if (count($this->_posts) === $this->getPageSize()) |
|
61 | 61 | { |
62 | - $this->NextPage->NavigateUrl=$this->formUrl($this->getPageOffset()+$this->getPageSize()); |
|
63 | - $this->NextPage->Visible=true; |
|
62 | + $this->NextPage->NavigateUrl = $this->formUrl($this->getPageOffset() + $this->getPageSize()); |
|
63 | + $this->NextPage->Visible = true; |
|
64 | 64 | } |
65 | 65 | } |
66 | 66 | } |
@@ -20,15 +20,17 @@ discard block |
||
20 | 20 | |
21 | 21 | private function getPageOffset() |
22 | 22 | { |
23 | - if(($offset=TPropertyValue::ensureInteger($this->Request['offset']))<=0) |
|
24 | - $offset=0; |
|
23 | + if(($offset=TPropertyValue::ensureInteger($this->Request['offset']))<=0) { |
|
24 | + $offset=0; |
|
25 | + } |
|
25 | 26 | return $offset; |
26 | 27 | } |
27 | 28 | |
28 | 29 | private function getPageSize() |
29 | 30 | { |
30 | - if(($limit=TPropertyValue::ensureInteger($this->Request['limit']))<=0) |
|
31 | - $limit=TPropertyValue::ensureInteger($this->Application->Parameters['PostPerPage']); |
|
31 | + if(($limit=TPropertyValue::ensureInteger($this->Request['limit']))<=0) { |
|
32 | + $limit=TPropertyValue::ensureInteger($this->Application->Parameters['PostPerPage']); |
|
33 | + } |
|
32 | 34 | return $limit; |
33 | 35 | } |
34 | 36 | |
@@ -36,12 +38,15 @@ discard block |
||
36 | 38 | { |
37 | 39 | $gets=array(); |
38 | 40 | $gets['offset']=$newOffset; |
39 | - if($this->Request['limit']!==null) |
|
40 | - $gets['limit']=$this->Request['limit']; |
|
41 | - if($this->Request['time']!==null) |
|
42 | - $gets['time']=$this->Request['time']; |
|
43 | - if($this->Request['cat']!==null) |
|
44 | - $gets['cat']=$this->Request['cat']; |
|
41 | + if($this->Request['limit']!==null) { |
|
42 | + $gets['limit']=$this->Request['limit']; |
|
43 | + } |
|
44 | + if($this->Request['time']!==null) { |
|
45 | + $gets['time']=$this->Request['time']; |
|
46 | + } |
|
47 | + if($this->Request['cat']!==null) { |
|
48 | + $gets['cat']=$this->Request['cat']; |
|
49 | + } |
|
45 | 50 | return $this->Service->constructUrl('Posts.ListPost',$gets); |
46 | 51 | } |
47 | 52 | |
@@ -52,8 +57,9 @@ discard block |
||
52 | 57 | $this->PostList->dataBind(); |
53 | 58 | if($this->getPageOffset()>0) |
54 | 59 | { |
55 | - if(($offset=$this->getPageOffset()-$this->getPageSize())<0) |
|
56 | - $offset=0; |
|
60 | + if(($offset=$this->getPageOffset()-$this->getPageSize())<0) { |
|
61 | + $offset=0; |
|
62 | + } |
|
57 | 63 | $this->PrevPage->NavigateUrl=$this->formUrl($offset); |
58 | 64 | $this->PrevPage->Visible=true; |
59 | 65 | } |
@@ -9,6 +9,9 @@ |
||
9 | 9 | $this->class_list->dataBind(); |
10 | 10 | } |
11 | 11 | |
12 | + /** |
|
13 | + * @param string $directory |
|
14 | + */ |
|
12 | 15 | protected function getRecordClassList($directory) |
13 | 16 | { |
14 | 17 | $list=array(); |
@@ -11,13 +11,13 @@ |
||
11 | 11 | |
12 | 12 | protected function getRecordClassList($directory) |
13 | 13 | { |
14 | - $list=array(); |
|
15 | - $folder=@opendir($directory); |
|
16 | - while($entry=@readdir($folder)) |
|
14 | + $list = array(); |
|
15 | + $folder = @opendir($directory); |
|
16 | + while ($entry = @readdir($folder)) |
|
17 | 17 | { |
18 | - if($entry[0]==='.') |
|
18 | + if ($entry[0] === '.') |
|
19 | 19 | continue; |
20 | - else if(is_file($directory.'/'.$entry) && strpos($entry,'.php')) |
|
20 | + else if (is_file($directory . '/' . $entry) && strpos($entry, '.php')) |
|
21 | 21 | $list[] = str_replace('.php', '', $entry); |
22 | 22 | } |
23 | 23 | closedir($folder); |
@@ -15,10 +15,11 @@ |
||
15 | 15 | $folder=@opendir($directory); |
16 | 16 | while($entry=@readdir($folder)) |
17 | 17 | { |
18 | - if($entry[0]==='.') |
|
19 | - continue; |
|
20 | - else if(is_file($directory.'/'.$entry) && strpos($entry,'.php')) |
|
21 | - $list[] = str_replace('.php', '', $entry); |
|
18 | + if($entry[0]==='.') { |
|
19 | + continue; |
|
20 | + } else if(is_file($directory.'/'.$entry) && strpos($entry,'.php')) { |
|
21 | + $list[] = str_replace('.php', '', $entry); |
|
22 | + } |
|
22 | 23 | } |
23 | 24 | closedir($folder); |
24 | 25 | return $list; |
@@ -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> |
@@ -37,8 +37,9 @@ discard block |
||
37 | 37 | $data = $this->getCommentData(); |
38 | 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 | 43 | $count[$r->block_id]++; |
43 | 44 | } |
44 | 45 | $js = "var comment_count = ".TJavascript::encode($count).";\n"; |
@@ -55,8 +56,9 @@ discard block |
||
55 | 56 | |
56 | 57 | function add_comment($sender, $param) |
57 | 58 | { |
58 | - if(!$this->Page->IsValid) |
|
59 | - return; |
|
59 | + if(!$this->Page->IsValid) { |
|
60 | + return; |
|
61 | + } |
|
60 | 62 | $record = new CommentRecord; |
61 | 63 | $record->username = $this->username->Text; |
62 | 64 | $record->date_added = date('Y-m-d h:i:s'); |
@@ -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 |
@@ -465,8 +465,9 @@ |
||
465 | 465 | */ |
466 | 466 | public function norm( $id, $fieldName ) |
467 | 467 | { |
468 | - if( $id >= $this->_docCount ) |
|
469 | - return null; |
|
468 | + if( $id >= $this->_docCount ) { |
|
469 | + return null; |
|
470 | + } |
|
470 | 471 | |
471 | 472 | $segCount = 0; |
472 | 473 | $nextSegmentStartId = $this->_segmentInfos[ 0 ]->count(); |
@@ -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 |
@@ -47,6 +47,9 @@ |
||
47 | 47 | |
48 | 48 | public $boost = 1.0; |
49 | 49 | |
50 | + /** |
|
51 | + * @param boolean $isStored |
|
52 | + */ |
|
50 | 53 | public function __construct($name, $stringValue, $isStored, $isIndexed, $isTokenized, $isBinary = false) |
51 | 54 | { |
52 | 55 | $this->name = $name; |
@@ -34,101 +34,101 @@ |
||
34 | 34 | */ |
35 | 35 | class Zend_Search_Lucene_Field |
36 | 36 | { |
37 | - public $kind; |
|
38 | - |
|
39 | - public $name = 'body'; |
|
40 | - public $stringValue = null; |
|
41 | - public $isStored = false; |
|
42 | - public $isIndexed = true; |
|
43 | - public $isTokenized = true; |
|
44 | - public $isBinary = false; |
|
45 | - |
|
46 | - public $storeTermVector = false; |
|
47 | - |
|
48 | - public $boost = 1.0; |
|
49 | - |
|
50 | - public function __construct($name, $stringValue, $isStored, $isIndexed, $isTokenized, $isBinary = false) |
|
51 | - { |
|
52 | - $this->name = $name; |
|
53 | - $this->stringValue = $stringValue; |
|
54 | - $this->isStored = $isStored; |
|
55 | - $this->isIndexed = $isIndexed; |
|
56 | - $this->isTokenized = $isTokenized; |
|
57 | - $this->isBinary = $isBinary; |
|
58 | - |
|
59 | - $this->storeTermVector = false; |
|
60 | - $this->boost = 1.0; |
|
61 | - } |
|
62 | - |
|
63 | - |
|
64 | - /** |
|
65 | - * Constructs a String-valued Field that is not tokenized, but is indexed |
|
66 | - * and stored. Useful for non-text fields, e.g. date or url. |
|
67 | - * |
|
68 | - * @param string $name |
|
69 | - * @param string $value |
|
70 | - * @return Zend_Search_Lucene_Field |
|
71 | - */ |
|
72 | - static public function Keyword($name, $value) |
|
73 | - { |
|
74 | - return new self($name, $value, true, true, false); |
|
75 | - } |
|
76 | - |
|
77 | - |
|
78 | - /** |
|
79 | - * Constructs a String-valued Field that is not tokenized nor indexed, |
|
80 | - * but is stored in the index, for return with hits. |
|
81 | - * |
|
82 | - * @param string $name |
|
83 | - * @param string $value |
|
84 | - * @return Zend_Search_Lucene_Field |
|
85 | - */ |
|
86 | - static public function UnIndexed($name, $value) |
|
87 | - { |
|
88 | - return new self($name, $value, true, false, false); |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - /** |
|
93 | - * Constructs a Binary String valued Field that is not tokenized nor indexed, |
|
94 | - * but is stored in the index, for return with hits. |
|
95 | - * |
|
96 | - * @param string $name |
|
97 | - * @param string $value |
|
98 | - * @return Zend_Search_Lucene_Field |
|
99 | - */ |
|
100 | - static public function Binary($name, $value) |
|
101 | - { |
|
102 | - return new self($name, $value, true, false, false, true); |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * Constructs a String-valued Field that is tokenized and indexed, |
|
107 | - * and is stored in the index, for return with hits. Useful for short text |
|
108 | - * fields, like "title" or "subject". Term vector will not be stored for this field. |
|
109 | - * |
|
110 | - * @param string $name |
|
111 | - * @param string $value |
|
112 | - * @return Zend_Search_Lucene_Field |
|
113 | - */ |
|
114 | - static public function Text($name, $value) |
|
115 | - { |
|
116 | - return new self($name, $value, true, true, true); |
|
117 | - } |
|
118 | - |
|
119 | - |
|
120 | - /** |
|
121 | - * Constructs a String-valued Field that is tokenized and indexed, |
|
122 | - * but that is not stored in the index. |
|
123 | - * |
|
124 | - * @param string $name |
|
125 | - * @param string $value |
|
126 | - * @return Zend_Search_Lucene_Field |
|
127 | - */ |
|
128 | - static public function UnStored($name, $value) |
|
129 | - { |
|
130 | - return new self($name, $value, false, true, true); |
|
131 | - } |
|
37 | + public $kind; |
|
38 | + |
|
39 | + public $name = 'body'; |
|
40 | + public $stringValue = null; |
|
41 | + public $isStored = false; |
|
42 | + public $isIndexed = true; |
|
43 | + public $isTokenized = true; |
|
44 | + public $isBinary = false; |
|
45 | + |
|
46 | + public $storeTermVector = false; |
|
47 | + |
|
48 | + public $boost = 1.0; |
|
49 | + |
|
50 | + public function __construct($name, $stringValue, $isStored, $isIndexed, $isTokenized, $isBinary = false) |
|
51 | + { |
|
52 | + $this->name = $name; |
|
53 | + $this->stringValue = $stringValue; |
|
54 | + $this->isStored = $isStored; |
|
55 | + $this->isIndexed = $isIndexed; |
|
56 | + $this->isTokenized = $isTokenized; |
|
57 | + $this->isBinary = $isBinary; |
|
58 | + |
|
59 | + $this->storeTermVector = false; |
|
60 | + $this->boost = 1.0; |
|
61 | + } |
|
62 | + |
|
63 | + |
|
64 | + /** |
|
65 | + * Constructs a String-valued Field that is not tokenized, but is indexed |
|
66 | + * and stored. Useful for non-text fields, e.g. date or url. |
|
67 | + * |
|
68 | + * @param string $name |
|
69 | + * @param string $value |
|
70 | + * @return Zend_Search_Lucene_Field |
|
71 | + */ |
|
72 | + static public function Keyword($name, $value) |
|
73 | + { |
|
74 | + return new self($name, $value, true, true, false); |
|
75 | + } |
|
76 | + |
|
77 | + |
|
78 | + /** |
|
79 | + * Constructs a String-valued Field that is not tokenized nor indexed, |
|
80 | + * but is stored in the index, for return with hits. |
|
81 | + * |
|
82 | + * @param string $name |
|
83 | + * @param string $value |
|
84 | + * @return Zend_Search_Lucene_Field |
|
85 | + */ |
|
86 | + static public function UnIndexed($name, $value) |
|
87 | + { |
|
88 | + return new self($name, $value, true, false, false); |
|
89 | + } |
|
90 | + |
|
91 | + |
|
92 | + /** |
|
93 | + * Constructs a Binary String valued Field that is not tokenized nor indexed, |
|
94 | + * but is stored in the index, for return with hits. |
|
95 | + * |
|
96 | + * @param string $name |
|
97 | + * @param string $value |
|
98 | + * @return Zend_Search_Lucene_Field |
|
99 | + */ |
|
100 | + static public function Binary($name, $value) |
|
101 | + { |
|
102 | + return new self($name, $value, true, false, false, true); |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * Constructs a String-valued Field that is tokenized and indexed, |
|
107 | + * and is stored in the index, for return with hits. Useful for short text |
|
108 | + * fields, like "title" or "subject". Term vector will not be stored for this field. |
|
109 | + * |
|
110 | + * @param string $name |
|
111 | + * @param string $value |
|
112 | + * @return Zend_Search_Lucene_Field |
|
113 | + */ |
|
114 | + static public function Text($name, $value) |
|
115 | + { |
|
116 | + return new self($name, $value, true, true, true); |
|
117 | + } |
|
118 | + |
|
119 | + |
|
120 | + /** |
|
121 | + * Constructs a String-valued Field that is tokenized and indexed, |
|
122 | + * but that is not stored in the index. |
|
123 | + * |
|
124 | + * @param string $name |
|
125 | + * @param string $value |
|
126 | + * @return Zend_Search_Lucene_Field |
|
127 | + */ |
|
128 | + static public function UnStored($name, $value) |
|
129 | + { |
|
130 | + return new self($name, $value, false, true, true); |
|
131 | + } |
|
132 | 132 | |
133 | 133 | } |
134 | 134 |
@@ -32,6 +32,10 @@ |
||
32 | 32 | public $number; |
33 | 33 | public $storeTermVector; |
34 | 34 | |
35 | + /** |
|
36 | + * @param string $name |
|
37 | + * @param integer $number |
|
38 | + */ |
|
35 | 39 | public function __construct( $name, $isIndexed, $number, $storeTermVector ) |
36 | 40 | { |
37 | 41 | $this->name = $name; |
@@ -27,17 +27,17 @@ |
||
27 | 27 | */ |
28 | 28 | class Zend_Search_Lucene_Index_FieldInfo |
29 | 29 | { |
30 | - public $name; |
|
31 | - public $isIndexed; |
|
32 | - public $number; |
|
33 | - public $storeTermVector; |
|
30 | + public $name; |
|
31 | + public $isIndexed; |
|
32 | + public $number; |
|
33 | + public $storeTermVector; |
|
34 | 34 | |
35 | - public function __construct( $name, $isIndexed, $number, $storeTermVector ) |
|
36 | - { |
|
37 | - $this->name = $name; |
|
38 | - $this->isIndexed = $isIndexed; |
|
39 | - $this->number = $number; |
|
40 | - $this->storeTermVector = $storeTermVector; |
|
41 | - } |
|
35 | + public function __construct( $name, $isIndexed, $number, $storeTermVector ) |
|
36 | + { |
|
37 | + $this->name = $name; |
|
38 | + $this->isIndexed = $isIndexed; |
|
39 | + $this->number = $number; |
|
40 | + $this->storeTermVector = $storeTermVector; |
|
41 | + } |
|
42 | 42 | } |
43 | 43 |
@@ -32,7 +32,7 @@ |
||
32 | 32 | public $number; |
33 | 33 | public $storeTermVector; |
34 | 34 | |
35 | - public function __construct( $name, $isIndexed, $number, $storeTermVector ) |
|
35 | + public function __construct($name, $isIndexed, $number, $storeTermVector) |
|
36 | 36 | { |
37 | 37 | $this->name = $name; |
38 | 38 | $this->isIndexed = $isIndexed; |
@@ -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 |
@@ -65,6 +65,11 @@ |
||
65 | 65 | */ |
66 | 66 | public $indexPointer; |
67 | 67 | |
68 | + /** |
|
69 | + * @param integer $docFreq |
|
70 | + * @param integer $skipOffset |
|
71 | + * @param integer $indexPointer |
|
72 | + */ |
|
68 | 73 | public function __construct($docFreq, $freqPointer, $proxPointer, $skipOffset, $indexPointer = null) |
69 | 74 | { |
70 | 75 | $this->docFreq = $docFreq; |
@@ -29,49 +29,49 @@ |
||
29 | 29 | */ |
30 | 30 | class Zend_Search_Lucene_Index_TermInfo |
31 | 31 | { |
32 | - /** |
|
33 | - * The number of documents which contain the term. |
|
34 | - * |
|
35 | - * @var integer |
|
36 | - */ |
|
37 | - public $docFreq; |
|
32 | + /** |
|
33 | + * The number of documents which contain the term. |
|
34 | + * |
|
35 | + * @var integer |
|
36 | + */ |
|
37 | + public $docFreq; |
|
38 | 38 | |
39 | - /** |
|
40 | - * Data offset in a Frequencies file. |
|
41 | - * |
|
42 | - * @var integer |
|
43 | - */ |
|
44 | - public $freqPointer; |
|
39 | + /** |
|
40 | + * Data offset in a Frequencies file. |
|
41 | + * |
|
42 | + * @var integer |
|
43 | + */ |
|
44 | + public $freqPointer; |
|
45 | 45 | |
46 | - /** |
|
47 | - * Data offset in a Positions file. |
|
48 | - * |
|
49 | - * @var integer |
|
50 | - */ |
|
51 | - public $proxPointer; |
|
46 | + /** |
|
47 | + * Data offset in a Positions file. |
|
48 | + * |
|
49 | + * @var integer |
|
50 | + */ |
|
51 | + public $proxPointer; |
|
52 | 52 | |
53 | - /** |
|
54 | - * ScipData offset in a Frequencies file. |
|
55 | - * |
|
56 | - * @var integer |
|
57 | - */ |
|
58 | - public $skipOffset; |
|
53 | + /** |
|
54 | + * ScipData offset in a Frequencies file. |
|
55 | + * |
|
56 | + * @var integer |
|
57 | + */ |
|
58 | + public $skipOffset; |
|
59 | 59 | |
60 | - /** |
|
61 | - * Term offset of the _next_ term in a TermDictionary file. |
|
62 | - * Used only for Term Index |
|
63 | - * |
|
64 | - * @var integer |
|
65 | - */ |
|
66 | - public $indexPointer; |
|
60 | + /** |
|
61 | + * Term offset of the _next_ term in a TermDictionary file. |
|
62 | + * Used only for Term Index |
|
63 | + * |
|
64 | + * @var integer |
|
65 | + */ |
|
66 | + public $indexPointer; |
|
67 | 67 | |
68 | - public function __construct($docFreq, $freqPointer, $proxPointer, $skipOffset, $indexPointer = null) |
|
69 | - { |
|
70 | - $this->docFreq = $docFreq; |
|
71 | - $this->freqPointer = $freqPointer; |
|
72 | - $this->proxPointer = $proxPointer; |
|
73 | - $this->skipOffset = $skipOffset; |
|
74 | - $this->indexPointer = $indexPointer; |
|
75 | - } |
|
68 | + public function __construct($docFreq, $freqPointer, $proxPointer, $skipOffset, $indexPointer = null) |
|
69 | + { |
|
70 | + $this->docFreq = $docFreq; |
|
71 | + $this->freqPointer = $freqPointer; |
|
72 | + $this->proxPointer = $proxPointer; |
|
73 | + $this->skipOffset = $skipOffset; |
|
74 | + $this->indexPointer = $indexPointer; |
|
75 | + } |
|
76 | 76 | } |
77 | 77 |