@@ -25,11 +25,11 @@ discard block |
||
| 25 | 25 | // don't check the server name as this will differ, just check the path is /search/ |
| 26 | 26 | $uri = $searchPage->SearchPageURI('testsearchpage'); |
| 27 | 27 | $splits = explode('/', $uri); |
| 28 | - $this->assertEquals($splits[3],'search'); |
|
| 28 | + $this->assertEquals($splits[3], 'search'); |
|
| 29 | 29 | |
| 30 | 30 | // check the form |
| 31 | 31 | $form = $searchPage->SearchPageForm('testsearchpage'); |
| 32 | - $this->assertInstanceOf('ElasticSearchForm',$form); |
|
| 32 | + $this->assertInstanceOf('ElasticSearchForm', $form); |
|
| 33 | 33 | |
| 34 | 34 | $fields = $form->Fields(); |
| 35 | 35 | $actions = $form->Actions(); |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | public function testButtonOverride() { |
| 46 | 46 | $searchPage = $this->objFromFixture('ElasticSearchPage', 'search'); |
| 47 | 47 | $buttonText = 'Search Me!'; |
| 48 | - $form = $searchPage->SearchPageForm('testsearchpage',$buttonText); |
|
| 48 | + $form = $searchPage->SearchPageForm('testsearchpage', $buttonText); |
|
| 49 | 49 | $actions = $form->Actions(); |
| 50 | 50 | $this->assertEquals($buttonText, $actions->FieldByName('action_submit')->Title()); |
| 51 | 51 | } |
@@ -86,12 +86,12 @@ discard block |
||
| 86 | 86 | $esp = new ElasticSearchPage(); |
| 87 | 87 | // ensure default identifier |
| 88 | 88 | $esp->Identifier = $searchPage->Identifier; |
| 89 | - $esp->Title='This should not be saved'; |
|
| 89 | + $esp->Title = 'This should not be saved'; |
|
| 90 | 90 | try { |
| 91 | 91 | $esp->write(); |
| 92 | 92 | $this->assertFalse(true, 'Duplicate identifier was incorrectly saved'); |
| 93 | 93 | } catch (Exception $e) { |
| 94 | - $this->assertTrue(true,'The page could not be saved as expected, due to duplicate '. |
|
| 94 | + $this->assertTrue(true, 'The page could not be saved as expected, due to duplicate ' . |
|
| 95 | 95 | 'identifier'); |
| 96 | 96 | } |
| 97 | 97 | } |
@@ -434,11 +434,11 @@ discard block |
||
| 434 | 434 | |
| 435 | 435 | |
| 436 | 436 | |
| 437 | - $query = new Query(); |
|
| 438 | - $query->setParams(array('query' => array('more_like_this' => $mlt))); |
|
| 437 | + $query = new Query(); |
|
| 438 | + $query->setParams(array('query' => array('more_like_this' => $mlt))); |
|
| 439 | 439 | |
| 440 | 440 | |
| 441 | - $elasticService = \Injector::inst()->create('SilverStripe\Elastica\ElasticaService'); |
|
| 441 | + $elasticService = \Injector::inst()->create('SilverStripe\Elastica\ElasticaService'); |
|
| 442 | 442 | $elasticService->setLocale($this->locale); |
| 443 | 443 | if ($testMode) { |
| 444 | 444 | $elasticService->setTestMode(true); |
@@ -450,7 +450,7 @@ discard block |
||
| 450 | 450 | $query->setFrom($this->start); |
| 451 | 451 | |
| 452 | 452 | $resultList = new ResultList($elasticService, $query, null); |
| 453 | - // at this point ResultList object, not yet executed search query |
|
| 453 | + // at this point ResultList object, not yet executed search query |
|
| 454 | 454 | $paginated = new \PaginatedList( |
| 455 | 455 | $resultList |
| 456 | 456 | ); |
@@ -230,6 +230,10 @@ discard block |
||
| 230 | 230 | /* |
| 231 | 231 | Set the highlight fields for subsequent searches |
| 232 | 232 | */ |
| 233 | + |
|
| 234 | + /** |
|
| 235 | + * @param string[] $newHighlightedFields |
|
| 236 | + */ |
|
| 233 | 237 | public function setHighlightedFields($newHighlightedFields) { |
| 234 | 238 | $this->highlightedFields = $newHighlightedFields; |
| 235 | 239 | } |
@@ -242,7 +246,7 @@ discard block |
||
| 242 | 246 | * @param string $queryText query string, e.g. 'New Zealand' |
| 243 | 247 | * @param array $fieldsToSearch Mapping of name to an array of mapping Weight and Elastic mapping, |
| 244 | 248 | * e.g. array('Title' => array('Weight' => 2, 'Type' => 'string')) |
| 245 | - * @return ArrayList SilverStripe DataObjects returned from the search against ElasticSearch |
|
| 249 | + * @return \PaginatedList SilverStripe DataObjects returned from the search against ElasticSearch |
|
| 246 | 250 | */ |
| 247 | 251 | public function search($queryText, $fieldsToSearch = null, $testMode = false) { |
| 248 | 252 | if ($this->locale == null) { |
@@ -307,6 +311,10 @@ discard block |
||
| 307 | 311 | |
| 308 | 312 | |
| 309 | 313 | /* Perform an autocomplete search */ |
| 314 | + |
|
| 315 | + /** |
|
| 316 | + * @param string $queryText |
|
| 317 | + */ |
|
| 310 | 318 | public function autocomplete_search($queryText, $field) { |
| 311 | 319 | if ($this->locale == null) { |
| 312 | 320 | if (class_exists('Translatable') && \SiteTree::has_extension('Translatable')) { |
@@ -358,11 +366,11 @@ discard block |
||
| 358 | 366 | |
| 359 | 367 | /** |
| 360 | 368 | * Perform a 'More Like This' search, aka relevance feedback, using the provided indexed DataObject |
| 361 | - * @param DataObject $indexedItem A DataObject that has been indexed in Elasticsearch |
|
| 369 | + * @param \DataObject|null $indexedItem A DataObject that has been indexed in Elasticsearch |
|
| 362 | 370 | * @param array $fieldsToSearch array of fieldnames to search, mapped to weighting |
| 363 | 371 | * @param $$testMode Use all shards, not just one, for consistent results during unit testing. See |
| 364 | 372 | * https://www.elastic.co/guide/en/elasticsearch/guide/current/relevance-is-broken.html#relevance-is-broken |
| 365 | - * @return resultList List of results |
|
| 373 | + * @return \PaginatedList List of results |
|
| 366 | 374 | */ |
| 367 | 375 | public function moreLikeThis($indexedItem, $fieldsToSearch, $testMode = false) { |
| 368 | 376 | echo "INDEXED ITEM:".$indexedItem; |
@@ -469,6 +477,9 @@ discard block |
||
| 469 | 477 | return $result; |
| 470 | 478 | } |
| 471 | 479 | |
| 480 | + /** |
|
| 481 | + * @return string |
|
| 482 | + */ |
|
| 472 | 483 | public function getSuggestedQuery() { |
| 473 | 484 | return $this->SuggestedQuery; |
| 474 | 485 | } |
@@ -244,7 +244,7 @@ discard block |
||
| 244 | 244 | * e.g. array('Title' => array('Weight' => 2, 'Type' => 'string')) |
| 245 | 245 | * @return ArrayList SilverStripe DataObjects returned from the search against ElasticSearch |
| 246 | 246 | */ |
| 247 | - public function search($queryText, $fieldsToSearch = null, $testMode = false) { |
|
| 247 | + public function search($queryText, $fieldsToSearch = null, $testMode = false) { |
|
| 248 | 248 | if ($this->locale == null) { |
| 249 | 249 | if (class_exists('Translatable') && \SiteTree::has_extension('Translatable')) { |
| 250 | 250 | $this->locale = \Translatable::get_current_locale(); |
@@ -365,14 +365,14 @@ discard block |
||
| 365 | 365 | * @return resultList List of results |
| 366 | 366 | */ |
| 367 | 367 | public function moreLikeThis($indexedItem, $fieldsToSearch, $testMode = false) { |
| 368 | - echo "INDEXED ITEM:".$indexedItem; |
|
| 368 | + echo "INDEXED ITEM:" . $indexedItem; |
|
| 369 | 369 | |
| 370 | 370 | if ($indexedItem == null) { |
| 371 | 371 | throw new \InvalidArgumentException('A searchable item cannot be null'); |
| 372 | 372 | } |
| 373 | 373 | |
| 374 | 374 | if (!$indexedItem->hasExtension('SilverStripe\Elastica\Searchable')) { |
| 375 | - throw new \InvalidArgumentException('Objects of class '.$indexedItem->ClassName.' are not searchable'); |
|
| 375 | + throw new \InvalidArgumentException('Objects of class ' . $indexedItem->ClassName . ' are not searchable'); |
|
| 376 | 376 | } |
| 377 | 377 | |
| 378 | 378 | if ($fieldsToSearch == null) { |
@@ -396,7 +396,7 @@ discard block |
||
| 396 | 396 | if (!is_numeric($weighting)) { |
| 397 | 397 | throw new \InvalidArgumentException('Fields must be of the form fieldname => weight'); |
| 398 | 398 | } |
| 399 | - $weightedField = $field.'^'.$weighting; |
|
| 399 | + $weightedField = $field . '^' . $weighting; |
|
| 400 | 400 | $weightedField = str_replace('^1', '', $weightedField); |
| 401 | 401 | array_push($weightedFieldsArray, $weightedField); |
| 402 | 402 | } |
@@ -38,8 +38,8 @@ |
||
| 38 | 38 | $to = $range['to']; |
| 39 | 39 | } |
| 40 | 40 | $rangeFilter = array('gte' => (string)$from, 'lt' => (string)$to); |
| 41 | - $filter = new \Elastica\Filter\Range('AspectRatio', $rangeFilter); |
|
| 42 | - $result = $filter; |
|
| 41 | + $filter = new \Elastica\Filter\Range('AspectRatio', $rangeFilter); |
|
| 42 | + $result = $filter; |
|
| 43 | 43 | } |
| 44 | 44 | } |
| 45 | 45 | |
@@ -10,12 +10,12 @@ |
||
| 10 | 10 | $this->Title = $title; |
| 11 | 11 | $this->Range = new \Elastica\Aggregation\Range($title); |
| 12 | 12 | $this->Range->setField($field); |
| 13 | - self::$ranged_aggregations[$title] = $this;; |
|
| 13 | + self::$ranged_aggregations[$title] = $this; ; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | |
| 17 | 17 | public function addRange($from, $to, $name) { |
| 18 | - $this->Range->addRange($from,$to,$name); |
|
| 18 | + $this->Range->addRange($from, $to, $name); |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | |
@@ -28,7 +28,7 @@ |
||
| 28 | 28 | $germanWithURLs = array( |
| 29 | 29 | 'tokenizer' => 'uax_url_email', |
| 30 | 30 | //'filter' => array('english_possessive_stemmer', 'lowercase', 'english_stop', /*'english_keywords',*/ 'english_stemmer' ), |
| 31 | - 'filter' => array('no_single_chars', 'german_snowball', 'lowercase', 'german_stop' ), |
|
| 31 | + 'filter' => array('no_single_chars', 'german_snowball', 'lowercase', 'german_stop'), |
|
| 32 | 32 | 'type' => 'custom' |
| 33 | 33 | ); |
| 34 | 34 | |
@@ -214,7 +214,7 @@ |
||
| 214 | 214 | $analyzers['folded'] = $analyzerFolded; |
| 215 | 215 | } |
| 216 | 216 | |
| 217 | - //Store bigrams in the index, namely pairs of words |
|
| 217 | + //Store bigrams in the index, namely pairs of words |
|
| 218 | 218 | $this->addFilter('filter_shingle', array( |
| 219 | 219 | 'type' => 'shingle', |
| 220 | 220 | 'min_shingle_size' => 2, |
@@ -177,10 +177,10 @@ discard block |
||
| 177 | 177 | 'type' => 'nGram', |
| 178 | 178 | 'min_gram' => 2, |
| 179 | 179 | 'max_gram' => 20, |
| 180 | - 'token_chars' => array('letter', 'digit','punctuation', 'symbol') |
|
| 180 | + 'token_chars' => array('letter', 'digit', 'punctuation', 'symbol') |
|
| 181 | 181 | )); |
| 182 | 182 | |
| 183 | - $this->addAnalyzer('autocomplete_index_analyzer',array( |
|
| 183 | + $this->addAnalyzer('autocomplete_index_analyzer', array( |
|
| 184 | 184 | 'type' => 'custom', |
| 185 | 185 | 'tokenizer' => 'whitespace', |
| 186 | 186 | 'filter' => array( |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | ) |
| 191 | 191 | )); |
| 192 | 192 | |
| 193 | - $this->addAnalyzer('autocomplete_search_analyzer',array( |
|
| 193 | + $this->addAnalyzer('autocomplete_search_analyzer', array( |
|
| 194 | 194 | 'type' => 'custom', |
| 195 | 195 | 'tokenizer' => 'whitespace', |
| 196 | 196 | 'filter' => array( |
@@ -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 | |
@@ -27,12 +27,12 @@ discard block |
||
| 27 | 27 | */ |
| 28 | 28 | |
| 29 | 29 | public function run($request) { |
| 30 | - $message = function ($content) { |
|
| 30 | + $message = function($content) { |
|
| 31 | 31 | print(\Director::is_cli() ? "$content\n" : "<p>$content</p>"); |
| 32 | 32 | }; |
| 33 | 33 | |
| 34 | 34 | $locales = array(); |
| 35 | - if(class_exists('Translatable') && singleton('SiteTree')->hasExtension('Translatable')) { |
|
| 35 | + if (class_exists('Translatable') && singleton('SiteTree')->hasExtension('Translatable')) { |
|
| 36 | 36 | foreach (\Translatable::get_existing_content_languages('SiteTree') as $code => $val) { |
| 37 | 37 | array_push($locales, $code); |
| 38 | 38 | } |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | // now iterate all the locales indexing each locale in turn using it's owner index settings |
| 44 | 44 | foreach ($locales as $locale) { |
| 45 | 45 | Searchable::$index_ctr = 0; |
| 46 | - $message('Indexing locale '.$locale); |
|
| 46 | + $message('Indexing locale ' . $locale); |
|
| 47 | 47 | |
| 48 | 48 | if (class_exists('Translatable')) { |
| 49 | 49 | \Translatable::set_current_locale($locale); |
@@ -62,10 +62,10 @@ discard block |
||
| 62 | 62 | $this->service->refresh(); |
| 63 | 63 | // display indexing speed stats |
| 64 | 64 | $endTime = microtime(true); |
| 65 | - $elapsed = $endTime-$startTime; |
|
| 65 | + $elapsed = $endTime - $startTime; |
|
| 66 | 66 | $perSecond = Searchable::$index_ctr / $elapsed; |
| 67 | - $info = "\nReindexing $locale completed \n ".Searchable::$index_ctr." docs in ".round($elapsed,2)." seconds "; |
|
| 68 | - $info .= "at ".round($perSecond,2)." documents per second\n\n"; |
|
| 67 | + $info = "\nReindexing $locale completed \n " . Searchable::$index_ctr . " docs in " . round($elapsed, 2) . " seconds "; |
|
| 68 | + $info .= "at " . round($perSecond, 2) . " documents per second\n\n"; |
|
| 69 | 69 | $message($info); |
| 70 | 70 | } |
| 71 | 71 | |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | public function run($request) { |
| 24 | - $message = function ($content) { |
|
| 24 | + $message = function($content) { |
|
| 25 | 25 | print(\Director::is_cli() ? "$content\n" : "<p>$content</p>"); |
| 26 | 26 | }; |
| 27 | 27 | |
@@ -45,12 +45,12 @@ discard block |
||
| 45 | 45 | $es->addFilter('IsInSiteTree', true); |
| 46 | 46 | $results = $es->search($query); |
| 47 | 47 | foreach ($results as $result) { |
| 48 | - $title = '['.$result->ClassName.', '.$result->ID.'] '; |
|
| 48 | + $title = '[' . $result->ClassName . ', ' . $result->ID . '] '; |
|
| 49 | 49 | $title .= $result->Title; |
| 50 | 50 | $message($title); |
| 51 | 51 | if ($result->SearchHighlightsByField->Content) { |
| 52 | 52 | foreach ($result->SearchHighlightsByField->Content as $highlight) { |
| 53 | - $message("- ".$highlight->Snippet); |
|
| 53 | + $message("- " . $highlight->Snippet); |
|
| 54 | 54 | } |
| 55 | 55 | } |
| 56 | 56 | |