Completed
Branch dev2 (85bfa2)
by Gordon
06:36 queued 02:41
created
src/SilverStripe/Elastica/SearchIndexTask.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 	}
22 22
 
23 23
 	public function run($request) {
24
-		$message = function ($content) {
24
+		$message = function($content) {
25 25
 			print(\Director::is_cli() ? "$content\n" : "<p>$content</p>");
26 26
 		};
27 27
 
@@ -45,12 +45,12 @@  discard block
 block discarded – undo
45 45
 		$es->addFilter('IsInSiteTree', true);
46 46
 		$results = $es->search($query);
47 47
 		foreach ($results as $result) {
48
-			$title = '['.$result->ClassName.', '.$result->ID.']  ';
48
+			$title = '[' . $result->ClassName . ', ' . $result->ID . ']  ';
49 49
 			$title .= $result->Title;
50 50
 			$message($title);
51 51
 			if ($result->SearchHighlightsByField->Content) {
52 52
 				foreach ($result->SearchHighlightsByField->Content as $highlight) {
53
-					$message("- ".$highlight->Snippet);
53
+					$message("- " . $highlight->Snippet);
54 54
 				}
55 55
 			}
56 56
 
Please login to merge, or discard this patch.
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.
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -350,12 +350,12 @@  discard block
 block discarded – undo
350 350
 
351 351
 		if (isset($_GET['progress'])) {
352 352
 			$progress = $_GET['progress'];
353
-			self::$progressInterval = (int) $progress;
353
+			self::$progressInterval = (int)$progress;
354 354
 		}
355 355
 
356 356
 		if (self::$progressInterval > 0) {
357 357
 			if (self::$index_ctr % self::$progressInterval === 0) {
358
-				ElasticaUtil::message("\t".$this->owner->ClassName." - Prepared ".self::$index_ctr." for indexing...");
358
+				ElasticaUtil::message("\t" . $this->owner->ClassName . " - Prepared " . self::$index_ctr . " for indexing...");
359 359
 			}
360 360
 		}
361 361
 
@@ -404,7 +404,7 @@  discard block
 block discarded – undo
404 404
 
405 405
 			} else {
406 406
 				if (in_array($field, $this->html_fields)) {
407
-					$fields[$field] = $this->owner->$field;;
407
+					$fields[$field] = $this->owner->$field; ;
408 408
 					if (gettype($this->owner->$field) !== 'NULL') {
409 409
 						$html = ShortcodeParser::get_active()->parse($this->owner->$field);
410 410
 						$txt = \Convert::html2raw($html);
@@ -416,8 +416,8 @@  discard block
 block discarded – undo
416 416
 						$data = $this->owner->$methodName();
417 417
 						$relArray = array();
418 418
 
419
-						echo "METHOD NAME:".$methodName;
420
-						echo "\nDATA:".$data->ID."\n";
419
+						echo "METHOD NAME:" . $methodName;
420
+						echo "\nDATA:" . $data->ID . "\n";
421 421
 
422 422
 						// get the fields of a has_one relational object
423 423
 						if (isset($has_ones[$methodName])) {
@@ -550,14 +550,14 @@  discard block
 block discarded – undo
550 550
 	 * Removes the record from the search index.
551 551
 	 */
552 552
 	protected function doDeleteDocument() {
553
-		try{
553
+		try {
554 554
 			if (!$this->owner->IndexingOff) {
555 555
 				// this goes to elastica service
556 556
 				$this->service->remove($this->owner);
557 557
 			}
558 558
 		}
559
-		catch(\Elastica\Exception\NotFoundException $e) {
560
-			trigger_error("Deleted document ".$this->owner->ClassName." (".$this->owner->ID.
559
+		catch (\Elastica\Exception\NotFoundException $e) {
560
+			trigger_error("Deleted document " . $this->owner->ClassName . " (" . $this->owner->ID .
561 561
 				") not found in search index.", E_USER_NOTICE);
562 562
 		}
563 563
 
@@ -574,7 +574,7 @@  discard block
 block discarded – undo
574 574
 		$fields = \Config::inst()->get(get_class($this->owner), 'searchable_fields');
575 575
 
576 576
 		// fallback to default method
577
-		if(!$fields) user_error('The field $searchable_fields must be set for the class '.$this->owner->ClassName);
577
+		if (!$fields) user_error('The field $searchable_fields must be set for the class ' . $this->owner->ClassName);
578 578
 
579 579
 		// get the values of these fields
580 580
 		$elasticaMapping = $this->fieldsToElasticaConfig($this->owner, $fields);
@@ -595,24 +595,24 @@  discard block
 block discarded – undo
595 595
 
596 596
 						$relClass = $has_lists[$methodName];
597 597
 						$fields = \Config::inst()->get($relClass, 'searchable_fields');
598
-						if(!$fields) user_error('The field $searchable_fields must be set for the class '.$relClass);
598
+						if (!$fields) user_error('The field $searchable_fields must be set for the class ' . $relClass);
599 599
 						$rewrite = $this->fieldsToElasticaConfig($relClass, $fields);
600 600
 
601 601
 						// mark as a method, the resultant fields are correct
602
-						$elasticaMapping[$methodName.'()'] = $rewrite;
602
+						$elasticaMapping[$methodName . '()'] = $rewrite;
603 603
 
604 604
 
605 605
 					} else if (isset($has_ones[$methodName])) {
606 606
 						$relClass = $has_ones[$methodName];
607 607
 						$fields = \Config::inst()->get($relClass, 'searchable_fields');
608
-						if(!$fields) user_error('The field $searchable_fields must be set for the class '.$relClass);
608
+						if (!$fields) user_error('The field $searchable_fields must be set for the class ' . $relClass);
609 609
 						$rewrite = $this->fieldsToElasticaConfig($relClass, $fields);
610 610
 						$classname = $has_ones[$methodName];
611 611
 
612 612
 						// mark as a method, the resultant fields are correct
613
-						$elasticaMapping[$methodName.'()'] = $rewrite;
613
+						$elasticaMapping[$methodName . '()'] = $rewrite;
614 614
 					} else {
615
-						user_error('The method '.$methodName.' not found in class '.$this->owner->ClassName.
615
+						user_error('The method ' . $methodName . ' not found in class ' . $this->owner->ClassName .
616 616
 								', please check configuration');
617 617
 					}
618 618
 				}
@@ -632,14 +632,14 @@  discard block
 block discarded – undo
632 632
 		//print_r($fields);
633 633
 		// rewrite array, if it is using shorthand syntax
634 634
 		$rewrite = array();
635
-		foreach($fields as $name => $specOrName) {
635
+		foreach ($fields as $name => $specOrName) {
636 636
 			$identifer = (is_int($name)) ? $specOrName : $name;
637 637
 			$rewrite[$identifer] = array();
638
-			if(!isset($rewrite[$identifer]['title'])) {
638
+			if (!isset($rewrite[$identifer]['title'])) {
639 639
 				$rewrite[$identifer]['title'] = (isset($labels[$identifer]))
640 640
 					? $labels[$identifer] : \FormField::name_to_label($identifer);
641 641
 			}
642
-			if(!isset($rewrite[$identifer]['filter'])) {
642
+			if (!isset($rewrite[$identifer]['filter'])) {
643 643
 				$rewrite[$identifer]['filter'] = 'PartialMatchFilter';
644 644
 			}
645 645
 		}
@@ -654,7 +654,7 @@  discard block
 block discarded – undo
654 654
 	public function requireDefaultRecords() {
655 655
 		parent::requireDefaultRecords();
656 656
 
657
-		$searchableFields = $this->getElasticaFields(true,true);
657
+		$searchableFields = $this->getElasticaFields(true, true);
658 658
 
659 659
 
660 660
 		$doSC = \SearchableClass::get()->filter(array('Name' => $this->owner->ClassName))->first();
@@ -687,7 +687,7 @@  discard block
 block discarded – undo
687 687
 
688 688
 				if (isset($searchableField['type'])) {
689 689
 					$doSF->Type = $searchableField['type'];
690
-				}  else {
690
+				} else {
691 691
 					$doSF->Name = $searchableField['properties']['__method'];
692 692
 					$doSF->Type = 'relationship';
693 693
 				}
@@ -698,7 +698,7 @@  discard block
 block discarded – undo
698 698
 				}
699 699
 
700 700
 				$doSF->write();
701
-				\DB::alteration_message("Created new searchable editable field ".$name,"changed");
701
+				\DB::alteration_message("Created new searchable editable field " . $name, "changed");
702 702
 			}
703 703
 
704 704
 			// FIXME deal with deletions
@@ -743,7 +743,7 @@  discard block
 block discarded – undo
743 743
 	 */
744 744
 	public function RenderResult($linkToContainer = '') {
745 745
 		$vars = new \ArrayData(array('SearchResult' => $this->owner, 'ContainerLink' => $linkToContainer));
746
-		$possibleTemplates = array($this->owner->ClassName.'ElasticSearchResult', 'ElasticSearchResult');
746
+		$possibleTemplates = array($this->owner->ClassName . 'ElasticSearchResult', 'ElasticSearchResult');
747 747
 		return $this->owner->customise($vars)->renderWith($possibleTemplates);
748 748
 	}
749 749
 
@@ -809,14 +809,14 @@  discard block
 block discarded – undo
809 809
 		       $underscored = str_replace('.', '_', $field);
810 810
 
811 811
 		        $gridField = new \GridField(
812
-		            'TermsFor'.$underscored, // Field name
813
-		            $field.'TITLE'.$field, // Field title
812
+		            'TermsFor' . $underscored, // Field name
813
+		            $field . 'TITLE' . $field, // Field title
814 814
 		            $terms,
815 815
 		            $config
816 816
 		        );
817 817
 
818 818
 		      // $tab = new \Tab($field, new \TextField('Test'.$field, 'Testing'));
819
-		       $fields->addFieldToTab('Root.ElasticaTerms.'.$underscored, $gridField);
819
+		       $fields->addFieldToTab('Root.ElasticaTerms.' . $underscored, $gridField);
820 820
 			}
821 821
 
822 822
 		}
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.
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.