Complex classes like SearchResultSetService often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use SearchResultSetService, and based on these observations, apply Extract Interface, too.
| 1 | <?php  | 
            ||
| 53 | class SearchResultSetService  | 
            ||
| 54 | { | 
            ||
| 55 | /**  | 
            ||
| 56 | * Additional filters, which will be added to the query, as well as to  | 
            ||
| 57 | * suggest queries.  | 
            ||
| 58 | *  | 
            ||
| 59 | * @var array  | 
            ||
| 60 | */  | 
            ||
| 61 | protected $additionalFilters = [];  | 
            ||
| 62 | |||
| 63 | /**  | 
            ||
| 64 | * Track, if the number of results per page has been changed by the current request  | 
            ||
| 65 | *  | 
            ||
| 66 | * @var bool  | 
            ||
| 67 | */  | 
            ||
| 68 | protected $resultsPerPageChanged = false;  | 
            ||
| 69 | |||
| 70 | /**  | 
            ||
| 71 | * @var Search  | 
            ||
| 72 | */  | 
            ||
| 73 | protected $search;  | 
            ||
| 74 | |||
| 75 | /**  | 
            ||
| 76 | * @var SearchResultSet  | 
            ||
| 77 | */  | 
            ||
| 78 | protected $lastResultSet = null;  | 
            ||
| 79 | |||
| 80 | /**  | 
            ||
| 81 | * @var boolean  | 
            ||
| 82 | */  | 
            ||
| 83 | protected $isSolrAvailable = false;  | 
            ||
| 84 | |||
| 85 | /**  | 
            ||
| 86 | * @var TypoScriptConfiguration  | 
            ||
| 87 | */  | 
            ||
| 88 | protected $typoScriptConfiguration;  | 
            ||
| 89 | |||
| 90 | /**  | 
            ||
| 91 | * @var SolrLogManager;  | 
            ||
| 92 | */  | 
            ||
| 93 | protected $logger = null;  | 
            ||
| 94 | |||
| 95 | /**  | 
            ||
| 96 | * @var SearchResultBuilder  | 
            ||
| 97 | */  | 
            ||
| 98 | protected $searchResultBuilder;  | 
            ||
| 99 | |||
| 100 | /**  | 
            ||
| 101 | * @param TypoScriptConfiguration $configuration  | 
            ||
| 102 | * @param Search $search  | 
            ||
| 103 | 45 | * @param SolrLogManager $solrLogManager  | 
            |
| 104 | * @param SearchResultBuilder $resultBuilder  | 
            ||
| 105 | 45 | */  | 
            |
| 106 | 45 | public function __construct(TypoScriptConfiguration $configuration, Search $search, SolrLogManager $solrLogManager = null, SearchResultBuilder $resultBuilder = null)  | 
            |
| 113 | |||
| 114 | 29 | /**  | 
            |
| 115 | * @param bool $useCache  | 
            ||
| 116 | 29 | * @return bool  | 
            |
| 117 | 29 | */  | 
            |
| 118 | public function getIsSolrAvailable($useCache = true)  | 
            ||
| 123 | 29 | ||
| 124 | /**  | 
            ||
| 125 | 29 | * @return bool  | 
            |
| 126 | */  | 
            ||
| 127 | public function getHasSearched()  | 
            ||
| 131 | |||
| 132 | /**  | 
            ||
| 133 | 2 | * Retrieves the used search instance.  | 
            |
| 134 | *  | 
            ||
| 135 | 2 | * @return Search  | 
            |
| 136 | */  | 
            ||
| 137 | public function getSearch()  | 
            ||
| 141 | |||
| 142 | /**  | 
            ||
| 143 | * Initializes the Query object and SearchComponents and returns  | 
            ||
| 144 | * the initialized query object, when a search should be executed.  | 
            ||
| 145 | *  | 
            ||
| 146 | * @param string|null $rawQuery  | 
            ||
| 147 | * @param int $resultsPerPage  | 
            ||
| 148 | * @return Query  | 
            ||
| 149 | */  | 
            ||
| 150 | protected function getPreparedQuery($rawQuery, $resultsPerPage)  | 
            ||
| 151 |     { | 
            ||
| 152 | /* @var $query Query */  | 
            ||
| 153 | $query = $this->getQueryInstance($rawQuery);  | 
            ||
| 154 | |||
| 155 | $this->applyPageSectionsRootLineFilter($query);  | 
            ||
| 156 | |||
| 157 |         if ($this->typoScriptConfiguration->getLoggingQuerySearchWords()) { | 
            ||
| 158 | $this->logger->log(  | 
            ||
| 159 | SolrLogManager::INFO,  | 
            ||
| 160 | 'Received search query',  | 
            ||
| 161 | [  | 
            ||
| 162 | 37 | $rawQuery  | 
            |
| 163 | ]  | 
            ||
| 164 | );  | 
            ||
| 165 | 37 | }  | 
            |
| 166 | |||
| 167 | 37 | $query->setResultsPerPage($resultsPerPage);  | 
            |
| 168 | |||
| 169 | 37 |         if ($this->typoScriptConfiguration->getSearchInitializeWithEmptyQuery() || $this->typoScriptConfiguration->getSearchQueryAllowEmptyQuery()) { | 
            |
| 170 | // empty main query, but using a "return everything"  | 
            ||
| 171 | // alternative query in q.alt  | 
            ||
| 172 |             $query->setAlternativeQuery('*:*'); | 
            ||
| 173 | }  | 
            ||
| 174 | |||
| 175 |         if ($this->typoScriptConfiguration->getSearchInitializeWithQuery()) { | 
            ||
| 176 | $query->setAlternativeQuery($this->typoScriptConfiguration->getSearchInitializeWithQuery());  | 
            ||
| 177 | }  | 
            ||
| 178 | |||
| 179 | 37 |         foreach ($this->getAdditionalFilters() as $additionalFilter) { | 
            |
| 180 | $query->getFilters()->add($additionalFilter);  | 
            ||
| 181 | 37 | }  | 
            |
| 182 | |||
| 183 | return $query;  | 
            ||
| 184 | 30 | }  | 
            |
| 185 | |||
| 186 | /**  | 
            ||
| 187 | 37 | * @param Query $query  | 
            |
| 188 | 3 | * @param SearchRequest $searchRequest  | 
            |
| 189 | */  | 
            ||
| 190 | protected function initializeRegisteredSearchComponents(Query $query, SearchRequest $searchRequest)  | 
            ||
| 191 | 37 |     { | 
            |
| 192 | 2 | $searchComponents = $this->getRegisteredSearchComponents();  | 
            |
| 193 | |||
| 194 |         foreach ($searchComponents as $searchComponent) { | 
            ||
| 195 | 37 | /** @var Search\SearchComponent $searchComponent */  | 
            |
| 196 | $searchComponent->setSearchConfiguration($this->typoScriptConfiguration->getSearchConfiguration());  | 
            ||
| 197 | |||
| 198 |             if ($searchComponent instanceof QueryAware) { | 
            ||
| 199 | $searchComponent->setQuery($query);  | 
            ||
| 200 | }  | 
            ||
| 201 | |||
| 202 | 37 |             if ($searchComponent instanceof SearchRequestAware) { | 
            |
| 203 | $searchComponent->setSearchRequest($searchRequest);  | 
            ||
| 204 | 37 | }  | 
            |
| 205 | |||
| 206 | 37 | $searchComponent->initializeSearchComponent();  | 
            |
| 207 | }  | 
            ||
| 208 | 31 | }  | 
            |
| 209 | |||
| 210 | 31 | /**  | 
            |
| 211 | 31 | * @return string  | 
            |
| 212 | */  | 
            ||
| 213 | protected function getResultSetClassName()  | 
            ||
| 218 | 31 | ||
| 219 | /**  | 
            ||
| 220 | 37 | * Initializes additional filters configured through TypoScript and  | 
            |
| 221 | * Flexforms for use in regular queries and suggest queries.  | 
            ||
| 222 | *  | 
            ||
| 223 | * @param Query $query  | 
            ||
| 224 | * @return void  | 
            ||
| 225 | */  | 
            ||
| 226 | protected function applyPageSectionsRootLineFilter(Query $query)  | 
            ||
| 239 | |||
| 240 | 37 | /**  | 
            |
| 241 | 37 | * Retrieves the configuration filters from the TypoScript configuration, except the __pageSections filter.  | 
            |
| 242 | *  | 
            ||
| 243 | 37 | * @return array  | 
            |
| 244 | 37 | */  | 
            |
| 245 | 3 | public function getAdditionalFilters()  | 
            |
| 281 | 39 | ||
| 282 | 1 | /**  | 
            |
| 283 | * Performs a search and returns a SearchResultSet.  | 
            ||
| 284 | 1 | *  | 
            |
| 285 | 1 | * @param SearchRequest $searchRequest  | 
            |
| 286 | 1 | * @return SearchResultSet  | 
            |
| 287 | 1 | */  | 
            |
| 288 | public function search(SearchRequest $searchRequest)  | 
            ||
| 353 | |||
| 354 | 39 | /**  | 
            |
| 355 | 1 | * Executes the search and builds a fake response for a current bug in Apache Solr 6.3  | 
            |
| 356 | *  | 
            ||
| 357 | * @param Query $query  | 
            ||
| 358 | * @param int $offSet  | 
            ||
| 359 | * @return \Apache_Solr_Response  | 
            ||
| 360 | 1 | */  | 
            |
| 361 | protected function doASearch($query, $offSet)  | 
            ||
| 370 | 1 | ||
| 371 | /**  | 
            ||
| 372 | * @param SearchResultSet $searchResultSet  | 
            ||
| 373 | 39 | * @return SearchResultSet  | 
            |
| 374 | 5 | */  | 
            |
| 375 | protected function getAutoCorrection(SearchResultSet $searchResultSet)  | 
            ||
| 396 | 28 | ||
| 397 | 28 | /**  | 
            |
| 398 | * @param SearchResultSet $searchResultSet  | 
            ||
| 399 | * @return SearchResultSet  | 
            ||
| 400 | */  | 
            ||
| 401 | 28 | protected function peformAutoCorrection(SearchResultSet $searchResultSet)  | 
            |
| 430 | 37 | ||
| 431 | /**  | 
            ||
| 432 | * Allows to modify a query before eventually handing it over to Solr.  | 
            ||
| 433 | *  | 
            ||
| 434 | * @param Query $query The current query before it's being handed over to Solr.  | 
            ||
| 435 | * @param SearchRequest $searchRequest The searchRequest, relevant in the current context  | 
            ||
| 436 | * @param Search $search The search, relevant in the current context  | 
            ||
| 437 | * @throws \UnexpectedValueException  | 
            ||
| 438 | * @return Query The modified query that is actually going to be given to Solr.  | 
            ||
| 439 | */  | 
            ||
| 440 | 37 | protected function modifyQuery(Query $query, SearchRequest $searchRequest, Search $search)  | 
            |
| 468 | 40 | ||
| 469 | /**  | 
            ||
| 470 | * Retrieves a single document from solr by document id.  | 
            ||
| 471 | 2 | *  | 
            |
| 472 | * @param string $documentId  | 
            ||
| 473 | * @return SearchResult  | 
            ||
| 474 | 2 | */  | 
            |
| 475 | public function getDocumentById($documentId)  | 
            ||
| 486 | 2 | ||
| 487 | /**  | 
            ||
| 488 | * This method is used to call the registered hooks during the search execution.  | 
            ||
| 489 | *  | 
            ||
| 490 | 2 | * @param string $eventName  | 
            |
| 491 | * @param SearchResultSet $resultSet  | 
            ||
| 492 | * @return SearchResultSet  | 
            ||
| 493 | 2 | */  | 
            |
| 494 | private function handleSearchHook($eventName, SearchResultSet $resultSet)  | 
            ||
| 509 | |||
| 510 | 39 | /**  | 
            |
| 511 | * @return SearchResultSet  | 
            ||
| 512 | 39 | */  | 
            |
| 513 | public function getLastResultSet()  | 
            ||
| 517 | 37 | ||
| 518 | /**  | 
            ||
| 519 | * This method returns true when the last search was executed with an empty query  | 
            ||
| 520 | * string or whitespaces only. When no search was triggered it will return false.  | 
            ||
| 521 | *  | 
            ||
| 522 | 37 | * @return bool  | 
            |
| 523 | 37 | */  | 
            |
| 524 | 37 | public function getLastSearchWasExecutedWithEmptyQueryString()  | 
            |
| 533 | |||
| 534 | 37 | /**  | 
            |
| 535 | * @return bool  | 
            ||
| 536 | */  | 
            ||
| 537 | 37 | protected function getInitialSearchIsConfigured()  | 
            |
| 541 | 37 | ||
| 542 | /**  | 
            ||
| 543 | * @return mixed  | 
            ||
| 544 | 2 | */  | 
            |
| 545 | protected function getRegisteredSearchComponents()  | 
            ||
| 549 | 37 | ||
| 550 | /**  | 
            ||
| 551 | 37 | * @param string $rawQuery  | 
            |
| 552 | 37 | * @return Query|object  | 
            |
| 553 | 37 | */  | 
            |
| 554 | 37 | protected function getQueryInstance($rawQuery)  | 
            |
| 559 | }  | 
            ||
| 560 | 
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.