Completed
Push — dev2 ( 1ebec9...91be19 )
by Gordon
03:33
created
searchpage/ElasticSearchForm.php 1 patch
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.
tests/ElasticSearcherUnitTest.php 2 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -233,6 +233,9 @@
 block discarded – undo
233 233
 
234 234
 
235 235
 
236
+	/**
237
+	 * @param PaginatedList $paginated
238
+	 */
236 239
 	private function makeCode($paginated) {
237 240
 		$results = $paginated->getList()->toArray();
238 241
 		$ctr = 0;
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
 		$results = $es->moreLikeThis($fp, $fields, true);
50 50
 
51 51
 		echo "RESULTS:\n";
52
-		foreach ($results as $result) {
52
+		foreach($results as $result) {
53 53
 			echo "-\t{$result->Title}\n";
54 54
 		}
55 55
 
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
 		$es->setClasses('FlickrPhotoTO');
130 130
 		$fields = array('Title.standard' => 1, 'Description.standard' => 1);
131 131
 		$paginated = $es->moreLikeThis($fp, $fields, true);
132
-		foreach ($paginated->getList() as $result) {
132
+		foreach($paginated->getList() as $result) {
133 133
 			echo $result->ID . ' : ' . $result->Title . "\n";
134 134
 		}
135 135
 		$this->assertEquals(32, $paginated->getTotalItems());
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
 		$es->setClasses('FlickrPhotoTO');
156 156
 		$fields = array('Title.standard' => 1, 'Description.standard' => 1);
157 157
 		$paginated = $es->moreLikeThis($fp, $fields, true);
158
-		foreach ($paginated->getList() as $result) {
158
+		foreach($paginated->getList() as $result) {
159 159
 			echo $result->ID . ' : ' . $result->Title . "\n";
160 160
 		}
161 161
 		$this->assertEquals(14, $paginated->getTotalItems());
@@ -211,16 +211,16 @@  discard block
 block discarded – undo
211 211
 		$paginated = $es->search($query, $fields);
212 212
 		$ctr = 0;
213 213
 
214
-		foreach ($paginated->getList()->toArray() as $result) {
214
+		foreach($paginated->getList()->toArray() as $result) {
215 215
 			$ctr++;
216
-			foreach ($result->SearchHighlightsByField->Description_standard->getIterator() as $highlight) {
216
+			foreach($result->SearchHighlightsByField->Description_standard->getIterator() as $highlight) {
217 217
 				$snippet = $highlight->Snippet;
218 218
 				$snippet = strtolower($snippet);
219 219
 				$wordFound = false;
220 220
 				$lcquery = explode(' ', strtolower($query));
221
-				foreach ($lcquery as $part) {
221
+				foreach($lcquery as $part) {
222 222
 					$bracketed = '<strong class="hl">' . $part . '</strong>';
223
-					if (strpos($snippet, $bracketed) > 0) {
223
+					if(strpos($snippet, $bracketed) > 0) {
224 224
 						$wordFound = true;
225 225
 					}
226 226
 				}
@@ -240,17 +240,17 @@  discard block
 block discarded – undo
240 240
 		$paginated = $es->search($query, $fields);
241 241
 		$ctr = 0;
242 242
 
243
-		foreach ($paginated->getList()->toArray() as $result) {
243
+		foreach($paginated->getList()->toArray() as $result) {
244 244
 			$ctr++;
245 245
 
246
-			foreach ($result->SearchHighlightsByField->Description->getIterator() as $highlight) {
246
+			foreach($result->SearchHighlightsByField->Description->getIterator() as $highlight) {
247 247
 				$snippet = $highlight->Snippet;
248 248
 				$snippet = strtolower($snippet);
249 249
 				$wordFound = false;
250 250
 				$lcquery = explode(' ', strtolower($query));
251
-				foreach ($lcquery as $part) {
251
+				foreach($lcquery as $part) {
252 252
 					$bracketed = '<strong class="hl">' . $part . '</strong>';
253
-					if (strpos($snippet, $bracketed) > 0) {
253
+					if(strpos($snippet, $bracketed) > 0) {
254 254
 						$wordFound = true;
255 255
 					}
256 256
 				}
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
 		$query = 'Lond';
268 268
 		$results = $es->autocomplete_search($query, 'Title');
269 269
 		$this->assertEquals(7, $results->getTotalItems());
270
-		foreach ($results->toArray() as $result) {
270
+		foreach($results->toArray() as $result) {
271 271
 			$this->assertTrue(strpos($result->Title, $query) > 0);
272 272
 		}
273 273
 	}
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
 		$results = $paginated->getList()->toArray();
278 278
 		$ctr = 0;
279 279
 		echo '$result = $paginated->getList()->toArray();' . "\n";
280
-		foreach ($results as $result) {
280
+		foreach($results as $result) {
281 281
 			echo '$this->assertEquals("' . $result->Title . '", $results[' . $ctr . ']->Title);' . "\n";
282 282
 			$ctr++;
283 283
 		}
Please login to merge, or discard this patch.
tests/SearchableTest.php 1 patch
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -479,6 +479,9 @@
 block discarded – undo
479 479
 	}
480 480
 
481 481
 
482
+	/**
483
+	 * @param string $query
484
+	 */
482 485
 	private function getResultsFor($query, $pageLength = 10, $fields = array('Title' => 1, 'Description' => 1)) {
483 486
 		$es = new ElasticSearcher();
484 487
 		$es->setStart(0);
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.
src/SilverStripe/Elastica/ElasticaService.php 1 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.
code/AutoCompleteOption.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 		parent::requireDefaultRecords();
28 28
 
29 29
 		$similar = AutoCompleteOption::get()->filter('Name', 'Similar')->first();
30
-		if (!$similar) {
30
+		if(!$similar) {
31 31
 			$similar = new AutoCompleteOption();
32 32
 			$similar->Name = 'Similar';
33 33
 			$similar->Slug = 'SIMILAR';
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 		}
38 38
 
39 39
 		$search = AutoCompleteOption::get()->filter('Name', 'Search')->first();
40
-		if (!$search) {
40
+		if(!$search) {
41 41
 			$search = new AutoCompleteOption();
42 42
 			$search->Name = 'Search';
43 43
 			$search->Description = 'Find records similar to the selected item';
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 		}
48 48
 
49 49
 		$goto = AutoCompleteOption::get()->filter('Name', 'GoToRecord')->first();
50
-		if (!$goto) {
50
+		if(!$goto) {
51 51
 			$goto = new AutoCompleteOption();
52 52
 			$goto->Name = 'GoToRecord';
53 53
 			$goto->Description = 'Go to the page of the selected item, found by the Link() method';
Please login to merge, or discard this patch.
code/ElasticaAutoCompleteController.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -20,24 +20,24 @@
 block discarded – undo
20 20
 		// Makes most sense to only provide one field here, e.g. Title, Name
21 21
 		$field = $this->request->getVar('field');
22 22
 
23
-		error_log('QUERY:'.$query);
23
+		error_log('QUERY:' . $query);
24 24
 
25 25
 		// start, and page length, i.e. pagination
26 26
 		$es->setPageLength(10);
27
-		if ($classes) {
27
+		if($classes) {
28 28
 			$es->setClasses($classes);
29 29
 		}
30 30
 
31
-		if ($filter) {
31
+		if($filter) {
32 32
 			$es->addFilter('InSiteTree', true);
33 33
 		}
34 34
 
35
-		$resultList = $es->autocomplete_search($query,$field);
35
+		$resultList = $es->autocomplete_search($query, $field);
36 36
 		$result = array();
37 37
 		$result['Query'] = $query;
38 38
 		$suggestions = array();
39 39
 
40
-		foreach ($resultList->getResults() as $singleResult) {
40
+		foreach($resultList->getResults() as $singleResult) {
41 41
 			$suggestion = array('value' => $singleResult->Title);
42 42
 			$suggestion['data'] = array(
43 43
 				'ID' => $singleResult->getParam('_id'),
Please login to merge, or discard this patch.
searchpage/ElasticSearchPage_Validator.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 		//return false;
23 23
 		//
24 24
 
25
-		if ($data['ClassesToSearch'] == array()) {
25
+		if($data['ClassesToSearch'] == array()) {
26 26
 			$data['ClassesToSearch'] = '';
27 27
 		}
28 28
 
@@ -30,8 +30,8 @@  discard block
 block discarded – undo
30 30
 		echo "STDATA:$debug\n";
31 31
 
32 32
 		// Check if any classes to search if site tree only is not ticked
33
-		if (!$data['SiteTreeOnly']) {
34
-			if (!$data['ClassesToSearch']) {
33
+		if(!$data['SiteTreeOnly']) {
34
+			if(!$data['ClassesToSearch']) {
35 35
 				$valid = false;
36 36
 				$this->validationError("ClassesToSearch",
37 37
 					"Please provide at least one class to search, or select 'Site Tree Only'",
@@ -39,15 +39,15 @@  discard block
 block discarded – undo
39 39
 				);
40 40
 			} else {
41 41
 				$toSearch = $data['ClassesToSearch'];
42
-				foreach ($toSearch as $clazz) {
42
+				foreach($toSearch as $clazz) {
43 43
 					try {
44 44
 						$instance = Injector::inst()->create($clazz);
45
-						if (!$instance->hasExtension('SilverStripe\Elastica\Searchable')) {
46
-							$this->validationError('ClassesToSearch', 'The class '.$clazz.' must have the Searchable extension');
45
+						if(!$instance->hasExtension('SilverStripe\Elastica\Searchable')) {
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,23 +58,23 @@  discard block
 block discarded – undo
58 58
 
59 59
 		// Check the identifier is unique
60 60
 		$mode = Versioned::get_reading_mode();
61
-		$suffix =  '';
62
-		if ($mode == 'Stage.Live') {
61
+		$suffix = '';
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
-		if ($existing > 0) {
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
 		}
74 74
 
75 75
 
76 76
 		// Check number of results per page >= 1
77
-		if ($data['ResultsPerPage'] <= 0) {
77
+		if($data['ResultsPerPage'] <= 0) {
78 78
 			$valid = false;
79 79
 			$this->validationError('ResultsPerPage',
80 80
 				'Results per page must be >=1'
Please login to merge, or discard this patch.
src/SilverStripe/Elastica/FindElasticaSearchPageExtension.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
 
13 13
 		$searchPage = $this->getSearchPage($identifier);
14 14
 
15
-		if ($searchPage) {
15
+		if($searchPage) {
16 16
 			$result = $searchPage->AbsoluteLink();
17 17
 		}
18 18
 		return $result;
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 
25 25
 		$searchPage = $this->getSearchPage($identifier);
26 26
 
27
-		if ($searchPage) {
27
+		if($searchPage) {
28 28
 			$result = $searchPage->SearchForm($buttonTextOverride);
29 29
 		}
30 30
 		return $result;
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
 
33 33
 
34 34
 	public function getSearchPage($identifier) {
35
-		if (!isset($this->_CachedLastEdited)) {
35
+		if(!isset($this->_CachedLastEdited)) {
36 36
 			$this->_CachedLastEdited = ElasticSearchPage::get()->max('LastEdited');
37 37
 		}
38 38
 		$ck = $this->_CachedLastEdited;
@@ -42,10 +42,10 @@  discard block
 block discarded – undo
42 42
 
43 43
 		$cache = SS_Cache::factory('searchpagecache');
44 44
 		$searchPage = null;
45
-		$cachekeyname = 'searchpageuri'.$identifier.$this->owner->Locale.$ck;
45
+		$cachekeyname = 'searchpageuri' . $identifier . $this->owner->Locale . $ck;
46 46
 
47 47
 		if(!($searchPage = unserialize($cache->load($cachekeyname)))) {
48
-			$searchPage = ElasticSearchPage::get()->filter('Identifier',$identifier)->first();
48
+			$searchPage = ElasticSearchPage::get()->filter('Identifier', $identifier)->first();
49 49
 			$cache->save(serialize($searchPage), $cachekeyname);
50 50
 		}
51 51
 		return $searchPage;
Please login to merge, or discard this patch.