@@ -230,6 +230,10 @@ discard block |
||
| 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 |
||
| 242 | 246 | * @param string $q 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($q, $fieldsToSearch = null, $testMode = false) { |
| 248 | 252 | if ($this->locale == null) { |
@@ -307,6 +311,10 @@ discard block |
||
| 307 | 311 | |
| 308 | 312 | |
| 309 | 313 | /* Perform an autocomplete search */ |
| 314 | + |
|
| 315 | + /** |
|
| 316 | + * @param string $q |
|
| 317 | + */ |
|
| 310 | 318 | public function autocomplete_search($q, $field) { |
| 311 | 319 | if ($this->locale == null) { |
| 312 | 320 | if (class_exists('Translatable') && \SiteTree::has_extension('Translatable')) { |
@@ -358,11 +366,11 @@ discard block |
||
| 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 |
||
| 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 | } |
@@ -434,11 +434,11 @@ discard block |
||
| 434 | 434 | |
| 435 | 435 | |
| 436 | 436 | |
| 437 | - $query = new Query(); |
|
| 438 | - $query->setParams(array('query' => array('more_like_this' => $mlt))); |
|
| 437 | + $query = new Query(); |
|
| 438 | + $query->setParams(array('query' => array('more_like_this' => $mlt))); |
|
| 439 | 439 | |
| 440 | 440 | |
| 441 | - $elasticService = \Injector::inst()->create('SilverStripe\Elastica\ElasticaService'); |
|
| 441 | + $elasticService = \Injector::inst()->create('SilverStripe\Elastica\ElasticaService'); |
|
| 442 | 442 | $elasticService->setLocale($this->locale); |
| 443 | 443 | if ($testMode) { |
| 444 | 444 | $elasticService->setTestMode(true); |
@@ -450,7 +450,7 @@ discard block |
||
| 450 | 450 | $query->setFrom($this->start); |
| 451 | 451 | |
| 452 | 452 | $resultList = new ResultList($elasticService, $query, null); |
| 453 | - // at this point ResultList object, not yet executed search query |
|
| 453 | + // at this point ResultList object, not yet executed search query |
|
| 454 | 454 | $paginated = new \PaginatedList( |
| 455 | 455 | $resultList |
| 456 | 456 | ); |
@@ -244,7 +244,7 @@ discard block |
||
| 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($q, $fieldsToSearch = null, $testMode = false) { |
|
| 247 | + public function search($q, $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 |
||
| 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 |
||
| 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 | } |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | /** |
| 5 | 5 | * Alter the query or add to it, perhaps for example adding aggregation |
| 6 | 6 | * @param Elastic\Query &$query query object from Elastica |
| 7 | - * @return [type] [description] |
|
| 7 | + * @return void [description] |
|
| 8 | 8 | */ |
| 9 | 9 | public function augmentQuery(&$query); |
| 10 | 10 | |
@@ -12,6 +12,7 @@ discard block |
||
| 12 | 12 | * Update filters, perhaps remaps them, prior to performing a search. |
| 13 | 13 | * This allows for aggregation values to be updated prior to rendering. |
| 14 | 14 | * @param array &$filters array of key/value pairs for query filtering |
| 15 | + * @return void |
|
| 15 | 16 | */ |
| 16 | 17 | public function updateFilters(&$filters); |
| 17 | 18 | |
@@ -19,7 +20,7 @@ discard block |
||
| 19 | 20 | * Manipulate the array of aggregations post search butprior to rendering |
| 20 | 21 | * them in a template. |
| 21 | 22 | * @param [type] &$aggs [description] |
| 22 | - * @return [type] [description] |
|
| 23 | + * @return void [description] |
|
| 23 | 24 | */ |
| 24 | 25 | public function updateAggregation(&$aggs); |
| 25 | 26 | |
@@ -81,7 +81,6 @@ discard block |
||
| 81 | 81 | |
| 82 | 82 | /** |
| 83 | 83 | * @param \Elastica\Client $client |
| 84 | - * @param string $index |
|
| 85 | 84 | */ |
| 86 | 85 | public function __construct(Client $client, $newIndexName) { |
| 87 | 86 | $this->client = $client; |
@@ -133,7 +132,7 @@ discard block |
||
| 133 | 132 | * |
| 134 | 133 | * @param \Elastica\Query|string|array $query |
| 135 | 134 | * @param array $types List of comma separated SilverStripe classes to search, or blank for all |
| 136 | - * @return ResultList |
|
| 135 | + * @return \Elastica\ResultSet |
|
| 137 | 136 | */ |
| 138 | 137 | public function search($query, $types = '', $debugTerms = false) { |
| 139 | 138 | $query = Query::create($query); // may be a string |
@@ -141,7 +141,7 @@ discard block |
||
| 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,23 +164,23 @@ discard block |
||
| 164 | 164 | if ($query->MoreLikeThis) { |
| 165 | 165 | $termsQuery = clone $query; |
| 166 | 166 | $path = $search->getPath(); |
| 167 | - $params = $search->getOptions(); |
|
| 167 | + $params = $search->getOptions(); |
|
| 168 | 168 | |
| 169 | - $termData = array(); |
|
| 170 | - $termData['query'] = $data['query']; |
|
| 169 | + $termData = array(); |
|
| 170 | + $termData['query'] = $data['query']; |
|
| 171 | 171 | |
| 172 | - $path = str_replace('_search', '_validate/query', $path); |
|
| 173 | - $params = array('explain' => true, 'rewrite' => true); |
|
| 174 | - if ($this->test_mode) { |
|
| 175 | - $params['search_type'] = Search::OPTION_SEARCH_TYPE_DFS_QUERY_THEN_FETCH; |
|
| 176 | - } |
|
| 172 | + $path = str_replace('_search', '_validate/query', $path); |
|
| 173 | + $params = array('explain' => true, 'rewrite' => true); |
|
| 174 | + if ($this->test_mode) { |
|
| 175 | + $params['search_type'] = Search::OPTION_SEARCH_TYPE_DFS_QUERY_THEN_FETCH; |
|
| 176 | + } |
|
| 177 | 177 | |
| 178 | - $response = $this->getClient()->request( |
|
| 179 | - $path, |
|
| 180 | - \Elastica\Request::GET, |
|
| 181 | - $termData, |
|
| 182 | - $params |
|
| 183 | - ); |
|
| 178 | + $response = $this->getClient()->request( |
|
| 179 | + $path, |
|
| 180 | + \Elastica\Request::GET, |
|
| 181 | + $termData, |
|
| 182 | + $params |
|
| 183 | + ); |
|
| 184 | 184 | |
| 185 | 185 | $r = $response->getData(); |
| 186 | 186 | $terms = null; // keep in scope |
@@ -196,14 +196,14 @@ discard block |
||
| 196 | 196 | } |
| 197 | 197 | } |
| 198 | 198 | |
| 199 | - if ($types) { |
|
| 200 | - foreach($types as $type) { |
|
| 201 | - $search->addType($type); |
|
| 202 | - } |
|
| 203 | - } |
|
| 199 | + if ($types) { |
|
| 200 | + foreach($types as $type) { |
|
| 201 | + $search->addType($type); |
|
| 202 | + } |
|
| 203 | + } |
|
| 204 | 204 | |
| 205 | - $path = $search->getPath(); |
|
| 206 | - $params = $search->getOptions(); |
|
| 205 | + $path = $search->getPath(); |
|
| 206 | + $params = $search->getOptions(); |
|
| 207 | 207 | |
| 208 | 208 | $highlightsCfg = \Config::inst()->get('Elastica', 'Highlights'); |
| 209 | 209 | $preTags = $highlightsCfg['PreTags']; |
@@ -271,14 +271,14 @@ discard block |
||
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | |
| 274 | - $path = $search->getPath(); |
|
| 275 | - $params = $search->getOptions(); |
|
| 274 | + $path = $search->getPath(); |
|
| 275 | + $params = $search->getOptions(); |
|
| 276 | 276 | $searchResults = $search->search($query, $params); |
| 277 | 277 | if (isset($this->MoreLikeThisTerms)) { |
| 278 | 278 | $searchResults->MoreLikeThisTerms = $this->MoreLikeThisTerms; |
| 279 | 279 | } |
| 280 | 280 | |
| 281 | - return $searchResults; |
|
| 281 | + return $searchResults; |
|
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | |
@@ -352,11 +352,11 @@ discard block |
||
| 352 | 352 | |
| 353 | 353 | public function listIndexes($trace) { |
| 354 | 354 | $command = "curl 'localhost:9200/_cat/indices?v'"; |
| 355 | - exec($command,$op); |
|
| 356 | - ElasticaUtil::message("\n++++ $trace ++++\n"); |
|
| 357 | - ElasticaUtil::message(print_r($op,1)); |
|
| 358 | - ElasticaUtil::message("++++ /{$trace} ++++\n\n"); |
|
| 359 | - return $op; |
|
| 355 | + exec($command,$op); |
|
| 356 | + ElasticaUtil::message("\n++++ $trace ++++\n"); |
|
| 357 | + ElasticaUtil::message(print_r($op,1)); |
|
| 358 | + ElasticaUtil::message("++++ /{$trace} ++++\n\n"); |
|
| 359 | + return $op; |
|
| 360 | 360 | } |
| 361 | 361 | |
| 362 | 362 | |
@@ -527,11 +527,11 @@ discard block |
||
| 527 | 527 | } else { |
| 528 | 528 | $class = new \ReflectionClass($classname); |
| 529 | 529 | while ($class = $class->getParentClass()) { |
| 530 | - $parentClass = $class->getName(); |
|
| 531 | - if ($parentClass == 'SiteTree') { |
|
| 532 | - $inSiteTree = true; |
|
| 533 | - break; |
|
| 534 | - } |
|
| 530 | + $parentClass = $class->getName(); |
|
| 531 | + if ($parentClass == 'SiteTree') { |
|
| 532 | + $inSiteTree = true; |
|
| 533 | + break; |
|
| 534 | + } |
|
| 535 | 535 | } |
| 536 | 536 | self::$site_tree_classes[$classname] = $inSiteTree; |
| 537 | 537 | } |
@@ -685,15 +685,15 @@ discard block |
||
| 685 | 685 | //FlickrPhoto/3829/_termvector |
| 686 | 686 | $path = $this->getIndex()->getName().'/'.$searchable->ClassName.'/'.$searchable->ID.'/_termvector'; |
| 687 | 687 | $response = $this->getClient()->request( |
| 688 | - $path, |
|
| 689 | - \Elastica\Request::GET, |
|
| 690 | - $data, |
|
| 691 | - $params |
|
| 692 | - ); |
|
| 688 | + $path, |
|
| 689 | + \Elastica\Request::GET, |
|
| 690 | + $data, |
|
| 691 | + $params |
|
| 692 | + ); |
|
| 693 | 693 | |
| 694 | 694 | |
| 695 | - $data = $response->getData(); |
|
| 696 | - return $data['term_vectors']; |
|
| 695 | + $data = $response->getData(); |
|
| 696 | + return $data['term_vectors']; |
|
| 697 | 697 | } |
| 698 | 698 | |
| 699 | 699 | } |
@@ -121,7 +121,7 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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, |
@@ -62,6 +62,9 @@ discard block |
||
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | |
| 65 | + /** |
|
| 66 | + * @param boolean $newShowResultsForEmptyQuery |
|
| 67 | + */ |
|
| 65 | 68 | public function setShowResultsForEmptyQuery($newShowResultsForEmptyQuery) { |
| 66 | 69 | $this->showResultsForEmptyQuery = $newShowResultsForEmptyQuery; |
| 67 | 70 | } |
@@ -72,11 +75,17 @@ discard block |
||
| 72 | 75 | } |
| 73 | 76 | |
| 74 | 77 | |
| 78 | + /** |
|
| 79 | + * @param integer $newPageLength |
|
| 80 | + */ |
|
| 75 | 81 | public function setPageLength($newPageLength) { |
| 76 | 82 | $this->pageLength = $newPageLength; |
| 77 | 83 | } |
| 78 | 84 | |
| 79 | 85 | |
| 86 | + /** |
|
| 87 | + * @param integer $newStart |
|
| 88 | + */ |
|
| 80 | 89 | public function setStart($newStart) { |
| 81 | 90 | $this->start = $newStart; |
| 82 | 91 | } |
@@ -317,6 +326,9 @@ discard block |
||
| 317 | 326 | } |
| 318 | 327 | |
| 319 | 328 | |
| 329 | + /** |
|
| 330 | + * @param Query $query |
|
| 331 | + */ |
|
| 320 | 332 | private function addAggregation(&$query) { |
| 321 | 333 | // aggregation (optional) |
| 322 | 334 | if ($this->manipulatorInstance) { |
@@ -384,16 +384,16 @@ |
||
| 384 | 384 | |
| 385 | 385 | if ($textQuery instanceof MultiMatch) { |
| 386 | 386 | $elasticaFields = $this->convertWeightedFieldsForElastica($this->fields); |
| 387 | - //$textQuery->setFields(array('Title^4','Content','Content.*')); |
|
| 388 | - //$fieldsCSV = implode(',', $fieldsToSearch); |
|
| 389 | - $textQuery->setFields($elasticaFields); |
|
| 390 | - $textQuery->setType('most_fields'); |
|
| 387 | + //$textQuery->setFields(array('Title^4','Content','Content.*')); |
|
| 388 | + //$fieldsCSV = implode(',', $fieldsToSearch); |
|
| 389 | + $textQuery->setFields($elasticaFields); |
|
| 390 | + $textQuery->setType('most_fields'); |
|
| 391 | 391 | |
| 392 | - //Setting the lenient flag means that numeric fields can be searched for text values |
|
| 393 | - $textQuery->setParam('lenient', true); |
|
| 392 | + //Setting the lenient flag means that numeric fields can be searched for text values |
|
| 393 | + $textQuery->setParam('lenient', true); |
|
| 394 | 394 | } |
| 395 | 395 | |
| 396 | - return $textQuery; |
|
| 396 | + return $textQuery; |
|
| 397 | 397 | } |
| 398 | 398 | |
| 399 | 399 | |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | 'size' => 10, |
| 210 | 210 | 'query' => array( |
| 211 | 211 | 'match' => array( |
| 212 | - $field.'.autocomplete' => array( |
|
| 212 | + $field . '.autocomplete' => array( |
|
| 213 | 213 | 'query' => $this->queryText, |
| 214 | 214 | 'operator' => 'and' |
| 215 | 215 | ) |
@@ -268,7 +268,7 @@ discard block |
||
| 268 | 268 | foreach ($this->selectedFilters as $key => $value) { |
| 269 | 269 | if (!in_array($key, $rangeFilterKeys)) { |
| 270 | 270 | $filter = new Term(); |
| 271 | - $filter->setTerm($key,$value); |
|
| 271 | + $filter->setTerm($key, $value); |
|
| 272 | 272 | $elFilters[] = $filter; |
| 273 | 273 | } else { |
| 274 | 274 | // get the selected range filter |
@@ -407,20 +407,20 @@ discard block |
||
| 407 | 407 | */ |
| 408 | 408 | public function convertWeightedFieldsForElastica($fields) { |
| 409 | 409 | $result = array(); |
| 410 | - $nameToType = self::getSearchFieldsMappingForClasses($this->classes,$fields); |
|
| 410 | + $nameToType = self::getSearchFieldsMappingForClasses($this->classes, $fields); |
|
| 411 | 411 | |
| 412 | 412 | if (sizeof($fields) != 0) { |
| 413 | 413 | foreach ($fields as $fieldName => $weight) { |
| 414 | 414 | $fieldCfg = "$fieldName"; |
| 415 | 415 | if ($weight != 1) { |
| 416 | - $fieldCfg .= '^'.$weight; |
|
| 416 | + $fieldCfg .= '^' . $weight; |
|
| 417 | 417 | } |
| 418 | 418 | array_push($result, $fieldCfg); |
| 419 | 419 | if (isset($nameToType[$fieldName])) { |
| 420 | 420 | if ($nameToType[$fieldName] == 'string') { |
| 421 | 421 | $fieldCfg = "{$fieldName}.*"; |
| 422 | 422 | if ($weight != 1) { |
| 423 | - $fieldCfg .= '^'.$weight; |
|
| 423 | + $fieldCfg .= '^' . $weight; |
|
| 424 | 424 | } |
| 425 | 425 | array_push($result, $fieldCfg); |
| 426 | 426 | } |
@@ -447,16 +447,16 @@ discard block |
||
| 447 | 447 | $cache = QueryGenerator::getCache(); |
| 448 | 448 | $csvClasses = $classes; |
| 449 | 449 | if (is_array($classes)) { |
| 450 | - $csvClasses = implode(',',$classes); |
|
| 450 | + $csvClasses = implode(',', $classes); |
|
| 451 | 451 | } |
| 452 | 452 | |
| 453 | 453 | error_log("CSV CLASSES: $csvClasses"); |
| 454 | 454 | |
| 455 | - $key ='SEARCHABLE_FIELDS_'.str_replace(',', '_', $csvClasses); |
|
| 455 | + $key = 'SEARCHABLE_FIELDS_' . str_replace(',', '_', $csvClasses); |
|
| 456 | 456 | |
| 457 | 457 | if ($fieldsAllowed) { |
| 458 | 458 | $fieldsAllowedCSV = self::convertToQuotedCSV(array_keys($fieldsAllowed)); |
| 459 | - $key .= '_' . str_replace(',', '_', str_replace("'", '_',$fieldsAllowedCSV)); |
|
| 459 | + $key .= '_' . str_replace(',', '_', str_replace("'", '_', $fieldsAllowedCSV)); |
|
| 460 | 460 | $key = str_replace('.', '_', $key); |
| 461 | 461 | $key = str_replace(' ', '_', $key); |
| 462 | 462 | } |
@@ -468,7 +468,7 @@ discard block |
||
| 468 | 468 | if (!$csvClasses) { |
| 469 | 469 | |
| 470 | 470 | $sql = "SELECT DISTINCT Name from SearchableClass where InSiteTree = 1 order by Name"; |
| 471 | - error_log('T1 - sql = '.$sql); |
|
| 471 | + error_log('T1 - sql = ' . $sql); |
|
| 472 | 472 | |
| 473 | 473 | $records = \DB::query($sql); |
| 474 | 474 | foreach ($records as $record) { |
@@ -492,7 +492,7 @@ discard block |
||
| 492 | 492 | } |
| 493 | 493 | } |
| 494 | 494 | |
| 495 | - error_log('T2 - sql = '.$sql); |
|
| 495 | + error_log('T2 - sql = ' . $sql); |
|
| 496 | 496 | |
| 497 | 497 | |
| 498 | 498 | $records = \DB::query($sql); |
@@ -510,11 +510,11 @@ discard block |
||
| 510 | 510 | $result[$name] = $type; |
| 511 | 511 | } |
| 512 | 512 | } |
| 513 | - $cache->save(json_encode($result),$key); |
|
| 514 | - } else { |
|
| 513 | + $cache->save(json_encode($result), $key); |
|
| 514 | + } else { |
|
| 515 | 515 | // true is necessary here to decode the array hash back to an array and not a struct |
| 516 | 516 | self::$cacheHitCtr++; |
| 517 | - $result = json_decode($result,true); |
|
| 517 | + $result = json_decode($result, true); |
|
| 518 | 518 | } |
| 519 | 519 | |
| 520 | 520 | return $result; |
@@ -546,11 +546,11 @@ discard block |
||
| 546 | 546 | $quoted = array(); |
| 547 | 547 | foreach ($asArray as $value) { |
| 548 | 548 | if (strlen($value) > 0) { |
| 549 | - $item = "'".$value."'"; |
|
| 549 | + $item = "'" . $value . "'"; |
|
| 550 | 550 | array_push($quoted, $item); |
| 551 | 551 | } |
| 552 | 552 | |
| 553 | 553 | } |
| 554 | - return implode(',', $quoted);; |
|
| 554 | + return implode(',', $quoted); ; |
|
| 555 | 555 | } |
| 556 | 556 | } |
@@ -511,7 +511,7 @@ |
||
| 511 | 511 | } |
| 512 | 512 | } |
| 513 | 513 | $cache->save(json_encode($result),$key); |
| 514 | - } else { |
|
| 514 | + } else { |
|
| 515 | 515 | // true is necessary here to decode the array hash back to an array and not a struct |
| 516 | 516 | self::$cacheHitCtr++; |
| 517 | 517 | $result = json_decode($result,true); |
@@ -6,6 +6,10 @@ discard block |
||
| 6 | 6 | private static $ranged_aggregations = array(); |
| 7 | 7 | |
| 8 | 8 | |
| 9 | + /** |
|
| 10 | + * @param string $title |
|
| 11 | + * @param string $field |
|
| 12 | + */ |
|
| 9 | 13 | public function __construct($title, $field) { |
| 10 | 14 | $this->Title = $title; |
| 11 | 15 | $this->Range = new \Elastica\Aggregation\Range($title); |
@@ -14,6 +18,11 @@ discard block |
||
| 14 | 18 | } |
| 15 | 19 | |
| 16 | 20 | |
| 21 | + /** |
|
| 22 | + * @param double $from |
|
| 23 | + * @param double $to |
|
| 24 | + * @param string $name |
|
| 25 | + */ |
|
| 17 | 26 | public function addRange($from, $to, $name) { |
| 18 | 27 | $this->Range->addRange($from,$to,$name); |
| 19 | 28 | } |
@@ -38,8 +38,8 @@ |
||
| 38 | 38 | $to = $range['to']; |
| 39 | 39 | } |
| 40 | 40 | $rangeFilter = array('gte' => (string)$from, 'lt' => (string)$to); |
| 41 | - $filter = new \Elastica\Filter\Range('AspectRatio', $rangeFilter); |
|
| 42 | - $result = $filter; |
|
| 41 | + $filter = new \Elastica\Filter\Range('AspectRatio', $rangeFilter); |
|
| 42 | + $result = $filter; |
|
| 43 | 43 | } |
| 44 | 44 | } |
| 45 | 45 | |
@@ -10,12 +10,12 @@ |
||
| 10 | 10 | $this->Title = $title; |
| 11 | 11 | $this->Range = new \Elastica\Aggregation\Range($title); |
| 12 | 12 | $this->Range->setField($field); |
| 13 | - self::$ranged_aggregations[$title] = $this;; |
|
| 13 | + self::$ranged_aggregations[$title] = $this; ; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | |
| 17 | 17 | public function addRange($from, $to, $name) { |
| 18 | - $this->Range->addRange($from,$to,$name); |
|
| 18 | + $this->Range->addRange($from, $to, $name); |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | |
@@ -250,6 +250,9 @@ |
||
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | |
| 253 | + /** |
|
| 254 | + * @return integer |
|
| 255 | + */ |
|
| 253 | 256 | public function getTotalItems() { |
| 254 | 257 | $this->getResults(); |
| 255 | 258 | return $this->TotalItems; |
@@ -12,14 +12,14 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | class ResultList extends \ViewableData implements \SS_Limitable, \SS_List { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * @var \Elastica\Index |
|
| 17 | - */ |
|
| 18 | - private $service; |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * @var \Elastica\Query |
|
| 22 | - */ |
|
| 15 | + /** |
|
| 16 | + * @var \Elastica\Index |
|
| 17 | + */ |
|
| 18 | + private $service; |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * @var \Elastica\Query |
|
| 22 | + */ |
|
| 23 | 23 | private $query; |
| 24 | 24 | |
| 25 | 25 | /** |
@@ -312,51 +312,51 @@ discard block |
||
| 312 | 312 | // Safeguards against indexed items which might no longer be in the DB |
| 313 | 313 | if(array_key_exists($item->getId(), $retrieved[$item->getType()])) { |
| 314 | 314 | |
| 315 | - $data_object = $retrieved[$item->getType()][$item->getId()]; |
|
| 316 | - $data_object->setElasticaResult($item); |
|
| 317 | - $highlights = $item->getHighlights(); |
|
| 315 | + $data_object = $retrieved[$item->getType()][$item->getId()]; |
|
| 316 | + $data_object->setElasticaResult($item); |
|
| 317 | + $highlights = $item->getHighlights(); |
|
| 318 | 318 | |
| 319 | - //$snippets will contain the highlights shown in the body of the search result |
|
| 320 | - //$namedSnippets will be used to add highlights to the Link and Title |
|
| 321 | - $snippets = new \ArrayList(); |
|
| 322 | - $namedSnippets = new \ArrayList(); |
|
| 319 | + //$snippets will contain the highlights shown in the body of the search result |
|
| 320 | + //$namedSnippets will be used to add highlights to the Link and Title |
|
| 321 | + $snippets = new \ArrayList(); |
|
| 322 | + $namedSnippets = new \ArrayList(); |
|
| 323 | 323 | |
| 324 | - foreach (array_keys($highlights) as $fieldName) { |
|
| 325 | - $fieldSnippets = new \ArrayList(); |
|
| 324 | + foreach (array_keys($highlights) as $fieldName) { |
|
| 325 | + $fieldSnippets = new \ArrayList(); |
|
| 326 | 326 | |
| 327 | - foreach ($highlights[$fieldName] as $snippet) { |
|
| 328 | - $do = new \DataObject(); |
|
| 329 | - $do->Snippet = $snippet; |
|
| 327 | + foreach ($highlights[$fieldName] as $snippet) { |
|
| 328 | + $do = new \DataObject(); |
|
| 329 | + $do->Snippet = $snippet; |
|
| 330 | 330 | |
| 331 | - // skip title and link in the summary of highlights |
|
| 332 | - if (!in_array($fieldName, $ignore)) { |
|
| 333 | - $snippets->push($do); |
|
| 334 | - } |
|
| 331 | + // skip title and link in the summary of highlights |
|
| 332 | + if (!in_array($fieldName, $ignore)) { |
|
| 333 | + $snippets->push($do); |
|
| 334 | + } |
|
| 335 | 335 | |
| 336 | - $fieldSnippets->push($do); |
|
| 337 | - } |
|
| 336 | + $fieldSnippets->push($do); |
|
| 337 | + } |
|
| 338 | 338 | |
| 339 | - if ($fieldSnippets->count() > 0) { |
|
| 340 | - //Fields may have a dot in their name, e.g. Title.standard - take this into account |
|
| 341 | - //As dots are an issue with template syntax, store as Title_standard |
|
| 342 | - $splits = explode('.', $fieldName); |
|
| 343 | - if (sizeof($splits) == 1) { |
|
| 344 | - $namedSnippets->$fieldName = $fieldSnippets; |
|
| 345 | - } else { |
|
| 346 | - // The Title.standard case, for example |
|
| 347 | - $splits = explode('.', $fieldName); |
|
| 348 | - $compositeFielddName = $splits[0].'_'.$splits[1]; |
|
| 349 | - $namedSnippets->$compositeFielddName = $fieldSnippets; |
|
| 350 | - } |
|
| 339 | + if ($fieldSnippets->count() > 0) { |
|
| 340 | + //Fields may have a dot in their name, e.g. Title.standard - take this into account |
|
| 341 | + //As dots are an issue with template syntax, store as Title_standard |
|
| 342 | + $splits = explode('.', $fieldName); |
|
| 343 | + if (sizeof($splits) == 1) { |
|
| 344 | + $namedSnippets->$fieldName = $fieldSnippets; |
|
| 345 | + } else { |
|
| 346 | + // The Title.standard case, for example |
|
| 347 | + $splits = explode('.', $fieldName); |
|
| 348 | + $compositeFielddName = $splits[0].'_'.$splits[1]; |
|
| 349 | + $namedSnippets->$compositeFielddName = $fieldSnippets; |
|
| 350 | + } |
|
| 351 | 351 | |
| 352 | - } |
|
| 352 | + } |
|
| 353 | 353 | |
| 354 | 354 | |
| 355 | - } |
|
| 355 | + } |
|
| 356 | 356 | |
| 357 | 357 | |
| 358 | - $data_object->SearchHighlights = $snippets; |
|
| 359 | - $data_object->SearchHighlightsByField = $namedSnippets; |
|
| 358 | + $data_object->SearchHighlights = $snippets; |
|
| 359 | + $data_object->SearchHighlightsByField = $namedSnippets; |
|
| 360 | 360 | |
| 361 | 361 | $result[] = $data_object; |
| 362 | 362 | |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | */ |
| 103 | 103 | public function getResults() { |
| 104 | 104 | if (!isset($this->_cachedResults)) { |
| 105 | - $ers = $this->service->search($this->query,$this->types); |
|
| 105 | + $ers = $this->service->search($this->query, $this->types); |
|
| 106 | 106 | |
| 107 | 107 | if (isset($ers->MoreLikeThisTerms)) { |
| 108 | 108 | $this->MoreLikeThisTerms = $ers->MoreLikeThisTerms; |
@@ -150,10 +150,10 @@ discard block |
||
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | // get the base URL for the current facets selected |
| 153 | - $baseURL = \Controller::curr()->Link().'?'; |
|
| 153 | + $baseURL = \Controller::curr()->Link() . '?'; |
|
| 154 | 154 | $prefixAmp = false; |
| 155 | 155 | if ($q !== '') { |
| 156 | - $baseURL .= 'q='.urlencode($q); |
|
| 156 | + $baseURL .= 'q=' . urlencode($q); |
|
| 157 | 157 | $prefixAmp = true; |
| 158 | 158 | } |
| 159 | 159 | |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | } else { |
| 165 | 165 | $prefixAmp = true; |
| 166 | 166 | } |
| 167 | - $baseURL .= $key.'='.urlencode($value); |
|
| 167 | + $baseURL .= $key . '=' . urlencode($value); |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | foreach (array_keys($aggs) as $key) { |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | $ct->DocumentCount = $value['doc_count']; |
| 188 | 188 | $query[$key] = $value; |
| 189 | 189 | if ($prefixAmp) { |
| 190 | - $url = $baseURL.'&'; |
|
| 190 | + $url = $baseURL . '&'; |
|
| 191 | 191 | } else { |
| 192 | 192 | $url = $baseURL; |
| 193 | 193 | $prefixAmp = true; |
@@ -203,24 +203,24 @@ discard block |
||
| 203 | 203 | // of the display of the facet can be done via the template. |
| 204 | 204 | $aggDO->IsSelected = true; |
| 205 | 205 | |
| 206 | - $urlParam = $key.'='.urlencode($this->filters[$key]); |
|
| 206 | + $urlParam = $key . '=' . urlencode($this->filters[$key]); |
|
| 207 | 207 | |
| 208 | 208 | //echo " - URL PARAM : $urlParam \n"; |
| 209 | 209 | |
| 210 | 210 | // possible ampersand combos to remove |
| 211 | - $v2 = '&'.$urlParam; |
|
| 212 | - $v3 = $urlParam.'&'; |
|
| 211 | + $v2 = '&' . $urlParam; |
|
| 212 | + $v3 = $urlParam . '&'; |
|
| 213 | 213 | $url = str_replace($v2, '', $url); |
| 214 | 214 | $url = str_replace($v3, '', $url); |
| 215 | 215 | $url = str_replace($urlParam, '', $url); |
| 216 | 216 | $ct->URL = $url; |
| 217 | 217 | } |
| 218 | 218 | } else { |
| 219 | - $url .= $key .'='.urlencode($value['key']); |
|
| 219 | + $url .= $key . '=' . urlencode($value['key']); |
|
| 220 | 220 | $prefixAmp = true; |
| 221 | 221 | } |
| 222 | 222 | |
| 223 | - $url = rtrim($url,'&'); |
|
| 223 | + $url = rtrim($url, '&'); |
|
| 224 | 224 | |
| 225 | 225 | $ct->URL = $url; |
| 226 | 226 | $bucketsAL->push($ct); |
@@ -310,7 +310,7 @@ discard block |
||
| 310 | 310 | |
| 311 | 311 | foreach ($found as $item) { |
| 312 | 312 | // Safeguards against indexed items which might no longer be in the DB |
| 313 | - if(array_key_exists($item->getId(), $retrieved[$item->getType()])) { |
|
| 313 | + if (array_key_exists($item->getId(), $retrieved[$item->getType()])) { |
|
| 314 | 314 | |
| 315 | 315 | $data_object = $retrieved[$item->getType()][$item->getId()]; |
| 316 | 316 | $data_object->setElasticaResult($item); |
@@ -345,7 +345,7 @@ discard block |
||
| 345 | 345 | } else { |
| 346 | 346 | // The Title.standard case, for example |
| 347 | 347 | $splits = explode('.', $fieldName); |
| 348 | - $compositeFielddName = $splits[0].'_'.$splits[1]; |
|
| 348 | + $compositeFielddName = $splits[0] . '_' . $splits[1]; |
|
| 349 | 349 | $namedSnippets->$compositeFielddName = $fieldSnippets; |
| 350 | 350 | } |
| 351 | 351 | |
@@ -396,7 +396,7 @@ discard block |
||
| 396 | 396 | } |
| 397 | 397 | |
| 398 | 398 | public function column($col = 'ID') { |
| 399 | - if($col == 'ID') { |
|
| 399 | + if ($col == 'ID') { |
|
| 400 | 400 | $ids = array(); |
| 401 | 401 | |
| 402 | 402 | foreach ($this->getResults() as $result) { |
@@ -1036,6 +1036,7 @@ |
||
| 1036 | 1036 | /** |
| 1037 | 1037 | * Test searching |
| 1038 | 1038 | * http://stackoverflow.com/questions/28305250/elasticsearch-customize-score-for-synonyms-stemming |
| 1039 | + * @param string $queryText |
|
| 1039 | 1040 | */ |
| 1040 | 1041 | private function search($queryText,$fields = array('Title' => 1, 'Description' => 1), |
| 1041 | 1042 | $filters = array()) { |
@@ -483,7 +483,7 @@ discard block |
||
| 483 | 483 | $resultList = $this->search(''); |
| 484 | 484 | |
| 485 | 485 | //assert there are actually some results |
| 486 | - $this->assertGreaterThan(0,$resultList->getTotalItems()); |
|
| 486 | + $this->assertGreaterThan(0, $resultList->getTotalItems()); |
|
| 487 | 487 | $aggregations = $resultList->getAggregations()->toArray(); |
| 488 | 488 | |
| 489 | 489 | /* |
@@ -502,49 +502,49 @@ discard block |
||
| 502 | 502 | //Asserting aggregate of ISO, 64 has count 5 |
| 503 | 503 | $this->assertEquals("64", $buckets[0]->Key); |
| 504 | 504 | $this->assertEquals(5, $buckets[0]->DocumentCount); |
| 505 | - $this->assertEquals(FlickrPhotoTO::get()->filter('ISO',64)->count(),5); |
|
| 505 | + $this->assertEquals(FlickrPhotoTO::get()->filter('ISO', 64)->count(), 5); |
|
| 506 | 506 | $bucketSum += $buckets[0]->DocumentCount; |
| 507 | 507 | |
| 508 | 508 | //Asserting aggregate of ISO, 100 has count 11 |
| 509 | 509 | $this->assertEquals("100", $buckets[1]->Key); |
| 510 | 510 | $this->assertEquals(11, $buckets[1]->DocumentCount); |
| 511 | - $this->assertEquals(FlickrPhotoTO::get()->filter('ISO',100)->count(),11); |
|
| 511 | + $this->assertEquals(FlickrPhotoTO::get()->filter('ISO', 100)->count(), 11); |
|
| 512 | 512 | $bucketSum += $buckets[1]->DocumentCount; |
| 513 | 513 | |
| 514 | 514 | //Asserting aggregate of ISO, 200 has count 12 |
| 515 | 515 | $this->assertEquals("200", $buckets[2]->Key); |
| 516 | 516 | $this->assertEquals(12, $buckets[2]->DocumentCount); |
| 517 | - $this->assertEquals(FlickrPhotoTO::get()->filter('ISO',200)->count(),12); |
|
| 517 | + $this->assertEquals(FlickrPhotoTO::get()->filter('ISO', 200)->count(), 12); |
|
| 518 | 518 | $bucketSum += $buckets[2]->DocumentCount; |
| 519 | 519 | |
| 520 | 520 | //Asserting aggregate of ISO, 400 has count 13 |
| 521 | 521 | $this->assertEquals("400", $buckets[3]->Key); |
| 522 | 522 | $this->assertEquals(13, $buckets[3]->DocumentCount); |
| 523 | - $this->assertEquals(FlickrPhotoTO::get()->filter('ISO',400)->count(),13); |
|
| 523 | + $this->assertEquals(FlickrPhotoTO::get()->filter('ISO', 400)->count(), 13); |
|
| 524 | 524 | $bucketSum += $buckets[3]->DocumentCount; |
| 525 | 525 | |
| 526 | 526 | //Asserting aggregate of ISO, 800 has count 16 |
| 527 | 527 | $this->assertEquals("800", $buckets[4]->Key); |
| 528 | 528 | $this->assertEquals(16, $buckets[4]->DocumentCount); |
| 529 | - $this->assertEquals(FlickrPhotoTO::get()->filter('ISO',800)->count(),16); |
|
| 529 | + $this->assertEquals(FlickrPhotoTO::get()->filter('ISO', 800)->count(), 16); |
|
| 530 | 530 | $bucketSum += $buckets[4]->DocumentCount; |
| 531 | 531 | |
| 532 | 532 | //Asserting aggregate of ISO, 1600 has count 13 |
| 533 | 533 | $this->assertEquals("1600", $buckets[5]->Key); |
| 534 | 534 | $this->assertEquals(13, $buckets[5]->DocumentCount); |
| 535 | - $this->assertEquals(FlickrPhotoTO::get()->filter('ISO',1600)->count(),13); |
|
| 535 | + $this->assertEquals(FlickrPhotoTO::get()->filter('ISO', 1600)->count(), 13); |
|
| 536 | 536 | $bucketSum += $buckets[5]->DocumentCount; |
| 537 | 537 | |
| 538 | 538 | //Asserting aggregate of ISO, 2000 has count 11 |
| 539 | 539 | $this->assertEquals("2000", $buckets[6]->Key); |
| 540 | 540 | $this->assertEquals(11, $buckets[6]->DocumentCount); |
| 541 | - $this->assertEquals(FlickrPhotoTO::get()->filter('ISO',2000)->count(),11); |
|
| 541 | + $this->assertEquals(FlickrPhotoTO::get()->filter('ISO', 2000)->count(), 11); |
|
| 542 | 542 | $bucketSum += $buckets[6]->DocumentCount; |
| 543 | 543 | |
| 544 | 544 | //Asserting aggregate of ISO, 3200 has count 19 |
| 545 | 545 | $this->assertEquals("3200", $buckets[7]->Key); |
| 546 | 546 | $this->assertEquals(19, $buckets[7]->DocumentCount); |
| 547 | - $this->assertEquals(FlickrPhotoTO::get()->filter('ISO',3200)->count(),19); |
|
| 547 | + $this->assertEquals(FlickrPhotoTO::get()->filter('ISO', 3200)->count(), 19); |
|
| 548 | 548 | $bucketSum += $buckets[7]->DocumentCount; |
| 549 | 549 | $this->assertEquals(100, $bucketSum); |
| 550 | 550 | |
@@ -557,43 +557,43 @@ discard block |
||
| 557 | 557 | //Asserting aggregate of Focal Length, 24 has count 12 |
| 558 | 558 | $this->assertEquals("24", $buckets[0]->Key); |
| 559 | 559 | $this->assertEquals(12, $buckets[0]->DocumentCount); |
| 560 | - $this->assertEquals(FlickrPhotoTO::get()->filter('FocalLength35mm',24)->count(),12); |
|
| 560 | + $this->assertEquals(FlickrPhotoTO::get()->filter('FocalLength35mm', 24)->count(), 12); |
|
| 561 | 561 | $bucketSum += $buckets[0]->DocumentCount; |
| 562 | 562 | |
| 563 | 563 | //Asserting aggregate of Focal Length, 50 has count 11 |
| 564 | 564 | $this->assertEquals("50", $buckets[1]->Key); |
| 565 | 565 | $this->assertEquals(11, $buckets[1]->DocumentCount); |
| 566 | - $this->assertEquals(FlickrPhotoTO::get()->filter('FocalLength35mm',50)->count(),11); |
|
| 566 | + $this->assertEquals(FlickrPhotoTO::get()->filter('FocalLength35mm', 50)->count(), 11); |
|
| 567 | 567 | $bucketSum += $buckets[1]->DocumentCount; |
| 568 | 568 | |
| 569 | 569 | //Asserting aggregate of Focal Length, 80 has count 11 |
| 570 | 570 | $this->assertEquals("80", $buckets[2]->Key); |
| 571 | 571 | $this->assertEquals(11, $buckets[2]->DocumentCount); |
| 572 | - $this->assertEquals(FlickrPhotoTO::get()->filter('FocalLength35mm',80)->count(),11); |
|
| 572 | + $this->assertEquals(FlickrPhotoTO::get()->filter('FocalLength35mm', 80)->count(), 11); |
|
| 573 | 573 | $bucketSum += $buckets[2]->DocumentCount; |
| 574 | 574 | |
| 575 | 575 | //Asserting aggregate of Focal Length, 90 has count 20 |
| 576 | 576 | $this->assertEquals("90", $buckets[3]->Key); |
| 577 | 577 | $this->assertEquals(20, $buckets[3]->DocumentCount); |
| 578 | - $this->assertEquals(FlickrPhotoTO::get()->filter('FocalLength35mm',90)->count(),20); |
|
| 578 | + $this->assertEquals(FlickrPhotoTO::get()->filter('FocalLength35mm', 90)->count(), 20); |
|
| 579 | 579 | $bucketSum += $buckets[3]->DocumentCount; |
| 580 | 580 | |
| 581 | 581 | //Asserting aggregate of Focal Length, 120 has count 12 |
| 582 | 582 | $this->assertEquals("120", $buckets[4]->Key); |
| 583 | 583 | $this->assertEquals(12, $buckets[4]->DocumentCount); |
| 584 | - $this->assertEquals(FlickrPhotoTO::get()->filter('FocalLength35mm',120)->count(),12); |
|
| 584 | + $this->assertEquals(FlickrPhotoTO::get()->filter('FocalLength35mm', 120)->count(), 12); |
|
| 585 | 585 | $bucketSum += $buckets[4]->DocumentCount; |
| 586 | 586 | |
| 587 | 587 | //Asserting aggregate of Focal Length, 150 has count 17 |
| 588 | 588 | $this->assertEquals("150", $buckets[5]->Key); |
| 589 | 589 | $this->assertEquals(17, $buckets[5]->DocumentCount); |
| 590 | - $this->assertEquals(FlickrPhotoTO::get()->filter('FocalLength35mm',150)->count(),17); |
|
| 590 | + $this->assertEquals(FlickrPhotoTO::get()->filter('FocalLength35mm', 150)->count(), 17); |
|
| 591 | 591 | $bucketSum += $buckets[5]->DocumentCount; |
| 592 | 592 | |
| 593 | 593 | //Asserting aggregate of Focal Length, 200 has count 17 |
| 594 | 594 | $this->assertEquals("200", $buckets[6]->Key); |
| 595 | 595 | $this->assertEquals(17, $buckets[6]->DocumentCount); |
| 596 | - $this->assertEquals(FlickrPhotoTO::get()->filter('FocalLength35mm',200)->count(),17); |
|
| 596 | + $this->assertEquals(FlickrPhotoTO::get()->filter('FocalLength35mm', 200)->count(), 17); |
|
| 597 | 597 | $bucketSum += $buckets[6]->DocumentCount; |
| 598 | 598 | $this->assertEquals(100, $bucketSum); |
| 599 | 599 | |
@@ -887,7 +887,7 @@ discard block |
||
| 887 | 887 | $originalAggregations = $resultList->getAggregations()->toArray(); |
| 888 | 888 | |
| 889 | 889 | $filters = array('ISO' => 3200); |
| 890 | - $resultListFiltered = $this->search('New Zealand', $fields,$filters); |
|
| 890 | + $resultListFiltered = $this->search('New Zealand', $fields, $filters); |
|
| 891 | 891 | $filteredAggregations = $resultListFiltered->getAggregations()->toArray(); |
| 892 | 892 | |
| 893 | 893 | $this->checkDrillingDownHasHappened($filteredAggregations, $originalAggregations); |
@@ -899,8 +899,8 @@ discard block |
||
| 899 | 899 | $resultList = $this->search('New Zealand', $fields, array('ISO' => 400)); |
| 900 | 900 | $originalAggregations = $resultList->getAggregations()->toArray(); |
| 901 | 901 | |
| 902 | - $filters = array('ISO' => 400, 'Aspect' => 'Vertical' ); |
|
| 903 | - $resultListFiltered = $this->search('New Zealand', $fields,$filters); |
|
| 902 | + $filters = array('ISO' => 400, 'Aspect' => 'Vertical'); |
|
| 903 | + $resultListFiltered = $this->search('New Zealand', $fields, $filters); |
|
| 904 | 904 | $filteredAggregations = $resultListFiltered->getAggregations()->toArray(); |
| 905 | 905 | |
| 906 | 906 | $this->checkDrillingDownHasHappened($filteredAggregations, $originalAggregations); |
@@ -916,8 +916,8 @@ discard block |
||
| 916 | 916 | 'Aspect' => 'Vertical')); |
| 917 | 917 | $originalAggregations = $resultList->getAggregations()->toArray(); |
| 918 | 918 | |
| 919 | - $filters = array('ISO' => 400, 'Aspect' => 'Vertical', 'Aperture' => 5 ); |
|
| 920 | - $resultListFiltered = $this->search('New Zealand', $fields,$filters); |
|
| 919 | + $filters = array('ISO' => 400, 'Aspect' => 'Vertical', 'Aperture' => 5); |
|
| 920 | + $resultListFiltered = $this->search('New Zealand', $fields, $filters); |
|
| 921 | 921 | $filteredAggregations = $resultListFiltered->getAggregations()->toArray(); |
| 922 | 922 | |
| 923 | 923 | $this->checkDrillingDownHasHappened($filteredAggregations, $originalAggregations); |
@@ -1018,7 +1018,7 @@ discard block |
||
| 1018 | 1018 | |
| 1019 | 1019 | //Add filters |
| 1020 | 1020 | foreach ($filters as $key => $value) { |
| 1021 | - $es->addFilter($key,$value); |
|
| 1021 | + $es->addFilter($key, $value); |
|
| 1022 | 1022 | } |
| 1023 | 1023 | |
| 1024 | 1024 | $es->showResultsForEmptySearch(); |
@@ -1037,7 +1037,7 @@ discard block |
||
| 1037 | 1037 | * Test searching |
| 1038 | 1038 | * http://stackoverflow.com/questions/28305250/elasticsearch-customize-score-for-synonyms-stemming |
| 1039 | 1039 | */ |
| 1040 | - private function search($queryText,$fields = array('Title' => 1, 'Description' => 1), |
|
| 1040 | + private function search($queryText, $fields = array('Title' => 1, 'Description' => 1), |
|
| 1041 | 1041 | $filters = array()) { |
| 1042 | 1042 | $es = new ElasticSearcher(); |
| 1043 | 1043 | $es->setStart(0); |
@@ -1049,7 +1049,7 @@ discard block |
||
| 1049 | 1049 | //Add filters |
| 1050 | 1050 | foreach ($filters as $key => $value) { |
| 1051 | 1051 | echo "ADDING FILTER:$key => $value\n"; |
| 1052 | - $es->addFilter($key,$value); |
|
| 1052 | + $es->addFilter($key, $value); |
|
| 1053 | 1053 | } |
| 1054 | 1054 | |
| 1055 | 1055 | $es->showResultsForEmptySearch(); |
@@ -1060,10 +1060,10 @@ discard block |
||
| 1060 | 1060 | echo "{$resultList->count()} items found searching for '$queryText'\n\n"; |
| 1061 | 1061 | foreach ($resultList as $result) { |
| 1062 | 1062 | $ctr++; |
| 1063 | - echo("($ctr) ".$result->Title."\n"); |
|
| 1063 | + echo("($ctr) " . $result->Title . "\n"); |
|
| 1064 | 1064 | if ($result->SearchHighlightsByField->Content) { |
| 1065 | 1065 | foreach ($result->SearchHighlightsByField->Content as $highlight) { |
| 1066 | - echo("- ".$highlight->Snippet); |
|
| 1066 | + echo("- " . $highlight->Snippet); |
|
| 1067 | 1067 | } |
| 1068 | 1068 | } |
| 1069 | 1069 | } |
@@ -153,6 +153,9 @@ |
||
| 153 | 153 | |
| 154 | 154 | /** |
| 155 | 155 | * Simulate a call to Elastica to get suggestions for a given phrase |
| 156 | + * @param string $phrase |
|
| 157 | + * @param string $suggestion |
|
| 158 | + * @param string $highlightedSuggestion |
|
| 156 | 159 | * @return [type] [description] |
| 157 | 160 | */ |
| 158 | 161 | private function getSuggestionArray($phrase, $suggestion, $highlightedSuggestion) { |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | * Note: characters are stripped from the content; make sure that your assertions take this into account. |
| 103 | 103 | * |
| 104 | 104 | * @param string $selector A basic CSS selector, e.g. 'li.jobs h3' |
| 105 | - * @param array|string $expectedMatches The content of at least one of the matched tags |
|
| 105 | + * @param integer $index |
|
| 106 | 106 | * @throws PHPUnit_Framework_AssertionFailedError |
| 107 | 107 | * @return boolean |
| 108 | 108 | */ |
@@ -133,6 +133,12 @@ discard block |
||
| 133 | 133 | /* |
| 134 | 134 | Check all the nodes matching the selector for attribute name = expected value |
| 135 | 135 | */ |
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * @param string $selector |
|
| 139 | + * @param string $attributeName |
|
| 140 | + * @param string $expectedValue |
|
| 141 | + */ |
|
| 136 | 142 | public function assertAttributeHasExactValue($selector, $attributeName, $expectedValue) { |
| 137 | 143 | $items = $this->cssParser()->getBySelector($selector); |
| 138 | 144 | foreach ($items as $item) { |
@@ -141,6 +147,9 @@ discard block |
||
| 141 | 147 | } |
| 142 | 148 | |
| 143 | 149 | |
| 150 | + /** |
|
| 151 | + * @param string $selector |
|
| 152 | + */ |
|
| 144 | 153 | public function assertAttributesHaveExactValues($selector, $expectedValues) { |
| 145 | 154 | $attributeNames = array_keys($expectedValues); |
| 146 | 155 | $items = $this->cssParser()->getBySelector($selector); |
@@ -154,6 +163,10 @@ discard block |
||
| 154 | 163 | } |
| 155 | 164 | |
| 156 | 165 | |
| 166 | + /** |
|
| 167 | + * @param string $selector |
|
| 168 | + * @param integer $expectedAmount |
|
| 169 | + */ |
|
| 157 | 170 | public function assertNumberOfNodes($selector, $expectedAmount) { |
| 158 | 171 | $items = $this->cssParser()->getBySelector($selector); |
| 159 | 172 | foreach ($items as $item) { |
@@ -8,8 +8,8 @@ discard block |
||
| 8 | 8 | public static $ignoreFixtureFileFor = array(); |
| 9 | 9 | |
| 10 | 10 | protected $extraDataObjects = array( |
| 11 | - 'SearchableTestPage','FlickrPhotoTO','FlickrAuthorTO','FlickrSetTO','FlickrTagTO', |
|
| 12 | - 'SearchableTestFatherPage','SearchableTestGrandFatherPage' |
|
| 11 | + 'SearchableTestPage', 'FlickrPhotoTO', 'FlickrAuthorTO', 'FlickrSetTO', 'FlickrTagTO', |
|
| 12 | + 'SearchableTestFatherPage', 'SearchableTestGrandFatherPage' |
|
| 13 | 13 | ); |
| 14 | 14 | |
| 15 | 15 | |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | |
| 30 | 30 | // this needs to be called in order to create the list of searchable |
| 31 | 31 | // classes and fields that are available. Simulates part of a build |
| 32 | - $classes = array('SearchableTestPage','SiteTree','Page','FlickrPhotoTO','FlickrSetTO', |
|
| 32 | + $classes = array('SearchableTestPage', 'SiteTree', 'Page', 'FlickrPhotoTO', 'FlickrSetTO', |
|
| 33 | 33 | 'FlickrTagTO', 'FlickrAuthorTO'); |
| 34 | 34 | $this->requireDefaultRecordsFrom = $classes; |
| 35 | 35 | |
@@ -60,8 +60,8 @@ discard block |
||
| 60 | 60 | print_r(static::$ignoreFixtureFileFor); |
| 61 | 61 | |
| 62 | 62 | foreach (static::$ignoreFixtureFileFor as $testPattern) { |
| 63 | - $pattern = '/'.$testPattern.'/'; |
|
| 64 | - echo "GREP: $pattern against ".$this->getName()."\n"; |
|
| 63 | + $pattern = '/' . $testPattern . '/'; |
|
| 64 | + echo "GREP: $pattern against " . $this->getName() . "\n"; |
|
| 65 | 65 | if (preg_match($pattern, $this->getName())) { |
| 66 | 66 | static::$fixture_file = null; |
| 67 | 67 | } |
@@ -88,8 +88,8 @@ discard block |
||
| 88 | 88 | // temporarily disable Elasticsearch indexing, it will be done in a batch |
| 89 | 89 | $page->IndexingOff = true; |
| 90 | 90 | |
| 91 | - echo "Publishing ".$page->Title."\n"; |
|
| 92 | - $page->publish('Stage','Live'); |
|
| 91 | + echo "Publishing " . $page->Title . "\n"; |
|
| 92 | + $page->publish('Stage', 'Live'); |
|
| 93 | 93 | } |
| 94 | 94 | } |
| 95 | 95 | |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | $text = strip_tags($item); |
| 116 | 116 | $escaped = str_replace("'", "\'", $text); |
| 117 | 117 | echo "SELECTED:\$this->assertSelectorStartsWithOrEquals('{$selector}', $ctr, '$escaped');\n"; |
| 118 | - echo "ITEM:".$item."\n"; |
|
| 118 | + echo "ITEM:" . $item . "\n"; |
|
| 119 | 119 | $ctr++; |
| 120 | 120 | } |
| 121 | 121 | |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | $result = array(); |
| 172 | 172 | foreach ($items as $item) { |
| 173 | 173 | $attr = $item->attributes()->id; |
| 174 | - array_push($result, $attr.""); |
|
| 174 | + array_push($result, $attr . ""); |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | return $result; |