@@ -340,10 +340,10 @@ discard block |
||
| 340 | 340 | |
| 341 | 341 | |
| 342 | 342 | /** |
| 343 | - * Get an elasticsearch document |
|
| 344 | - * |
|
| 345 | - * @return \Elastica\Document |
|
| 346 | - */ |
|
| 343 | + * Get an elasticsearch document |
|
| 344 | + * |
|
| 345 | + * @return \Elastica\Document |
|
| 346 | + */ |
|
| 347 | 347 | public function getElasticaDocument() { |
| 348 | 348 | self::$index_ctr++; |
| 349 | 349 | $fields = $this->getFieldValuesAsArray(); |
@@ -754,7 +754,7 @@ discard block |
||
| 754 | 754 | } |
| 755 | 755 | |
| 756 | 756 | |
| 757 | - public function updateCMSFields(\FieldList $fields) { |
|
| 757 | + public function updateCMSFields(\FieldList $fields) { |
|
| 758 | 758 | $isIndexed = false; |
| 759 | 759 | // SIteTree object must have a live record, ShowInSearch = true |
| 760 | 760 | if ($this->isInSiteTree($this->owner->ClassName)) { |
@@ -781,47 +781,47 @@ discard block |
||
| 781 | 781 | $terms = new \ArrayList(); |
| 782 | 782 | |
| 783 | 783 | foreach (array_keys($termVectors[$field]['terms']) as $term) { |
| 784 | - $do = new \DataObject(); |
|
| 785 | - $do->Term = $term; |
|
| 786 | - $stats = $termVectors[$field]['terms'][$term]; |
|
| 787 | - if (isset($stats['ttf'])) { |
|
| 788 | - $do->TTF = $stats['ttf']; |
|
| 789 | - } |
|
| 790 | - |
|
| 791 | - if (isset($stats['doc_freq'])) { |
|
| 792 | - $do->DocFreq = $stats['doc_freq']; |
|
| 793 | - } |
|
| 794 | - |
|
| 795 | - if (isset($stats['term_freq'])) { |
|
| 796 | - $do->TermFreq = $stats['term_freq']; |
|
| 797 | - } |
|
| 798 | - $terms->push($do); |
|
| 799 | - } |
|
| 800 | - |
|
| 801 | - $config = \GridFieldConfig_RecordViewer::create(100); |
|
| 784 | + $do = new \DataObject(); |
|
| 785 | + $do->Term = $term; |
|
| 786 | + $stats = $termVectors[$field]['terms'][$term]; |
|
| 787 | + if (isset($stats['ttf'])) { |
|
| 788 | + $do->TTF = $stats['ttf']; |
|
| 789 | + } |
|
| 790 | + |
|
| 791 | + if (isset($stats['doc_freq'])) { |
|
| 792 | + $do->DocFreq = $stats['doc_freq']; |
|
| 793 | + } |
|
| 794 | + |
|
| 795 | + if (isset($stats['term_freq'])) { |
|
| 796 | + $do->TermFreq = $stats['term_freq']; |
|
| 797 | + } |
|
| 798 | + $terms->push($do); |
|
| 799 | + } |
|
| 800 | + |
|
| 801 | + $config = \GridFieldConfig_RecordViewer::create(100); |
|
| 802 | 802 | $config->getComponentByType('GridFieldDataColumns')->setDisplayFields(array( |
| 803 | - 'Term' => 'Term', |
|
| 804 | - 'TTF' => 'Total term frequency (how often a term occurs in all documents)', |
|
| 805 | - 'DocFreq' => 'n documents with this term', |
|
| 806 | - 'TermFreq'=> 'n times this term appears in this field' |
|
| 807 | - )); |
|
| 808 | - |
|
| 809 | - $underscored = str_replace('.', '_', $field); |
|
| 810 | - |
|
| 811 | - $gridField = new \GridField( |
|
| 812 | - 'TermsFor'.$underscored, // Field name |
|
| 813 | - $field.'TITLE'.$field, // Field title |
|
| 814 | - $terms, |
|
| 815 | - $config |
|
| 816 | - ); |
|
| 817 | - |
|
| 818 | - // $tab = new \Tab($field, new \TextField('Test'.$field, 'Testing')); |
|
| 819 | - $fields->addFieldToTab('Root.ElasticaTerms.'.$underscored, $gridField); |
|
| 803 | + 'Term' => 'Term', |
|
| 804 | + 'TTF' => 'Total term frequency (how often a term occurs in all documents)', |
|
| 805 | + 'DocFreq' => 'n documents with this term', |
|
| 806 | + 'TermFreq'=> 'n times this term appears in this field' |
|
| 807 | + )); |
|
| 808 | + |
|
| 809 | + $underscored = str_replace('.', '_', $field); |
|
| 810 | + |
|
| 811 | + $gridField = new \GridField( |
|
| 812 | + 'TermsFor'.$underscored, // Field name |
|
| 813 | + $field.'TITLE'.$field, // Field title |
|
| 814 | + $terms, |
|
| 815 | + $config |
|
| 816 | + ); |
|
| 817 | + |
|
| 818 | + // $tab = new \Tab($field, new \TextField('Test'.$field, 'Testing')); |
|
| 819 | + $fields->addFieldToTab('Root.ElasticaTerms.'.$underscored, $gridField); |
|
| 820 | 820 | } |
| 821 | 821 | |
| 822 | 822 | } |
| 823 | 823 | |
| 824 | - return $fields; |
|
| 824 | + return $fields; |
|
| 825 | 825 | } |
| 826 | 826 | |
| 827 | 827 | |
@@ -555,8 +555,7 @@ discard block |
||
| 555 | 555 | // this goes to elastica service |
| 556 | 556 | $this->service->remove($this->owner); |
| 557 | 557 | } |
| 558 | - } |
|
| 559 | - catch(\Elastica\Exception\NotFoundException $e) { |
|
| 558 | + } catch(\Elastica\Exception\NotFoundException $e) { |
|
| 560 | 559 | trigger_error("Deleted document ".$this->owner->ClassName." (".$this->owner->ID. |
| 561 | 560 | ") not found in search index.", E_USER_NOTICE); |
| 562 | 561 | } |
@@ -574,7 +573,9 @@ discard block |
||
| 574 | 573 | $fields = \Config::inst()->get(get_class($this->owner), 'searchable_fields'); |
| 575 | 574 | |
| 576 | 575 | // fallback to default method |
| 577 | - if(!$fields) user_error('The field $searchable_fields must be set for the class '.$this->owner->ClassName); |
|
| 576 | + if(!$fields) { |
|
| 577 | + user_error('The field $searchable_fields must be set for the class '.$this->owner->ClassName); |
|
| 578 | + } |
|
| 578 | 579 | |
| 579 | 580 | // get the values of these fields |
| 580 | 581 | $elasticaMapping = $this->fieldsToElasticaConfig($this->owner, $fields); |
@@ -595,7 +596,9 @@ discard block |
||
| 595 | 596 | |
| 596 | 597 | $relClass = $has_lists[$methodName]; |
| 597 | 598 | $fields = \Config::inst()->get($relClass, 'searchable_fields'); |
| 598 | - if(!$fields) user_error('The field $searchable_fields must be set for the class '.$relClass); |
|
| 599 | + if(!$fields) { |
|
| 600 | + user_error('The field $searchable_fields must be set for the class '.$relClass); |
|
| 601 | + } |
|
| 599 | 602 | $rewrite = $this->fieldsToElasticaConfig($relClass, $fields); |
| 600 | 603 | |
| 601 | 604 | // mark as a method, the resultant fields are correct |
@@ -605,7 +608,9 @@ discard block |
||
| 605 | 608 | } else if (isset($has_ones[$methodName])) { |
| 606 | 609 | $relClass = $has_ones[$methodName]; |
| 607 | 610 | $fields = \Config::inst()->get($relClass, 'searchable_fields'); |
| 608 | - if(!$fields) user_error('The field $searchable_fields must be set for the class '.$relClass); |
|
| 611 | + if(!$fields) { |
|
| 612 | + user_error('The field $searchable_fields must be set for the class '.$relClass); |
|
| 613 | + } |
|
| 609 | 614 | $rewrite = $this->fieldsToElasticaConfig($relClass, $fields); |
| 610 | 615 | $classname = $has_ones[$methodName]; |
| 611 | 616 | |
@@ -687,7 +692,7 @@ discard block |
||
| 687 | 692 | |
| 688 | 693 | if (isset($searchableField['type'])) { |
| 689 | 694 | $doSF->Type = $searchableField['type']; |
| 690 | - } else { |
|
| 695 | + } else { |
|
| 691 | 696 | $doSF->Name = $searchableField['properties']['__method']; |
| 692 | 697 | $doSF->Type = 'relationship'; |
| 693 | 698 | } |
@@ -312,12 +312,12 @@ discard block |
||
| 312 | 312 | |
| 313 | 313 | if (isset($_GET['progress'])) { |
| 314 | 314 | $progress = $_GET['progress']; |
| 315 | - self::$progressInterval = (int) $progress; |
|
| 315 | + self::$progressInterval = (int)$progress; |
|
| 316 | 316 | } |
| 317 | 317 | |
| 318 | 318 | if (self::$progressInterval > 0) { |
| 319 | 319 | if (self::$index_ctr % self::$progressInterval === 0) { |
| 320 | - ElasticaUtil::message("\t".$this->owner->ClassName." - Prepared ".self::$index_ctr." for indexing..."); |
|
| 320 | + ElasticaUtil::message("\t" . $this->owner->ClassName . " - Prepared " . self::$index_ctr . " for indexing..."); |
|
| 321 | 321 | } |
| 322 | 322 | } |
| 323 | 323 | |
@@ -508,14 +508,14 @@ discard block |
||
| 508 | 508 | * Removes the record from the search index. |
| 509 | 509 | */ |
| 510 | 510 | protected function doDeleteDocument() { |
| 511 | - try{ |
|
| 511 | + try { |
|
| 512 | 512 | if (!$this->owner->IndexingOff) { |
| 513 | 513 | // this goes to elastica service |
| 514 | 514 | $this->service->remove($this->owner); |
| 515 | 515 | } |
| 516 | 516 | } |
| 517 | - catch(\Elastica\Exception\NotFoundException $e) { |
|
| 518 | - trigger_error("Deleted document ".$this->owner->ClassName." (".$this->owner->ID. |
|
| 517 | + catch (\Elastica\Exception\NotFoundException $e) { |
|
| 518 | + trigger_error("Deleted document " . $this->owner->ClassName . " (" . $this->owner->ID . |
|
| 519 | 519 | ") not found in search index.", E_USER_NOTICE); |
| 520 | 520 | } |
| 521 | 521 | |
@@ -532,7 +532,7 @@ discard block |
||
| 532 | 532 | $fields = \Config::inst()->get(get_class($this->owner), 'searchable_fields'); |
| 533 | 533 | |
| 534 | 534 | // fallback to default method |
| 535 | - if(!$fields) user_error('The field $searchable_fields must be set for the class '.$this->owner->ClassName); |
|
| 535 | + if (!$fields) user_error('The field $searchable_fields must be set for the class ' . $this->owner->ClassName); |
|
| 536 | 536 | |
| 537 | 537 | // get the values of these fields |
| 538 | 538 | $elasticaMapping = $this->fieldsToElasticaConfig($this->owner, $fields); |
@@ -553,24 +553,24 @@ discard block |
||
| 553 | 553 | |
| 554 | 554 | $relClass = $has_lists[$methodName]; |
| 555 | 555 | $fields = \Config::inst()->get($relClass, 'searchable_fields'); |
| 556 | - if(!$fields) user_error('The field $searchable_fields must be set for the class '.$relClass); |
|
| 556 | + if (!$fields) user_error('The field $searchable_fields must be set for the class ' . $relClass); |
|
| 557 | 557 | $rewrite = $this->fieldsToElasticaConfig($relClass, $fields); |
| 558 | 558 | |
| 559 | 559 | // mark as a method, the resultant fields are correct |
| 560 | - $elasticaMapping[$methodName.'()'] = $rewrite; |
|
| 560 | + $elasticaMapping[$methodName . '()'] = $rewrite; |
|
| 561 | 561 | |
| 562 | 562 | |
| 563 | 563 | } else if (isset($has_ones[$methodName])) { |
| 564 | 564 | $relClass = $has_ones[$methodName]; |
| 565 | 565 | $fields = \Config::inst()->get($relClass, 'searchable_fields'); |
| 566 | - if(!$fields) user_error('The field $searchable_fields must be set for the class '.$relClass); |
|
| 566 | + if (!$fields) user_error('The field $searchable_fields must be set for the class ' . $relClass); |
|
| 567 | 567 | $rewrite = $this->fieldsToElasticaConfig($relClass, $fields); |
| 568 | 568 | $classname = $has_ones[$methodName]; |
| 569 | 569 | |
| 570 | 570 | // mark as a method, the resultant fields are correct |
| 571 | - $elasticaMapping[$methodName.'()'] = $rewrite; |
|
| 571 | + $elasticaMapping[$methodName . '()'] = $rewrite; |
|
| 572 | 572 | } else { |
| 573 | - user_error('The method '.$methodName.' not found in class '.$this->owner->ClassName. |
|
| 573 | + user_error('The method ' . $methodName . ' not found in class ' . $this->owner->ClassName . |
|
| 574 | 574 | ', please check configuration'); |
| 575 | 575 | } |
| 576 | 576 | } |
@@ -587,14 +587,14 @@ discard block |
||
| 587 | 587 | private function fieldsToElasticaConfig($objectInContext, $fields) { |
| 588 | 588 | // Copied from DataObject::searchableFields() as there is no separate accessible method |
| 589 | 589 | $rewrite = array(); |
| 590 | - foreach($fields as $name => $specOrName) { |
|
| 590 | + foreach ($fields as $name => $specOrName) { |
|
| 591 | 591 | $identifer = (is_int($name)) ? $specOrName : $name; |
| 592 | 592 | $rewrite[$identifer] = array(); |
| 593 | - if(!isset($rewrite[$identifer]['title'])) { |
|
| 593 | + if (!isset($rewrite[$identifer]['title'])) { |
|
| 594 | 594 | $rewrite[$identifer]['title'] = (isset($labels[$identifer])) |
| 595 | 595 | ? $labels[$identifer] : \FormField::name_to_label($identifer); |
| 596 | 596 | } |
| 597 | - if(!isset($rewrite[$identifer]['filter'])) { |
|
| 597 | + if (!isset($rewrite[$identifer]['filter'])) { |
|
| 598 | 598 | $rewrite[$identifer]['filter'] = 'PartialMatchFilter'; |
| 599 | 599 | } |
| 600 | 600 | } |
@@ -606,7 +606,7 @@ discard block |
||
| 606 | 606 | public function requireDefaultRecords() { |
| 607 | 607 | parent::requireDefaultRecords(); |
| 608 | 608 | |
| 609 | - $searchableFields = $this->getElasticaFields(true,true); |
|
| 609 | + $searchableFields = $this->getElasticaFields(true, true); |
|
| 610 | 610 | |
| 611 | 611 | |
| 612 | 612 | $doSC = \SearchableClass::get()->filter(array('Name' => $this->owner->ClassName))->first(); |
@@ -639,7 +639,7 @@ discard block |
||
| 639 | 639 | |
| 640 | 640 | if (isset($searchableField['type'])) { |
| 641 | 641 | $doSF->Type = $searchableField['type']; |
| 642 | - } else { |
|
| 642 | + } else { |
|
| 643 | 643 | $doSF->Name = $searchableField['properties']['__method']; |
| 644 | 644 | $doSF->Type = 'relationship'; |
| 645 | 645 | } |
@@ -650,7 +650,7 @@ discard block |
||
| 650 | 650 | } |
| 651 | 651 | |
| 652 | 652 | $doSF->write(); |
| 653 | - \DB::alteration_message("Created new searchable editable field ".$name,"changed"); |
|
| 653 | + \DB::alteration_message("Created new searchable editable field " . $name, "changed"); |
|
| 654 | 654 | } |
| 655 | 655 | |
| 656 | 656 | // FIXME deal with deletions |
@@ -695,7 +695,7 @@ discard block |
||
| 695 | 695 | */ |
| 696 | 696 | public function RenderResult($linkToContainer = '') { |
| 697 | 697 | $vars = new \ArrayData(array('SearchResult' => $this->owner, 'ContainerLink' => $linkToContainer)); |
| 698 | - $possibleTemplates = array($this->owner->ClassName.'ElasticSearchResult', 'ElasticSearchResult'); |
|
| 698 | + $possibleTemplates = array($this->owner->ClassName . 'ElasticSearchResult', 'ElasticSearchResult'); |
|
| 699 | 699 | return $this->owner->customise($vars)->renderWith($possibleTemplates); |
| 700 | 700 | } |
| 701 | 701 | |
@@ -761,14 +761,14 @@ discard block |
||
| 761 | 761 | $underscored = str_replace('.', '_', $field); |
| 762 | 762 | |
| 763 | 763 | $gridField = new \GridField( |
| 764 | - 'TermsFor'.$underscored, // Field name |
|
| 765 | - $field.'TITLE'.$field, // Field title |
|
| 764 | + 'TermsFor' . $underscored, // Field name |
|
| 765 | + $field . 'TITLE' . $field, // Field title |
|
| 766 | 766 | $terms, |
| 767 | 767 | $config |
| 768 | 768 | ); |
| 769 | 769 | |
| 770 | 770 | // $tab = new \Tab($field, new \TextField('Test'.$field, 'Testing')); |
| 771 | - $fields->addFieldToTab('Root.ElasticaTerms.'.$underscored, $gridField); |
|
| 771 | + $fields->addFieldToTab('Root.ElasticaTerms.' . $underscored, $gridField); |
|
| 772 | 772 | } |
| 773 | 773 | |
| 774 | 774 | } |
@@ -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, |
@@ -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 |
@@ -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,21 +164,21 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 | } |
@@ -40,10 +40,10 @@ |
||
| 40 | 40 | |
| 41 | 41 | $cache = SS_Cache::factory('searchpagecache'); |
| 42 | 42 | $searchPage = null; |
| 43 | - $cachekeyname = 'searchpageuri'.$identifier.$this->owner->Locale.$ck; |
|
| 43 | + $cachekeyname = 'searchpageuri' . $identifier . $this->owner->Locale . $ck; |
|
| 44 | 44 | |
| 45 | - if(!($searchPage = unserialize($cache->load($cachekeyname)))) { |
|
| 46 | - $searchPage = ElasticSearchPage::get()->filter('Identifier',$identifier)->first(); |
|
| 45 | + if (!($searchPage = unserialize($cache->load($cachekeyname)))) { |
|
| 46 | + $searchPage = ElasticSearchPage::get()->filter('Identifier', $identifier)->first(); |
|
| 47 | 47 | $cache->save(serialize($searchPage), $cachekeyname); |
| 48 | 48 | } |
| 49 | 49 | return $searchPage; |
@@ -43,11 +43,11 @@ discard block |
||
| 43 | 43 | try { |
| 44 | 44 | $instance = Injector::inst()->create($clazz); |
| 45 | 45 | if (!$instance->hasExtension('SilverStripe\Elastica\Searchable')) { |
| 46 | - $this->validationError('ClassesToSearch', 'The class '.$clazz.' must have the Searchable extension'); |
|
| 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,16 +58,16 @@ discard block |
||
| 58 | 58 | |
| 59 | 59 | // Check the identifier is unique |
| 60 | 60 | $mode = Versioned::get_reading_mode(); |
| 61 | - $suffix = ''; |
|
| 61 | + $suffix = ''; |
|
| 62 | 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 | 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 | } |
@@ -39,7 +39,7 @@ |
||
| 39 | 39 | |
| 40 | 40 | $this->SubmitButton = $fa; |
| 41 | 41 | |
| 42 | - if(class_exists('Translatable') && singleton('SiteTree')->hasExtension('Translatable')) { |
|
| 42 | + if (class_exists('Translatable') && singleton('SiteTree')->hasExtension('Translatable')) { |
|
| 43 | 43 | $fields->push(new HiddenField('searchlocale', 'searchlocale', Translatable::get_current_locale())); |
| 44 | 44 | } |
| 45 | 45 | |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Elastica Search Form |
|
| 4 | - */ |
|
| 3 | + * Elastica Search Form |
|
| 4 | + */ |
|
| 5 | 5 | |
| 6 | 6 | use Elastica\Document; |
| 7 | 7 | use Elastica\Query; |
@@ -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 | } |
@@ -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 | |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | ); |
| 63 | 63 | |
| 64 | 64 | private static $many_many_extraFields = array( |
| 65 | - 'ElasticaSearchableFields' => array( |
|
| 65 | + 'ElasticaSearchableFields' => array( |
|
| 66 | 66 | 'Searchable' => 'Boolean', // allows the option of turning off a single field for searching |
| 67 | 67 | 'SimilarSearchable' => 'Boolean', // allows field to be used in more like this queries. |
| 68 | 68 | 'Active' => 'Boolean', // preserve previous edits of weighting when classes changed |
@@ -104,10 +104,10 @@ discard block |
||
| 104 | 104 | $sortedWords = $this->SimilarityStopWords; |
| 105 | 105 | |
| 106 | 106 | $stopwordsField = StringTagField::create( |
| 107 | - 'SimilarityStopWords', |
|
| 108 | - 'Stop Words for Similar Search', |
|
| 109 | - $sortedWords, |
|
| 110 | - $sortedWords |
|
| 107 | + 'SimilarityStopWords', |
|
| 108 | + 'Stop Words for Similar Search', |
|
| 109 | + $sortedWords, |
|
| 110 | + $sortedWords |
|
| 111 | 111 | ); |
| 112 | 112 | |
| 113 | 113 | $stopwordsField->setShouldLazyLoad(true); // tags should be lazy loaded |
@@ -190,15 +190,15 @@ discard block |
||
| 190 | 190 | $fields->addFieldToTab('Root.Search.Aggregations', new TextField('SearchHelper', |
| 191 | 191 | 'ClassName of object to manipulate search details and results. Leave blank for standard search')); |
| 192 | 192 | |
| 193 | - $ottos = AutoCompleteOption::get()->Filter('Locale', $this->Locale)->map('ID', 'Name')-> |
|
| 194 | - toArray(); |
|
| 195 | - $df = DropdownField::create('AutoCompleteFunctionID', 'Autocomplete Function')-> |
|
| 196 | - setSource($ottos); |
|
| 197 | - $df->setEmptyString('-- Please select what do do after find as you type has occurred --'); |
|
| 193 | + $ottos = AutoCompleteOption::get()->Filter('Locale', $this->Locale)->map('ID', 'Name')-> |
|
| 194 | + toArray(); |
|
| 195 | + $df = DropdownField::create('AutoCompleteFunctionID', 'Autocomplete Function')-> |
|
| 196 | + setSource($ottos); |
|
| 197 | + $df->setEmptyString('-- Please select what do do after find as you type has occurred --'); |
|
| 198 | 198 | |
| 199 | - $ottos = $this->ElasticaSearchableFields()->filter('EnableAutocomplete',1)->Map('ID', 'Name')->toArray(); |
|
| 200 | - $autoCompleteFieldDF = DropDownField::create('AutoCompleteFieldID', 'Field to use for autocomplete')->setSource($ottos); |
|
| 201 | - $autoCompleteFieldDF->setEmptyString('-- Please select which field to use for autocomplete --'); |
|
| 199 | + $ottos = $this->ElasticaSearchableFields()->filter('EnableAutocomplete',1)->Map('ID', 'Name')->toArray(); |
|
| 200 | + $autoCompleteFieldDF = DropDownField::create('AutoCompleteFieldID', 'Field to use for autocomplete')->setSource($ottos); |
|
| 201 | + $autoCompleteFieldDF->setEmptyString('-- Please select which field to use for autocomplete --'); |
|
| 202 | 202 | |
| 203 | 203 | $fields->addFieldToTab("Root.Search.AutoComplete", |
| 204 | 204 | FieldGroup::create( |
@@ -223,7 +223,7 @@ discard block |
||
| 223 | 223 | $pickerConfig->removeComponentsByType(new PickerFieldAddExistingSearchButton()); |
| 224 | 224 | $pickerConfig->getComponentByType('GridFieldPaginator')->setItemsPerPage(100); |
| 225 | 225 | |
| 226 | - $searchPicker->enableEdit(); |
|
| 226 | + $searchPicker->enableEdit(); |
|
| 227 | 227 | $edittest = $pickerConfig->getComponentByType('GridFieldDetailForm'); |
| 228 | 228 | $edittest->setFields(FieldList::create( |
| 229 | 229 | TextField::create('Name', 'Field Name'), |
@@ -257,23 +257,23 @@ discard block |
||
| 257 | 257 | |
| 258 | 258 | // What do display on the grid of searchable fields |
| 259 | 259 | $dataColumns = $pickerConfig->getComponentByType('GridFieldDataColumns'); |
| 260 | - $dataColumns->setDisplayFields(array( |
|
| 260 | + $dataColumns->setDisplayFields(array( |
|
| 261 | 261 | 'Name' => 'Name', |
| 262 | - 'ClazzName' => 'Class', |
|
| 262 | + 'ClazzName' => 'Class', |
|
| 263 | 263 | 'Type' => 'Type', |
| 264 | 264 | 'Searchable' => 'Use for Search?', |
| 265 | 265 | 'SimilarSearchable' => 'Use for Similar Search?', |
| 266 | 266 | 'ShowHighlights' => 'Show Search Highlights', |
| 267 | 267 | 'Weight' => 'Weighting' |
| 268 | - )); |
|
| 268 | + )); |
|
| 269 | 269 | |
| 270 | 270 | return $fields; |
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | |
| 274 | 274 | public function getCMSValidator() { |
| 275 | - return new ElasticSearchPage_Validator(); |
|
| 276 | - } |
|
| 275 | + return new ElasticSearchPage_Validator(); |
|
| 276 | + } |
|
| 277 | 277 | |
| 278 | 278 | |
| 279 | 279 | /** |
@@ -358,7 +358,7 @@ discard block |
||
| 358 | 358 | $esfs = $this->ElasticaSearchableFields(); |
| 359 | 359 | |
| 360 | 360 | // Remove existing searchable fields for this page from the list of all available |
| 361 | - $delta = array_keys($esfs->map()->toArray()); |
|
| 361 | + $delta = array_keys($esfs->map()->toArray()); |
|
| 362 | 362 | $newSearchableFields = $sfs->exclude('ID', $delta); |
| 363 | 363 | |
| 364 | 364 | if ($newSearchableFields->count() > 0) { |
@@ -448,7 +448,7 @@ discard block |
||
| 448 | 448 | Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js'); |
| 449 | 449 | Requirements::javascript("elastica/javascript/jquery.autocomplete.js"); |
| 450 | 450 | Requirements::javascript("elastica/javascript/elastica.js"); |
| 451 | - Requirements::css("elastica/css/elastica.css"); |
|
| 451 | + Requirements::css("elastica/css/elastica.css"); |
|
| 452 | 452 | } |
| 453 | 453 | |
| 454 | 454 | |
@@ -522,9 +522,9 @@ discard block |
||
| 522 | 522 | |
| 523 | 523 | try { |
| 524 | 524 | // Simulate server being down for testing purposes |
| 525 | - if (isset($_GET['ServerDown'])) { |
|
| 526 | - throw new Elastica\Exception\Connection\HttpException('Unable to reach search server'); |
|
| 527 | - } |
|
| 525 | + if (isset($_GET['ServerDown'])) { |
|
| 526 | + throw new Elastica\Exception\Connection\HttpException('Unable to reach search server'); |
|
| 527 | + } |
|
| 528 | 528 | if (class_exists($class)) { |
| 529 | 529 | $instance = \DataObject::get_by_id($class,$instanceID); |
| 530 | 530 | |
@@ -664,9 +664,9 @@ discard block |
||
| 664 | 664 | $paginated = null; |
| 665 | 665 | try { |
| 666 | 666 | // Simulate server being down for testing purposes |
| 667 | - if (isset($_GET['ServerDown'])) { |
|
| 668 | - throw new Elastica\Exception\Connection\HttpException('Unable to reach search server'); |
|
| 669 | - } |
|
| 667 | + if (isset($_GET['ServerDown'])) { |
|
| 668 | + throw new Elastica\Exception\Connection\HttpException('Unable to reach search server'); |
|
| 669 | + } |
|
| 670 | 670 | |
| 671 | 671 | // now actually perform the search using the original query |
| 672 | 672 | $paginated = $es->search($queryText, $fieldsToSearch, $testMode); |
@@ -118,29 +118,29 @@ discard block |
||
| 118 | 118 | 'Default values are those used by Elastica')); |
| 119 | 119 | $fields->addFieldToTab("Root.Search.Similarity", $lf); |
| 120 | 120 | $fields->addFieldToTab("Root.Search.Similarity", new TextField('MinTermFreq', |
| 121 | - 'The minimum term frequency below which the terms will be ignored from the input '. |
|
| 121 | + 'The minimum term frequency below which the terms will be ignored from the input ' . |
|
| 122 | 122 | 'document. Defaults to 2.')); |
| 123 | 123 | $fields->addFieldToTab("Root.Search.Similarity", new TextField('MaxTermFreq', |
| 124 | - 'The maximum number of query terms that will be selected. Increasing this value gives '. |
|
| 124 | + 'The maximum number of query terms that will be selected. Increasing this value gives ' . |
|
| 125 | 125 | 'greater accuracy at the expense of query execution speed. Defaults to 25.')); |
| 126 | 126 | $fields->addFieldToTab("Root.Search.Similarity", new TextField('MinWordLength', |
| 127 | 127 | 'The minimum word length below which the terms will be ignored. Defaults to 0.')); |
| 128 | 128 | $fields->addFieldToTab("Root.Search.Similarity", new TextField('MinDocFreq', |
| 129 | - 'The minimum document frequency below which the terms will be ignored from the input '. |
|
| 129 | + 'The minimum document frequency below which the terms will be ignored from the input ' . |
|
| 130 | 130 | 'document. Defaults to 5.')); |
| 131 | 131 | $fields->addFieldToTab("Root.Search.Similarity", new TextField('MaxDocFreq', |
| 132 | - 'The maximum document frequency above which the terms will be ignored from the input '. |
|
| 133 | - 'document. This could be useful in order to ignore highly frequent words such as stop '. |
|
| 132 | + 'The maximum document frequency above which the terms will be ignored from the input ' . |
|
| 133 | + 'document. This could be useful in order to ignore highly frequent words such as stop ' . |
|
| 134 | 134 | 'words. Defaults to unbounded (0).')); |
| 135 | 135 | $fields->addFieldToTab("Root.Search.Similarity", new TextField('MinWordLength', |
| 136 | - 'The minimum word length below which the terms will be ignored. The old name min_'. |
|
| 136 | + 'The minimum word length below which the terms will be ignored. The old name min_' . |
|
| 137 | 137 | 'word_len is deprecated. Defaults to 0.')); |
| 138 | 138 | $fields->addFieldToTab("Root.Search.Similarity", new TextField('MaxWordLength', |
| 139 | - 'The maximum word length above which the terms will be ignored. The old name max_word_'. |
|
| 139 | + 'The maximum word length above which the terms will be ignored. The old name max_word_' . |
|
| 140 | 140 | 'len is deprecated. Defaults to unbounded (0).')); |
| 141 | 141 | $fields->addFieldToTab("Root.Search.Similarity", new TextField('MinShouldMatch', |
| 142 | - 'This parameter controls the number of terms that must match. This can be either a '. |
|
| 143 | - 'number or a percentage. See '. |
|
| 142 | + 'This parameter controls the number of terms that must match. This can be either a ' . |
|
| 143 | + 'number or a percentage. See ' . |
|
| 144 | 144 | 'https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-minimum-should-match.html')); |
| 145 | 145 | |
| 146 | 146 | // ---- search details tab ---- |
@@ -177,9 +177,9 @@ discard block |
||
| 177 | 177 | |
| 178 | 178 | $html = '<div class="field text" id="SiteTreeOnlyInfo">'; |
| 179 | 179 | $html .= "<p>Copy the following into the above field to ensure that all SiteTree classes are searched</p>"; |
| 180 | - $html .= '<p class="message">'.$list; |
|
| 180 | + $html .= '<p class="message">' . $list; |
|
| 181 | 181 | $html .= "</p></div>"; |
| 182 | - $infoField = new LiteralField('InfoField',$html); |
|
| 182 | + $infoField = new LiteralField('InfoField', $html); |
|
| 183 | 183 | $fields->addFieldToTab('Root.Search.SearchFor', $infoField); |
| 184 | 184 | |
| 185 | 185 | $fields->addFieldToTab('Root.Main', new HTMLEditorField('ContentForEmptySearch')); |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | setSource($ottos); |
| 197 | 197 | $df->setEmptyString('-- Please select what do do after find as you type has occurred --'); |
| 198 | 198 | |
| 199 | - $ottos = $this->ElasticaSearchableFields()->filter('EnableAutocomplete',1)->Map('ID', 'Name')->toArray(); |
|
| 199 | + $ottos = $this->ElasticaSearchableFields()->filter('EnableAutocomplete', 1)->Map('ID', 'Name')->toArray(); |
|
| 200 | 200 | $autoCompleteFieldDF = DropDownField::create('AutoCompleteFieldID', 'Field to use for autocomplete')->setSource($ottos); |
| 201 | 201 | $autoCompleteFieldDF->setEmptyString('-- Please select which field to use for autocomplete --'); |
| 202 | 202 | |
@@ -208,9 +208,9 @@ discard block |
||
| 208 | 208 | ); |
| 209 | 209 | |
| 210 | 210 | // ---- grid of searchable fields ---- |
| 211 | - $html = '<p id="SearchFieldIntro">'._t('SiteConfig.ELASTICA_SEARCH_INFO', |
|
| 212 | - "Select a field to edit it's properties").'</p>'; |
|
| 213 | - $fields->addFieldToTab('Root.Search.Fields', $h1=new LiteralField('SearchInfo', $html)); |
|
| 211 | + $html = '<p id="SearchFieldIntro">' . _t('SiteConfig.ELASTICA_SEARCH_INFO', |
|
| 212 | + "Select a field to edit it's properties") . '</p>'; |
|
| 213 | + $fields->addFieldToTab('Root.Search.Fields', $h1 = new LiteralField('SearchInfo', $html)); |
|
| 214 | 214 | $searchPicker = new PickerField('ElasticaSearchableFields', 'Searchable Fields', |
| 215 | 215 | $this->ElasticaSearchableFields()->filter('Active', 1)->sort('Name')); |
| 216 | 216 | |
@@ -283,7 +283,7 @@ discard block |
||
| 283 | 283 | public function validate() { |
| 284 | 284 | $result = parent::validate(); |
| 285 | 285 | $mode = Versioned::get_reading_mode(); |
| 286 | - $suffix = ''; |
|
| 286 | + $suffix = ''; |
|
| 287 | 287 | if ($mode == 'Stage.Live') { |
| 288 | 288 | $suffix = '_Live'; |
| 289 | 289 | } |
@@ -292,17 +292,17 @@ discard block |
||
| 292 | 292 | $result->error('The identifier cannot be blank'); |
| 293 | 293 | } |
| 294 | 294 | |
| 295 | - $where = 'ElasticSearchPage'.$suffix.'.ID != '.$this->ID." AND `Identifier` = '{$this->Identifier}'"; |
|
| 295 | + $where = 'ElasticSearchPage' . $suffix . '.ID != ' . $this->ID . " AND `Identifier` = '{$this->Identifier}'"; |
|
| 296 | 296 | $existing = ElasticSearchPage::get()->where($where)->count(); |
| 297 | 297 | if ($existing > 0) { |
| 298 | - $result->error('The identifier '.$this->Identifier.' already exists'); |
|
| 298 | + $result->error('The identifier ' . $this->Identifier . ' already exists'); |
|
| 299 | 299 | } |
| 300 | 300 | |
| 301 | 301 | |
| 302 | - error_log('CTS:'.$this->ClassesToSearch); |
|
| 302 | + error_log('CTS:' . $this->ClassesToSearch); |
|
| 303 | 303 | |
| 304 | 304 | // now check classes to search actually exist, assuming in site tree not set |
| 305 | - error_log('STO:'.$this->SiteTreeOnly); |
|
| 305 | + error_log('STO:' . $this->SiteTreeOnly); |
|
| 306 | 306 | if (!$this->SiteTreeOnly) { |
| 307 | 307 | if ($this->ClassesToSearch == '') { |
| 308 | 308 | $result->error('At least one searchable class must be available, or SiteTreeOnly flag set'); |
@@ -312,10 +312,10 @@ discard block |
||
| 312 | 312 | try { |
| 313 | 313 | $instance = Injector::inst()->create($clazz); |
| 314 | 314 | if (!$instance->hasExtension('SilverStripe\Elastica\Searchable')) { |
| 315 | - $result->error('The class '.$clazz.' must have the Searchable extension'); |
|
| 315 | + $result->error('The class ' . $clazz . ' must have the Searchable extension'); |
|
| 316 | 316 | } |
| 317 | 317 | } catch (ReflectionException $e) { |
| 318 | - $result->error('The class '.$clazz.' does not exist'); |
|
| 318 | + $result->error('The class ' . $clazz . ' does not exist'); |
|
| 319 | 319 | } |
| 320 | 320 | } |
| 321 | 321 | } |
@@ -363,7 +363,7 @@ discard block |
||
| 363 | 363 | |
| 364 | 364 | if ($newSearchableFields->count() > 0) { |
| 365 | 365 | foreach ($newSearchableFields->getIterator() as $newSearchableField) { |
| 366 | - error_log('NEW FIELD:'.$newSearchableField->Name); |
|
| 366 | + error_log('NEW FIELD:' . $newSearchableField->Name); |
|
| 367 | 367 | $newSearchableField->Active = true; |
| 368 | 368 | $newSearchableField->Weight = 1; |
| 369 | 369 | |
@@ -371,7 +371,7 @@ discard block |
||
| 371 | 371 | |
| 372 | 372 | // Note 1 used instead of true for SQLite3 testing compatibility |
| 373 | 373 | $sql = "UPDATE ElasticSearchPage_ElasticaSearchableFields SET "; |
| 374 | - $sql .= 'Active=1, Weight=1 WHERE ElasticSearchPageID = '.$this->ID; |
|
| 374 | + $sql .= 'Active=1, Weight=1 WHERE ElasticSearchPageID = ' . $this->ID; |
|
| 375 | 375 | DB::query($sql); |
| 376 | 376 | } |
| 377 | 377 | } |
@@ -418,7 +418,7 @@ discard block |
||
| 418 | 418 | $qField->setAttribute('data-autocomplete-field', 'Title'); |
| 419 | 419 | $qField->setAttribute('data-autocomplete-classes', $this->ClassesToSearch); |
| 420 | 420 | $qField->setAttribute('data-autocomplete-sitetree', $this->SiteTreeOnly); |
| 421 | - $qField->setAttribute('data-autocomplete-source',$this->Link()); |
|
| 421 | + $qField->setAttribute('data-autocomplete-source', $this->Link()); |
|
| 422 | 422 | $qField->setAttribute('data-autocomplete-function', |
| 423 | 423 | $this->AutocompleteFunction()->Slug); |
| 424 | 424 | } |
@@ -440,7 +440,7 @@ discard block |
||
| 440 | 440 | |
| 441 | 441 | class ElasticSearchPage_Controller extends Page_Controller { |
| 442 | 442 | |
| 443 | - private static $allowed_actions = array('SearchForm', 'submit','index','similar'); |
|
| 443 | + private static $allowed_actions = array('SearchForm', 'submit', 'index', 'similar'); |
|
| 444 | 444 | |
| 445 | 445 | public function init() { |
| 446 | 446 | parent::init(); |
@@ -516,7 +516,7 @@ discard block |
||
| 516 | 516 | |
| 517 | 517 | // Use the standard field for more like this, ie not stemmed |
| 518 | 518 | foreach ($fieldsToSearch as $field => $value) { |
| 519 | - $fieldsToSearch[$field.'.standard'] = $value; |
|
| 519 | + $fieldsToSearch[$field . '.standard'] = $value; |
|
| 520 | 520 | unset($fieldsToSearch[$field]); |
| 521 | 521 | } |
| 522 | 522 | |
@@ -526,7 +526,7 @@ discard block |
||
| 526 | 526 | throw new Elastica\Exception\Connection\HttpException('Unable to reach search server'); |
| 527 | 527 | } |
| 528 | 528 | if (class_exists($class)) { |
| 529 | - $instance = \DataObject::get_by_id($class,$instanceID); |
|
| 529 | + $instance = \DataObject::get_by_id($class, $instanceID); |
|
| 530 | 530 | |
| 531 | 531 | $paginated = $es->moreLikeThis($instance, $fieldsToSearch); |
| 532 | 532 | |
@@ -570,7 +570,7 @@ discard block |
||
| 570 | 570 | |
| 571 | 571 | // calculate time |
| 572 | 572 | $endTime = microtime(true); |
| 573 | - $elapsed = round(100*($endTime-$startTime))/100; |
|
| 573 | + $elapsed = round(100 * ($endTime - $startTime)) / 100; |
|
| 574 | 574 | |
| 575 | 575 | // store variables for the template to use |
| 576 | 576 | $data['ElapsedTime'] = $elapsed; |
@@ -624,11 +624,11 @@ discard block |
||
| 624 | 624 | $testMode = isset($_GET['TestMode']); |
| 625 | 625 | |
| 626 | 626 | // filters for aggregations |
| 627 | - $ignore = array('url', 'start','q','is'); |
|
| 627 | + $ignore = array('url', 'start', 'q', 'is'); |
|
| 628 | 628 | $ignore = \Config::inst()->get('Elastica', 'BlackList'); |
| 629 | 629 | foreach ($this->request->getVars() as $key => $value) { |
| 630 | 630 | if (!in_array($key, $ignore)) { |
| 631 | - $es->addFilter($key,$value); |
|
| 631 | + $es->addFilter($key, $value); |
|
| 632 | 632 | } |
| 633 | 633 | } |
| 634 | 634 | |
@@ -677,7 +677,7 @@ discard block |
||
| 677 | 677 | $data['SuggestedQuery'] = $es->getSuggestedQuery(); |
| 678 | 678 | $data['SuggestedQueryHighlighted'] = $es->getSuggestedQueryHighlighted(); |
| 679 | 679 | //Link for if the user really wants to try their original query |
| 680 | - $sifLink = rtrim($this->Link(),'/').'?q='.$queryText.'&is=1'; |
|
| 680 | + $sifLink = rtrim($this->Link(), '/') . '?q=' . $queryText . '&is=1'; |
|
| 681 | 681 | $data['SearchInsteadForLink'] = $sifLink; |
| 682 | 682 | $paginated = $es->search($es->getSuggestedQuery(), $fieldsToSearch); |
| 683 | 683 | |
@@ -685,7 +685,7 @@ discard block |
||
| 685 | 685 | |
| 686 | 686 | // calculate time |
| 687 | 687 | $endTime = microtime(true); |
| 688 | - $elapsed = round(100*($endTime-$startTime))/100; |
|
| 688 | + $elapsed = round(100 * ($endTime - $startTime)) / 100; |
|
| 689 | 689 | |
| 690 | 690 | // store variables for the template to use |
| 691 | 691 | $data['ElapsedTime'] = $elapsed; |
@@ -716,7 +716,7 @@ discard block |
||
| 716 | 716 | */ |
| 717 | 717 | public function QueryIsEmpty() { |
| 718 | 718 | $result = !isset($_GET['q']); |
| 719 | - if (isset($_GET['q'])) { |
|
| 719 | + if (isset($_GET['q'])) { |
|
| 720 | 720 | $queryText = $_GET['q']; |
| 721 | 721 | if ($queryText == '') { |
| 722 | 722 | $result = true; |
@@ -735,7 +735,7 @@ discard block |
||
| 735 | 735 | $queryText = $data['q']; |
| 736 | 736 | $url = $this->Link(); |
| 737 | 737 | $url = rtrim($url, '/'); |
| 738 | - $link = rtrim($url, '/').'?q='.$queryText.'&sfid='.$data['identifier']; |
|
| 738 | + $link = rtrim($url, '/') . '?q=' . $queryText . '&sfid=' . $data['identifier']; |
|
| 739 | 739 | $this->redirect($link); |
| 740 | 740 | } |
| 741 | 741 | |
@@ -759,7 +759,7 @@ discard block |
||
| 759 | 759 | |
| 760 | 760 | } |
| 761 | 761 | |
| 762 | - if($this->action == 'similar') { |
|
| 762 | + if ($this->action == 'similar') { |
|
| 763 | 763 | $queryField->setDisabled(true); |
| 764 | 764 | $actions = $form->Actions(); |
| 765 | 765 | foreach ($actions as $field) { |
@@ -775,7 +775,7 @@ discard block |
||
| 775 | 775 | $queryField->setAttribute('data-autocomplete-field', 'Title'); |
| 776 | 776 | $queryField->setAttribute('data-autocomplete-classes', $this->ClassesToSearch); |
| 777 | 777 | $queryField->setAttribute('data-autocomplete-sitetree', $this->SiteTreeOnly); |
| 778 | - $queryField->setAttribute('data-autocomplete-source',$this->Link()); |
|
| 778 | + $queryField->setAttribute('data-autocomplete-source', $this->Link()); |
|
| 779 | 779 | $queryField->setAttribute('data-autocomplete-function', |
| 780 | 780 | $this->AutocompleteFunction()->Slug); |
| 781 | 781 | } |