@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | } |
122 | 122 | |
123 | 123 | private function getLocaleIndexName() { |
124 | - $name = $this->indexName.'-'.$this->locale; |
|
124 | + $name = $this->indexName . '-' . $this->locale; |
|
125 | 125 | $name = strtolower($name); |
126 | 126 | $name = str_replace('-', '_', $name); |
127 | 127 | return $name; |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | $search = new Search(new Client()); |
153 | 153 | |
154 | 154 | if ($this->test_mode) { |
155 | - $search->setOption('search_type',Search::OPTION_SEARCH_TYPE_DFS_QUERY_THEN_FETCH); |
|
155 | + $search->setOption('search_type', Search::OPTION_SEARCH_TYPE_DFS_QUERY_THEN_FETCH); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | } |
196 | 196 | |
197 | 197 | if (!$empty($types)) { |
198 | - foreach($types as $type) { |
|
198 | + foreach ($types as $type) { |
|
199 | 199 | $search->addType($type); |
200 | 200 | } |
201 | 201 | } |
@@ -263,7 +263,7 @@ discard block |
||
263 | 263 | //$search = new Search(new Client()); |
264 | 264 | $search->addIndex($this->getLocaleIndexName()); |
265 | 265 | if (!$empty($types)) { |
266 | - foreach($types as $type) { |
|
266 | + foreach ($types as $type) { |
|
267 | 267 | $search->addType($type); |
268 | 268 | } |
269 | 269 | } |
@@ -350,9 +350,9 @@ discard block |
||
350 | 350 | |
351 | 351 | public function listIndexes($trace) { |
352 | 352 | $command = "curl 'localhost:9200/_cat/indices?v'"; |
353 | - exec($command,$op); |
|
353 | + exec($command, $op); |
|
354 | 354 | ElasticaUtil::message("\n++++ $trace ++++\n"); |
355 | - ElasticaUtil::message(print_r($op,1)); |
|
355 | + ElasticaUtil::message(print_r($op, 1)); |
|
356 | 356 | ElasticaUtil::message("++++ /{$trace} ++++\n\n"); |
357 | 357 | return $op; |
358 | 358 | } |
@@ -375,12 +375,12 @@ discard block |
||
375 | 375 | ElasticaUtil::message("\tAdding $amount documents to the index\n"); |
376 | 376 | if (isset($this->StartTime)) { |
377 | 377 | $elapsed = microtime(true) - $this->StartTime; |
378 | - $timePerDoc = ($elapsed)/($this->nDocumentsIndexed); |
|
378 | + $timePerDoc = ($elapsed) / ($this->nDocumentsIndexed); |
|
379 | 379 | $documentsRemaining = $this->nDocumentsToIndexForLocale - $this->nDocumentsIndexed; |
380 | - $eta = ($documentsRemaining)*$timePerDoc; |
|
381 | - $hours = (int)($eta/3600); |
|
382 | - $minutes = (int)(($eta-$hours*3600)/60); |
|
383 | - $seconds = (int)(0.5+$eta-$minutes*60-$hours*3600); |
|
380 | + $eta = ($documentsRemaining) * $timePerDoc; |
|
381 | + $hours = (int)($eta / 3600); |
|
382 | + $minutes = (int)(($eta - $hours * 3600) / 60); |
|
383 | + $seconds = (int)(0.5 + $eta - $minutes * 60 - $hours * 3600); |
|
384 | 384 | $etaHR = "{$hours}h {$minutes}m {$seconds}s"; |
385 | 385 | ElasticaUtil::message("ETA to completion of indexing $this->locale ($documentsRemaining documents): $etaHR"); |
386 | 386 | } |
@@ -451,17 +451,17 @@ discard block |
||
451 | 451 | * @return \DataObject[] $records |
452 | 452 | */ |
453 | 453 | protected function recordsByClassConsiderVersioned($class, $pageSize = 0, $page = 0) { |
454 | - $offset = $page*$pageSize; |
|
454 | + $offset = $page * $pageSize; |
|
455 | 455 | |
456 | 456 | if ($class::has_extension("Versioned")) { |
457 | - if ($pageSize >0) { |
|
457 | + if ($pageSize > 0) { |
|
458 | 458 | $records = \Versioned::get_by_stage($class, 'Live')->limit($pageSize, $offset); |
459 | 459 | } else { |
460 | 460 | $records = \Versioned::get_by_stage($class, 'Live'); |
461 | 461 | } |
462 | 462 | } else { |
463 | - if ($pageSize >0) { |
|
464 | - $records = $class::get()->limit($pageSize,$offset); |
|
463 | + if ($pageSize > 0) { |
|
464 | + $records = $class::get()->limit($pageSize, $offset); |
|
465 | 465 | } else { |
466 | 466 | $records = $class::get(); |
467 | 467 | } |
@@ -479,12 +479,12 @@ discard block |
||
479 | 479 | protected function refreshClass($class) { |
480 | 480 | $nRecords = $this->recordsByClassConsiderVersioned($class)->count(); |
481 | 481 | $batchSize = 500; |
482 | - $pages = $nRecords/$batchSize + 1; |
|
482 | + $pages = $nRecords / $batchSize + 1; |
|
483 | 483 | $processing = true; |
484 | 484 | |
485 | - for ($i=0; $i < $pages; $i++) { |
|
485 | + for ($i = 0; $i < $pages; $i++) { |
|
486 | 486 | $this->startBulkIndex(); |
487 | - $pagedRecords = $this->recordsByClassConsiderVersioned($class,$batchSize, $i); |
|
487 | + $pagedRecords = $this->recordsByClassConsiderVersioned($class, $batchSize, $i); |
|
488 | 488 | $this->nDocumentsIndexed += $pagedRecords->count(); |
489 | 489 | $batch = $pagedRecords->toArray(); |
490 | 490 | $this->refreshRecords($batch); |
@@ -506,7 +506,7 @@ discard block |
||
506 | 506 | |
507 | 507 | //Count the number of documents for this locale |
508 | 508 | $amount = 0; |
509 | - echo "CURRENT LOCALE:".$this->locale; |
|
509 | + echo "CURRENT LOCALE:" . $this->locale; |
|
510 | 510 | foreach ($classes as $class) { |
511 | 511 | $amount += $this->recordsByClassConsiderVersioned($class)->count(); |
512 | 512 | } |
@@ -582,7 +582,7 @@ discard block |
||
582 | 582 | $settingsClassName = $indexSettings[$this->locale]; |
583 | 583 | $result = \Injector::inst()->create($settingsClassName); |
584 | 584 | } else { |
585 | - throw new \Exception('ERROR: No index settings are provided for locale '.$this->locale."\n"); |
|
585 | + throw new \Exception('ERROR: No index settings are provided for locale ' . $this->locale . "\n"); |
|
586 | 586 | |
587 | 587 | } |
588 | 588 | return $result; |
@@ -598,7 +598,7 @@ discard block |
||
598 | 598 | $classes = array(); |
599 | 599 | |
600 | 600 | $whitelist = array('SearchableTestPage', 'SearchableTestFatherPage', 'SearchableTestGrandFatherPage', |
601 | - 'FlickrPhotoTO','FlickrTagTO','FlickrPhotoTO','FlickrAuthorTO','FlickrSetTO'); |
|
601 | + 'FlickrPhotoTO', 'FlickrTagTO', 'FlickrPhotoTO', 'FlickrAuthorTO', 'FlickrSetTO'); |
|
602 | 602 | |
603 | 603 | foreach (\ClassInfo::subclassesFor('DataObject') as $candidate) { |
604 | 604 | $instance = singleton($candidate); |
@@ -661,7 +661,7 @@ discard block |
||
661 | 661 | if (isset($mapping['fields'])) { |
662 | 662 | $subFields = array_keys($mapping['fields']); |
663 | 663 | foreach ($subFields as $subField) { |
664 | - $name = $field.'.'.$subField; |
|
664 | + $name = $field . '.' . $subField; |
|
665 | 665 | array_push($allFields, $name); |
666 | 666 | } |
667 | 667 | } |
@@ -681,7 +681,7 @@ discard block |
||
681 | 681 | ); |
682 | 682 | |
683 | 683 | //FlickrPhoto/3829/_termvector |
684 | - $path = $this->getIndex()->getName().'/'.$searchable->ClassName.'/'.$searchable->ID.'/_termvector'; |
|
684 | + $path = $this->getIndex()->getName() . '/' . $searchable->ClassName . '/' . $searchable->ID . '/_termvector'; |
|
685 | 685 | $response = $this->getClient()->request( |
686 | 686 | $path, |
687 | 687 | \Elastica\Request::GET, |