@@ -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); |
@@ -126,12 +126,12 @@ discard block |
||
| 126 | 126 | $queryTextExists = ($this->queryText != ''); |
| 127 | 127 | $isMultiMatch = ($this->fields != null); |
| 128 | 128 | |
| 129 | - if ($this->selectedFilters == null) { |
|
| 129 | + if($this->selectedFilters == null) { |
|
| 130 | 130 | $this->selectedFilters = array(); |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | $this->manipulatorInstance = null; |
| 134 | - if ($this->manipulator) { |
|
| 134 | + if($this->manipulator) { |
|
| 135 | 135 | $this->manipulatorInstance = \Injector::inst()->create($this->manipulator); |
| 136 | 136 | $this->manipulatorInstance->queryGenerator = $this; |
| 137 | 137 | $this->manipulatorInstance->originalQueryString = $this->queryText; |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | //This is a query_string object |
| 141 | 141 | $textQuery = null; |
| 142 | 142 | |
| 143 | - if (!$isMultiMatch) { |
|
| 143 | + if(!$isMultiMatch) { |
|
| 144 | 144 | $textQuery = $this->simpleTextQuery(); |
| 145 | 145 | } else { |
| 146 | 146 | $textQuery = $this->multiMatchQuery(); |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | $query->setLimit($this->pageLength); |
| 160 | 160 | $query->setFrom($this->start); |
| 161 | 161 | |
| 162 | - if ($this->manipulatorInstance && !$queryTextExists) { |
|
| 162 | + if($this->manipulatorInstance && !$queryTextExists) { |
|
| 163 | 163 | $sort = $this->manipulatorInstance->getDefaultSort(); |
| 164 | 164 | $query->setSort($sort); |
| 165 | 165 | } |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | 'size' => 10, |
| 191 | 191 | 'query' => array( |
| 192 | 192 | 'match' => array( |
| 193 | - $field.'.autocomplete' => array( |
|
| 193 | + $field . '.autocomplete' => array( |
|
| 194 | 194 | 'query' => $this->queryText, |
| 195 | 195 | 'operator' => 'and' |
| 196 | 196 | ) |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | ); |
| 200 | 200 | |
| 201 | 201 | // The query clause can only have one entry, so a bit of mangling |
| 202 | - if (!empty($this->selectedFilters)) { |
|
| 202 | + if(!empty($this->selectedFilters)) { |
|
| 203 | 203 | $filtered = array(); |
| 204 | 204 | $filtered['query'] = $data['query']; |
| 205 | 205 | unset($data['query']); |
@@ -228,17 +228,17 @@ discard block |
||
| 228 | 228 | * @param Elastica\Query\QueryString $textQuery A query_string representing the current query |
| 229 | 229 | */ |
| 230 | 230 | private function addFilters($textQuery) { |
| 231 | - if ($this->manipulator) { |
|
| 231 | + if($this->manipulator) { |
|
| 232 | 232 | $this->manipulatorInstance->updateFilters($this->selectedFilters); |
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | $elFilters = array(); |
| 236 | 236 | $rangeFilterKeys = RangedAggregation::getTitles(); |
| 237 | 237 | |
| 238 | - foreach ($this->selectedFilters as $key => $value) { |
|
| 239 | - if (!in_array($key, $rangeFilterKeys)) { |
|
| 238 | + foreach($this->selectedFilters as $key => $value) { |
|
| 239 | + if(!in_array($key, $rangeFilterKeys)) { |
|
| 240 | 240 | $filter = new Term(); |
| 241 | - $filter->setTerm($key,$value); |
|
| 241 | + $filter->setTerm($key, $value); |
|
| 242 | 242 | $elFilters[] = $filter; |
| 243 | 243 | } else { |
| 244 | 244 | // get the selected range filter |
@@ -251,7 +251,7 @@ discard block |
||
| 251 | 251 | |
| 252 | 252 | // if not facets selected, pass through null |
| 253 | 253 | $queryFilter = null; |
| 254 | - switch (count($this->selectedFilters)) { |
|
| 254 | + switch(count($this->selectedFilters)) { |
|
| 255 | 255 | case 0: |
| 256 | 256 | // filter already null |
| 257 | 257 | break; |
@@ -261,18 +261,18 @@ discard block |
||
| 261 | 261 | default: |
| 262 | 262 | $queryFilter = new BoolAnd(); |
| 263 | 263 | |
| 264 | - foreach ($elFilters as $filter) { |
|
| 264 | + foreach($elFilters as $filter) { |
|
| 265 | 265 | $queryFilter->addFilter($filter); |
| 266 | 266 | } |
| 267 | 267 | break; |
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | // the Elastica query object |
| 271 | - if ($queryFilter == null) { |
|
| 271 | + if($queryFilter == null) { |
|
| 272 | 272 | $query = new Query($textQuery); |
| 273 | 273 | } else { |
| 274 | 274 | //MatchAll appears not be allowed inside a filtered query which is a bit of a pain. |
| 275 | - if ($textQuery instanceof MatchAll) { |
|
| 275 | + if($textQuery instanceof MatchAll) { |
|
| 276 | 276 | $textQuery = null; |
| 277 | 277 | } |
| 278 | 278 | |
@@ -289,7 +289,7 @@ discard block |
||
| 289 | 289 | |
| 290 | 290 | private function addAggregation(&$query) { |
| 291 | 291 | // aggregation (optional) |
| 292 | - if ($this->manipulatorInstance) { |
|
| 292 | + if($this->manipulatorInstance) { |
|
| 293 | 293 | $this->manipulatorInstance->augmentQuery($query); |
| 294 | 294 | } |
| 295 | 295 | } |
@@ -316,7 +316,7 @@ discard block |
||
| 316 | 316 | //Setting the lenient flag means that numeric fields can be searched for text values |
| 317 | 317 | $textQuery->setParam('lenient', true); |
| 318 | 318 | |
| 319 | - if ($this->showResultsForEmptyQuery && $this->queryText == '') { |
|
| 319 | + if($this->showResultsForEmptyQuery && $this->queryText == '') { |
|
| 320 | 320 | $textQuery = new MatchAll(); |
| 321 | 321 | } |
| 322 | 322 | |
@@ -329,8 +329,8 @@ discard block |
||
| 329 | 329 | $textQuery = new MultiMatch(); |
| 330 | 330 | |
| 331 | 331 | // Differing cases for showing and not showing empty string |
| 332 | - if ($this->queryText == '') { |
|
| 333 | - if (!$this->showResultsForEmptyQuery) { |
|
| 332 | + if($this->queryText == '') { |
|
| 333 | + if(!$this->showResultsForEmptyQuery) { |
|
| 334 | 334 | $textQuery->setQuery(''); |
| 335 | 335 | } else { |
| 336 | 336 | //WIP |
@@ -343,7 +343,7 @@ discard block |
||
| 343 | 343 | $textQuery->setQuery($this->queryText); |
| 344 | 344 | } |
| 345 | 345 | |
| 346 | - if ($textQuery instanceof MultiMatch) { |
|
| 346 | + if($textQuery instanceof MultiMatch) { |
|
| 347 | 347 | $elasticaFields = $this->convertWeightedFieldsForElastica($this->fields); |
| 348 | 348 | $textQuery->setFields($elasticaFields); |
| 349 | 349 | $textQuery->setType('most_fields'); |
@@ -366,20 +366,20 @@ discard block |
||
| 366 | 366 | */ |
| 367 | 367 | public function convertWeightedFieldsForElastica($fields) { |
| 368 | 368 | $result = array(); |
| 369 | - $nameToType = self::getSearchFieldsMappingForClasses($this->classes,$fields); |
|
| 369 | + $nameToType = self::getSearchFieldsMappingForClasses($this->classes, $fields); |
|
| 370 | 370 | |
| 371 | - if (sizeof($fields) != 0) { |
|
| 372 | - foreach ($fields as $fieldName => $weight) { |
|
| 371 | + if(sizeof($fields) != 0) { |
|
| 372 | + foreach($fields as $fieldName => $weight) { |
|
| 373 | 373 | $fieldCfg = "$fieldName"; |
| 374 | - if ($weight != 1) { |
|
| 375 | - $fieldCfg .= '^'.$weight; |
|
| 374 | + if($weight != 1) { |
|
| 375 | + $fieldCfg .= '^' . $weight; |
|
| 376 | 376 | } |
| 377 | 377 | array_push($result, $fieldCfg); |
| 378 | - if (isset($nameToType[$fieldName])) { |
|
| 379 | - if ($nameToType[$fieldName] == 'string') { |
|
| 378 | + if(isset($nameToType[$fieldName])) { |
|
| 379 | + if($nameToType[$fieldName] == 'string') { |
|
| 380 | 380 | $fieldCfg = "{$fieldName}.*"; |
| 381 | - if ($weight != 1) { |
|
| 382 | - $fieldCfg .= '^'.$weight; |
|
| 381 | + if($weight != 1) { |
|
| 382 | + $fieldCfg .= '^' . $weight; |
|
| 383 | 383 | } |
| 384 | 384 | array_push($result, $fieldCfg); |
| 385 | 385 | } |
@@ -405,29 +405,29 @@ discard block |
||
| 405 | 405 | // Get a array of relevant classes to search |
| 406 | 406 | $cache = QueryGenerator::getCache(); |
| 407 | 407 | $csvClasses = $classes; |
| 408 | - if (is_array($classes)) { |
|
| 409 | - $csvClasses = implode(',',$classes); |
|
| 408 | + if(is_array($classes)) { |
|
| 409 | + $csvClasses = implode(',', $classes); |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | error_log("CSV CLASSES: $csvClasses"); |
| 413 | 413 | |
| 414 | - $key ='SEARCHABLE_FIELDS_'.str_replace(',', '_', $csvClasses); |
|
| 414 | + $key = 'SEARCHABLE_FIELDS_' . str_replace(',', '_', $csvClasses); |
|
| 415 | 415 | |
| 416 | - if ($fieldsAllowed) { |
|
| 416 | + if($fieldsAllowed) { |
|
| 417 | 417 | $fieldsAllowedCSV = self::convertToQuotedCSV(array_keys($fieldsAllowed)); |
| 418 | - $key .= '_' . str_replace(',', '_', str_replace("'", '_',$fieldsAllowedCSV)); |
|
| 418 | + $key .= '_' . str_replace(',', '_', str_replace("'", '_', $fieldsAllowedCSV)); |
|
| 419 | 419 | $key = str_replace('.', '_', $key); |
| 420 | 420 | $key = str_replace(' ', '_', $key); |
| 421 | 421 | } |
| 422 | 422 | |
| 423 | 423 | $result = $cache->load($key); |
| 424 | 424 | error_log("RESULT:$result for key $key \n"); |
| 425 | - if (!$result) { |
|
| 425 | + if(!$result) { |
|
| 426 | 426 | $relevantClasses = array(); |
| 427 | - if (empty($csvClasses)) { |
|
| 427 | + if(empty($csvClasses)) { |
|
| 428 | 428 | $sql = "SELECT DISTINCT Name from SearchableClass where InSiteTree = 1 order by Name"; |
| 429 | 429 | $records = \DB::query($sql); |
| 430 | - foreach ($records as $record) { |
|
| 430 | + foreach($records as $record) { |
|
| 431 | 431 | array_push($relevantClasses, $record['Name']); |
| 432 | 432 | } |
| 433 | 433 | } else { |
@@ -435,21 +435,21 @@ discard block |
||
| 435 | 435 | } |
| 436 | 436 | |
| 437 | 437 | $result = array(); |
| 438 | - if (sizeof($relevantClasses) > 0) { |
|
| 438 | + if(sizeof($relevantClasses) > 0) { |
|
| 439 | 439 | $relevantClassesCSV = self::convertToQuotedCSV($relevantClasses); |
| 440 | 440 | |
| 441 | 441 | //Perform a database query to get get a list of searchable fieldnames to Elasticsearch mapping |
| 442 | 442 | $sql = "SELECT sf.Name,sf.Type FROM SearchableClass sc INNER JOIN SearchableField sf ON " |
| 443 | 443 | . "sc.id = sf.SearchableClassID WHERE sc.name IN ($relevantClassesCSV)"; |
| 444 | - if ($fieldsAllowed) { |
|
| 444 | + if($fieldsAllowed) { |
|
| 445 | 445 | $fieldsAllowedCSV = self::convertToQuotedCSV(array_keys($fieldsAllowed)); |
| 446 | - if (strlen($fieldsAllowedCSV) > 0) { |
|
| 446 | + if(strlen($fieldsAllowedCSV) > 0) { |
|
| 447 | 447 | $sql .= " AND sf.Name IN ($fieldsAllowedCSV)"; |
| 448 | 448 | } |
| 449 | 449 | } |
| 450 | 450 | |
| 451 | 451 | $records = \DB::query($sql); |
| 452 | - foreach ($records as $record) { |
|
| 452 | + foreach($records as $record) { |
|
| 453 | 453 | $name = $record['Name']; |
| 454 | 454 | $type = $record['Type']; |
| 455 | 455 | |
@@ -463,11 +463,11 @@ discard block |
||
| 463 | 463 | $result[$name] = $type; |
| 464 | 464 | } |
| 465 | 465 | } |
| 466 | - $cache->save(json_encode($result),$key); |
|
| 467 | - } else { |
|
| 466 | + $cache->save(json_encode($result), $key); |
|
| 467 | + } else { |
|
| 468 | 468 | // true is necessary here to decode the array hash back to an array and not a struct |
| 469 | 469 | self::$cacheHitCtr++; |
| 470 | - $result = json_decode($result,true); |
|
| 470 | + $result = json_decode($result, true); |
|
| 471 | 471 | } |
| 472 | 472 | |
| 473 | 473 | return $result; |
@@ -488,21 +488,21 @@ discard block |
||
| 488 | 488 | */ |
| 489 | 489 | public static function convertToQuotedCSV($csvOrArray) { |
| 490 | 490 | $asArray = $csvOrArray; |
| 491 | - if (!is_array($csvOrArray)) { |
|
| 492 | - if ($csvOrArray == null) { |
|
| 491 | + if(!is_array($csvOrArray)) { |
|
| 492 | + if($csvOrArray == null) { |
|
| 493 | 493 | $asArray = array(); |
| 494 | 494 | } else { |
| 495 | 495 | $asArray = explode(',', $csvOrArray); |
| 496 | 496 | } |
| 497 | 497 | } |
| 498 | 498 | $quoted = array(); |
| 499 | - foreach ($asArray as $value) { |
|
| 500 | - if (strlen($value) > 0) { |
|
| 501 | - $item = "'".$value."'"; |
|
| 499 | + foreach($asArray as $value) { |
|
| 500 | + if(strlen($value) > 0) { |
|
| 501 | + $item = "'" . $value . "'"; |
|
| 502 | 502 | array_push($quoted, $item); |
| 503 | 503 | } |
| 504 | 504 | |
| 505 | 505 | } |
| 506 | - return implode(',', $quoted);; |
|
| 506 | + return implode(',', $quoted); ; |
|
| 507 | 507 | } |
| 508 | 508 | } |
@@ -47,6 +47,9 @@ discard block |
||
| 47 | 47 | private $classes = ''; |
| 48 | 48 | |
| 49 | 49 | |
| 50 | + /** |
|
| 51 | + * @param string $newQueryText |
|
| 52 | + */ |
|
| 50 | 53 | public function setQueryText($newQueryText) { |
| 51 | 54 | $this->queryText = $newQueryText; |
| 52 | 55 | } |
@@ -62,6 +65,9 @@ discard block |
||
| 62 | 65 | } |
| 63 | 66 | |
| 64 | 67 | |
| 68 | + /** |
|
| 69 | + * @param boolean $newShowResultsForEmptyQuery |
|
| 70 | + */ |
|
| 65 | 71 | public function setShowResultsForEmptyQuery($newShowResultsForEmptyQuery) { |
| 66 | 72 | $this->showResultsForEmptyQuery = $newShowResultsForEmptyQuery; |
| 67 | 73 | } |
@@ -72,11 +78,17 @@ discard block |
||
| 72 | 78 | } |
| 73 | 79 | |
| 74 | 80 | |
| 81 | + /** |
|
| 82 | + * @param integer $newPageLength |
|
| 83 | + */ |
|
| 75 | 84 | public function setPageLength($newPageLength) { |
| 76 | 85 | $this->pageLength = $newPageLength; |
| 77 | 86 | } |
| 78 | 87 | |
| 79 | 88 | |
| 89 | + /** |
|
| 90 | + * @param integer $newStart |
|
| 91 | + */ |
|
| 80 | 92 | public function setStart($newStart) { |
| 81 | 93 | $this->start = $newStart; |
| 82 | 94 | } |
@@ -287,6 +299,9 @@ discard block |
||
| 287 | 299 | } |
| 288 | 300 | |
| 289 | 301 | |
| 302 | + /** |
|
| 303 | + * @param Query $query |
|
| 304 | + */ |
|
| 290 | 305 | private function addAggregation(&$query) { |
| 291 | 306 | // aggregation (optional) |
| 292 | 307 | if ($this->manipulatorInstance) { |
@@ -27,17 +27,17 @@ discard block |
||
| 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 |
||
| 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 | } |
@@ -233,6 +233,9 @@ |
||
| 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; |
@@ -49,7 +49,7 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 | } |
@@ -479,6 +479,9 @@ |
||
| 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); |
@@ -9,7 +9,7 @@ |
||
| 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 | |
@@ -133,7 +133,7 @@ |
||
| 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 |
@@ -27,7 +27,7 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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'; |
@@ -20,24 +20,24 @@ |
||
| 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'), |
@@ -22,7 +22,7 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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' |