@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | $this->invokeMethod($this->service, 'createIndex', array()); |
| 28 | 28 | $this->assertFalse(true, "Creation of index with unknown locale should have failed"); |
| 29 | 29 | } catch (Exception $e) { |
| 30 | - $this->assertTrue(true,"Creation of index with unknown locale failed as expected"); |
|
| 30 | + $this->assertTrue(true, "Creation of index with unknown locale failed as expected"); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | $fp->write(); |
| 117 | 117 | $this->service->getIndex()->refresh(); |
| 118 | 118 | |
| 119 | - $this->checkNumberOfIndexedDocuments($nDocsAtStart-1); |
|
| 119 | + $this->checkNumberOfIndexedDocuments($nDocsAtStart - 1); |
|
| 120 | 120 | |
| 121 | 121 | $fp->ShowInSearch = true; |
| 122 | 122 | $fp->write(); |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | $fp->doUnpublish(); |
| 135 | 135 | |
| 136 | 136 | $this->service->getIndex()->refresh(); |
| 137 | - $this->checkNumberOfIndexedDocuments($nDocsAtStart-1); |
|
| 137 | + $this->checkNumberOfIndexedDocuments($nDocsAtStart - 1); |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | $fp->delete(); |
| 147 | 147 | |
| 148 | 148 | $this->service->getIndex()->refresh(); |
| 149 | - $this->checkNumberOfIndexedDocuments($nDocsAtStart-1); |
|
| 149 | + $this->checkNumberOfIndexedDocuments($nDocsAtStart - 1); |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | $fp->delete(); |
| 159 | 159 | |
| 160 | 160 | $this->service->getIndex()->refresh(); |
| 161 | - $this->checkNumberOfIndexedDocuments($nDocsAtStart-1); |
|
| 161 | + $this->checkNumberOfIndexedDocuments($nDocsAtStart - 1); |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | //Check that the number of indexing requests has increased by 2 |
| 178 | 178 | $deltaReqs = $this->service->getIndexingRequestCtr() - $reqs; |
| 179 | 179 | //One call is made for each of Page and FlickrPhotoTO |
| 180 | - $this->assertEquals(2,$deltaReqs); |
|
| 180 | + $this->assertEquals(2, $deltaReqs); |
|
| 181 | 181 | |
| 182 | 182 | // default installed pages plus 100 FlickrPhotoTOs |
| 183 | 183 | $this->checkNumberOfIndexedDocuments(103); |
@@ -195,21 +195,21 @@ discard block |
||
| 195 | 195 | $fp = new FlickrPhotoTO(); |
| 196 | 196 | $fp->Title = 'The cat sits on the mat'; |
| 197 | 197 | $fp->write(); |
| 198 | - $this->checkNumberOfIndexedDocuments($nDocsAtStart+1); |
|
| 198 | + $this->checkNumberOfIndexedDocuments($nDocsAtStart + 1); |
|
| 199 | 199 | |
| 200 | 200 | $fp2 = new FlickrPhotoTO(); |
| 201 | 201 | $fp2->Title = 'The cat sat on the hat'; |
| 202 | 202 | $fp2->write(); |
| 203 | - $this->checkNumberOfIndexedDocuments($nDocsAtStart+2); |
|
| 203 | + $this->checkNumberOfIndexedDocuments($nDocsAtStart + 2); |
|
| 204 | 204 | |
| 205 | 205 | $fp3 = new FlickrPhotoTO(); |
| 206 | 206 | $fp3->Title = 'The bat flew around the cat'; |
| 207 | 207 | $fp3->write(); |
| 208 | - $this->checkNumberOfIndexedDocuments($nDocsAtStart+3); |
|
| 208 | + $this->checkNumberOfIndexedDocuments($nDocsAtStart + 3); |
|
| 209 | 209 | |
| 210 | 210 | //Check that the number of indexing requests has increased by 3 |
| 211 | 211 | $deltaReqs = $this->service->getIndexingRequestCtr() - $reqs; |
| 212 | - $this->assertEquals(3,$deltaReqs); |
|
| 212 | + $this->assertEquals(3, $deltaReqs); |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | |
@@ -283,6 +283,6 @@ discard block |
||
| 283 | 283 | public function testListIndexes() { |
| 284 | 284 | $message = 'This is a test trace'; |
| 285 | 285 | $trace = $this->service->listIndexes($message); |
| 286 | - $this->assertContains('elastica_ss_module_test_en_us', print_r($trace,1)); |
|
| 286 | + $this->assertContains('elastica_ss_module_test_en_us', print_r($trace, 1)); |
|
| 287 | 287 | } |
| 288 | 288 | } |
@@ -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 | ); |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | |
| 128 | 128 | /** |
| 129 | 129 | * Set the manipulator, mainly used for aggregation |
| 130 | - * @param ElasticaSearchHelper $newManipulator manipulator used for aggregation |
|
| 130 | + * @param string $newManipulator manipulator used for aggregation |
|
| 131 | 131 | */ |
| 132 | 132 | public function setQueryResultManipulator($newManipulator) { |
| 133 | 133 | $this->manipulator = $newManipulator; |
@@ -199,6 +199,7 @@ discard block |
||
| 199 | 199 | /** |
| 200 | 200 | * Set the maximum number of documents a term can reside in for consideration as |
| 201 | 201 | * part of the input query |
| 202 | + * @param integer $newMaxDocFreq |
|
| 202 | 203 | */ |
| 203 | 204 | public function setMaxDocFreq($newMaxDocFreq) { |
| 204 | 205 | $this->maxDocFreq = $newMaxDocFreq; |
@@ -251,9 +251,9 @@ discard block |
||
| 251 | 251 | * e.g. array('Title' => array('Weight' => 2, 'Type' => 'string')) |
| 252 | 252 | * @return \PaginatedList SilverStripe DataObjects returned from the search against ElasticSearch |
| 253 | 253 | */ |
| 254 | - public function search($queryText, $fieldsToSearch = null, $testMode = false) { |
|
| 255 | - if ($this->locale == null) { |
|
| 256 | - if (class_exists('Translatable') && \SiteTree::has_extension('Translatable')) { |
|
| 254 | + public function search($queryText, $fieldsToSearch = null, $testMode = false) { |
|
| 255 | + if($this->locale == null) { |
|
| 256 | + if(class_exists('Translatable') && \SiteTree::has_extension('Translatable')) { |
|
| 257 | 257 | $this->locale = \Translatable::get_current_locale(); |
| 258 | 258 | } else { |
| 259 | 259 | // if no translatable we only have the default locale |
@@ -280,7 +280,7 @@ discard block |
||
| 280 | 280 | $elasticService = \Injector::inst()->create('SilverStripe\Elastica\ElasticaService'); |
| 281 | 281 | $elasticService->setLocale($this->locale); |
| 282 | 282 | $elasticService->setHighlightedFields($this->highlightedFields); |
| 283 | - if ($testMode) { |
|
| 283 | + if($testMode) { |
|
| 284 | 284 | $elasticService->setTestMode(true); |
| 285 | 285 | } |
| 286 | 286 | $resultList = new ResultList($elasticService, $query, $queryText, $this->filters); |
@@ -305,7 +305,7 @@ discard block |
||
| 305 | 305 | |
| 306 | 306 | $this->aggregations = $resultList->getAggregations(); |
| 307 | 307 | |
| 308 | - if ($resultList->SuggestedQuery) { |
|
| 308 | + if($resultList->SuggestedQuery) { |
|
| 309 | 309 | $this->SuggestedQuery = $resultList->SuggestedQuery; |
| 310 | 310 | $this->SuggestedQueryHighlighted = $resultList->SuggestedQueryHighlighted; |
| 311 | 311 | } |
@@ -319,8 +319,8 @@ discard block |
||
| 319 | 319 | * @param string $queryText |
| 320 | 320 | */ |
| 321 | 321 | public function autocomplete_search($queryText, $field) { |
| 322 | - if ($this->locale == null) { |
|
| 323 | - if (class_exists('Translatable') && \SiteTree::has_extension('Translatable')) { |
|
| 322 | + if($this->locale == null) { |
|
| 323 | + if(class_exists('Translatable') && \SiteTree::has_extension('Translatable')) { |
|
| 324 | 324 | $this->locale = \Translatable::get_current_locale(); |
| 325 | 325 | } else { |
| 326 | 326 | // if no translatable we only have the default locale |
@@ -333,11 +333,11 @@ discard block |
||
| 333 | 333 | |
| 334 | 334 | //only one field but must be array |
| 335 | 335 | $qg->setFields(array($field => 1)); |
| 336 | - if ($this->classes) { |
|
| 336 | + if($this->classes) { |
|
| 337 | 337 | $qg->setClasses($this->classes); |
| 338 | 338 | } |
| 339 | 339 | |
| 340 | - if (!empty($this->filters)) { |
|
| 340 | + if(!empty($this->filters)) { |
|
| 341 | 341 | $qg->setSelectedFilters($this->filters); |
| 342 | 342 | } |
| 343 | 343 | |
@@ -370,20 +370,20 @@ discard block |
||
| 370 | 370 | * @return \PaginatedList List of results |
| 371 | 371 | */ |
| 372 | 372 | public function moreLikeThis($indexedItem, $fieldsToSearch, $testMode = false) { |
| 373 | - if ($indexedItem == null) { |
|
| 373 | + if($indexedItem == null) { |
|
| 374 | 374 | throw new \InvalidArgumentException('A searchable item cannot be null'); |
| 375 | 375 | } |
| 376 | 376 | |
| 377 | - if (!$indexedItem->hasExtension('SilverStripe\Elastica\Searchable')) { |
|
| 378 | - throw new \InvalidArgumentException('Objects of class '.$indexedItem->ClassName.' are not searchable'); |
|
| 377 | + if(!$indexedItem->hasExtension('SilverStripe\Elastica\Searchable')) { |
|
| 378 | + throw new \InvalidArgumentException('Objects of class ' . $indexedItem->ClassName . ' are not searchable'); |
|
| 379 | 379 | } |
| 380 | 380 | |
| 381 | - if ($fieldsToSearch == null) { |
|
| 381 | + if($fieldsToSearch == null) { |
|
| 382 | 382 | throw new \InvalidArgumentException('Fields cannot be null'); |
| 383 | 383 | } |
| 384 | 384 | |
| 385 | - if ($this->locale == null) { |
|
| 386 | - if (class_exists('Translatable') && \SiteTree::has_extension('Translatable')) { |
|
| 385 | + if($this->locale == null) { |
|
| 386 | + if(class_exists('Translatable') && \SiteTree::has_extension('Translatable')) { |
|
| 387 | 387 | $this->locale = \Translatable::get_current_locale(); |
| 388 | 388 | } else { |
| 389 | 389 | // if no translatable we only have the default locale |
@@ -392,14 +392,14 @@ discard block |
||
| 392 | 392 | } |
| 393 | 393 | |
| 394 | 394 | $weightedFieldsArray = array(); |
| 395 | - foreach ($fieldsToSearch as $field => $weighting) { |
|
| 396 | - if (!is_string($field)) { |
|
| 395 | + foreach($fieldsToSearch as $field => $weighting) { |
|
| 396 | + if(!is_string($field)) { |
|
| 397 | 397 | throw new \InvalidArgumentException('Fields must be of the form fieldname => weight'); |
| 398 | 398 | } |
| 399 | - if (!is_numeric($weighting)) { |
|
| 399 | + if(!is_numeric($weighting)) { |
|
| 400 | 400 | throw new \InvalidArgumentException('Fields must be of the form fieldname => weight'); |
| 401 | 401 | } |
| 402 | - $weightedField = $field.'^'.$weighting; |
|
| 402 | + $weightedField = $field . '^' . $weighting; |
|
| 403 | 403 | $weightedField = str_replace('^1', '', $weightedField); |
| 404 | 404 | array_push($weightedFieldsArray, $weightedField); |
| 405 | 405 | } |
@@ -430,7 +430,7 @@ discard block |
||
| 430 | 430 | 'stop_words' => explode(',', $this->similarityStopWords) |
| 431 | 431 | ); |
| 432 | 432 | |
| 433 | - if ($this->maxDocFreq > 0) { |
|
| 433 | + if($this->maxDocFreq > 0) { |
|
| 434 | 434 | $mlt['max_doc_freq'] = $this->maxDocFreq; |
| 435 | 435 | } |
| 436 | 436 | |
@@ -442,7 +442,7 @@ discard block |
||
| 442 | 442 | |
| 443 | 443 | $elasticService = \Injector::inst()->create('SilverStripe\Elastica\ElasticaService'); |
| 444 | 444 | $elasticService->setLocale($this->locale); |
| 445 | - if ($testMode) { |
|
| 445 | + if($testMode) { |
|
| 446 | 446 | $elasticService->setTestMode(true); |
| 447 | 447 | } |
| 448 | 448 | |
@@ -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 | |
@@ -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, |
@@ -86,9 +86,9 @@ discard block |
||
| 86 | 86 | * @param array or string $newStopWords An array of stopwords or a CSV string of stopwords |
| 87 | 87 | */ |
| 88 | 88 | public function setStopwords($newStopWords) { |
| 89 | - if (is_array($newStopWords)) { |
|
| 89 | + if(is_array($newStopWords)) { |
|
| 90 | 90 | $this->stopWords = $newStopWords; |
| 91 | - } else if (is_string($newStopWords)) { |
|
| 91 | + } else if(is_string($newStopWords)) { |
|
| 92 | 92 | $this->stopWords = explode(',', $newStopWords); |
| 93 | 93 | } else { |
| 94 | 94 | throw new Exception("ERROR: Stopwords must be a string or an array"); |
@@ -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( |
@@ -210,7 +210,7 @@ discard block |
||
| 210 | 210 | $this->analyzers['unstemmed'] = $analyzerNotStemmed; |
| 211 | 211 | |
| 212 | 212 | |
| 213 | - if ($this->foldedAscii) { |
|
| 213 | + if($this->foldedAscii) { |
|
| 214 | 214 | $analyzers['folded'] = $analyzerFolded; |
| 215 | 215 | } |
| 216 | 216 | |
@@ -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 | |
@@ -511,7 +511,7 @@ |
||
| 511 | 511 | } |
| 512 | 512 | } |
| 513 | 513 | $cache->save(json_encode($result),$key); |
| 514 | - } else { |
|
| 514 | + } else { |
|
| 515 | 515 | // true is necessary here to decode the array hash back to an array and not a struct |
| 516 | 516 | self::$cacheHitCtr++; |
| 517 | 517 | $result = json_decode($result,true); |
@@ -126,12 +126,12 @@ discard block |
||
| 126 | 126 | $queryTextExists = ($this->queryText != ''); |
| 127 | 127 | $isMultiMatch = ($this->fields != null); |
| 128 | 128 | |
| 129 | - if ($this->selectedFilters == null) { |
|
| 129 | + if($this->selectedFilters == null) { |
|
| 130 | 130 | $this->selectedFilters = array(); |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | $this->manipulatorInstance = null; |
| 134 | - if ($this->manipulator) { |
|
| 134 | + if($this->manipulator) { |
|
| 135 | 135 | $this->manipulatorInstance = \Injector::inst()->create($this->manipulator); |
| 136 | 136 | $this->manipulatorInstance->queryGenerator = $this; |
| 137 | 137 | $this->manipulatorInstance->originalQueryString = $this->queryText; |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | //This is a query_string object |
| 141 | 141 | $textQuery = null; |
| 142 | 142 | |
| 143 | - if (!$isMultiMatch) { |
|
| 143 | + if(!$isMultiMatch) { |
|
| 144 | 144 | $textQuery = $this->simpleTextQuery(); |
| 145 | 145 | } else { |
| 146 | 146 | $textQuery = $this->multiMatchQuery(); |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | $query->setLimit($this->pageLength); |
| 160 | 160 | $query->setFrom($this->start); |
| 161 | 161 | |
| 162 | - if ($this->manipulatorInstance && !$queryTextExists) { |
|
| 162 | + if($this->manipulatorInstance && !$queryTextExists) { |
|
| 163 | 163 | $sort = $this->manipulatorInstance->getDefaultSort(); |
| 164 | 164 | $query->setSort($sort); |
| 165 | 165 | } |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | 'size' => 10, |
| 191 | 191 | 'query' => array( |
| 192 | 192 | 'match' => array( |
| 193 | - $field.'.autocomplete' => array( |
|
| 193 | + $field . '.autocomplete' => array( |
|
| 194 | 194 | 'query' => $this->queryText, |
| 195 | 195 | 'operator' => 'and' |
| 196 | 196 | ) |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | ); |
| 200 | 200 | |
| 201 | 201 | // The query clause can only have one entry, so a bit of mangling |
| 202 | - if (!empty($this->selectedFilters)) { |
|
| 202 | + if(!empty($this->selectedFilters)) { |
|
| 203 | 203 | $filtered = array(); |
| 204 | 204 | $filtered['query'] = $data['query']; |
| 205 | 205 | unset($data['query']); |
@@ -228,17 +228,17 @@ discard block |
||
| 228 | 228 | * @param Elastica\Query\QueryString $textQuery A query_string representing the current query |
| 229 | 229 | */ |
| 230 | 230 | private function addFilters($textQuery) { |
| 231 | - if ($this->manipulator) { |
|
| 231 | + if($this->manipulator) { |
|
| 232 | 232 | $this->manipulatorInstance->updateFilters($this->selectedFilters); |
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | $elFilters = array(); |
| 236 | 236 | $rangeFilterKeys = RangedAggregation::getTitles(); |
| 237 | 237 | |
| 238 | - foreach ($this->selectedFilters as $key => $value) { |
|
| 239 | - if (!in_array($key, $rangeFilterKeys)) { |
|
| 238 | + foreach($this->selectedFilters as $key => $value) { |
|
| 239 | + if(!in_array($key, $rangeFilterKeys)) { |
|
| 240 | 240 | $filter = new Term(); |
| 241 | - $filter->setTerm($key,$value); |
|
| 241 | + $filter->setTerm($key, $value); |
|
| 242 | 242 | $elFilters[] = $filter; |
| 243 | 243 | } else { |
| 244 | 244 | // get the selected range filter |
@@ -251,7 +251,7 @@ discard block |
||
| 251 | 251 | |
| 252 | 252 | // if not facets selected, pass through null |
| 253 | 253 | $queryFilter = null; |
| 254 | - switch (count($this->selectedFilters)) { |
|
| 254 | + switch(count($this->selectedFilters)) { |
|
| 255 | 255 | case 0: |
| 256 | 256 | // filter already null |
| 257 | 257 | break; |
@@ -261,18 +261,18 @@ discard block |
||
| 261 | 261 | default: |
| 262 | 262 | $queryFilter = new BoolAnd(); |
| 263 | 263 | |
| 264 | - foreach ($elFilters as $filter) { |
|
| 264 | + foreach($elFilters as $filter) { |
|
| 265 | 265 | $queryFilter->addFilter($filter); |
| 266 | 266 | } |
| 267 | 267 | break; |
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | // the Elastica query object |
| 271 | - if ($queryFilter == null) { |
|
| 271 | + if($queryFilter == null) { |
|
| 272 | 272 | $query = new Query($textQuery); |
| 273 | 273 | } else { |
| 274 | 274 | //MatchAll appears not be allowed inside a filtered query which is a bit of a pain. |
| 275 | - if ($textQuery instanceof MatchAll) { |
|
| 275 | + if($textQuery instanceof MatchAll) { |
|
| 276 | 276 | $textQuery = null; |
| 277 | 277 | } |
| 278 | 278 | |
@@ -289,7 +289,7 @@ discard block |
||
| 289 | 289 | |
| 290 | 290 | private function addAggregation(&$query) { |
| 291 | 291 | // aggregation (optional) |
| 292 | - if ($this->manipulatorInstance) { |
|
| 292 | + if($this->manipulatorInstance) { |
|
| 293 | 293 | $this->manipulatorInstance->augmentQuery($query); |
| 294 | 294 | } |
| 295 | 295 | } |
@@ -316,7 +316,7 @@ discard block |
||
| 316 | 316 | //Setting the lenient flag means that numeric fields can be searched for text values |
| 317 | 317 | $textQuery->setParam('lenient', true); |
| 318 | 318 | |
| 319 | - if ($this->showResultsForEmptyQuery && $this->queryText == '') { |
|
| 319 | + if($this->showResultsForEmptyQuery && $this->queryText == '') { |
|
| 320 | 320 | $textQuery = new MatchAll(); |
| 321 | 321 | } |
| 322 | 322 | |
@@ -329,8 +329,8 @@ discard block |
||
| 329 | 329 | $textQuery = new MultiMatch(); |
| 330 | 330 | |
| 331 | 331 | // Differing cases for showing and not showing empty string |
| 332 | - if ($this->queryText == '') { |
|
| 333 | - if (!$this->showResultsForEmptyQuery) { |
|
| 332 | + if($this->queryText == '') { |
|
| 333 | + if(!$this->showResultsForEmptyQuery) { |
|
| 334 | 334 | $textQuery->setQuery(''); |
| 335 | 335 | } else { |
| 336 | 336 | //WIP |
@@ -343,7 +343,7 @@ discard block |
||
| 343 | 343 | $textQuery->setQuery($this->queryText); |
| 344 | 344 | } |
| 345 | 345 | |
| 346 | - if ($textQuery instanceof MultiMatch) { |
|
| 346 | + if($textQuery instanceof MultiMatch) { |
|
| 347 | 347 | $elasticaFields = $this->convertWeightedFieldsForElastica($this->fields); |
| 348 | 348 | $textQuery->setFields($elasticaFields); |
| 349 | 349 | $textQuery->setType('most_fields'); |
@@ -366,20 +366,20 @@ discard block |
||
| 366 | 366 | */ |
| 367 | 367 | public function convertWeightedFieldsForElastica($fields) { |
| 368 | 368 | $result = array(); |
| 369 | - $nameToType = self::getSearchFieldsMappingForClasses($this->classes,$fields); |
|
| 369 | + $nameToType = self::getSearchFieldsMappingForClasses($this->classes, $fields); |
|
| 370 | 370 | |
| 371 | - if (sizeof($fields) != 0) { |
|
| 372 | - foreach ($fields as $fieldName => $weight) { |
|
| 371 | + if(sizeof($fields) != 0) { |
|
| 372 | + foreach($fields as $fieldName => $weight) { |
|
| 373 | 373 | $fieldCfg = "$fieldName"; |
| 374 | - if ($weight != 1) { |
|
| 375 | - $fieldCfg .= '^'.$weight; |
|
| 374 | + if($weight != 1) { |
|
| 375 | + $fieldCfg .= '^' . $weight; |
|
| 376 | 376 | } |
| 377 | 377 | array_push($result, $fieldCfg); |
| 378 | - if (isset($nameToType[$fieldName])) { |
|
| 379 | - if ($nameToType[$fieldName] == 'string') { |
|
| 378 | + if(isset($nameToType[$fieldName])) { |
|
| 379 | + if($nameToType[$fieldName] == 'string') { |
|
| 380 | 380 | $fieldCfg = "{$fieldName}.*"; |
| 381 | - if ($weight != 1) { |
|
| 382 | - $fieldCfg .= '^'.$weight; |
|
| 381 | + if($weight != 1) { |
|
| 382 | + $fieldCfg .= '^' . $weight; |
|
| 383 | 383 | } |
| 384 | 384 | array_push($result, $fieldCfg); |
| 385 | 385 | } |
@@ -405,29 +405,29 @@ discard block |
||
| 405 | 405 | // Get a array of relevant classes to search |
| 406 | 406 | $cache = QueryGenerator::getCache(); |
| 407 | 407 | $csvClasses = $classes; |
| 408 | - if (is_array($classes)) { |
|
| 409 | - $csvClasses = implode(',',$classes); |
|
| 408 | + if(is_array($classes)) { |
|
| 409 | + $csvClasses = implode(',', $classes); |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | error_log("CSV CLASSES: $csvClasses"); |
| 413 | 413 | |
| 414 | - $key ='SEARCHABLE_FIELDS_'.str_replace(',', '_', $csvClasses); |
|
| 414 | + $key = 'SEARCHABLE_FIELDS_' . str_replace(',', '_', $csvClasses); |
|
| 415 | 415 | |
| 416 | - if ($fieldsAllowed) { |
|
| 416 | + if($fieldsAllowed) { |
|
| 417 | 417 | $fieldsAllowedCSV = self::convertToQuotedCSV(array_keys($fieldsAllowed)); |
| 418 | - $key .= '_' . str_replace(',', '_', str_replace("'", '_',$fieldsAllowedCSV)); |
|
| 418 | + $key .= '_' . str_replace(',', '_', str_replace("'", '_', $fieldsAllowedCSV)); |
|
| 419 | 419 | $key = str_replace('.', '_', $key); |
| 420 | 420 | $key = str_replace(' ', '_', $key); |
| 421 | 421 | } |
| 422 | 422 | |
| 423 | 423 | $result = $cache->load($key); |
| 424 | 424 | error_log("RESULT:$result for key $key \n"); |
| 425 | - if (!$result) { |
|
| 425 | + if(!$result) { |
|
| 426 | 426 | $relevantClasses = array(); |
| 427 | - if (empty($csvClasses)) { |
|
| 427 | + if(empty($csvClasses)) { |
|
| 428 | 428 | $sql = "SELECT DISTINCT Name from SearchableClass where InSiteTree = 1 order by Name"; |
| 429 | 429 | $records = \DB::query($sql); |
| 430 | - foreach ($records as $record) { |
|
| 430 | + foreach($records as $record) { |
|
| 431 | 431 | array_push($relevantClasses, $record['Name']); |
| 432 | 432 | } |
| 433 | 433 | } else { |
@@ -435,21 +435,21 @@ discard block |
||
| 435 | 435 | } |
| 436 | 436 | |
| 437 | 437 | $result = array(); |
| 438 | - if (sizeof($relevantClasses) > 0) { |
|
| 438 | + if(sizeof($relevantClasses) > 0) { |
|
| 439 | 439 | $relevantClassesCSV = self::convertToQuotedCSV($relevantClasses); |
| 440 | 440 | |
| 441 | 441 | //Perform a database query to get get a list of searchable fieldnames to Elasticsearch mapping |
| 442 | 442 | $sql = "SELECT sf.Name,sf.Type FROM SearchableClass sc INNER JOIN SearchableField sf ON " |
| 443 | 443 | . "sc.id = sf.SearchableClassID WHERE sc.name IN ($relevantClassesCSV)"; |
| 444 | - if ($fieldsAllowed) { |
|
| 444 | + if($fieldsAllowed) { |
|
| 445 | 445 | $fieldsAllowedCSV = self::convertToQuotedCSV(array_keys($fieldsAllowed)); |
| 446 | - if (strlen($fieldsAllowedCSV) > 0) { |
|
| 446 | + if(strlen($fieldsAllowedCSV) > 0) { |
|
| 447 | 447 | $sql .= " AND sf.Name IN ($fieldsAllowedCSV)"; |
| 448 | 448 | } |
| 449 | 449 | } |
| 450 | 450 | |
| 451 | 451 | $records = \DB::query($sql); |
| 452 | - foreach ($records as $record) { |
|
| 452 | + foreach($records as $record) { |
|
| 453 | 453 | $name = $record['Name']; |
| 454 | 454 | $type = $record['Type']; |
| 455 | 455 | |
@@ -463,11 +463,11 @@ discard block |
||
| 463 | 463 | $result[$name] = $type; |
| 464 | 464 | } |
| 465 | 465 | } |
| 466 | - $cache->save(json_encode($result),$key); |
|
| 467 | - } else { |
|
| 466 | + $cache->save(json_encode($result), $key); |
|
| 467 | + } else { |
|
| 468 | 468 | // true is necessary here to decode the array hash back to an array and not a struct |
| 469 | 469 | self::$cacheHitCtr++; |
| 470 | - $result = json_decode($result,true); |
|
| 470 | + $result = json_decode($result, true); |
|
| 471 | 471 | } |
| 472 | 472 | |
| 473 | 473 | return $result; |
@@ -488,21 +488,21 @@ discard block |
||
| 488 | 488 | */ |
| 489 | 489 | public static function convertToQuotedCSV($csvOrArray) { |
| 490 | 490 | $asArray = $csvOrArray; |
| 491 | - if (!is_array($csvOrArray)) { |
|
| 492 | - if ($csvOrArray == null) { |
|
| 491 | + if(!is_array($csvOrArray)) { |
|
| 492 | + if($csvOrArray == null) { |
|
| 493 | 493 | $asArray = array(); |
| 494 | 494 | } else { |
| 495 | 495 | $asArray = explode(',', $csvOrArray); |
| 496 | 496 | } |
| 497 | 497 | } |
| 498 | 498 | $quoted = array(); |
| 499 | - foreach ($asArray as $value) { |
|
| 500 | - if (strlen($value) > 0) { |
|
| 501 | - $item = "'".$value."'"; |
|
| 499 | + foreach($asArray as $value) { |
|
| 500 | + if(strlen($value) > 0) { |
|
| 501 | + $item = "'" . $value . "'"; |
|
| 502 | 502 | array_push($quoted, $item); |
| 503 | 503 | } |
| 504 | 504 | |
| 505 | 505 | } |
| 506 | - return implode(',', $quoted);; |
|
| 506 | + return implode(',', $quoted); ; |
|
| 507 | 507 | } |
| 508 | 508 | } |
@@ -47,6 +47,9 @@ discard block |
||
| 47 | 47 | private $classes = ''; |
| 48 | 48 | |
| 49 | 49 | |
| 50 | + /** |
|
| 51 | + * @param string $newQueryText |
|
| 52 | + */ |
|
| 50 | 53 | public function setQueryText($newQueryText) { |
| 51 | 54 | $this->queryText = $newQueryText; |
| 52 | 55 | } |
@@ -62,6 +65,9 @@ discard block |
||
| 62 | 65 | } |
| 63 | 66 | |
| 64 | 67 | |
| 68 | + /** |
|
| 69 | + * @param boolean $newShowResultsForEmptyQuery |
|
| 70 | + */ |
|
| 65 | 71 | public function setShowResultsForEmptyQuery($newShowResultsForEmptyQuery) { |
| 66 | 72 | $this->showResultsForEmptyQuery = $newShowResultsForEmptyQuery; |
| 67 | 73 | } |
@@ -72,11 +78,17 @@ discard block |
||
| 72 | 78 | } |
| 73 | 79 | |
| 74 | 80 | |
| 81 | + /** |
|
| 82 | + * @param integer $newPageLength |
|
| 83 | + */ |
|
| 75 | 84 | public function setPageLength($newPageLength) { |
| 76 | 85 | $this->pageLength = $newPageLength; |
| 77 | 86 | } |
| 78 | 87 | |
| 79 | 88 | |
| 89 | + /** |
|
| 90 | + * @param integer $newStart |
|
| 91 | + */ |
|
| 80 | 92 | public function setStart($newStart) { |
| 81 | 93 | $this->start = $newStart; |
| 82 | 94 | } |
@@ -287,6 +299,9 @@ discard block |
||
| 287 | 299 | } |
| 288 | 300 | |
| 289 | 301 | |
| 302 | + /** |
|
| 303 | + * @param Query $query |
|
| 304 | + */ |
|
| 290 | 305 | private function addAggregation(&$query) { |
| 291 | 306 | // aggregation (optional) |
| 292 | 307 | if ($this->manipulatorInstance) { |