Completed
Push — dev2 ( 76a09a...1cd385 )
by Gordon
14:51
created
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   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -202,16 +202,16 @@  discard block
 block discarded – undo
202 202
 		$paginated = $es->search($query, $fields);
203 203
 		$ctr = 0;
204 204
 
205
-		foreach ($paginated->getList()->toArray() as $result) {
205
+		foreach($paginated->getList()->toArray() as $result) {
206 206
 			$ctr++;
207
-			foreach ($result->SearchHighlightsByField->Description_standard->getIterator() as $highlight) {
207
+			foreach($result->SearchHighlightsByField->Description_standard->getIterator() as $highlight) {
208 208
 				$snippet = $highlight->Snippet;
209 209
 				$snippet = strtolower($snippet);
210 210
 				$wordFound = false;
211 211
 				$lcquery = explode(' ', strtolower($query));
212
-				foreach ($lcquery as $part) {
212
+				foreach($lcquery as $part) {
213 213
 					$bracketed = '<strong class="hl">' . $part . '</strong>';
214
-					if (strpos($snippet, $bracketed) > 0) {
214
+					if(strpos($snippet, $bracketed) > 0) {
215 215
 						$wordFound = true;
216 216
 					}
217 217
 				}
@@ -231,17 +231,17 @@  discard block
 block discarded – undo
231 231
 		$paginated = $es->search($query, $fields);
232 232
 		$ctr = 0;
233 233
 
234
-		foreach ($paginated->getList()->toArray() as $result) {
234
+		foreach($paginated->getList()->toArray() as $result) {
235 235
 			$ctr++;
236 236
 
237
-			foreach ($result->SearchHighlightsByField->Description->getIterator() as $highlight) {
237
+			foreach($result->SearchHighlightsByField->Description->getIterator() as $highlight) {
238 238
 				$snippet = $highlight->Snippet;
239 239
 				$snippet = strtolower($snippet);
240 240
 				$wordFound = false;
241 241
 				$lcquery = explode(' ', strtolower($query));
242
-				foreach ($lcquery as $part) {
242
+				foreach($lcquery as $part) {
243 243
 					$bracketed = '<strong class="hl">' . $part . '</strong>';
244
-					if (strpos($snippet, $bracketed) > 0) {
244
+					if(strpos($snippet, $bracketed) > 0) {
245 245
 						$wordFound = true;
246 246
 					}
247 247
 				}
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
 		$query = 'Lond';
259 259
 		$results = $es->autocomplete_search($query, 'Title');
260 260
 		$this->assertEquals(7, $results->getTotalItems());
261
-		foreach ($results->toArray() as $result) {
261
+		foreach($results->toArray() as $result) {
262 262
 			$this->assertTrue(strpos($result->Title, $query) > 0);
263 263
 		}
264 264
 	}
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
 		$results = $paginated->getList()->toArray();
269 269
 		$ctr = 0;
270 270
 		echo '$result = $paginated->getList()->toArray();' . "\n";
271
-		foreach ($results as $result) {
271
+		foreach($results as $result) {
272 272
 			echo '$this->assertEquals("' . $result->Title . '", $results[' . $ctr . ']->Title);' . "\n";
273 273
 			$ctr++;
274 274
 		}
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.
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.
src/SilverStripe/Elastica/ReindexTask.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -27,13 +27,13 @@  discard block
 block discarded – undo
27 27
 	*/
28 28
 
29 29
 	public function run($request) {
30
-		$message = function ($content) {
30
+		$message = function($content) {
31 31
 			print(\Director::is_cli() ? "$content\n" : "<p>$content</p>");
32 32
 		};
33 33
 
34 34
 		$locales = array();
35 35
 		if(class_exists('Translatable') && singleton('SiteTree')->hasExtension('Translatable')) {
36
-			foreach (\Translatable::get_existing_content_languages('SiteTree') as $code => $val) {
36
+			foreach(\Translatable::get_existing_content_languages('SiteTree') as $code => $val) {
37 37
 				array_push($locales, $code);
38 38
 			}
39 39
 		} else {
@@ -41,11 +41,11 @@  discard block
 block discarded – undo
41 41
 		}
42 42
 
43 43
 		// now iterate all the locales indexing each locale in turn using it's owner index settings
44
-		foreach ($locales as $locale) {
44
+		foreach($locales as $locale) {
45 45
 			Searchable::$index_ctr = 0;
46
-			$message('Indexing locale '.$locale);
46
+			$message('Indexing locale ' . $locale);
47 47
 
48
-			if (class_exists('Translatable')) {
48
+			if(class_exists('Translatable')) {
49 49
 				\Translatable::set_current_locale($locale);
50 50
 			}
51 51
 
@@ -62,10 +62,10 @@  discard block
 block discarded – undo
62 62
 			$this->service->refresh();
63 63
 			// display indexing speed stats
64 64
 			$endTime = microtime(true);
65
-			$elapsed = $endTime-$startTime;
65
+			$elapsed = $endTime - $startTime;
66 66
 			$perSecond = Searchable::$index_ctr / $elapsed;
67
-			$info = "\nReindexing $locale completed \n ".Searchable::$index_ctr." docs in ".round($elapsed,2)." seconds ";
68
-			$info .= "at ".round($perSecond,2)." documents per second\n\n";
67
+			$info = "\nReindexing $locale completed \n " . Searchable::$index_ctr . " docs in " . round($elapsed, 2) . " seconds ";
68
+			$info .= "at " . round($perSecond, 2) . " documents per second\n\n";
69 69
 			$message($info);
70 70
 		}
71 71
 
Please login to merge, or discard this patch.
src/SilverStripe/Elastica/SearchIndexTask.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -21,17 +21,17 @@  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
 
28 28
 		$locales = array();
29 29
 
30
-		if ($this->locale == null) {
31
-			if (class_exists('Translatable') && \SiteTree::has_extension('Translatable')) {
30
+		if($this->locale == null) {
31
+			if(class_exists('Translatable') && \SiteTree::has_extension('Translatable')) {
32 32
 				$this->locale = \Translatable::get_current_locale();
33 33
 			} else {
34
-				foreach (\Translatable::get_existing_content_languages('SiteTree') as $code => $val) {
34
+				foreach(\Translatable::get_existing_content_languages('SiteTree') as $code => $val) {
35 35
 					array_push($locales, $code);
36 36
 				}
37 37
 			}
@@ -44,13 +44,13 @@  discard block
 block discarded – undo
44 44
 		$es->setPageLength(20);
45 45
 		$es->addFilter('IsInSiteTree', true);
46 46
 		$results = $es->search($query);
47
-		foreach ($results as $result) {
48
-			$title = '['.$result->ClassName.', '.$result->ID.']  ';
47
+		foreach($results as $result) {
48
+			$title = '[' . $result->ClassName . ', ' . $result->ID . ']  ';
49 49
 			$title .= $result->Title;
50 50
 			$message($title);
51
-			if ($result->SearchHighlightsByField->Content) {
52
-				foreach ($result->SearchHighlightsByField->Content as $highlight) {
53
-					$message("- ".$highlight->Snippet);
51
+			if($result->SearchHighlightsByField->Content) {
52
+				foreach($result->SearchHighlightsByField->Content as $highlight) {
53
+					$message("- " . $highlight->Snippet);
54 54
 				}
55 55
 			}
56 56
 
Please login to merge, or discard this patch.
tests/SearchableFieldTest.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 
16 16
 		$fields = $sf->getCMSFields();
17 17
 
18
-		$tab = $this->checkTabExists($fields,'Main');
18
+		$tab = $this->checkTabExists($fields, 'Main');
19 19
 
20 20
 		//Check fields
21 21
 		$nf = $this->checkFieldExists($tab, 'Name');
@@ -33,8 +33,8 @@  discard block
 block discarded – undo
33 33
 		$extraFields = array('Searchable' => 1, 'SimilarSearchable' => 1, 'Active' => 1,
34 34
 			'Weight' => 0);
35 35
 		$esfs = $searchPage->ElasticaSearchableFields();
36
-		foreach ($esfs as $sf) {
37
-			if ($sf->Name == 'Title' || $sf->Name == 'Description') {
36
+		foreach($esfs as $sf) {
37
+			if($sf->Name == 'Title' || $sf->Name == 'Description') {
38 38
 				$esfs->remove($sf);
39 39
 				$esfs->add($sf, $extraFields);
40 40
 			}
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 			$this->fail('Searchable fail should have failed to write');
46 46
 		} catch (ValidationException $e) {
47 47
 			$this->assertInstanceOf('ValidationException', $e);
48
-			$expected = 'The field SearchableTestPage.Title has a zero weight. ; The field '.
48
+			$expected = 'The field SearchableTestPage.Title has a zero weight. ; The field ' .
49 49
 			'SiteTree.Title has a zero weight. ; The field Page.Title has a zero weight. ';
50 50
 			$this->assertEquals($expected, $e->getMessage());
51 51
 		}
@@ -64,8 +64,8 @@  discard block
 block discarded – undo
64 64
 		$extraFields = array('Searchable' => 1, 'SimilarSearchable' => 1, 'Active' => 1,
65 65
 			'Weight' => -1);
66 66
 		$esfs = $searchPage->ElasticaSearchableFields();
67
-		foreach ($esfs as $sf) {
68
-			if ($sf->Name == 'Title' || $sf->Name == 'Description') {
67
+		foreach($esfs as $sf) {
68
+			if($sf->Name == 'Title' || $sf->Name == 'Description') {
69 69
 				$esfs->remove($sf);
70 70
 				$esfs->add($sf, $extraFields);
71 71
 			}
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
 			$this->fail('Searchable fail should have failed to write');
77 77
 		} catch (ValidationException $e) {
78 78
 			$this->assertInstanceOf('ValidationException', $e);
79
-			$expected = 'The field SearchableTestPage.Title has a negative weight. ; The field '.
79
+			$expected = 'The field SearchableTestPage.Title has a negative weight. ; The field ' .
80 80
 			'SiteTree.Title has a negative weight. ; The field Page.Title has a negative weight. ';
81 81
 			$this->assertEquals($expected, $e->getMessage());
82 82
 		}
Please login to merge, or discard this patch.