Completed
Push — dev2 ( 4b4116...f1c508 )
by Gordon
03:48
created
src/SilverStripe/Elastica/ElasticaSearcher.php 2 patches
Doc Comments   +14 added lines, -3 removed lines patch added patch discarded remove patch
@@ -230,6 +230,10 @@  discard block
 block discarded – undo
230 230
 	/*
231 231
 	Set the highlight fields for subsequent searches
232 232
 	 */
233
+
234
+	/**
235
+	 * @param string[] $newHighlightedFields
236
+	 */
233 237
 	public function setHighlightedFields($newHighlightedFields) {
234 238
 		$this->highlightedFields = $newHighlightedFields;
235 239
 	}
@@ -242,7 +246,7 @@  discard block
 block discarded – undo
242 246
 	 * @param  string $queryText query string, e.g. 'New Zealand'
243 247
 	 * @param array $fieldsToSearch Mapping of name to an array of mapping Weight and Elastic mapping,
244 248
 	 *                              e.g. array('Title' => array('Weight' => 2, 'Type' => 'string'))
245
-	 * @return ArrayList    SilverStripe DataObjects returned from the search against ElasticSearch
249
+	 * @return \PaginatedList    SilverStripe DataObjects returned from the search against ElasticSearch
246 250
 	 */
247 251
 	public function search($queryText, $fieldsToSearch = null,  $testMode = false) {
248 252
 		if ($this->locale == null) {
@@ -307,6 +311,10 @@  discard block
 block discarded – undo
307 311
 
308 312
 
309 313
 	/* Perform an autocomplete search */
314
+
315
+	/**
316
+	 * @param string $queryText
317
+	 */
310 318
 	public function autocomplete_search($queryText, $field) {
311 319
 		if ($this->locale == null) {
312 320
 			if (class_exists('Translatable') && \SiteTree::has_extension('Translatable')) {
@@ -358,11 +366,11 @@  discard block
 block discarded – undo
358 366
 
359 367
 	/**
360 368
 	 * Perform a 'More Like This' search, aka relevance feedback, using the provided indexed DataObject
361
-	 * @param  DataObject $indexedItem A DataObject that has been indexed in Elasticsearch
369
+	 * @param  \DataObject|null $indexedItem A DataObject that has been indexed in Elasticsearch
362 370
 	 * @param  array $fieldsToSearch  array of fieldnames to search, mapped to weighting
363 371
 	 * @param  $$testMode Use all shards, not just one, for consistent results during unit testing. See
364 372
 	 *         https://www.elastic.co/guide/en/elasticsearch/guide/current/relevance-is-broken.html#relevance-is-broken
365
-	 * @return resultList  List of results
373
+	 * @return \PaginatedList  List of results
366 374
 	 */
367 375
 	public function moreLikeThis($indexedItem, $fieldsToSearch, $testMode = false) {
368 376
 		echo "INDEXED ITEM:".$indexedItem;
@@ -469,6 +477,9 @@  discard block
 block discarded – undo
469 477
 		return $result;
470 478
 	}
471 479
 
480
+	/**
481
+	 * @return string
482
+	 */
472 483
 	public function getSuggestedQuery() {
473 484
 		return $this->SuggestedQuery;
474 485
 	}
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
 	 *                              e.g. array('Title' => array('Weight' => 2, 'Type' => 'string'))
245 245
 	 * @return ArrayList    SilverStripe DataObjects returned from the search against ElasticSearch
246 246
 	 */
247
-	public function search($queryText, $fieldsToSearch = null,  $testMode = false) {
247
+	public function search($queryText, $fieldsToSearch = null, $testMode = false) {
248 248
 		if ($this->locale == null) {
249 249
 			if (class_exists('Translatable') && \SiteTree::has_extension('Translatable')) {
250 250
 				$this->locale = \Translatable::get_current_locale();
@@ -365,14 +365,14 @@  discard block
 block discarded – undo
365 365
 	 * @return resultList  List of results
366 366
 	 */
367 367
 	public function moreLikeThis($indexedItem, $fieldsToSearch, $testMode = false) {
368
-		echo "INDEXED ITEM:".$indexedItem;
368
+		echo "INDEXED ITEM:" . $indexedItem;
369 369
 
370 370
 		if ($indexedItem == null) {
371 371
 			throw new \InvalidArgumentException('A searchable item cannot be null');
372 372
 		}
373 373
 
374 374
 		if (!$indexedItem->hasExtension('SilverStripe\Elastica\Searchable')) {
375
-			throw new \InvalidArgumentException('Objects of class '.$indexedItem->ClassName.' are not searchable');
375
+			throw new \InvalidArgumentException('Objects of class ' . $indexedItem->ClassName . ' are not searchable');
376 376
 		}
377 377
 
378 378
 		if ($fieldsToSearch == null) {
@@ -396,7 +396,7 @@  discard block
 block discarded – undo
396 396
 			if (!is_numeric($weighting)) {
397 397
 				throw new \InvalidArgumentException('Fields must be of the form fieldname => weight');
398 398
 			}
399
-			$weightedField = $field.'^'.$weighting;
399
+			$weightedField = $field . '^' . $weighting;
400 400
 			$weightedField = str_replace('^1', '', $weightedField);
401 401
 			array_push($weightedFieldsArray, $weightedField);
402 402
 		}
Please login to merge, or discard this patch.
src/SilverStripe/Elastica/ElasticaService.php 1 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 (!$empty($types)) {
198
-        	foreach($types as $type) {
199
-        		$search->addType($type);
200
-        	}
201
-        }
197
+		if (!$empty($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.