Completed
Push — dev2 ( 815c11...450ef9 )
by Gordon
03:12
created
src/SilverStripe/Elastica/Searchable.php 3 patches
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -340,10 +340,10 @@  discard block
 block discarded – undo
340 340
 
341 341
 
342 342
 	/**
343
-	* Get an elasticsearch document
344
-	*
345
-	* @return \Elastica\Document
346
-	*/
343
+	 * Get an elasticsearch document
344
+	 *
345
+	 * @return \Elastica\Document
346
+	 */
347 347
 	public function getElasticaDocument() {
348 348
 		self::$index_ctr++;
349 349
 		$fields = $this->getFieldValuesAsArray();
@@ -754,7 +754,7 @@  discard block
 block discarded – undo
754 754
 	}
755 755
 
756 756
 
757
-    public function updateCMSFields(\FieldList $fields) {
757
+	public function updateCMSFields(\FieldList $fields) {
758 758
 		$isIndexed = false;
759 759
 		// SIteTree object must have a live record, ShowInSearch = true
760 760
 		if ($this->isInSiteTree($this->owner->ClassName)) {
@@ -781,47 +781,47 @@  discard block
 block discarded – undo
781 781
 				$terms = new \ArrayList();
782 782
 
783 783
 				foreach (array_keys($termVectors[$field]['terms']) as $term) {
784
-		        	$do = new \DataObject();
785
-			        $do->Term = $term;
786
-			        $stats = $termVectors[$field]['terms'][$term];
787
-			        if (isset($stats['ttf'])) {
788
-			        	$do->TTF = $stats['ttf'];
789
-			        }
790
-
791
-			        if (isset($stats['doc_freq'])) {
792
-			        	$do->DocFreq = $stats['doc_freq'];
793
-			        }
794
-
795
-			        if (isset($stats['term_freq'])) {
796
-			        	$do->TermFreq = $stats['term_freq'];
797
-			        }
798
-			        $terms->push($do);
799
-		        }
800
-
801
-		        $config = \GridFieldConfig_RecordViewer::create(100);
784
+					$do = new \DataObject();
785
+					$do->Term = $term;
786
+					$stats = $termVectors[$field]['terms'][$term];
787
+					if (isset($stats['ttf'])) {
788
+						$do->TTF = $stats['ttf'];
789
+					}
790
+
791
+					if (isset($stats['doc_freq'])) {
792
+						$do->DocFreq = $stats['doc_freq'];
793
+					}
794
+
795
+					if (isset($stats['term_freq'])) {
796
+						$do->TermFreq = $stats['term_freq'];
797
+					}
798
+					$terms->push($do);
799
+				}
800
+
801
+				$config = \GridFieldConfig_RecordViewer::create(100);
802 802
 				$config->getComponentByType('GridFieldDataColumns')->setDisplayFields(array(
803
-		            'Term' => 'Term',
804
-		            'TTF' => 'Total term frequency (how often a term occurs in all documents)',
805
-		            'DocFreq' => 'n documents with this term',
806
-		            'TermFreq'=> 'n times this term appears in this field'
807
-		        ));
808
-
809
-		       $underscored = str_replace('.', '_', $field);
810
-
811
-		        $gridField = new \GridField(
812
-		            'TermsFor'.$underscored, // Field name
813
-		            $field.'TITLE'.$field, // Field title
814
-		            $terms,
815
-		            $config
816
-		        );
817
-
818
-		      // $tab = new \Tab($field, new \TextField('Test'.$field, 'Testing'));
819
-		       $fields->addFieldToTab('Root.ElasticaTerms.'.$underscored, $gridField);
803
+					'Term' => 'Term',
804
+					'TTF' => 'Total term frequency (how often a term occurs in all documents)',
805
+					'DocFreq' => 'n documents with this term',
806
+					'TermFreq'=> 'n times this term appears in this field'
807
+				));
808
+
809
+			   $underscored = str_replace('.', '_', $field);
810
+
811
+				$gridField = new \GridField(
812
+					'TermsFor'.$underscored, // Field name
813
+					$field.'TITLE'.$field, // Field title
814
+					$terms,
815
+					$config
816
+				);
817
+
818
+			  // $tab = new \Tab($field, new \TextField('Test'.$field, 'Testing'));
819
+			   $fields->addFieldToTab('Root.ElasticaTerms.'.$underscored, $gridField);
820 820
 			}
821 821
 
822 822
 		}
823 823
 
824
-	    return $fields;
824
+		return $fields;
825 825
 	}
826 826
 
827 827
 
Please login to merge, or discard this patch.
Braces   +11 added lines, -6 removed lines patch added patch discarded remove patch
@@ -555,8 +555,7 @@  discard block
 block discarded – undo
555 555
 				// this goes to elastica service
556 556
 				$this->service->remove($this->owner);
557 557
 			}
558
-		}
559
-		catch(\Elastica\Exception\NotFoundException $e) {
558
+		} catch(\Elastica\Exception\NotFoundException $e) {
560 559
 			trigger_error("Deleted document ".$this->owner->ClassName." (".$this->owner->ID.
561 560
 				") not found in search index.", E_USER_NOTICE);
562 561
 		}
@@ -574,7 +573,9 @@  discard block
 block discarded – undo
574 573
 		$fields = \Config::inst()->get(get_class($this->owner), 'searchable_fields');
575 574
 
576 575
 		// fallback to default method
577
-		if(!$fields) user_error('The field $searchable_fields must be set for the class '.$this->owner->ClassName);
576
+		if(!$fields) {
577
+			user_error('The field $searchable_fields must be set for the class '.$this->owner->ClassName);
578
+		}
578 579
 
579 580
 		// get the values of these fields
580 581
 		$elasticaMapping = $this->fieldsToElasticaConfig($this->owner, $fields);
@@ -595,7 +596,9 @@  discard block
 block discarded – undo
595 596
 
596 597
 						$relClass = $has_lists[$methodName];
597 598
 						$fields = \Config::inst()->get($relClass, 'searchable_fields');
598
-						if(!$fields) user_error('The field $searchable_fields must be set for the class '.$relClass);
599
+						if(!$fields) {
600
+							user_error('The field $searchable_fields must be set for the class '.$relClass);
601
+						}
599 602
 						$rewrite = $this->fieldsToElasticaConfig($relClass, $fields);
600 603
 
601 604
 						// mark as a method, the resultant fields are correct
@@ -605,7 +608,9 @@  discard block
 block discarded – undo
605 608
 					} else if (isset($has_ones[$methodName])) {
606 609
 						$relClass = $has_ones[$methodName];
607 610
 						$fields = \Config::inst()->get($relClass, 'searchable_fields');
608
-						if(!$fields) user_error('The field $searchable_fields must be set for the class '.$relClass);
611
+						if(!$fields) {
612
+							user_error('The field $searchable_fields must be set for the class '.$relClass);
613
+						}
609 614
 						$rewrite = $this->fieldsToElasticaConfig($relClass, $fields);
610 615
 						$classname = $has_ones[$methodName];
611 616
 
@@ -687,7 +692,7 @@  discard block
 block discarded – undo
687 692
 
688 693
 				if (isset($searchableField['type'])) {
689 694
 					$doSF->Type = $searchableField['type'];
690
-				}  else {
695
+				} else {
691 696
 					$doSF->Name = $searchableField['properties']['__method'];
692 697
 					$doSF->Type = 'relationship';
693 698
 				}
Please login to merge, or discard this patch.
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -312,12 +312,12 @@  discard block
 block discarded – undo
312 312
 
313 313
 		if (isset($_GET['progress'])) {
314 314
 			$progress = $_GET['progress'];
315
-			self::$progressInterval = (int) $progress;
315
+			self::$progressInterval = (int)$progress;
316 316
 		}
317 317
 
318 318
 		if (self::$progressInterval > 0) {
319 319
 			if (self::$index_ctr % self::$progressInterval === 0) {
320
-				ElasticaUtil::message("\t".$this->owner->ClassName." - Prepared ".self::$index_ctr." for indexing...");
320
+				ElasticaUtil::message("\t" . $this->owner->ClassName . " - Prepared " . self::$index_ctr . " for indexing...");
321 321
 			}
322 322
 		}
323 323
 
@@ -366,7 +366,7 @@  discard block
 block discarded – undo
366 366
 
367 367
 			} else {
368 368
 				if (in_array($field, $this->html_fields)) {
369
-					$fields[$field] = $this->owner->$field;;
369
+					$fields[$field] = $this->owner->$field; ;
370 370
 					if (gettype($this->owner->$field) !== 'NULL') {
371 371
 						$html = ShortcodeParser::get_active()->parse($this->owner->$field);
372 372
 						$txt = \Convert::html2raw($html);
@@ -508,14 +508,14 @@  discard block
 block discarded – undo
508 508
 	 * Removes the record from the search index.
509 509
 	 */
510 510
 	protected function doDeleteDocument() {
511
-		try{
511
+		try {
512 512
 			if (!$this->owner->IndexingOff) {
513 513
 				// this goes to elastica service
514 514
 				$this->service->remove($this->owner);
515 515
 			}
516 516
 		}
517
-		catch(\Elastica\Exception\NotFoundException $e) {
518
-			trigger_error("Deleted document ".$this->owner->ClassName." (".$this->owner->ID.
517
+		catch (\Elastica\Exception\NotFoundException $e) {
518
+			trigger_error("Deleted document " . $this->owner->ClassName . " (" . $this->owner->ID .
519 519
 				") not found in search index.", E_USER_NOTICE);
520 520
 		}
521 521
 
@@ -532,7 +532,7 @@  discard block
 block discarded – undo
532 532
 		$fields = \Config::inst()->get(get_class($this->owner), 'searchable_fields');
533 533
 
534 534
 		// fallback to default method
535
-		if(!$fields) user_error('The field $searchable_fields must be set for the class '.$this->owner->ClassName);
535
+		if (!$fields) user_error('The field $searchable_fields must be set for the class ' . $this->owner->ClassName);
536 536
 
537 537
 		// get the values of these fields
538 538
 		$elasticaMapping = $this->fieldsToElasticaConfig($this->owner, $fields);
@@ -553,24 +553,24 @@  discard block
 block discarded – undo
553 553
 
554 554
 						$relClass = $has_lists[$methodName];
555 555
 						$fields = \Config::inst()->get($relClass, 'searchable_fields');
556
-						if(!$fields) user_error('The field $searchable_fields must be set for the class '.$relClass);
556
+						if (!$fields) user_error('The field $searchable_fields must be set for the class ' . $relClass);
557 557
 						$rewrite = $this->fieldsToElasticaConfig($relClass, $fields);
558 558
 
559 559
 						// mark as a method, the resultant fields are correct
560
-						$elasticaMapping[$methodName.'()'] = $rewrite;
560
+						$elasticaMapping[$methodName . '()'] = $rewrite;
561 561
 
562 562
 
563 563
 					} else if (isset($has_ones[$methodName])) {
564 564
 						$relClass = $has_ones[$methodName];
565 565
 						$fields = \Config::inst()->get($relClass, 'searchable_fields');
566
-						if(!$fields) user_error('The field $searchable_fields must be set for the class '.$relClass);
566
+						if (!$fields) user_error('The field $searchable_fields must be set for the class ' . $relClass);
567 567
 						$rewrite = $this->fieldsToElasticaConfig($relClass, $fields);
568 568
 						$classname = $has_ones[$methodName];
569 569
 
570 570
 						// mark as a method, the resultant fields are correct
571
-						$elasticaMapping[$methodName.'()'] = $rewrite;
571
+						$elasticaMapping[$methodName . '()'] = $rewrite;
572 572
 					} else {
573
-						user_error('The method '.$methodName.' not found in class '.$this->owner->ClassName.
573
+						user_error('The method ' . $methodName . ' not found in class ' . $this->owner->ClassName .
574 574
 								', please check configuration');
575 575
 					}
576 576
 				}
@@ -587,14 +587,14 @@  discard block
 block discarded – undo
587 587
 	private function fieldsToElasticaConfig($objectInContext, $fields) {
588 588
 		// Copied from DataObject::searchableFields() as there is no separate accessible method
589 589
 		$rewrite = array();
590
-		foreach($fields as $name => $specOrName) {
590
+		foreach ($fields as $name => $specOrName) {
591 591
 			$identifer = (is_int($name)) ? $specOrName : $name;
592 592
 			$rewrite[$identifer] = array();
593
-			if(!isset($rewrite[$identifer]['title'])) {
593
+			if (!isset($rewrite[$identifer]['title'])) {
594 594
 				$rewrite[$identifer]['title'] = (isset($labels[$identifer]))
595 595
 					? $labels[$identifer] : \FormField::name_to_label($identifer);
596 596
 			}
597
-			if(!isset($rewrite[$identifer]['filter'])) {
597
+			if (!isset($rewrite[$identifer]['filter'])) {
598 598
 				$rewrite[$identifer]['filter'] = 'PartialMatchFilter';
599 599
 			}
600 600
 		}
@@ -606,7 +606,7 @@  discard block
 block discarded – undo
606 606
 	public function requireDefaultRecords() {
607 607
 		parent::requireDefaultRecords();
608 608
 
609
-		$searchableFields = $this->getElasticaFields(true,true);
609
+		$searchableFields = $this->getElasticaFields(true, true);
610 610
 
611 611
 
612 612
 		$doSC = \SearchableClass::get()->filter(array('Name' => $this->owner->ClassName))->first();
@@ -639,7 +639,7 @@  discard block
 block discarded – undo
639 639
 
640 640
 				if (isset($searchableField['type'])) {
641 641
 					$doSF->Type = $searchableField['type'];
642
-				}  else {
642
+				} else {
643 643
 					$doSF->Name = $searchableField['properties']['__method'];
644 644
 					$doSF->Type = 'relationship';
645 645
 				}
@@ -650,7 +650,7 @@  discard block
 block discarded – undo
650 650
 				}
651 651
 
652 652
 				$doSF->write();
653
-				\DB::alteration_message("Created new searchable editable field ".$name,"changed");
653
+				\DB::alteration_message("Created new searchable editable field " . $name, "changed");
654 654
 			}
655 655
 
656 656
 			// FIXME deal with deletions
@@ -695,7 +695,7 @@  discard block
 block discarded – undo
695 695
 	 */
696 696
 	public function RenderResult($linkToContainer = '') {
697 697
 		$vars = new \ArrayData(array('SearchResult' => $this->owner, 'ContainerLink' => $linkToContainer));
698
-		$possibleTemplates = array($this->owner->ClassName.'ElasticSearchResult', 'ElasticSearchResult');
698
+		$possibleTemplates = array($this->owner->ClassName . 'ElasticSearchResult', 'ElasticSearchResult');
699 699
 		return $this->owner->customise($vars)->renderWith($possibleTemplates);
700 700
 	}
701 701
 
@@ -761,14 +761,14 @@  discard block
 block discarded – undo
761 761
 		       $underscored = str_replace('.', '_', $field);
762 762
 
763 763
 		        $gridField = new \GridField(
764
-		            'TermsFor'.$underscored, // Field name
765
-		            $field.'TITLE'.$field, // Field title
764
+		            'TermsFor' . $underscored, // Field name
765
+		            $field . 'TITLE' . $field, // Field title
766 766
 		            $terms,
767 767
 		            $config
768 768
 		        );
769 769
 
770 770
 		      // $tab = new \Tab($field, new \TextField('Test'.$field, 'Testing'));
771
-		       $fields->addFieldToTab('Root.ElasticaTerms.'.$underscored, $gridField);
771
+		       $fields->addFieldToTab('Root.ElasticaTerms.' . $underscored, $gridField);
772 772
 			}
773 773
 
774 774
 		}
Please login to merge, or discard this patch.
src/SilverStripe/Elastica/ElasticaService.php 3 patches
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
 		}
198 198
 
199 199
         if ($types) {
200
-        	foreach($types as $type) {
200
+        	foreach ($types as $type) {
201 201
         		$search->addType($type);
202 202
         	}
203 203
         }
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
 		//$search = new Search(new Client());
266 266
 		$search->addIndex($this->getLocaleIndexName());
267 267
 		if ($types) {
268
-			foreach($types as $type) {
268
+			foreach ($types as $type) {
269 269
 				$search->addType($type);
270 270
 			}
271 271
 		}
@@ -352,9 +352,9 @@  discard block
 block discarded – undo
352 352
 
353 353
 	public function listIndexes($trace) {
354 354
 		$command = "curl 'localhost:9200/_cat/indices?v'";
355
-        exec($command,$op);
355
+        exec($command, $op);
356 356
         ElasticaUtil::message("\n++++ $trace ++++\n");
357
-        ElasticaUtil::message(print_r($op,1));
357
+        ElasticaUtil::message(print_r($op, 1));
358 358
         ElasticaUtil::message("++++ /{$trace} ++++\n\n");
359 359
         return $op;
360 360
 	}
@@ -377,12 +377,12 @@  discard block
 block discarded – undo
377 377
 			ElasticaUtil::message("\tAdding $amount documents to the index\n");
378 378
 			if (isset($this->StartTime)) {
379 379
 				$elapsed = microtime(true) - $this->StartTime;
380
-				$timePerDoc = ($elapsed)/($this->nDocumentsIndexed);
380
+				$timePerDoc = ($elapsed) / ($this->nDocumentsIndexed);
381 381
 				$documentsRemaining = $this->nDocumentsToIndexForLocale - $this->nDocumentsIndexed;
382
-				$eta = ($documentsRemaining)*$timePerDoc;
383
-				$hours = (int)($eta/3600);
384
-				$minutes = (int)(($eta-$hours*3600)/60);
385
-				$seconds = (int)(0.5+$eta-$minutes*60-$hours*3600);
382
+				$eta = ($documentsRemaining) * $timePerDoc;
383
+				$hours = (int)($eta / 3600);
384
+				$minutes = (int)(($eta - $hours * 3600) / 60);
385
+				$seconds = (int)(0.5 + $eta - $minutes * 60 - $hours * 3600);
386 386
 				$etaHR = "{$hours}h {$minutes}m {$seconds}s";
387 387
 				ElasticaUtil::message("ETA to completion of indexing $this->locale ($documentsRemaining documents): $etaHR");
388 388
 			}
@@ -453,17 +453,17 @@  discard block
 block discarded – undo
453 453
 	 * @return \DataObject[] $records
454 454
 	 */
455 455
 	protected function recordsByClassConsiderVersioned($class, $pageSize = 0, $page = 0) {
456
-		$offset = $page*$pageSize;
456
+		$offset = $page * $pageSize;
457 457
 
458 458
 		if ($class::has_extension("Versioned")) {
459
-			if ($pageSize >0) {
459
+			if ($pageSize > 0) {
460 460
 				$records = \Versioned::get_by_stage($class, 'Live')->limit($pageSize, $offset);
461 461
 			} else {
462 462
 				$records = \Versioned::get_by_stage($class, 'Live');
463 463
 			}
464 464
 		} else {
465
-			if ($pageSize >0) {
466
-				$records = $class::get()->limit($pageSize,$offset);
465
+			if ($pageSize > 0) {
466
+				$records = $class::get()->limit($pageSize, $offset);
467 467
 			} else {
468 468
 				$records = $class::get();
469 469
 			}
@@ -481,12 +481,12 @@  discard block
 block discarded – undo
481 481
 	protected function refreshClass($class) {
482 482
 		$nRecords = $this->recordsByClassConsiderVersioned($class)->count();
483 483
 		$batchSize = 500;
484
-		$pages = $nRecords/$batchSize + 1;
484
+		$pages = $nRecords / $batchSize + 1;
485 485
 		$processing = true;
486 486
 
487
-		for ($i=0; $i < $pages; $i++) {
487
+		for ($i = 0; $i < $pages; $i++) {
488 488
 			$this->startBulkIndex();
489
-			$pagedRecords = $this->recordsByClassConsiderVersioned($class,$batchSize, $i);
489
+			$pagedRecords = $this->recordsByClassConsiderVersioned($class, $batchSize, $i);
490 490
 			$this->nDocumentsIndexed += $pagedRecords->count();
491 491
 			$batch = $pagedRecords->toArray();
492 492
 			$this->refreshRecords($batch);
@@ -508,7 +508,7 @@  discard block
 block discarded – undo
508 508
 
509 509
 		//Count the number of documents for this locale
510 510
 		$amount = 0;
511
-		echo "CURRENT LOCALE:".$this->locale;
511
+		echo "CURRENT LOCALE:" . $this->locale;
512 512
 		foreach ($classes as $class) {
513 513
 			$amount += $this->recordsByClassConsiderVersioned($class)->count();
514 514
 		}
@@ -584,7 +584,7 @@  discard block
 block discarded – undo
584 584
 			$settingsClassName = $indexSettings[$this->locale];
585 585
 			$result = \Injector::inst()->create($settingsClassName);
586 586
 		} else {
587
-			throw new \Exception('ERROR: No index settings are provided for locale '.$this->locale."\n");
587
+			throw new \Exception('ERROR: No index settings are provided for locale ' . $this->locale . "\n");
588 588
 
589 589
 		}
590 590
 		return $result;
@@ -600,7 +600,7 @@  discard block
 block discarded – undo
600 600
 		$classes = array();
601 601
 
602 602
 		$whitelist = array('SearchableTestPage', 'SearchableTestFatherPage', 'SearchableTestGrandFatherPage',
603
-			'FlickrPhotoTO','FlickrTagTO','FlickrPhotoTO','FlickrAuthorTO','FlickrSetTO');
603
+			'FlickrPhotoTO', 'FlickrTagTO', 'FlickrPhotoTO', 'FlickrAuthorTO', 'FlickrSetTO');
604 604
 
605 605
 		foreach (\ClassInfo::subclassesFor('DataObject') as $candidate) {
606 606
 			$instance = singleton($candidate);
@@ -663,7 +663,7 @@  discard block
 block discarded – undo
663 663
 			if (isset($mapping['fields'])) {
664 664
 				$subFields = array_keys($mapping['fields']);
665 665
 				foreach ($subFields as $subField) {
666
-					$name = $field.'.'.$subField;
666
+					$name = $field . '.' . $subField;
667 667
 					array_push($allFields, $name);
668 668
 				}
669 669
 			}
@@ -683,7 +683,7 @@  discard block
 block discarded – undo
683 683
 		);
684 684
 
685 685
 		//FlickrPhoto/3829/_termvector
686
-		$path = $this->getIndex()->getName().'/'.$searchable->ClassName.'/'.$searchable->ID.'/_termvector';
686
+		$path = $this->getIndex()->getName() . '/' . $searchable->ClassName . '/' . $searchable->ID . '/_termvector';
687 687
 		$response = $this->getClient()->request(
688 688
 	            $path,
689 689
 	            \Elastica\Request::GET,
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -133,7 +133,7 @@
 block discarded – undo
133 133
 	 *
134 134
 	 * @param \Elastica\Query|string|array $query
135 135
 	 * @param string|array $types List of comma separated SilverStripe classes to search, or blank for all
136
-	 * @return \Elastica\ResultList
136
+	 * @return \Elastica\ResultSet
137 137
 	 */
138 138
 	public function search($query, $types = '') {
139 139
 		$query = Query::create($query); // may be a string
Please login to merge, or discard this patch.
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
 			$types = explode(',', $types);
142 142
 		}
143 143
 
144
-        $data = $query->toArray();
144
+		$data = $query->toArray();
145 145
 		if (isset($data['query']['more_like_this'])) {
146 146
 			$query->MoreLikeThis = true;
147 147
 		} else {
@@ -164,21 +164,21 @@  discard block
 block discarded – undo
164 164
 		if ($query->MoreLikeThis) {
165 165
 			$path = $search->getPath();
166 166
 
167
-	        $termData = array();
168
-	        $termData['query'] = $data['query'];
167
+			$termData = array();
168
+			$termData['query'] = $data['query'];
169 169
 
170
-	        $path = str_replace('_search', '_validate/query', $path);
171
-	        $params = array('explain' => true, 'rewrite' => true);
172
-	        if ($this->test_mode) {
173
-	        	$params['search_type'] = Search::OPTION_SEARCH_TYPE_DFS_QUERY_THEN_FETCH;
174
-	        }
170
+			$path = str_replace('_search', '_validate/query', $path);
171
+			$params = array('explain' => true, 'rewrite' => true);
172
+			if ($this->test_mode) {
173
+				$params['search_type'] = Search::OPTION_SEARCH_TYPE_DFS_QUERY_THEN_FETCH;
174
+			}
175 175
 
176
-	        $response = $this->getClient()->request(
177
-	            $path,
178
-	            \Elastica\Request::GET,
179
-	            $termData,
180
-	            $params
181
-	        );
176
+			$response = $this->getClient()->request(
177
+				$path,
178
+				\Elastica\Request::GET,
179
+				$termData,
180
+				$params
181
+			);
182 182
 
183 183
 			$r = $response->getData();
184 184
 			$terms = null; // keep in scope
@@ -194,14 +194,14 @@  discard block
 block discarded – undo
194 194
 			}
195 195
 		}
196 196
 
197
-        if ($types) {
198
-        	foreach($types as $type) {
199
-        		$search->addType($type);
200
-        	}
201
-        }
197
+		if ($types) {
198
+			foreach($types as $type) {
199
+				$search->addType($type);
200
+			}
201
+		}
202 202
 
203
-        $path = $search->getPath();
204
-        $params = $search->getOptions();
203
+		$path = $search->getPath();
204
+		$params = $search->getOptions();
205 205
 
206 206
 		$highlightsCfg = \Config::inst()->get('Elastica', 'Highlights');
207 207
 		$preTags = $highlightsCfg['PreTags'];
@@ -269,14 +269,14 @@  discard block
 block discarded – undo
269 269
 		}
270 270
 
271 271
 
272
-        $path = $search->getPath();
273
-        $params = $search->getOptions();
272
+		$path = $search->getPath();
273
+		$params = $search->getOptions();
274 274
 		$searchResults = $search->search($query, $params);
275 275
 		if (isset($this->MoreLikeThisTerms)) {
276 276
 			$searchResults->MoreLikeThisTerms = $this->MoreLikeThisTerms;
277 277
 		}
278 278
 
279
-        return $searchResults;
279
+		return $searchResults;
280 280
 	}
281 281
 
282 282
 
@@ -350,11 +350,11 @@  discard block
 block discarded – undo
350 350
 
351 351
 	public function listIndexes($trace) {
352 352
 		$command = "curl 'localhost:9200/_cat/indices?v'";
353
-        exec($command,$op);
354
-        ElasticaUtil::message("\n++++ $trace ++++\n");
355
-        ElasticaUtil::message(print_r($op,1));
356
-        ElasticaUtil::message("++++ /{$trace} ++++\n\n");
357
-        return $op;
353
+		exec($command,$op);
354
+		ElasticaUtil::message("\n++++ $trace ++++\n");
355
+		ElasticaUtil::message(print_r($op,1));
356
+		ElasticaUtil::message("++++ /{$trace} ++++\n\n");
357
+		return $op;
358 358
 	}
359 359
 
360 360
 
@@ -525,11 +525,11 @@  discard block
 block discarded – undo
525 525
 			} else {
526 526
 				$class = new \ReflectionClass($classname);
527 527
 				while ($class = $class->getParentClass()) {
528
-				    $parentClass = $class->getName();
529
-				    if ($parentClass == 'SiteTree') {
530
-				    	$inSiteTree = true;
531
-				    	break;
532
-				    }
528
+					$parentClass = $class->getName();
529
+					if ($parentClass == 'SiteTree') {
530
+						$inSiteTree = true;
531
+						break;
532
+					}
533 533
 				}
534 534
 				self::$site_tree_classes[$classname] = $inSiteTree;
535 535
 			}
@@ -683,15 +683,15 @@  discard block
 block discarded – undo
683 683
 		//FlickrPhoto/3829/_termvector
684 684
 		$path = $this->getIndex()->getName().'/'.$searchable->ClassName.'/'.$searchable->ID.'/_termvector';
685 685
 		$response = $this->getClient()->request(
686
-	            $path,
687
-	            \Elastica\Request::GET,
688
-	            $data,
689
-	            $params
690
-	    );
686
+				$path,
687
+				\Elastica\Request::GET,
688
+				$data,
689
+				$params
690
+		);
691 691
 
692 692
 
693
-	    $data = $response->getData();
694
-	    return $data['term_vectors'];
693
+		$data = $response->getData();
694
+		return $data['term_vectors'];
695 695
 	}
696 696
 
697 697
 }
Please login to merge, or discard this patch.
src/SilverStripe/Elastica/FindElasticaSearchPageExtension.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -40,10 +40,10 @@
 block discarded – undo
40 40
 
41 41
 		$cache = SS_Cache::factory('searchpagecache');
42 42
 		$searchPage = null;
43
-		$cachekeyname = 'searchpageuri'.$identifier.$this->owner->Locale.$ck;
43
+		$cachekeyname = 'searchpageuri' . $identifier . $this->owner->Locale . $ck;
44 44
 
45
-		if(!($searchPage = unserialize($cache->load($cachekeyname)))) {
46
-			$searchPage = ElasticSearchPage::get()->filter('Identifier',$identifier)->first();
45
+		if (!($searchPage = unserialize($cache->load($cachekeyname)))) {
46
+			$searchPage = ElasticSearchPage::get()->filter('Identifier', $identifier)->first();
47 47
 			$cache->save(serialize($searchPage), $cachekeyname);
48 48
 		}
49 49
 		return $searchPage;
Please login to merge, or discard this patch.
searchpage/ElasticSearchPage_Validator.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -43,11 +43,11 @@  discard block
 block discarded – undo
43 43
 					try {
44 44
 						$instance = Injector::inst()->create($clazz);
45 45
 						if (!$instance->hasExtension('SilverStripe\Elastica\Searchable')) {
46
-							$this->validationError('ClassesToSearch', 'The class '.$clazz.' must have the Searchable extension');
46
+							$this->validationError('ClassesToSearch', 'The class ' . $clazz . ' must have the Searchable extension');
47 47
 						}
48 48
 					} catch (ReflectionException $e) {
49 49
 						$this->validationError("ClassesToSearch",
50
-							'The class '.$clazz.' does not exist',
50
+							'The class ' . $clazz . ' does not exist',
51 51
 							'error'
52 52
 						);
53 53
 					}
@@ -58,16 +58,16 @@  discard block
 block discarded – undo
58 58
 
59 59
 		// Check the identifier is unique
60 60
 		$mode = Versioned::get_reading_mode();
61
-		$suffix =  '';
61
+		$suffix = '';
62 62
 		if ($mode == 'Stage.Live') {
63 63
 			$suffix = '_Live';
64 64
 		}
65
-		$where = 'ElasticSearchPage'.$suffix.'.ID != '.$data['ID']." AND `Identifier` = '".$data['Identifier']."'";
65
+		$where = 'ElasticSearchPage' . $suffix . '.ID != ' . $data['ID'] . " AND `Identifier` = '" . $data['Identifier'] . "'";
66 66
 		$existing = ElasticSearchPage::get()->where($where)->count();
67 67
 		if ($existing > 0) {
68 68
 			$valid = false;
69 69
 			$this->validationError('Identifier',
70
-					'The identifier '.$data['Identifier'].' already exists',
70
+					'The identifier ' . $data['Identifier'] . ' already exists',
71 71
 					'error'
72 72
 			);
73 73
 		}
Please login to merge, or discard this patch.
searchpage/ElasticSearchPage.php 2 patches
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 	);
63 63
 
64 64
 	private static $many_many_extraFields = array(
65
-    	'ElasticaSearchableFields' => array(
65
+		'ElasticaSearchableFields' => array(
66 66
 		'Searchable' => 'Boolean', // allows the option of turning off a single field for searching
67 67
 		'SimilarSearchable' => 'Boolean', // allows field to be used in more like this queries.
68 68
 		'Active' => 'Boolean', // preserve previous edits of weighting when classes changed
@@ -104,10 +104,10 @@  discard block
 block discarded – undo
104 104
 		$sortedWords = $this->SimilarityStopWords;
105 105
 
106 106
 		$stopwordsField = StringTagField::create(
107
-		    'SimilarityStopWords',
108
-		    'Stop Words for Similar Search',
109
-		    $sortedWords,
110
-		    $sortedWords
107
+			'SimilarityStopWords',
108
+			'Stop Words for Similar Search',
109
+			$sortedWords,
110
+			$sortedWords
111 111
 		);
112 112
 
113 113
 		//	public function __construct($name, $title = '', $source = array(), $value = array()) {
@@ -192,18 +192,18 @@  discard block
 block discarded – undo
192 192
 		$fields->addFieldToTab('Root.Search.Aggregations', new TextField('SearchHelper',
193 193
 			'ClassName of object to manipulate search details and results.  Leave blank for standard search'));
194 194
 
195
-        $ottos = AutoCompleteOption::get()->Filter('Locale', $this->Locale)->map('ID', 'Name')->
196
-        									toArray();
197
-        $df = DropdownField::create('AutoCompleteFunctionID', 'Autocomplete Function')->
198
-        							setSource($ottos);
199
-        $df->setEmptyString('-- Please select what do do after find as you type has occurred --');
195
+		$ottos = AutoCompleteOption::get()->Filter('Locale', $this->Locale)->map('ID', 'Name')->
196
+											toArray();
197
+		$df = DropdownField::create('AutoCompleteFunctionID', 'Autocomplete Function')->
198
+									setSource($ottos);
199
+		$df->setEmptyString('-- Please select what do do after find as you type has occurred --');
200 200
 
201
-        $ottos = $this->ElasticaSearchableFields()->filter('EnableAutocomplete',1)->Map('ID', 'Name')->toArray();
202
-        $autoCompleteFieldDF = DropDownField::create('AutoCompleteFieldID', 'Field to use for autocomplete')->setSource($ottos);
203
-        $autoCompleteFieldDF->setEmptyString('-- Please select which field to use for autocomplete --');
201
+		$ottos = $this->ElasticaSearchableFields()->filter('EnableAutocomplete',1)->Map('ID', 'Name')->toArray();
202
+		$autoCompleteFieldDF = DropDownField::create('AutoCompleteFieldID', 'Field to use for autocomplete')->setSource($ottos);
203
+		$autoCompleteFieldDF->setEmptyString('-- Please select which field to use for autocomplete --');
204 204
 
205
-        //$fieldSet = new \FieldSet($df);
206
-        //$fields->addFieldToTab('Root.SearchDetails', $fieldSet);
205
+		//$fieldSet = new \FieldSet($df);
206
+		//$fields->addFieldToTab('Root.SearchDetails', $fieldSet);
207 207
 
208 208
 		$fields->addFieldToTab("Root.Search.AutoComplete",
209 209
 		  		FieldGroup::create(
@@ -211,8 +211,8 @@  discard block
 block discarded – undo
211 211
 		 			$df
212 212
 		 		)->setTitle('Autocomplete')
213 213
 		 );
214
-		        // ---- grid of searchable fields ----
215
-        		//$searchTabName = 'Root.'._t('SiteConfig.ELASTICA', 'Search');
214
+				// ---- grid of searchable fields ----
215
+				//$searchTabName = 'Root.'._t('SiteConfig.ELASTICA', 'Search');
216 216
 		$html = '<p id="SearchFieldIntro">'._t('SiteConfig.ELASTICA_SEARCH_INFO',
217 217
 				"Select a field to edit it's properties").'</p>';
218 218
 		$fields->addFieldToTab('Root.Search.Fields', $h1=new LiteralField('SearchInfo', $html));
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
 		$pickerConfig->removeComponentsByType(new PickerFieldAddExistingSearchButton());
229 229
 		$pickerConfig->getComponentByType('GridFieldPaginator')->setItemsPerPage(100);
230 230
 
231
-        $searchPicker->enableEdit();
231
+		$searchPicker->enableEdit();
232 232
 		$edittest = $pickerConfig->getComponentByType('GridFieldDetailForm');
233 233
 		$edittest->setFields(FieldList::create(
234 234
 			TextField::create('Name', 'Field Name'),
@@ -262,23 +262,23 @@  discard block
 block discarded – undo
262 262
 
263 263
 		// What do display on the grid of searchable fields
264 264
 		$dataColumns = $pickerConfig->getComponentByType('GridFieldDataColumns');
265
-        $dataColumns->setDisplayFields(array(
265
+		$dataColumns->setDisplayFields(array(
266 266
 			'Name' => 'Name',
267
-        	'ClazzName' => 'Class',
267
+			'ClazzName' => 'Class',
268 268
 			'Type' => 'Type',
269 269
 			'Searchable' => 'Use for Search?',
270 270
 			'SimilarSearchable' => 'Use for Similar Search?',
271 271
 			'ShowHighlights' => 'Show Search Highlights',
272 272
 			'Weight' => 'Weighting'
273
-        ));
273
+		));
274 274
 
275 275
 		return $fields;
276 276
 	}
277 277
 
278 278
 
279 279
 	public function getCMSValidator() {
280
-        return new ElasticSearchPage_Validator();
281
-    }
280
+		return new ElasticSearchPage_Validator();
281
+	}
282 282
 
283 283
 
284 284
 	/**
@@ -363,7 +363,7 @@  discard block
 block discarded – undo
363 363
 		$esfs = $this->ElasticaSearchableFields();
364 364
 
365 365
 		// Remove existing searchable fields for this page from the list of all available
366
-    	$delta = array_keys($esfs->map()->toArray());
366
+		$delta = array_keys($esfs->map()->toArray());
367 367
 		$newSearchableFields = $sfs->exclude('ID', $delta);
368 368
 
369 369
 		if ($newSearchableFields->count() > 0) {
@@ -453,7 +453,7 @@  discard block
 block discarded – undo
453 453
 		Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
454 454
 		Requirements::javascript("elastica/javascript/jquery.autocomplete.js");
455 455
 		Requirements::javascript("elastica/javascript/elastica.js");
456
-        Requirements::css("elastica/css/elastica.css");
456
+		Requirements::css("elastica/css/elastica.css");
457 457
 	}
458 458
 
459 459
 
@@ -532,9 +532,9 @@  discard block
 block discarded – undo
532 532
 
533 533
 		try {
534 534
 			// Simulate server being down for testing purposes
535
-	        if (isset($_GET['ServerDown'])) {
536
-	        	throw new Elastica\Exception\Connection\HttpException('Unable to reach search server');
537
-	        }
535
+			if (isset($_GET['ServerDown'])) {
536
+				throw new Elastica\Exception\Connection\HttpException('Unable to reach search server');
537
+			}
538 538
 			if (class_exists($class)) {
539 539
 				$instance = DataObject::get_by_id($class,$instanceID);
540 540
 
@@ -678,9 +678,9 @@  discard block
 block discarded – undo
678 678
 		$paginated = null;
679 679
 		try {
680 680
 			// Simulate server being down for testing purposes
681
-	        if (isset($_GET['ServerDown'])) {
682
-	        	throw new Elastica\Exception\Connection\HttpException('Unable to reach search server');
683
-	        }
681
+			if (isset($_GET['ServerDown'])) {
682
+				throw new Elastica\Exception\Connection\HttpException('Unable to reach search server');
683
+			}
684 684
 
685 685
 			// now actually perform the search using the original query
686 686
 			$paginated = $es->search($q, $fieldsToSearch, $testMode);
Please login to merge, or discard this patch.
Spacing   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -120,29 +120,29 @@  discard block
 block discarded – undo
120 120
 			'Default values are those used by Elastica'));
121 121
 		$fields->addFieldToTab("Root.Search.Similarity", $lf);
122 122
 		$fields->addFieldToTab("Root.Search.Similarity", new TextField('MinTermFreq',
123
-			'The minimum term frequency below which the terms will be ignored from the input '.
123
+			'The minimum term frequency below which the terms will be ignored from the input ' .
124 124
 			'document. Defaults to 2.'));
125 125
 		$fields->addFieldToTab("Root.Search.Similarity", new TextField('MaxTermFreq',
126
-			'The maximum number of query terms that will be selected. Increasing this value gives '.
126
+			'The maximum number of query terms that will be selected. Increasing this value gives ' .
127 127
 			'greater accuracy at the expense of query execution speed. Defaults to 25.'));
128 128
 		$fields->addFieldToTab("Root.Search.Similarity", new TextField('MinWordLength',
129 129
 			'The minimum word length below which the terms will be ignored.  Defaults to 0.'));
130 130
 		$fields->addFieldToTab("Root.Search.Similarity", new TextField('MinDocFreq',
131
-			'The minimum document frequency below which the terms will be ignored from the input '.
131
+			'The minimum document frequency below which the terms will be ignored from the input ' .
132 132
 			'document. Defaults to 5.'));
133 133
 		$fields->addFieldToTab("Root.Search.Similarity", new TextField('MaxDocFreq',
134
-			'The maximum document frequency above which the terms will be ignored from the input '.
135
-			'document. This could be useful in order to ignore highly frequent words such as stop '.
134
+			'The maximum document frequency above which the terms will be ignored from the input ' .
135
+			'document. This could be useful in order to ignore highly frequent words such as stop ' .
136 136
 			'words. Defaults to unbounded (0).'));
137 137
 		$fields->addFieldToTab("Root.Search.Similarity", new TextField('MinWordLength',
138
-			'The minimum word length below which the terms will be ignored. The old name min_'.
138
+			'The minimum word length below which the terms will be ignored. The old name min_' .
139 139
 			'word_len is deprecated. Defaults to 0.'));
140 140
 		$fields->addFieldToTab("Root.Search.Similarity", new TextField('MaxWordLength',
141
-			'The maximum word length above which the terms will be ignored. The old name max_word_'.
141
+			'The maximum word length above which the terms will be ignored. The old name max_word_' .
142 142
 			'len is deprecated. Defaults to unbounded (0).'));
143 143
 		$fields->addFieldToTab("Root.Search.Similarity", new TextField('MinShouldMatch',
144
-			'This parameter controls the number of terms that must match. This can be either a '.
145
-			'number or a percentage.  See '.
144
+			'This parameter controls the number of terms that must match. This can be either a ' .
145
+			'number or a percentage.  See ' .
146 146
 			'https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-minimum-should-match.html'));
147 147
 
148 148
 		// ---- search details tab ----
@@ -179,9 +179,9 @@  discard block
 block discarded – undo
179 179
 
180 180
 		$html = '<div class="field text" id="SiteTreeOnlyInfo">';
181 181
 		$html .= "<p>Copy the following into the above field to ensure that all SiteTree classes are searched</p>";
182
-		$html .= '<p class="message">'.$list;
182
+		$html .= '<p class="message">' . $list;
183 183
 		$html .= "</p></div>";
184
-		$infoField = new LiteralField('InfoField',$html);
184
+		$infoField = new LiteralField('InfoField', $html);
185 185
 		$fields->addFieldToTab('Root.Search.SearchFor', $infoField);
186 186
 
187 187
 		$fields->addFieldToTab('Root.Main', new HTMLEditorField('ContentForEmptySearch'));
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
         							setSource($ottos);
199 199
         $df->setEmptyString('-- Please select what do do after find as you type has occurred --');
200 200
 
201
-        $ottos = $this->ElasticaSearchableFields()->filter('EnableAutocomplete',1)->Map('ID', 'Name')->toArray();
201
+        $ottos = $this->ElasticaSearchableFields()->filter('EnableAutocomplete', 1)->Map('ID', 'Name')->toArray();
202 202
         $autoCompleteFieldDF = DropDownField::create('AutoCompleteFieldID', 'Field to use for autocomplete')->setSource($ottos);
203 203
         $autoCompleteFieldDF->setEmptyString('-- Please select which field to use for autocomplete --');
204 204
 
@@ -213,9 +213,9 @@  discard block
 block discarded – undo
213 213
 		 );
214 214
 		        // ---- grid of searchable fields ----
215 215
         		//$searchTabName = 'Root.'._t('SiteConfig.ELASTICA', 'Search');
216
-		$html = '<p id="SearchFieldIntro">'._t('SiteConfig.ELASTICA_SEARCH_INFO',
217
-				"Select a field to edit it's properties").'</p>';
218
-		$fields->addFieldToTab('Root.Search.Fields', $h1=new LiteralField('SearchInfo', $html));
216
+		$html = '<p id="SearchFieldIntro">' . _t('SiteConfig.ELASTICA_SEARCH_INFO',
217
+				"Select a field to edit it's properties") . '</p>';
218
+		$fields->addFieldToTab('Root.Search.Fields', $h1 = new LiteralField('SearchInfo', $html));
219 219
 		$searchPicker = new PickerField('ElasticaSearchableFields', 'Searchable Fields',
220 220
 			$this->ElasticaSearchableFields()->filter('Active', 1)->sort('Name')); //, 'Select Owner(s)', 'SortOrder');
221 221
 
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
 	public function validate() {
289 289
 		$result = parent::validate();
290 290
 		$mode = Versioned::get_reading_mode();
291
-		$suffix =  '';
291
+		$suffix = '';
292 292
 		if ($mode == 'Stage.Live') {
293 293
 			$suffix = '_Live';
294 294
 		}
@@ -297,17 +297,17 @@  discard block
 block discarded – undo
297 297
 			$result->error('The identifier cannot be blank');
298 298
 		}
299 299
 
300
-		$where = 'ElasticSearchPage'.$suffix.'.ID != '.$this->ID." AND `Identifier` = '{$this->Identifier}'";
300
+		$where = 'ElasticSearchPage' . $suffix . '.ID != ' . $this->ID . " AND `Identifier` = '{$this->Identifier}'";
301 301
 		$existing = ElasticSearchPage::get()->where($where)->count();
302 302
 		if ($existing > 0) {
303
-			$result->error('The identifier '.$this->Identifier.' already exists');
303
+			$result->error('The identifier ' . $this->Identifier . ' already exists');
304 304
 		}
305 305
 
306 306
 
307
-		error_log('CTS:'.$this->ClassesToSearch);
307
+		error_log('CTS:' . $this->ClassesToSearch);
308 308
 
309 309
 		// now check classes to search actually exist, assuming in site tree not set
310
-		error_log('STO:'.$this->SiteTreeOnly);
310
+		error_log('STO:' . $this->SiteTreeOnly);
311 311
 		if (!$this->SiteTreeOnly) {
312 312
 			if ($this->ClassesToSearch == '') {
313 313
 				$result->error('At least one searchable class must be available, or SiteTreeOnly flag set');
@@ -317,10 +317,10 @@  discard block
 block discarded – undo
317 317
 					try {
318 318
 						$instance = Injector::inst()->create($clazz);
319 319
 						if (!$instance->hasExtension('SilverStripe\Elastica\Searchable')) {
320
-							$result->error('The class '.$clazz.' must have the Searchable extension');
320
+							$result->error('The class ' . $clazz . ' must have the Searchable extension');
321 321
 						}
322 322
 					} catch (ReflectionException $e) {
323
-						$result->error('The class '.$clazz.' does not exist');
323
+						$result->error('The class ' . $clazz . ' does not exist');
324 324
 					}
325 325
 				}
326 326
 			}
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
 
369 369
 		if ($newSearchableFields->count() > 0) {
370 370
 			foreach ($newSearchableFields->getIterator() as $newSearchableField) {
371
-				error_log('NEW FIELD:'.$newSearchableField->Name);
371
+				error_log('NEW FIELD:' . $newSearchableField->Name);
372 372
 				$newSearchableField->Active = true;
373 373
 				$newSearchableField->Weight = 1;
374 374
 
@@ -376,7 +376,7 @@  discard block
 block discarded – undo
376 376
 
377 377
 				// Note 1 used instead of true for SQLite3 testing compatibility
378 378
 				$sql = "UPDATE ElasticSearchPage_ElasticaSearchableFields SET ";
379
-				$sql .= 'Active=1, Weight=1 WHERE ElasticSearchPageID = '.$this->ID;
379
+				$sql .= 'Active=1, Weight=1 WHERE ElasticSearchPageID = ' . $this->ID;
380 380
 				DB::query($sql);
381 381
 			}
382 382
 		}
@@ -423,7 +423,7 @@  discard block
 block discarded – undo
423 423
 			$q->setAttribute('data-autocomplete-field', 'Title');
424 424
 			$q->setAttribute('data-autocomplete-classes', $this->ClassesToSearch);
425 425
 			$q->setAttribute('data-autocomplete-sitetree', $this->SiteTreeOnly);
426
-			$q->setAttribute('data-autocomplete-source',$this->Link());
426
+			$q->setAttribute('data-autocomplete-source', $this->Link());
427 427
 			$q->setAttribute('data-autocomplete-function',
428 428
 			$this->AutocompleteFunction()->Slug);
429 429
 		}
@@ -445,7 +445,7 @@  discard block
 block discarded – undo
445 445
 
446 446
 class ElasticSearchPage_Controller extends Page_Controller {
447 447
 
448
-	private static $allowed_actions = array('SearchForm', 'submit','index','similar');
448
+	private static $allowed_actions = array('SearchForm', 'submit', 'index', 'similar');
449 449
 
450 450
 	public function init() {
451 451
 		parent::init();
@@ -522,7 +522,7 @@  discard block
 block discarded – undo
522 522
 		// Use the standard field for more like this, ie not stemmed
523 523
 		$standardFields = array();
524 524
 		foreach ($fieldsToSearch as $field => $value) {
525
-			$fieldsToSearch[$field.'.standard'] = $value;
525
+			$fieldsToSearch[$field . '.standard'] = $value;
526 526
 
527 527
 			//Experiment here with other fields to ad to similarity searching
528 528
 			//$fieldsToSearch[$field.'.shingles'] = $value;
@@ -536,7 +536,7 @@  discard block
 block discarded – undo
536 536
 	        	throw new Elastica\Exception\Connection\HttpException('Unable to reach search server');
537 537
 	        }
538 538
 			if (class_exists($class)) {
539
-				$instance = DataObject::get_by_id($class,$instanceID);
539
+				$instance = DataObject::get_by_id($class, $instanceID);
540 540
 
541 541
 				$paginated = $es->moreLikeThis($instance, $fieldsToSearch);
542 542
 
@@ -583,7 +583,7 @@  discard block
 block discarded – undo
583 583
 
584 584
 		// calculate time
585 585
 		$endTime = microtime(true);
586
-		$elapsed = round(100*($endTime-$startTime))/100;
586
+		$elapsed = round(100 * ($endTime - $startTime)) / 100;
587 587
 
588 588
 		// store variables for the template to use
589 589
 		$data['ElapsedTime'] = $elapsed;
@@ -637,11 +637,11 @@  discard block
 block discarded – undo
637 637
 		$testMode = isset($_GET['TestMode']);
638 638
 
639 639
 		// filters for aggregations
640
-		$ignore = array('url', 'start','q','is');
640
+		$ignore = array('url', 'start', 'q', 'is');
641 641
 		$ignore = \Config::inst()->get('Elastica', 'BlackList');
642 642
 		foreach ($this->request->getVars() as $key => $value) {
643 643
 			if (!in_array($key, $ignore)) {
644
-				$es->addFilter($key,$value);
644
+				$es->addFilter($key, $value);
645 645
 			}
646 646
 		}
647 647
 
@@ -691,7 +691,7 @@  discard block
 block discarded – undo
691 691
 				$data['SuggestedQuery'] = $es->getSuggestedQuery();
692 692
 				$data['SuggestedQueryHighlighted'] = $es->getSuggestedQueryHighlighted();
693 693
 				//Link for if the user really wants to try their original query
694
-				$sifLink = rtrim($this->Link(),'/').'?q='.$q.'&is=1';
694
+				$sifLink = rtrim($this->Link(), '/') . '?q=' . $q . '&is=1';
695 695
 				$data['SearchInsteadForLink'] = $sifLink;
696 696
 				$paginated = $es->search($es->getSuggestedQuery(), $fieldsToSearch);
697 697
 
@@ -699,7 +699,7 @@  discard block
 block discarded – undo
699 699
 
700 700
 			// calculate time
701 701
 			$endTime = microtime(true);
702
-			$elapsed = round(100*($endTime-$startTime))/100;
702
+			$elapsed = round(100 * ($endTime - $startTime)) / 100;
703 703
 
704 704
 			// store variables for the template to use
705 705
 			$data['ElapsedTime'] = $elapsed;
@@ -730,7 +730,7 @@  discard block
 block discarded – undo
730 730
 	 */
731 731
 	public function QueryIsEmpty() {
732 732
 		$result = !isset($_GET['q']);
733
-		if (isset($_GET['q']))	{
733
+		if (isset($_GET['q'])) {
734 734
 			$q = $_GET['q'];
735 735
 			if ($q == '') {
736 736
 				$result = true;
@@ -749,7 +749,7 @@  discard block
 block discarded – undo
749 749
 		$query = $data['q'];
750 750
 		$url = $this->Link();
751 751
 		$url = rtrim($url, '/');
752
-		$link = rtrim($url, '/').'?q='.$query.'&sfid='.$data['identifier'];
752
+		$link = rtrim($url, '/') . '?q=' . $query . '&sfid=' . $data['identifier'];
753 753
 		$this->redirect($link);
754 754
 	}
755 755
 
@@ -773,7 +773,7 @@  discard block
 block discarded – undo
773 773
 
774 774
 		}
775 775
 
776
-		if($this->action == 'similar') {
776
+		if ($this->action == 'similar') {
777 777
 			$q->setDisabled(true);
778 778
 			$actions = $form->Actions();
779 779
 			foreach ($actions as $field) {
@@ -789,7 +789,7 @@  discard block
 block discarded – undo
789 789
 			$q->setAttribute('data-autocomplete-field', 'Title');
790 790
 			$q->setAttribute('data-autocomplete-classes', $this->ClassesToSearch);
791 791
 			$q->setAttribute('data-autocomplete-sitetree', $this->SiteTreeOnly);
792
-			$q->setAttribute('data-autocomplete-source',$this->Link());
792
+			$q->setAttribute('data-autocomplete-source', $this->Link());
793 793
 			$q->setAttribute('data-autocomplete-function',
794 794
 			$this->AutocompleteFunction()->Slug);
795 795
 		}
Please login to merge, or discard this patch.
searchpage/ElasticSearchForm.php 2 patches
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -27,17 +27,17 @@  discard block
 block discarded – undo
27 27
 	 */
28 28
 	public function __construct($controller, $name, $fields = null, $actions = null) {
29 29
 		$searchText = isset($this->Query) ? $this->Query : '';
30
-        $fields = new FieldList(
31
-           $tf = new TextField("q", "", $searchText)
32
-        );
30
+		$fields = new FieldList(
31
+		   $tf = new TextField("q", "", $searchText)
32
+		);
33 33
 
34 34
 
35
-        $buttonText = _t('SearchPage.SEARCH', 'Search');
36
-        $actions = new FieldList(
37
-            $fa = new FormAction('submit', $buttonText)
38
-        );
35
+		$buttonText = _t('SearchPage.SEARCH', 'Search');
36
+		$actions = new FieldList(
37
+			$fa = new FormAction('submit', $buttonText)
38
+		);
39 39
 
40
-        $this->SubmitButton = $fa;
40
+		$this->SubmitButton = $fa;
41 41
 
42 42
 		if(class_exists('Translatable') && singleton('SiteTree')->hasExtension('Translatable')) {
43 43
 			$fields->push(new HiddenField('searchlocale', 'searchlocale', Translatable::get_current_locale()));
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 	 */
65 65
 	public function setButtonText($newButtonText) {
66 66
 		$this->actions = new FieldList(
67
-            $fa = new FormAction('submit', $newButtonText)
68
-        );
67
+			$fa = new FormAction('submit', $newButtonText)
68
+		);
69 69
 	}
70 70
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@
 block discarded – undo
39 39
 
40 40
         $this->SubmitButton = $fa;
41 41
 
42
-		if(class_exists('Translatable') && singleton('SiteTree')->hasExtension('Translatable')) {
42
+		if (class_exists('Translatable') && singleton('SiteTree')->hasExtension('Translatable')) {
43 43
 			$fields->push(new HiddenField('searchlocale', 'searchlocale', Translatable::get_current_locale()));
44 44
 		}
45 45
 
Please login to merge, or discard this patch.
tests/TranslatableSearchableTest.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@
 block discarded – undo
9 9
 	public function setUp() {
10 10
 		// this needs to be called in order to create the list of searchable
11 11
 		// classes and fields that are available.  Simulates part of a build
12
-		$classes = array('SearchableTestPage','SiteTree','Page','FlickrPhotoTO','FlickrSetTO',
12
+		$classes = array('SearchableTestPage', 'SiteTree', 'Page', 'FlickrPhotoTO', 'FlickrSetTO',
13 13
 			'FlickrTagTO', 'FlickrAuthorTO', 'FlickrSetTO');
14 14
 		$this->requireDefaultRecordsFrom = $classes;
15 15
 
Please login to merge, or discard this patch.