@@ -47,7 +47,7 @@ |
||
| 47 | 47 | $englishWithURLs = array( |
| 48 | 48 | 'tokenizer' => 'uax_url_email', |
| 49 | 49 | //'filter' => array('english_possessive_stemmer', 'lowercase', 'english_stop', /*'english_keywords',*/ 'english_stemmer' ), |
| 50 | - 'filter' => array('no_single_chars', 'english_snowball', 'lowercase', $this->stopWordFilter ), |
|
| 50 | + 'filter' => array('no_single_chars', 'english_snowball', 'lowercase', $this->stopWordFilter), |
|
| 51 | 51 | 'type' => 'custom' |
| 52 | 52 | ); |
| 53 | 53 | |
@@ -24,7 +24,7 @@ |
||
| 24 | 24 | * Execute the task to delete the currently configured index |
| 25 | 25 | */ |
| 26 | 26 | public function run($request) { |
| 27 | - $message = function ($content) { |
|
| 27 | + $message = function($content) { |
|
| 28 | 28 | print(\Director::is_cli() ? "$content\n" : "<p>$content</p>"); |
| 29 | 29 | }; |
| 30 | 30 | |
@@ -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 | } |
@@ -131,32 +131,32 @@ discard block |
||
| 131 | 131 | $fields = $this->getAllSearchableFields(); |
| 132 | 132 | $result = array(); |
| 133 | 133 | |
| 134 | - foreach ($fields as $name => $params) { |
|
| 134 | + foreach($fields as $name => $params) { |
|
| 135 | 135 | $spec = array(); |
| 136 | 136 | $name = str_replace('()', '', $name); |
| 137 | 137 | |
| 138 | - if (array_key_exists($name, $db)) { |
|
| 138 | + if(array_key_exists($name, $db)) { |
|
| 139 | 139 | $class = $db[$name]; |
| 140 | 140 | |
| 141 | - if (($pos = strpos($class, '('))) { |
|
| 141 | + if(($pos = strpos($class, '('))) { |
|
| 142 | 142 | // Valid in the case of Varchar(255) |
| 143 | 143 | $class = substr($class, 0, $pos); |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | - if (array_key_exists($class, self::$mappings)) { |
|
| 146 | + if(array_key_exists($class, self::$mappings)) { |
|
| 147 | 147 | $spec['type'] = self::$mappings[$class]; |
| 148 | - if ($spec['type'] === 'date') { |
|
| 149 | - if ($class == 'Date') { |
|
| 148 | + if($spec['type'] === 'date') { |
|
| 149 | + if($class == 'Date') { |
|
| 150 | 150 | $spec['format'] = 'y-M-d'; |
| 151 | - } elseif ($class == 'SS_Datetime') { |
|
| 151 | + } elseif($class == 'SS_Datetime') { |
|
| 152 | 152 | $spec['format'] = 'y-M-d H:m:s'; |
| 153 | - } elseif ($class == 'Datetime') { |
|
| 153 | + } elseif($class == 'Datetime') { |
|
| 154 | 154 | $spec['format'] = 'y-M-d H:m:s'; |
| 155 | - } elseif ($class == 'Time') { |
|
| 155 | + } elseif($class == 'Time') { |
|
| 156 | 156 | $spec['format'] = 'H:m:s'; |
| 157 | 157 | } |
| 158 | 158 | } |
| 159 | - if ($class === 'HTMLText' || $class === 'HTMLVarchar') { |
|
| 159 | + if($class === 'HTMLText' || $class === 'HTMLVarchar') { |
|
| 160 | 160 | array_push($this->html_fields, $name); |
| 161 | 161 | } |
| 162 | 162 | } |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | $has_ones = $this->owner->has_one(); |
| 168 | 168 | |
| 169 | 169 | // check has_many and many_many relations |
| 170 | - if (isset($has_lists[$name])) { |
|
| 170 | + if(isset($has_lists[$name])) { |
|
| 171 | 171 | // FIX ME how to do nested mapping |
| 172 | 172 | // See https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-array-type.html |
| 173 | 173 | |
@@ -178,13 +178,13 @@ discard block |
||
| 178 | 178 | $resultTypeMapping = array(); |
| 179 | 179 | |
| 180 | 180 | // get the fields for the result type, but do not recurse |
| 181 | - if ($recurse) { |
|
| 181 | + if($recurse) { |
|
| 182 | 182 | $resultTypeMapping = $resultTypeInstance->getElasticaFields($storeMethodName, false); |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | $resultTypeMapping['ID'] = array('type' => 'integer'); |
| 186 | 186 | |
| 187 | - if ($storeMethodName) { |
|
| 187 | + if($storeMethodName) { |
|
| 188 | 188 | $resultTypeMapping['__method'] = $name; |
| 189 | 189 | } |
| 190 | 190 | |
@@ -193,20 +193,20 @@ discard block |
||
| 193 | 193 | |
| 194 | 194 | // we now change the name to the result type, not the method name |
| 195 | 195 | $name = $resultType; |
| 196 | - } else if (isset($has_ones[$name])) { |
|
| 196 | + } else if(isset($has_ones[$name])) { |
|
| 197 | 197 | $resultType = $has_ones[$name]; |
| 198 | 198 | $resultTypeInstance = \Injector::inst()->create($resultType); |
| 199 | 199 | |
| 200 | 200 | $resultTypeMapping = array(); |
| 201 | 201 | |
| 202 | 202 | // get the fields for the result type, but do not recurse |
| 203 | - if ($recurse) { |
|
| 203 | + if($recurse) { |
|
| 204 | 204 | $resultTypeMapping = $resultTypeInstance->getElasticaFields($storeMethodName, false); |
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | $resultTypeMapping['ID'] = array('type' => 'integer'); |
| 208 | 208 | |
| 209 | - if ($storeMethodName) { |
|
| 209 | + if($storeMethodName) { |
|
| 210 | 210 | $resultTypeMapping['__method'] = $name; |
| 211 | 211 | } |
| 212 | 212 | $spec = array('properties' => $resultTypeMapping); |
@@ -220,8 +220,8 @@ discard block |
||
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | // in the case of a relationship type will not be set |
| 223 | - if (isset($spec['type'])) { |
|
| 224 | - if ($spec['type'] == 'string') { |
|
| 223 | + if(isset($spec['type'])) { |
|
| 224 | + if($spec['type'] == 'string') { |
|
| 225 | 225 | $unstemmed = array(); |
| 226 | 226 | $unstemmed['type'] = "string"; |
| 227 | 227 | $unstemmed['analyzer'] = "unstemmed"; |
@@ -237,7 +237,7 @@ discard block |
||
| 237 | 237 | //Add autocomplete field if so required |
| 238 | 238 | $autocomplete = \Config::inst()->get($this->owner->ClassName, 'searchable_autocomplete'); |
| 239 | 239 | |
| 240 | - if (isset($autocomplete) && in_array($name, $autocomplete)) { |
|
| 240 | + if(isset($autocomplete) && in_array($name, $autocomplete)) { |
|
| 241 | 241 | $autocompleteField = array(); |
| 242 | 242 | $autocompleteField['type'] = "string"; |
| 243 | 243 | $autocompleteField['index_analyzer'] = "autocomplete_index_analyzer"; |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | $result[$name] = $spec; |
| 257 | 257 | } |
| 258 | 258 | |
| 259 | - if ($this->owner->hasMethod('updateElasticHTMLFields')) { |
|
| 259 | + if($this->owner->hasMethod('updateElasticHTMLFields')) { |
|
| 260 | 260 | $this->html_fields = $this->owner->updateElasticHTMLFields($this->html_fields); |
| 261 | 261 | } |
| 262 | 262 | |
@@ -276,7 +276,7 @@ discard block |
||
| 276 | 276 | |
| 277 | 277 | $localeMapping = array(); |
| 278 | 278 | |
| 279 | - if ($this->owner->hasField('Locale')) { |
|
| 279 | + if($this->owner->hasField('Locale')) { |
|
| 280 | 280 | $localeMapping['type'] = 'string'; |
| 281 | 281 | // we wish the locale to be stored as is |
| 282 | 282 | $localeMapping['index'] = 'not_analyzed'; |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | //_all field picks up all possible suggestions |
| 296 | 296 | $mapping->enableAllField(); |
| 297 | 297 | |
| 298 | - if ($this->owner->hasMethod('updateElasticsearchMapping')) { |
|
| 298 | + if($this->owner->hasMethod('updateElasticsearchMapping')) { |
|
| 299 | 299 | $mapping = $this->owner->updateElasticsearchMapping($mapping); |
| 300 | 300 | } |
| 301 | 301 | return $mapping; |
@@ -311,20 +311,20 @@ discard block |
||
| 311 | 311 | self::$index_ctr++; |
| 312 | 312 | $fields = $this->getFieldValuesAsArray(); |
| 313 | 313 | |
| 314 | - if (isset($_GET['progress'])) { |
|
| 314 | + if(isset($_GET['progress'])) { |
|
| 315 | 315 | $progress = $_GET['progress']; |
| 316 | - self::$progressInterval = (int) $progress; |
|
| 316 | + self::$progressInterval = (int)$progress; |
|
| 317 | 317 | } |
| 318 | 318 | |
| 319 | - if (self::$progressInterval > 0) { |
|
| 320 | - if (self::$index_ctr % self::$progressInterval === 0) { |
|
| 321 | - ElasticaUtil::message("\t".$this->owner->ClassName." - Prepared ".self::$index_ctr." for indexing..."); |
|
| 319 | + if(self::$progressInterval > 0) { |
|
| 320 | + if(self::$index_ctr % self::$progressInterval === 0) { |
|
| 321 | + ElasticaUtil::message("\t" . $this->owner->ClassName . " - Prepared " . self::$index_ctr . " for indexing..."); |
|
| 322 | 322 | } |
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | // Optionally update the document |
| 326 | 326 | $document = new Document($this->owner->ID, $fields); |
| 327 | - if ($this->owner->hasMethod('updateElasticsearchDocument')) { |
|
| 327 | + if($this->owner->hasMethod('updateElasticsearchDocument')) { |
|
| 328 | 328 | $document = $this->owner->updateElasticsearchDocument($document); |
| 329 | 329 | } |
| 330 | 330 | |
@@ -335,11 +335,11 @@ discard block |
||
| 335 | 335 | |
| 336 | 336 | $document->set('IsInSiteTree', $inSiteTree); |
| 337 | 337 | |
| 338 | - if ($inSiteTree) { |
|
| 338 | + if($inSiteTree) { |
|
| 339 | 339 | $document->set('Link', $this->owner->AbsoluteLink()); |
| 340 | 340 | } |
| 341 | 341 | |
| 342 | - if (isset($this->owner->Locale)) { |
|
| 342 | + if(isset($this->owner->Locale)) { |
|
| 343 | 343 | $document->set('Locale', $this->owner->Locale); |
| 344 | 344 | } |
| 345 | 345 | |
@@ -351,10 +351,10 @@ discard block |
||
| 351 | 351 | $fields = array(); |
| 352 | 352 | $has_ones = $this->owner->has_one(); |
| 353 | 353 | |
| 354 | - foreach ($this->getElasticaFields($recurse) as $field => $config) { |
|
| 355 | - if (null === $this->owner->$field && is_callable(get_class($this->owner) . "::" . $field)) { |
|
| 354 | + foreach($this->getElasticaFields($recurse) as $field => $config) { |
|
| 355 | + if(null === $this->owner->$field && is_callable(get_class($this->owner) . "::" . $field)) { |
|
| 356 | 356 | // call a method to get a field value |
| 357 | - if (in_array($field, $this->html_fields)) { |
|
| 357 | + if(in_array($field, $this->html_fields)) { |
|
| 358 | 358 | // Parse short codes in HTML, and then convert to text |
| 359 | 359 | $fields[$field] = $this->owner->$field; |
| 360 | 360 | $html = ShortcodeParser::get_active()->parse($this->owner->$field()); |
@@ -366,30 +366,30 @@ discard block |
||
| 366 | 366 | } |
| 367 | 367 | |
| 368 | 368 | } else { |
| 369 | - if (in_array($field, $this->html_fields)) { |
|
| 369 | + if(in_array($field, $this->html_fields)) { |
|
| 370 | 370 | $fields[$field] = $this->owner->$field; |
| 371 | - if (gettype($this->owner->$field) !== 'NULL') { |
|
| 371 | + if(gettype($this->owner->$field) !== 'NULL') { |
|
| 372 | 372 | $html = ShortcodeParser::get_active()->parse($this->owner->$field); |
| 373 | 373 | $txt = \Convert::html2raw($html); |
| 374 | 374 | $fields[$field] = $txt; |
| 375 | 375 | } |
| 376 | 376 | } else { |
| 377 | - if (isset($config['properties']['__method'])) { |
|
| 377 | + if(isset($config['properties']['__method'])) { |
|
| 378 | 378 | $methodName = $config['properties']['__method']; |
| 379 | 379 | $data = $this->owner->$methodName(); |
| 380 | 380 | $relArray = array(); |
| 381 | 381 | |
| 382 | 382 | // get the fields of a has_one relational object |
| 383 | - if (isset($has_ones[$methodName])) { |
|
| 384 | - if ($data->ID > 0) { |
|
| 383 | + if(isset($has_ones[$methodName])) { |
|
| 384 | + if($data->ID > 0) { |
|
| 385 | 385 | $item = $data->getFieldValuesAsArray(false); |
| 386 | 386 | $relArray = $item; |
| 387 | 387 | } |
| 388 | 388 | |
| 389 | 389 | // get the fields for a has_many or many_many relational list |
| 390 | 390 | } else { |
| 391 | - foreach ($data->getIterator() as $item) { |
|
| 392 | - if ($recurse) { |
|
| 391 | + foreach($data->getIterator() as $item) { |
|
| 392 | + if($recurse) { |
|
| 393 | 393 | // populate the subitem but do not recurse any further if more relationships |
| 394 | 394 | $itemDoc = $item->getFieldValuesAsArray(false); |
| 395 | 395 | array_push($relArray, $itemDoc); |
@@ -426,8 +426,8 @@ discard block |
||
| 426 | 426 | * Delete the record from the search index if ShowInSearch is deactivated (non-SiteTree). |
| 427 | 427 | */ |
| 428 | 428 | public function onBeforeWrite() { |
| 429 | - if (($this->owner instanceof \SiteTree)) { |
|
| 430 | - if ($this->owner->hasField('ShowInSearch') && |
|
| 429 | + if(($this->owner instanceof \SiteTree)) { |
|
| 430 | + if($this->owner->hasField('ShowInSearch') && |
|
| 431 | 431 | $this->owner->isChanged('ShowInSearch', 2) && false == $this->owner->ShowInSearch) { |
| 432 | 432 | $this->doDeleteDocument(); |
| 433 | 433 | } |
@@ -439,11 +439,11 @@ discard block |
||
| 439 | 439 | * Delete the record from the search index if ShowInSearch is deactivated (SiteTree). |
| 440 | 440 | */ |
| 441 | 441 | public function onBeforePublish() { |
| 442 | - if (false == $this->owner->ShowInSearch) { |
|
| 443 | - if ($this->owner->isPublished()) { |
|
| 442 | + if(false == $this->owner->ShowInSearch) { |
|
| 443 | + if($this->owner->isPublished()) { |
|
| 444 | 444 | $liveRecord = \Versioned::get_by_stage(get_class($this->owner), 'Live')-> |
| 445 | 445 | byID($this->owner->ID); |
| 446 | - if ($liveRecord->ShowInSearch != $this->owner->ShowInSearch) { |
|
| 446 | + if($liveRecord->ShowInSearch != $this->owner->ShowInSearch) { |
|
| 447 | 447 | $this->doDeleteDocument(); |
| 448 | 448 | } |
| 449 | 449 | } |
@@ -471,8 +471,8 @@ discard block |
||
| 471 | 471 | * Updates the record in the search index. |
| 472 | 472 | */ |
| 473 | 473 | protected function doIndexDocument() { |
| 474 | - if ($this->showRecordInSearch()) { |
|
| 475 | - if (!$this->owner->IndexingOff) { |
|
| 474 | + if($this->showRecordInSearch()) { |
|
| 475 | + if(!$this->owner->IndexingOff) { |
|
| 476 | 476 | $this->service->index($this->owner); |
| 477 | 477 | } |
| 478 | 478 | } |
@@ -499,7 +499,7 @@ discard block |
||
| 499 | 499 | * Removes the record from the search index if the "ShowInSearch" attribute is set to true. |
| 500 | 500 | */ |
| 501 | 501 | protected function doDeleteDocumentIfInSearch() { |
| 502 | - if ($this->showRecordInSearch()) { |
|
| 502 | + if($this->showRecordInSearch()) { |
|
| 503 | 503 | $this->doDeleteDocument(); |
| 504 | 504 | } |
| 505 | 505 | } |
@@ -509,14 +509,14 @@ discard block |
||
| 509 | 509 | * Removes the record from the search index. |
| 510 | 510 | */ |
| 511 | 511 | protected function doDeleteDocument() { |
| 512 | - try{ |
|
| 513 | - if (!$this->owner->IndexingOff) { |
|
| 512 | + try { |
|
| 513 | + if(!$this->owner->IndexingOff) { |
|
| 514 | 514 | // this goes to elastica service |
| 515 | 515 | $this->service->remove($this->owner); |
| 516 | 516 | } |
| 517 | 517 | } |
| 518 | - catch(\Elastica\Exception\NotFoundException $e) { |
|
| 519 | - trigger_error("Deleted document ".$this->owner->ClassName." (".$this->owner->ID. |
|
| 518 | + catch (\Elastica\Exception\NotFoundException $e) { |
|
| 519 | + trigger_error("Deleted document " . $this->owner->ClassName . " (" . $this->owner->ID . |
|
| 520 | 520 | ") not found in search index.", E_USER_NOTICE); |
| 521 | 521 | } |
| 522 | 522 | |
@@ -533,42 +533,42 @@ discard block |
||
| 533 | 533 | $fields = \Config::inst()->get(get_class($this->owner), 'searchable_fields'); |
| 534 | 534 | |
| 535 | 535 | // fallback to default method |
| 536 | - if(!$fields) user_error('The field $searchable_fields must be set for the class '.$this->owner->ClassName); |
|
| 536 | + if(!$fields) user_error('The field $searchable_fields must be set for the class ' . $this->owner->ClassName); |
|
| 537 | 537 | |
| 538 | 538 | // get the values of these fields |
| 539 | 539 | $elasticaMapping = $this->fieldsToElasticaConfig($fields); |
| 540 | 540 | |
| 541 | - if ($recurse) { |
|
| 541 | + if($recurse) { |
|
| 542 | 542 | // now for the associated methods and their results |
| 543 | 543 | $methodDescs = \Config::inst()->get(get_class($this->owner), 'searchable_relationships'); |
| 544 | 544 | $has_ones = $this->owner->has_one(); |
| 545 | 545 | $has_lists = $this->getListRelationshipMethods(); |
| 546 | 546 | |
| 547 | - if (isset($methodDescs) && is_array($methodDescs)) { |
|
| 548 | - foreach ($methodDescs as $methodDesc) { |
|
| 547 | + if(isset($methodDescs) && is_array($methodDescs)) { |
|
| 548 | + foreach($methodDescs as $methodDesc) { |
|
| 549 | 549 | // split before the brackets which can optionally list which fields to index |
| 550 | 550 | $splits = explode('(', $methodDesc); |
| 551 | 551 | $methodName = $splits[0]; |
| 552 | 552 | |
| 553 | - if (isset($has_lists[$methodName])) { |
|
| 553 | + if(isset($has_lists[$methodName])) { |
|
| 554 | 554 | |
| 555 | 555 | $relClass = $has_lists[$methodName]; |
| 556 | 556 | $fields = \Config::inst()->get($relClass, 'searchable_fields'); |
| 557 | - if(!$fields) user_error('The field $searchable_fields must be set for the class '.$relClass); |
|
| 557 | + if(!$fields) user_error('The field $searchable_fields must be set for the class ' . $relClass); |
|
| 558 | 558 | $rewrite = $this->fieldsToElasticaConfig($fields); |
| 559 | 559 | |
| 560 | 560 | // mark as a method, the resultant fields are correct |
| 561 | - $elasticaMapping[$methodName.'()'] = $rewrite; |
|
| 562 | - } else if (isset($has_ones[$methodName])) { |
|
| 561 | + $elasticaMapping[$methodName . '()'] = $rewrite; |
|
| 562 | + } else if(isset($has_ones[$methodName])) { |
|
| 563 | 563 | $relClass = $has_ones[$methodName]; |
| 564 | 564 | $fields = \Config::inst()->get($relClass, 'searchable_fields'); |
| 565 | - if(!$fields) user_error('The field $searchable_fields must be set for the class '.$relClass); |
|
| 565 | + if(!$fields) user_error('The field $searchable_fields must be set for the class ' . $relClass); |
|
| 566 | 566 | $rewrite = $this->fieldsToElasticaConfig($fields); |
| 567 | 567 | |
| 568 | 568 | // mark as a method, the resultant fields are correct |
| 569 | - $elasticaMapping[$methodName.'()'] = $rewrite; |
|
| 569 | + $elasticaMapping[$methodName . '()'] = $rewrite; |
|
| 570 | 570 | } else { |
| 571 | - user_error('The method '.$methodName.' not found in class '.$this->owner->ClassName. |
|
| 571 | + user_error('The method ' . $methodName . ' not found in class ' . $this->owner->ClassName . |
|
| 572 | 572 | ', please check configuration'); |
| 573 | 573 | } |
| 574 | 574 | } |
@@ -604,11 +604,11 @@ discard block |
||
| 604 | 604 | public function requireDefaultRecords() { |
| 605 | 605 | parent::requireDefaultRecords(); |
| 606 | 606 | |
| 607 | - $searchableFields = $this->getElasticaFields(true,true); |
|
| 607 | + $searchableFields = $this->getElasticaFields(true, true); |
|
| 608 | 608 | |
| 609 | 609 | |
| 610 | 610 | $doSC = \SearchableClass::get()->filter(array('Name' => $this->owner->ClassName))->first(); |
| 611 | - if (!$doSC) { |
|
| 611 | + if(!$doSC) { |
|
| 612 | 612 | $doSC = new \SearchableClass(); |
| 613 | 613 | $doSC->Name = $this->owner->ClassName; |
| 614 | 614 | |
@@ -618,9 +618,9 @@ discard block |
||
| 618 | 618 | $doSC->write(); |
| 619 | 619 | } |
| 620 | 620 | |
| 621 | - foreach ($searchableFields as $name => $searchableField) { |
|
| 621 | + foreach($searchableFields as $name => $searchableField) { |
|
| 622 | 622 | // check for existence of methods and if they exist use that as the name |
| 623 | - if (!isset($searchableField['type'])) { |
|
| 623 | + if(!isset($searchableField['type'])) { |
|
| 624 | 624 | $name = $searchableField['properties']['__method']; |
| 625 | 625 | } |
| 626 | 626 | |
@@ -628,25 +628,25 @@ discard block |
||
| 628 | 628 | $doSF = \SearchableField::get()->filter($filter)->first(); |
| 629 | 629 | |
| 630 | 630 | |
| 631 | - if (!$doSF) { |
|
| 631 | + if(!$doSF) { |
|
| 632 | 632 | $doSF = new \SearchableField(); |
| 633 | 633 | $doSF->ClazzName = $this->owner->ClassName; |
| 634 | 634 | $doSF->Name = $name; |
| 635 | 635 | |
| 636 | - if (isset($searchableField['type'])) { |
|
| 636 | + if(isset($searchableField['type'])) { |
|
| 637 | 637 | $doSF->Type = $searchableField['type']; |
| 638 | - } else { |
|
| 638 | + } else { |
|
| 639 | 639 | $doSF->Name = $searchableField['properties']['__method']; |
| 640 | 640 | $doSF->Type = 'relationship'; |
| 641 | 641 | } |
| 642 | 642 | $doSF->SearchableClassID = $doSC->ID; |
| 643 | 643 | |
| 644 | - if (isset($searchableField['fields']['autocomplete'])) { |
|
| 644 | + if(isset($searchableField['fields']['autocomplete'])) { |
|
| 645 | 645 | $doSF->Autocomplete = true; |
| 646 | 646 | } |
| 647 | 647 | |
| 648 | 648 | $doSF->write(); |
| 649 | - \DB::alteration_message("Created new searchable editable field ".$name,"changed"); |
|
| 649 | + \DB::alteration_message("Created new searchable editable field " . $name, "changed"); |
|
| 650 | 650 | } |
| 651 | 651 | |
| 652 | 652 | // FIXME deal with deletions |
@@ -660,7 +660,7 @@ discard block |
||
| 660 | 660 | |
| 661 | 661 | // array of method name to retuned object ClassName for relationships returning lists |
| 662 | 662 | $has_lists = $has_manys; |
| 663 | - foreach (array_keys($many_manys) as $key) { |
|
| 663 | + foreach(array_keys($many_manys) as $key) { |
|
| 664 | 664 | $has_lists[$key] = $many_manys[$key]; |
| 665 | 665 | } |
| 666 | 666 | |
@@ -671,11 +671,11 @@ discard block |
||
| 671 | 671 | private function isInSiteTree($classname) { |
| 672 | 672 | $inSiteTree = $classname === 'SiteTree' ? true : false; |
| 673 | 673 | |
| 674 | - if (!$inSiteTree) { |
|
| 674 | + if(!$inSiteTree) { |
|
| 675 | 675 | $class = new \ReflectionClass($this->owner->ClassName); |
| 676 | - while ($class = $class->getParentClass()) { |
|
| 676 | + while($class = $class->getParentClass()) { |
|
| 677 | 677 | $parentClass = $class->getName(); |
| 678 | - if ($parentClass == 'SiteTree') { |
|
| 678 | + if($parentClass == 'SiteTree') { |
|
| 679 | 679 | $inSiteTree = true; |
| 680 | 680 | break; |
| 681 | 681 | } |
@@ -691,7 +691,7 @@ discard block |
||
| 691 | 691 | */ |
| 692 | 692 | public function RenderResult($linkToContainer = '') { |
| 693 | 693 | $vars = new \ArrayData(array('SearchResult' => $this->owner, 'ContainerLink' => $linkToContainer)); |
| 694 | - $possibleTemplates = array($this->owner->ClassName.'ElasticSearchResult', 'ElasticSearchResult'); |
|
| 694 | + $possibleTemplates = array($this->owner->ClassName . 'ElasticSearchResult', 'ElasticSearchResult'); |
|
| 695 | 695 | return $this->owner->customise($vars)->renderWith($possibleTemplates); |
| 696 | 696 | } |
| 697 | 697 | |
@@ -705,10 +705,10 @@ discard block |
||
| 705 | 705 | public function updateCMSFields(\FieldList $fields) { |
| 706 | 706 | $isIndexed = false; |
| 707 | 707 | // SIteTree object must have a live record, ShowInSearch = true |
| 708 | - if ($this->isInSiteTree($this->owner->ClassName)) { |
|
| 708 | + if($this->isInSiteTree($this->owner->ClassName)) { |
|
| 709 | 709 | $liveRecord = \Versioned::get_by_stage(get_class($this->owner), 'Live')-> |
| 710 | 710 | byID($this->owner->ID); |
| 711 | - if ($liveRecord->ShowInSearch) { |
|
| 711 | + if($liveRecord->ShowInSearch) { |
|
| 712 | 712 | $isIndexed = true; |
| 713 | 713 | } else { |
| 714 | 714 | $isIndexed = false; |
@@ -718,27 +718,27 @@ discard block |
||
| 718 | 718 | $isIndexed = true; |
| 719 | 719 | } |
| 720 | 720 | |
| 721 | - if ($isIndexed) { |
|
| 721 | + if($isIndexed) { |
|
| 722 | 722 | $termVectors = $this->getTermVectors(); |
| 723 | 723 | $termFields = array_keys($termVectors); |
| 724 | 724 | sort($termFields); |
| 725 | 725 | |
| 726 | - foreach ($termFields as $field) { |
|
| 726 | + foreach($termFields as $field) { |
|
| 727 | 727 | $terms = new \ArrayList(); |
| 728 | 728 | |
| 729 | - foreach (array_keys($termVectors[$field]['terms']) as $term) { |
|
| 729 | + foreach(array_keys($termVectors[$field]['terms']) as $term) { |
|
| 730 | 730 | $do = new \DataObject(); |
| 731 | 731 | $do->Term = $term; |
| 732 | 732 | $stats = $termVectors[$field]['terms'][$term]; |
| 733 | - if (isset($stats['ttf'])) { |
|
| 733 | + if(isset($stats['ttf'])) { |
|
| 734 | 734 | $do->TTF = $stats['ttf']; |
| 735 | 735 | } |
| 736 | 736 | |
| 737 | - if (isset($stats['doc_freq'])) { |
|
| 737 | + if(isset($stats['doc_freq'])) { |
|
| 738 | 738 | $do->DocFreq = $stats['doc_freq']; |
| 739 | 739 | } |
| 740 | 740 | |
| 741 | - if (isset($stats['term_freq'])) { |
|
| 741 | + if(isset($stats['term_freq'])) { |
|
| 742 | 742 | $do->TermFreq = $stats['term_freq']; |
| 743 | 743 | } |
| 744 | 744 | $terms->push($do); |
@@ -755,14 +755,14 @@ discard block |
||
| 755 | 755 | $underscored = str_replace('.', '_', $field); |
| 756 | 756 | |
| 757 | 757 | $gridField = new \GridField( |
| 758 | - 'TermsFor'.$underscored, // Field name |
|
| 759 | - $field.'TITLE'.$field, // Field title |
|
| 758 | + 'TermsFor' . $underscored, // Field name |
|
| 759 | + $field . 'TITLE' . $field, // Field title |
|
| 760 | 760 | $terms, |
| 761 | 761 | $config |
| 762 | 762 | ); |
| 763 | 763 | |
| 764 | 764 | // $tab = new \Tab($field, new \TextField('Test'.$field, 'Testing')); |
| 765 | - $fields->addFieldToTab('Root.ElasticaTerms.'.$underscored, $gridField); |
|
| 765 | + $fields->addFieldToTab('Root.ElasticaTerms.' . $underscored, $gridField); |
|
| 766 | 766 | } |
| 767 | 767 | |
| 768 | 768 | } |
@@ -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 | } |
@@ -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 |
@@ -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; |
@@ -137,12 +137,12 @@ discard block |
||
| 137 | 137 | */ |
| 138 | 138 | public function search($query, $types = '') { |
| 139 | 139 | $query = Query::create($query); // may be a string |
| 140 | - if (is_string($types)) { |
|
| 140 | + if(is_string($types)) { |
|
| 141 | 141 | $types = explode(',', $types); |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | $data = $query->toArray(); |
| 145 | - if (isset($data['query']['more_like_this'])) { |
|
| 145 | + if(isset($data['query']['more_like_this'])) { |
|
| 146 | 146 | $query->MoreLikeThis = true; |
| 147 | 147 | } else { |
| 148 | 148 | $query->MoreLikeThis = false; |
@@ -151,8 +151,8 @@ discard block |
||
| 151 | 151 | |
| 152 | 152 | $search = new Search(new Client()); |
| 153 | 153 | |
| 154 | - if ($this->test_mode) { |
|
| 155 | - $search->setOption('search_type',Search::OPTION_SEARCH_TYPE_DFS_QUERY_THEN_FETCH); |
|
| 154 | + if($this->test_mode) { |
|
| 155 | + $search->setOption('search_type', Search::OPTION_SEARCH_TYPE_DFS_QUERY_THEN_FETCH); |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | |
| 162 | 162 | // If the query is a 'more like this' we can get the terms used for searching by performing |
| 163 | 163 | // an extra query, in this case a query validation with explain and rewrite turned on |
| 164 | - if ($query->MoreLikeThis) { |
|
| 164 | + if($query->MoreLikeThis) { |
|
| 165 | 165 | $path = $search->getPath(); |
| 166 | 166 | |
| 167 | 167 | $termData = array(); |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | |
| 170 | 170 | $path = str_replace('_search', '_validate/query', $path); |
| 171 | 171 | $params = array('explain' => true, 'rewrite' => true); |
| 172 | - if ($this->test_mode) { |
|
| 172 | + if($this->test_mode) { |
|
| 173 | 173 | $params['search_type'] = Search::OPTION_SEARCH_TYPE_DFS_QUERY_THEN_FETCH; |
| 174 | 174 | } |
| 175 | 175 | |
@@ -183,18 +183,18 @@ discard block |
||
| 183 | 183 | $r = $response->getData(); |
| 184 | 184 | $terms = null; // keep in scope |
| 185 | 185 | |
| 186 | - if (isset($r['explanations'])) { |
|
| 186 | + if(isset($r['explanations'])) { |
|
| 187 | 187 | $explanation = $r['explanations'][0]['explanation']; |
| 188 | 188 | //echo $explanation; |
| 189 | 189 | $terms = ElasticaUtil::parseSuggestionExplanation($explanation); |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | - if (isset($terms)) { |
|
| 192 | + if(isset($terms)) { |
|
| 193 | 193 | $this->MoreLikeThisTerms = $terms; |
| 194 | 194 | } |
| 195 | 195 | } |
| 196 | 196 | |
| 197 | - if (!$empty($types)) { |
|
| 197 | + if(!$empty($types)) { |
|
| 198 | 198 | foreach($types as $type) { |
| 199 | 199 | $search->addType($type); |
| 200 | 200 | } |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | $stringFields = $this->highlightedFields; |
| 216 | 216 | $usingProvidedHighlightFields = true; |
| 217 | 217 | |
| 218 | - if (sizeof($stringFields) == 0) { |
|
| 218 | + if(sizeof($stringFields) == 0) { |
|
| 219 | 219 | $filter = array('Type' => 'string', 'ShowHighlights' => true); |
| 220 | 220 | $stringFields = \SearchableField::get()->filter($filter)->map('Name')->toArray(); |
| 221 | 221 | $usingProvidedHighlightFields = false; |
@@ -223,10 +223,10 @@ discard block |
||
| 223 | 223 | |
| 224 | 224 | |
| 225 | 225 | $highlightFields = array(); |
| 226 | - foreach ($stringFields as $name) { |
|
| 226 | + foreach($stringFields as $name) { |
|
| 227 | 227 | // Add the stemmed and the unstemmed for now |
| 228 | 228 | $fieldName = $name; |
| 229 | - if (!$usingProvidedHighlightFields) { |
|
| 229 | + if(!$usingProvidedHighlightFields) { |
|
| 230 | 230 | $fieldName .= '.standard'; |
| 231 | 231 | } |
| 232 | 232 | $highlightFields[$fieldName] = array( |
@@ -242,9 +242,9 @@ discard block |
||
| 242 | 242 | 'fields' => $highlightFields |
| 243 | 243 | ); |
| 244 | 244 | |
| 245 | - if ($query->MoreLikeThis) { |
|
| 245 | + if($query->MoreLikeThis) { |
|
| 246 | 246 | $termsMatchingQuery = array(); |
| 247 | - foreach ($this->MoreLikeThisTerms as $field => $terms) { |
|
| 247 | + foreach($this->MoreLikeThisTerms as $field => $terms) { |
|
| 248 | 248 | $termQuery = array('multi_match' => array( |
| 249 | 249 | 'query' => implode(' ', $terms), |
| 250 | 250 | 'type' => 'most_fields', |
@@ -262,7 +262,7 @@ discard block |
||
| 262 | 262 | |
| 263 | 263 | //$search = new Search(new Client()); |
| 264 | 264 | $search->addIndex($this->getLocaleIndexName()); |
| 265 | - if (!$empty($types)) { |
|
| 265 | + if(!$empty($types)) { |
|
| 266 | 266 | foreach($types as $type) { |
| 267 | 267 | $search->addType($type); |
| 268 | 268 | } |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | $path = $search->getPath(); |
| 273 | 273 | $params = $search->getOptions(); |
| 274 | 274 | $searchResults = $search->search($query, $params); |
| 275 | - if (isset($this->MoreLikeThisTerms)) { |
|
| 275 | + if(isset($this->MoreLikeThisTerms)) { |
|
| 276 | 276 | $searchResults->MoreLikeThisTerms = $this->MoreLikeThisTerms; |
| 277 | 277 | } |
| 278 | 278 | |
@@ -285,7 +285,7 @@ discard block |
||
| 285 | 285 | */ |
| 286 | 286 | protected function ensureIndex() { |
| 287 | 287 | $index = $this->getIndex(); |
| 288 | - if (!$index->exists()) { |
|
| 288 | + if(!$index->exists()) { |
|
| 289 | 289 | $this->createIndex(); |
| 290 | 290 | } |
| 291 | 291 | } |
@@ -300,7 +300,7 @@ discard block |
||
| 300 | 300 | */ |
| 301 | 301 | protected function ensureMapping(\Elastica\Type $type, \DataObject $record) { |
| 302 | 302 | $mapping = $type->getMapping(); |
| 303 | - if ($mapping == array()) { |
|
| 303 | + if($mapping == array()) { |
|
| 304 | 304 | $this->ensureIndex(); |
| 305 | 305 | $mapping = $record->getElasticaMapping(); |
| 306 | 306 | $type->setMapping($mapping); |
@@ -319,8 +319,8 @@ discard block |
||
| 319 | 319 | $document = $record->getElasticaDocument(); |
| 320 | 320 | $typeName = $record->getElasticaType(); |
| 321 | 321 | |
| 322 | - if ($this->buffered) { |
|
| 323 | - if (array_key_exists($typeName, $this->buffer)) { |
|
| 322 | + if($this->buffered) { |
|
| 323 | + if(array_key_exists($typeName, $this->buffer)) { |
|
| 324 | 324 | $this->buffer[$typeName][] = $document; |
| 325 | 325 | } else { |
| 326 | 326 | $this->buffer[$typeName] = array($document); |
@@ -350,9 +350,9 @@ discard block |
||
| 350 | 350 | |
| 351 | 351 | public function listIndexes($trace) { |
| 352 | 352 | $command = "curl 'localhost:9200/_cat/indices?v'"; |
| 353 | - exec($command,$op); |
|
| 353 | + exec($command, $op); |
|
| 354 | 354 | ElasticaUtil::message("\n++++ $trace ++++\n"); |
| 355 | - ElasticaUtil::message(print_r($op,1)); |
|
| 355 | + ElasticaUtil::message(print_r($op, 1)); |
|
| 356 | 356 | ElasticaUtil::message("++++ /{$trace} ++++\n\n"); |
| 357 | 357 | return $op; |
| 358 | 358 | } |
@@ -363,24 +363,24 @@ discard block |
||
| 363 | 363 | */ |
| 364 | 364 | public function endBulkIndex() { |
| 365 | 365 | $index = $this->getIndex(); |
| 366 | - foreach ($this->buffer as $type => $documents) { |
|
| 366 | + foreach($this->buffer as $type => $documents) { |
|
| 367 | 367 | $amount = 0; |
| 368 | 368 | |
| 369 | - foreach (array_keys($this->buffer) as $key) { |
|
| 369 | + foreach(array_keys($this->buffer) as $key) { |
|
| 370 | 370 | $amount += sizeof($this->buffer[$key]); |
| 371 | 371 | } |
| 372 | 372 | $index->getType($type)->addDocuments($documents); |
| 373 | 373 | $index->refresh(); |
| 374 | 374 | |
| 375 | 375 | ElasticaUtil::message("\tAdding $amount documents to the index\n"); |
| 376 | - if (isset($this->StartTime)) { |
|
| 376 | + if(isset($this->StartTime)) { |
|
| 377 | 377 | $elapsed = microtime(true) - $this->StartTime; |
| 378 | - $timePerDoc = ($elapsed)/($this->nDocumentsIndexed); |
|
| 378 | + $timePerDoc = ($elapsed) / ($this->nDocumentsIndexed); |
|
| 379 | 379 | $documentsRemaining = $this->nDocumentsToIndexForLocale - $this->nDocumentsIndexed; |
| 380 | - $eta = ($documentsRemaining)*$timePerDoc; |
|
| 381 | - $hours = (int)($eta/3600); |
|
| 382 | - $minutes = (int)(($eta-$hours*3600)/60); |
|
| 383 | - $seconds = (int)(0.5+$eta-$minutes*60-$hours*3600); |
|
| 380 | + $eta = ($documentsRemaining) * $timePerDoc; |
|
| 381 | + $hours = (int)($eta / 3600); |
|
| 382 | + $minutes = (int)(($eta - $hours * 3600) / 60); |
|
| 383 | + $seconds = (int)(0.5 + $eta - $minutes * 60 - $hours * 3600); |
|
| 384 | 384 | $etaHR = "{$hours}h {$minutes}m {$seconds}s"; |
| 385 | 385 | ElasticaUtil::message("ETA to completion of indexing $this->locale ($documentsRemaining documents): $etaHR"); |
| 386 | 386 | } |
@@ -412,12 +412,12 @@ discard block |
||
| 412 | 412 | $index = $this->getIndex(); |
| 413 | 413 | |
| 414 | 414 | # Recreate the index |
| 415 | - if ($index->exists()) { |
|
| 415 | + if($index->exists()) { |
|
| 416 | 416 | $index->delete(); |
| 417 | 417 | } |
| 418 | 418 | $this->createIndex(); |
| 419 | 419 | |
| 420 | - foreach ($this->getIndexedClasses() as $class) { |
|
| 420 | + foreach($this->getIndexedClasses() as $class) { |
|
| 421 | 421 | /** @var $sng Searchable */ |
| 422 | 422 | $sng = singleton($class); |
| 423 | 423 | $mapping = $sng->getElasticaMapping(); |
@@ -434,8 +434,8 @@ discard block |
||
| 434 | 434 | * @param \DataList $records |
| 435 | 435 | */ |
| 436 | 436 | protected function refreshRecords($records) { |
| 437 | - foreach ($records as $record) { |
|
| 438 | - if ($record->showRecordInSearch()) { |
|
| 437 | + foreach($records as $record) { |
|
| 438 | + if($record->showRecordInSearch()) { |
|
| 439 | 439 | $this->index($record); |
| 440 | 440 | } |
| 441 | 441 | } |
@@ -451,17 +451,17 @@ discard block |
||
| 451 | 451 | * @return \DataObject[] $records |
| 452 | 452 | */ |
| 453 | 453 | protected function recordsByClassConsiderVersioned($class, $pageSize = 0, $page = 0) { |
| 454 | - $offset = $page*$pageSize; |
|
| 454 | + $offset = $page * $pageSize; |
|
| 455 | 455 | |
| 456 | - if ($class::has_extension("Versioned")) { |
|
| 457 | - if ($pageSize >0) { |
|
| 456 | + if($class::has_extension("Versioned")) { |
|
| 457 | + if($pageSize > 0) { |
|
| 458 | 458 | $records = \Versioned::get_by_stage($class, 'Live')->limit($pageSize, $offset); |
| 459 | 459 | } else { |
| 460 | 460 | $records = \Versioned::get_by_stage($class, 'Live'); |
| 461 | 461 | } |
| 462 | 462 | } else { |
| 463 | - if ($pageSize >0) { |
|
| 464 | - $records = $class::get()->limit($pageSize,$offset); |
|
| 463 | + if($pageSize > 0) { |
|
| 464 | + $records = $class::get()->limit($pageSize, $offset); |
|
| 465 | 465 | } else { |
| 466 | 466 | $records = $class::get(); |
| 467 | 467 | } |
@@ -479,12 +479,12 @@ discard block |
||
| 479 | 479 | protected function refreshClass($class) { |
| 480 | 480 | $nRecords = $this->recordsByClassConsiderVersioned($class)->count(); |
| 481 | 481 | $batchSize = 500; |
| 482 | - $pages = $nRecords/$batchSize + 1; |
|
| 482 | + $pages = $nRecords / $batchSize + 1; |
|
| 483 | 483 | $processing = true; |
| 484 | 484 | |
| 485 | - for ($i=0; $i < $pages; $i++) { |
|
| 485 | + for($i = 0; $i < $pages; $i++) { |
|
| 486 | 486 | $this->startBulkIndex(); |
| 487 | - $pagedRecords = $this->recordsByClassConsiderVersioned($class,$batchSize, $i); |
|
| 487 | + $pagedRecords = $this->recordsByClassConsiderVersioned($class, $batchSize, $i); |
|
| 488 | 488 | $this->nDocumentsIndexed += $pagedRecords->count(); |
| 489 | 489 | $batch = $pagedRecords->toArray(); |
| 490 | 490 | $this->refreshRecords($batch); |
@@ -506,8 +506,8 @@ discard block |
||
| 506 | 506 | |
| 507 | 507 | //Count the number of documents for this locale |
| 508 | 508 | $amount = 0; |
| 509 | - echo "CURRENT LOCALE:".$this->locale; |
|
| 510 | - foreach ($classes as $class) { |
|
| 509 | + echo "CURRENT LOCALE:" . $this->locale; |
|
| 510 | + foreach($classes as $class) { |
|
| 511 | 511 | $amount += $this->recordsByClassConsiderVersioned($class)->count(); |
| 512 | 512 | } |
| 513 | 513 | |
@@ -516,17 +516,17 @@ discard block |
||
| 516 | 516 | |
| 517 | 517 | $index = $this->getIndex(); |
| 518 | 518 | |
| 519 | - foreach ($this->getIndexedClasses() as $classname) { |
|
| 519 | + foreach($this->getIndexedClasses() as $classname) { |
|
| 520 | 520 | ElasticaUtil::message("Indexing class $classname"); |
| 521 | 521 | |
| 522 | 522 | $inSiteTree = $classname === 'SiteTree' ? true : false; |
| 523 | - if (isset(self::$site_tree_classes[$classname])) { |
|
| 523 | + if(isset(self::$site_tree_classes[$classname])) { |
|
| 524 | 524 | $inSiteTree = self::$site_tree_classes[$classname]; |
| 525 | 525 | } else { |
| 526 | 526 | $class = new \ReflectionClass($classname); |
| 527 | - while ($class = $class->getParentClass()) { |
|
| 527 | + while($class = $class->getParentClass()) { |
|
| 528 | 528 | $parentClass = $class->getName(); |
| 529 | - if ($parentClass == 'SiteTree') { |
|
| 529 | + if($parentClass == 'SiteTree') { |
|
| 530 | 530 | $inSiteTree = true; |
| 531 | 531 | break; |
| 532 | 532 | } |
@@ -537,9 +537,9 @@ discard block |
||
| 537 | 537 | //$this->refreshClass($classname); |
| 538 | 538 | |
| 539 | 539 | |
| 540 | - if ($inSiteTree) { |
|
| 540 | + if($inSiteTree) { |
|
| 541 | 541 | // this prevents the same item being indexed twice due to class inheritance |
| 542 | - if ($classname === 'SiteTree') { |
|
| 542 | + if($classname === 'SiteTree') { |
|
| 543 | 543 | $this->refreshClass($classname); |
| 544 | 544 | } |
| 545 | 545 | // Data objects |
@@ -578,11 +578,11 @@ discard block |
||
| 578 | 578 | public function getIndexSettingsForCurrentLocale() { |
| 579 | 579 | $result = null; |
| 580 | 580 | $indexSettings = \Config::inst()->get('Elastica', 'indexsettings'); |
| 581 | - if (isset($indexSettings[$this->locale])) { |
|
| 581 | + if(isset($indexSettings[$this->locale])) { |
|
| 582 | 582 | $settingsClassName = $indexSettings[$this->locale]; |
| 583 | 583 | $result = \Injector::inst()->create($settingsClassName); |
| 584 | 584 | } else { |
| 585 | - throw new \Exception('ERROR: No index settings are provided for locale '.$this->locale."\n"); |
|
| 585 | + throw new \Exception('ERROR: No index settings are provided for locale ' . $this->locale . "\n"); |
|
| 586 | 586 | |
| 587 | 587 | } |
| 588 | 588 | return $result; |
@@ -598,16 +598,16 @@ discard block |
||
| 598 | 598 | $classes = array(); |
| 599 | 599 | |
| 600 | 600 | $whitelist = array('SearchableTestPage', 'SearchableTestFatherPage', 'SearchableTestGrandFatherPage', |
| 601 | - 'FlickrPhotoTO','FlickrTagTO','FlickrPhotoTO','FlickrAuthorTO','FlickrSetTO'); |
|
| 601 | + 'FlickrPhotoTO', 'FlickrTagTO', 'FlickrPhotoTO', 'FlickrAuthorTO', 'FlickrSetTO'); |
|
| 602 | 602 | |
| 603 | - foreach (\ClassInfo::subclassesFor('DataObject') as $candidate) { |
|
| 603 | + foreach(\ClassInfo::subclassesFor('DataObject') as $candidate) { |
|
| 604 | 604 | $instance = singleton($candidate); |
| 605 | 605 | |
| 606 | 606 | $interfaces = class_implements($candidate); |
| 607 | 607 | // Only allow test classes in testing mode |
| 608 | - if (isset($interfaces['TestOnly'])) { |
|
| 609 | - if (in_array($candidate, $whitelist)) { |
|
| 610 | - if (!$this->test_mode) { |
|
| 608 | + if(isset($interfaces['TestOnly'])) { |
|
| 609 | + if(in_array($candidate, $whitelist)) { |
|
| 610 | + if(!$this->test_mode) { |
|
| 611 | 611 | continue; |
| 612 | 612 | } |
| 613 | 613 | } else { |
@@ -616,7 +616,7 @@ discard block |
||
| 616 | 616 | } |
| 617 | 617 | } |
| 618 | 618 | |
| 619 | - if ($instance->hasExtension('SilverStripe\\Elastica\\Searchable')) { |
|
| 619 | + if($instance->hasExtension('SilverStripe\\Elastica\\Searchable')) { |
|
| 620 | 620 | $classes[] = $candidate; |
| 621 | 621 | } |
| 622 | 622 | } |
@@ -652,16 +652,16 @@ discard block |
||
| 652 | 652 | |
| 653 | 653 | $fields = array_keys($fieldMappings); |
| 654 | 654 | $allFields = array(); |
| 655 | - foreach ($fields as $field) { |
|
| 655 | + foreach($fields as $field) { |
|
| 656 | 656 | array_push($allFields, $field); |
| 657 | 657 | |
| 658 | 658 | $mapping = $fieldMappings[$field]; |
| 659 | 659 | |
| 660 | 660 | |
| 661 | - if (isset($mapping['fields'])) { |
|
| 661 | + if(isset($mapping['fields'])) { |
|
| 662 | 662 | $subFields = array_keys($mapping['fields']); |
| 663 | - foreach ($subFields as $subField) { |
|
| 664 | - $name = $field.'.'.$subField; |
|
| 663 | + foreach($subFields as $subField) { |
|
| 664 | + $name = $field . '.' . $subField; |
|
| 665 | 665 | array_push($allFields, $name); |
| 666 | 666 | } |
| 667 | 667 | } |
@@ -681,7 +681,7 @@ discard block |
||
| 681 | 681 | ); |
| 682 | 682 | |
| 683 | 683 | //FlickrPhoto/3829/_termvector |
| 684 | - $path = $this->getIndex()->getName().'/'.$searchable->ClassName.'/'.$searchable->ID.'/_termvector'; |
|
| 684 | + $path = $this->getIndex()->getName() . '/' . $searchable->ClassName . '/' . $searchable->ID . '/_termvector'; |
|
| 685 | 685 | $response = $this->getClient()->request( |
| 686 | 686 | $path, |
| 687 | 687 | \Elastica\Request::GET, |
@@ -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 ---- |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | |
| 158 | 158 | $classes = array(); |
| 159 | 159 | $records = DB::query($sql); |
| 160 | - foreach ($records as $record) { |
|
| 160 | + foreach($records as $record) { |
|
| 161 | 161 | array_push($classes, $record['ClassName']); |
| 162 | 162 | } |
| 163 | 163 | $list = implode(',', $classes); |
@@ -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 | |
@@ -246,7 +246,7 @@ discard block |
||
| 246 | 246 | $fields->dataFieldByName('Name')->setReadOnly(true); |
| 247 | 247 | $fields->dataFieldByName('Name')->setDisabled(true); |
| 248 | 248 | |
| 249 | - if (!$fieldAutocomplete->Value() == '1') { |
|
| 249 | + if(!$fieldAutocomplete->Value() == '1') { |
|
| 250 | 250 | $fieldEnableAutcomplete->setDisabled(true); |
| 251 | 251 | $fieldEnableAutcomplete->setReadOnly(true); |
| 252 | 252 | $fieldEnableAutcomplete->setTitle("Autcomplete is not available for this field"); |
@@ -283,49 +283,49 @@ discard block |
||
| 283 | 283 | public function validate() { |
| 284 | 284 | $result = parent::validate(); |
| 285 | 285 | $mode = Versioned::get_reading_mode(); |
| 286 | - $suffix = ''; |
|
| 287 | - if ($mode == 'Stage.Live') { |
|
| 286 | + $suffix = ''; |
|
| 287 | + if($mode == 'Stage.Live') { |
|
| 288 | 288 | $suffix = '_Live'; |
| 289 | 289 | } |
| 290 | 290 | |
| 291 | - if (!$this->Identifier) { |
|
| 291 | + if(!$this->Identifier) { |
|
| 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 | - if ($existing > 0) { |
|
| 298 | - $result->error('The identifier '.$this->Identifier.' already exists'); |
|
| 297 | + if($existing > 0) { |
|
| 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); |
|
| 306 | - if (!$this->SiteTreeOnly) { |
|
| 307 | - if ($this->ClassesToSearch == '') { |
|
| 305 | + error_log('STO:' . $this->SiteTreeOnly); |
|
| 306 | + if(!$this->SiteTreeOnly) { |
|
| 307 | + if($this->ClassesToSearch == '') { |
|
| 308 | 308 | $result->error('At least one searchable class must be available, or SiteTreeOnly flag set'); |
| 309 | 309 | } else { |
| 310 | 310 | $toSearch = explode(',', $this->ClassesToSearch); |
| 311 | - foreach ($toSearch as $clazz) { |
|
| 311 | + foreach($toSearch as $clazz) { |
|
| 312 | 312 | try { |
| 313 | 313 | $instance = Injector::inst()->create($clazz); |
| 314 | - if (!$instance->hasExtension('SilverStripe\Elastica\Searchable')) { |
|
| 315 | - $result->error('The class '.$clazz.' must have the Searchable extension'); |
|
| 314 | + if(!$instance->hasExtension('SilverStripe\Elastica\Searchable')) { |
|
| 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 | } |
| 322 | 322 | } |
| 323 | 323 | |
| 324 | 324 | |
| 325 | - foreach ($this->ElasticaSearchableFields() as $esf) { |
|
| 326 | - if ($esf->Weight == 0) { |
|
| 325 | + foreach($this->ElasticaSearchableFields() as $esf) { |
|
| 326 | + if($esf->Weight == 0) { |
|
| 327 | 327 | $result->error("The field {$esf->ClazzName}.{$esf->Name} has a zero weight. "); |
| 328 | - } else if ($esf->Weight < 0) { |
|
| 328 | + } else if($esf->Weight < 0) { |
|
| 329 | 329 | $result->error("The field {$esf->ClazzName}.{$esf->Name} has a negative weight. "); |
| 330 | 330 | } |
| 331 | 331 | } |
@@ -341,7 +341,7 @@ discard block |
||
| 341 | 341 | |
| 342 | 342 | #FIXME - SiteTree only |
| 343 | 343 | $relevantClasses = $this->ClassesToSearch; // due to validation this will be valid |
| 344 | - if ($this->SiteTreeOnly) { |
|
| 344 | + if($this->SiteTreeOnly) { |
|
| 345 | 345 | $relevantClasses = SearchableClass::get()->filter('InSiteTree', true)->Map('Name')->toArray(); |
| 346 | 346 | |
| 347 | 347 | } |
@@ -361,9 +361,9 @@ discard block |
||
| 361 | 361 | $delta = array_keys($esfs->map()->toArray()); |
| 362 | 362 | $newSearchableFields = $sfs->exclude('ID', $delta); |
| 363 | 363 | |
| 364 | - if ($newSearchableFields->count() > 0) { |
|
| 365 | - foreach ($newSearchableFields->getIterator() as $newSearchableField) { |
|
| 366 | - error_log('NEW FIELD:'.$newSearchableField->Name); |
|
| 364 | + if($newSearchableFields->count() > 0) { |
|
| 365 | + foreach($newSearchableFields->getIterator() as $newSearchableField) { |
|
| 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 | } |
@@ -406,19 +406,19 @@ discard block |
||
| 406 | 406 | $qField = $fields->fieldByName('q'); |
| 407 | 407 | |
| 408 | 408 | |
| 409 | - if ($buttonTextOverride) { |
|
| 409 | + if($buttonTextOverride) { |
|
| 410 | 410 | $result->setButtonText($buttonTextOverride); |
| 411 | 411 | } |
| 412 | 412 | |
| 413 | 413 | /* |
| 414 | 414 | A field needs to be chosen for autocompletion, if not no autocomplete |
| 415 | 415 | */ |
| 416 | - if ($this->AutoCompleteFieldID > 0) { |
|
| 416 | + if($this->AutoCompleteFieldID > 0) { |
|
| 417 | 417 | $qField->setAttribute('data-autocomplete', 'true'); |
| 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(); |
@@ -494,7 +494,7 @@ discard block |
||
| 494 | 494 | |
| 495 | 495 | |
| 496 | 496 | // filter by class or site tree |
| 497 | - if ($ep->SiteTreeOnly) { |
|
| 497 | + if($ep->SiteTreeOnly) { |
|
| 498 | 498 | T7; //FIXME test missing |
| 499 | 499 | $es->addFilter('IsInSiteTree', true); |
| 500 | 500 | } else { |
@@ -510,23 +510,23 @@ discard block |
||
| 510 | 510 | 'SimilarSearchable' => true |
| 511 | 511 | )); |
| 512 | 512 | |
| 513 | - foreach ($editedSearchFields->getIterator() as $searchField) { |
|
| 513 | + foreach($editedSearchFields->getIterator() as $searchField) { |
|
| 514 | 514 | $fieldsToSearch[$searchField->Name] = $searchField->Weight; |
| 515 | 515 | } |
| 516 | 516 | |
| 517 | 517 | // Use the standard field for more like this, ie not stemmed |
| 518 | - foreach ($fieldsToSearch as $field => $value) { |
|
| 519 | - $fieldsToSearch[$field.'.standard'] = $value; |
|
| 518 | + foreach($fieldsToSearch as $field => $value) { |
|
| 519 | + $fieldsToSearch[$field . '.standard'] = $value; |
|
| 520 | 520 | unset($fieldsToSearch[$field]); |
| 521 | 521 | } |
| 522 | 522 | |
| 523 | 523 | try { |
| 524 | 524 | // Simulate server being down for testing purposes |
| 525 | - if (isset($_GET['ServerDown'])) { |
|
| 525 | + if(isset($_GET['ServerDown'])) { |
|
| 526 | 526 | throw new Elastica\Exception\Connection\HttpException('Unable to reach search server'); |
| 527 | 527 | } |
| 528 | - if (class_exists($class)) { |
|
| 529 | - $instance = \DataObject::get_by_id($class,$instanceID); |
|
| 528 | + if(class_exists($class)) { |
|
| 529 | + $instance = \DataObject::get_by_id($class, $instanceID); |
|
| 530 | 530 | |
| 531 | 531 | $paginated = $es->moreLikeThis($instance, $fieldsToSearch); |
| 532 | 532 | |
@@ -540,10 +540,10 @@ discard block |
||
| 540 | 540 | |
| 541 | 541 | $moreLikeThisTerms = $paginated->getList()->MoreLikeThisTerms; |
| 542 | 542 | $fieldToTerms = new ArrayList(); |
| 543 | - foreach (array_keys($moreLikeThisTerms) as $fieldName) { |
|
| 543 | + foreach(array_keys($moreLikeThisTerms) as $fieldName) { |
|
| 544 | 544 | $readableFieldName = str_replace('.standard', '', $fieldName); |
| 545 | 545 | $fieldTerms = new ArrayList(); |
| 546 | - foreach ($moreLikeThisTerms[$fieldName] as $value) { |
|
| 546 | + foreach($moreLikeThisTerms[$fieldName] as $value) { |
|
| 547 | 547 | $do = new DataObject(); |
| 548 | 548 | $do->Term = $value; |
| 549 | 549 | $fieldTerms->push($do); |
@@ -570,14 +570,14 @@ 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; |
| 577 | 577 | $data['Elapsed'] = $elapsed; |
| 578 | 578 | |
| 579 | 579 | // allow the optional use of overriding the search result page, e.g. for photos, maps or facets |
| 580 | - if ($this->hasExtension('PageControllerTemplateOverrideExtension')) { |
|
| 580 | + if($this->hasExtension('PageControllerTemplateOverrideExtension')) { |
|
| 581 | 581 | return $this->useTemplateOverride($data); |
| 582 | 582 | } else { |
| 583 | 583 | return $data; |
@@ -617,23 +617,23 @@ discard block |
||
| 617 | 617 | |
| 618 | 618 | // query string |
| 619 | 619 | $queryText = ''; |
| 620 | - if (isset($_GET['q'])) { |
|
| 620 | + if(isset($_GET['q'])) { |
|
| 621 | 621 | $queryText = $_GET['q']; |
| 622 | 622 | } |
| 623 | 623 | |
| 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 | - foreach ($this->request->getVars() as $key => $value) { |
|
| 630 | - if (!in_array($key, $ignore)) { |
|
| 631 | - $es->addFilter($key,$value); |
|
| 629 | + foreach($this->request->getVars() as $key => $value) { |
|
| 630 | + if(!in_array($key, $ignore)) { |
|
| 631 | + $es->addFilter($key, $value); |
|
| 632 | 632 | } |
| 633 | 633 | } |
| 634 | 634 | |
| 635 | 635 | // filter by class or site tree |
| 636 | - if ($ep->SiteTreeOnly) { |
|
| 636 | + if($ep->SiteTreeOnly) { |
|
| 637 | 637 | $es->addFilter('IsInSiteTree', true); |
| 638 | 638 | } else { |
| 639 | 639 | $es->setClasses($ep->ClassesToSearch); |
@@ -642,7 +642,7 @@ discard block |
||
| 642 | 642 | // set the optional aggregation manipulator |
| 643 | 643 | // In the event of a manipulator being present, show all the results for search |
| 644 | 644 | // Otherwise aggregations are all zero |
| 645 | - if ($this->SearchHelper) { |
|
| 645 | + if($this->SearchHelper) { |
|
| 646 | 646 | $es->setQueryResultManipulator($this->SearchHelper); |
| 647 | 647 | $es->showResultsForEmptySearch(); |
| 648 | 648 | } else { |
@@ -657,14 +657,14 @@ discard block |
||
| 657 | 657 | 'Searchable' => true |
| 658 | 658 | )); |
| 659 | 659 | |
| 660 | - foreach ($editedSearchFields->getIterator() as $searchField) { |
|
| 660 | + foreach($editedSearchFields->getIterator() as $searchField) { |
|
| 661 | 661 | $fieldsToSearch[$searchField->Name] = $searchField->Weight; |
| 662 | 662 | } |
| 663 | 663 | |
| 664 | 664 | $paginated = null; |
| 665 | 665 | try { |
| 666 | 666 | // Simulate server being down for testing purposes |
| 667 | - if (isset($_GET['ServerDown'])) { |
|
| 667 | + if(isset($_GET['ServerDown'])) { |
|
| 668 | 668 | throw new Elastica\Exception\Connection\HttpException('Unable to reach search server'); |
| 669 | 669 | } |
| 670 | 670 | |
@@ -673,11 +673,11 @@ discard block |
||
| 673 | 673 | |
| 674 | 674 | // This is the case of the original query having a better one suggested. Do a |
| 675 | 675 | // second search for the suggested query, throwing away the original |
| 676 | - if ($es->hasSuggestedQuery() && !$ignoreSuggestions) { |
|
| 676 | + if($es->hasSuggestedQuery() && !$ignoreSuggestions) { |
|
| 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; |
@@ -702,7 +702,7 @@ discard block |
||
| 702 | 702 | $data['OriginalQuery'] = $queryText; |
| 703 | 703 | $data['IgnoreSuggestions'] = $ignoreSuggestions; |
| 704 | 704 | |
| 705 | - if ($this->has_extension('PageControllerTemplateOverrideExtension')) { |
|
| 705 | + if($this->has_extension('PageControllerTemplateOverrideExtension')) { |
|
| 706 | 706 | return $this->useTemplateOverride($data); |
| 707 | 707 | } else { |
| 708 | 708 | return $data; |
@@ -716,9 +716,9 @@ 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 | - if ($queryText == '') { |
|
| 721 | + if($queryText == '') { |
|
| 722 | 722 | $result = true; |
| 723 | 723 | } |
| 724 | 724 | } |
@@ -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 | |
@@ -752,8 +752,8 @@ discard block |
||
| 752 | 752 | $fields->push($identifierField); |
| 753 | 753 | $queryField = $fields->fieldByName('q'); |
| 754 | 754 | |
| 755 | - if (isset($_GET['q']) && isset($_GET['sfid'])) { |
|
| 756 | - if ($_GET['sfid'] == $ep->Identifier) { |
|
| 755 | + if(isset($_GET['q']) && isset($_GET['sfid'])) { |
|
| 756 | + if($_GET['sfid'] == $ep->Identifier) { |
|
| 757 | 757 | $queryField->setValue($_GET['q']); |
| 758 | 758 | } |
| 759 | 759 | |
@@ -762,7 +762,7 @@ discard block |
||
| 762 | 762 | if($this->action == 'similar') { |
| 763 | 763 | $queryField->setDisabled(true); |
| 764 | 764 | $actions = $form->Actions(); |
| 765 | - foreach ($actions as $field) { |
|
| 765 | + foreach($actions as $field) { |
|
| 766 | 766 | $field->setDisabled(true); |
| 767 | 767 | } |
| 768 | 768 | } |
@@ -770,12 +770,12 @@ discard block |
||
| 770 | 770 | /* |
| 771 | 771 | A field needs to be chosen for autocompletion, if not no autocomplete |
| 772 | 772 | */ |
| 773 | - if ($this->AutoCompleteFieldID > 0) { |
|
| 773 | + if($this->AutoCompleteFieldID > 0) { |
|
| 774 | 774 | $queryField->setAttribute('data-autocomplete', 'true'); |
| 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 | } |
@@ -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'; |