@@ -101,17 +101,17 @@ discard block |
||
| 101 | 101 | * @return array |
| 102 | 102 | */ |
| 103 | 103 | public function getResults() { |
| 104 | - if (!isset($this->_cachedResults)) { |
|
| 105 | - $ers = $this->service->search($this->query,$this->types); |
|
| 104 | + if(!isset($this->_cachedResults)) { |
|
| 105 | + $ers = $this->service->search($this->query, $this->types); |
|
| 106 | 106 | |
| 107 | - if (isset($ers->MoreLikeThisTerms)) { |
|
| 107 | + if(isset($ers->MoreLikeThisTerms)) { |
|
| 108 | 108 | $this->MoreLikeThisTerms = $ers->MoreLikeThisTerms; |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - if (isset($ers->getSuggests()['query-phrase-suggestions'])) { |
|
| 111 | + if(isset($ers->getSuggests()['query-phrase-suggestions'])) { |
|
| 112 | 112 | $suggest = $ers->getSuggests()['query-phrase-suggestions']; |
| 113 | 113 | $suggestedPhraseAndHL = ElasticaUtil::getPhraseSuggestion($suggest); |
| 114 | - if ($suggestedPhraseAndHL) { |
|
| 114 | + if($suggestedPhraseAndHL) { |
|
| 115 | 115 | $this->SuggestedQuery = $suggestedPhraseAndHL['suggestedQuery']; |
| 116 | 116 | $this->SuggestedQueryHighlighted = $suggestedPhraseAndHL['suggestedQueryHighlighted']; |
| 117 | 117 | } |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | $indexedFieldTitleMapping = array(); |
| 129 | 129 | |
| 130 | 130 | // optionally remap keys and store chosen aggregations from get params |
| 131 | - if (isset($this->SearchHelper)) { |
|
| 131 | + if(isset($this->SearchHelper)) { |
|
| 132 | 132 | $manipulator = \Injector::inst()->create($this->SearchHelper); |
| 133 | 133 | $manipulator->query = $this->query; |
| 134 | 134 | $manipulator->updateAggregation($aggs); |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | $queryText = $this->originalQueryText; |
| 142 | 142 | |
| 143 | 143 | // if not search term remove it and aggregate with a blank query |
| 144 | - if ($qqueryText== '' && sizeof($aggs) > 0) { |
|
| 144 | + if($qqueryText == '' && sizeof($aggs) > 0) { |
|
| 145 | 145 | $params = $this->query->getParams(); |
| 146 | 146 | unset($params['query']); |
| 147 | 147 | $this->query->setParams($params); |
@@ -149,87 +149,87 @@ discard block |
||
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | // get the base URL for the current facets selected |
| 152 | - $baseURL = \Controller::curr()->Link().'?'; |
|
| 152 | + $baseURL = \Controller::curr()->Link() . '?'; |
|
| 153 | 153 | $prefixAmp = false; |
| 154 | - if ($queryText !== '') { |
|
| 155 | - $baseURL .= 'q='.urlencode($queryText); |
|
| 154 | + if($queryText !== '') { |
|
| 155 | + $baseURL .= 'q=' . urlencode($queryText); |
|
| 156 | 156 | $prefixAmp = true; |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | // now add the selected facets |
| 160 | - foreach ($this->filters as $key => $value) { |
|
| 161 | - if ($prefixAmp) { |
|
| 160 | + foreach($this->filters as $key => $value) { |
|
| 161 | + if($prefixAmp) { |
|
| 162 | 162 | $baseURL .= '&'; |
| 163 | 163 | } else { |
| 164 | 164 | $prefixAmp = true; |
| 165 | 165 | } |
| 166 | - $baseURL .= $key.'='.urlencode($value); |
|
| 166 | + $baseURL .= $key . '=' . urlencode($value); |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | - foreach (array_keys($aggs) as $key) { |
|
| 169 | + foreach(array_keys($aggs) as $key) { |
|
| 170 | 170 | //echo "MARKING SELECTED AGGS FOR $key \n"; |
| 171 | 171 | $aggDO = new \DataObject(); |
| 172 | 172 | //FIXME - Camel case separate here |
| 173 | - if (isset($indexedFieldTitleMapping[$key])) { |
|
| 173 | + if(isset($indexedFieldTitleMapping[$key])) { |
|
| 174 | 174 | $aggDO->Name = $indexedFieldTitleMapping[$key]; |
| 175 | 175 | } else { |
| 176 | 176 | $aggDO->Name = $key; |
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | // now the buckets |
| 180 | - if (isset($aggs[$key]['buckets'])) { |
|
| 180 | + if(isset($aggs[$key]['buckets'])) { |
|
| 181 | 181 | //echo "Buckets found for $key \n"; |
| 182 | 182 | $bucketsAL = new \ArrayList(); |
| 183 | - foreach ($aggs[$key]['buckets'] as $value) { |
|
| 183 | + foreach($aggs[$key]['buckets'] as $value) { |
|
| 184 | 184 | $ct = new \DataObject(); |
| 185 | 185 | $ct->Key = $value['key']; |
| 186 | 186 | $ct->DocumentCount = $value['doc_count']; |
| 187 | 187 | $query[$key] = $value; |
| 188 | - if ($prefixAmp) { |
|
| 189 | - $url = $baseURL.'&'; |
|
| 188 | + if($prefixAmp) { |
|
| 189 | + $url = $baseURL . '&'; |
|
| 190 | 190 | } else { |
| 191 | 191 | $url = $baseURL; |
| 192 | 192 | $prefixAmp = true; |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | // check if currently selected |
| 196 | - if (isset($this->filters[$key])) { |
|
| 196 | + if(isset($this->filters[$key])) { |
|
| 197 | 197 | |
| 198 | - if ($this->filters[$key] === (string)$value['key']) { |
|
| 198 | + if($this->filters[$key] === (string)$value['key']) { |
|
| 199 | 199 | //echo " - Marked as selected \n"; |
| 200 | 200 | $ct->IsSelected = true; |
| 201 | 201 | // mark this facet as having been selected, so optional toggling |
| 202 | 202 | // of the display of the facet can be done via the template. |
| 203 | 203 | $aggDO->IsSelected = true; |
| 204 | 204 | |
| 205 | - $urlParam = $key.'='.urlencode($this->filters[$key]); |
|
| 205 | + $urlParam = $key . '=' . urlencode($this->filters[$key]); |
|
| 206 | 206 | |
| 207 | 207 | //echo " - URL PARAM : $urlParam \n"; |
| 208 | 208 | |
| 209 | 209 | // possible ampersand combos to remove |
| 210 | - $v2 = '&'.$urlParam; |
|
| 211 | - $v3 = $urlParam.'&'; |
|
| 210 | + $v2 = '&' . $urlParam; |
|
| 211 | + $v3 = $urlParam . '&'; |
|
| 212 | 212 | $url = str_replace($v2, '', $url); |
| 213 | 213 | $url = str_replace($v3, '', $url); |
| 214 | 214 | $url = str_replace($urlParam, '', $url); |
| 215 | 215 | $ct->URL = $url; |
| 216 | 216 | } |
| 217 | 217 | } else { |
| 218 | - $url .= $key .'='.urlencode($value['key']); |
|
| 218 | + $url .= $key . '=' . urlencode($value['key']); |
|
| 219 | 219 | $prefixAmp = true; |
| 220 | 220 | } |
| 221 | 221 | |
| 222 | - $url = rtrim($url,'&'); |
|
| 222 | + $url = rtrim($url, '&'); |
|
| 223 | 223 | |
| 224 | 224 | $ct->URL = $url; |
| 225 | 225 | $bucketsAL->push($ct); |
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | // in the case of range queries we wish to remove the non selected ones |
| 229 | - if ($aggDO->IsSelected) { |
|
| 229 | + if($aggDO->IsSelected) { |
|
| 230 | 230 | $newList = new \ArrayList(); |
| 231 | - foreach ($bucketsAL->getIterator() as $bucket) { |
|
| 232 | - if ($bucket->IsSelected) { |
|
| 231 | + foreach($bucketsAL->getIterator() as $bucket) { |
|
| 232 | + if($bucket->IsSelected) { |
|
| 233 | 233 | $newList->push($bucket); |
| 234 | 234 | break; |
| 235 | 235 | } |
@@ -286,10 +286,10 @@ discard block |
||
| 286 | 286 | $needed = array(); |
| 287 | 287 | $retrieved = array(); |
| 288 | 288 | |
| 289 | - foreach ($found as $item) { |
|
| 289 | + foreach($found as $item) { |
|
| 290 | 290 | $type = $item->getType(); |
| 291 | 291 | |
| 292 | - if (!array_key_exists($type, $needed)) { |
|
| 292 | + if(!array_key_exists($type, $needed)) { |
|
| 293 | 293 | $needed[$type] = array($item->getId()); |
| 294 | 294 | $retrieved[$type] = array(); |
| 295 | 295 | } else { |
@@ -297,8 +297,8 @@ discard block |
||
| 297 | 297 | } |
| 298 | 298 | } |
| 299 | 299 | |
| 300 | - foreach ($needed as $class => $ids) { |
|
| 301 | - foreach ($class::get()->byIDs($ids) as $record) { |
|
| 300 | + foreach($needed as $class => $ids) { |
|
| 301 | + foreach($class::get()->byIDs($ids) as $record) { |
|
| 302 | 302 | $retrieved[$class][$record->ID] = $record; |
| 303 | 303 | } |
| 304 | 304 | } |
@@ -306,7 +306,7 @@ discard block |
||
| 306 | 306 | // Title and Link are special cases |
| 307 | 307 | $ignore = array('Title', 'Link', 'Title.standard', 'Link.standard'); |
| 308 | 308 | |
| 309 | - foreach ($found as $item) { |
|
| 309 | + foreach($found as $item) { |
|
| 310 | 310 | // Safeguards against indexed items which might no longer be in the DB |
| 311 | 311 | if(array_key_exists($item->getId(), $retrieved[$item->getType()])) { |
| 312 | 312 | |
@@ -319,31 +319,31 @@ discard block |
||
| 319 | 319 | $snippets = new \ArrayList(); |
| 320 | 320 | $namedSnippets = new \ArrayList(); |
| 321 | 321 | |
| 322 | - foreach (array_keys($highlights) as $fieldName) { |
|
| 322 | + foreach(array_keys($highlights) as $fieldName) { |
|
| 323 | 323 | $fieldSnippets = new \ArrayList(); |
| 324 | 324 | |
| 325 | - foreach ($highlights[$fieldName] as $snippet) { |
|
| 325 | + foreach($highlights[$fieldName] as $snippet) { |
|
| 326 | 326 | $do = new \DataObject(); |
| 327 | 327 | $do->Snippet = $snippet; |
| 328 | 328 | |
| 329 | 329 | // skip title and link in the summary of highlights |
| 330 | - if (!in_array($fieldName, $ignore)) { |
|
| 330 | + if(!in_array($fieldName, $ignore)) { |
|
| 331 | 331 | $snippets->push($do); |
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | $fieldSnippets->push($do); |
| 335 | 335 | } |
| 336 | 336 | |
| 337 | - if ($fieldSnippets->count() > 0) { |
|
| 337 | + if($fieldSnippets->count() > 0) { |
|
| 338 | 338 | //Fields may have a dot in their name, e.g. Title.standard - take this into account |
| 339 | 339 | //As dots are an issue with template syntax, store as Title_standard |
| 340 | 340 | $splits = explode('.', $fieldName); |
| 341 | - if (sizeof($splits) == 1) { |
|
| 341 | + if(sizeof($splits) == 1) { |
|
| 342 | 342 | $namedSnippets->$fieldName = $fieldSnippets; |
| 343 | 343 | } else { |
| 344 | 344 | // The Title.standard case, for example |
| 345 | 345 | $splits = explode('.', $fieldName); |
| 346 | - $compositeFielddName = $splits[0].'_'.$splits[1]; |
|
| 346 | + $compositeFielddName = $splits[0] . '_' . $splits[1]; |
|
| 347 | 347 | $namedSnippets->$compositeFielddName = $fieldSnippets; |
| 348 | 348 | } |
| 349 | 349 | |
@@ -372,7 +372,7 @@ discard block |
||
| 372 | 372 | public function toNestedArray() { |
| 373 | 373 | $result = array(); |
| 374 | 374 | |
| 375 | - foreach ($this as $record) { |
|
| 375 | + foreach($this as $record) { |
|
| 376 | 376 | $result[] = $record->toMap(); |
| 377 | 377 | } |
| 378 | 378 | |
@@ -397,7 +397,7 @@ discard block |
||
| 397 | 397 | if($col == 'ID') { |
| 398 | 398 | $ids = array(); |
| 399 | 399 | |
| 400 | - foreach ($this->getResults() as $result) { |
|
| 400 | + foreach($this->getResults() as $result) { |
|
| 401 | 401 | $ids[] = $result->getId(); |
| 402 | 402 | } |
| 403 | 403 | |