Complex classes like SolrService 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 SolrService, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
34 | class SolrService extends \Apache_Solr_Service |
||
35 | { |
||
36 | const LUKE_SERVLET = 'admin/luke'; |
||
37 | const SYSTEM_SERVLET = 'admin/system'; |
||
38 | const PLUGINS_SERVLET = 'admin/plugins'; |
||
39 | const CORES_SERVLET = 'admin/cores'; |
||
40 | const SCHEMA_SERVLET = 'schema'; |
||
41 | const SYNONYMS_SERVLET = 'schema/analysis/synonyms/'; |
||
42 | const STOPWORDS_SERVLET = 'schema/analysis/stopwords/'; |
||
43 | |||
44 | const SCHEME_HTTP = 'http'; |
||
45 | const SCHEME_HTTPS = 'https'; |
||
46 | |||
47 | /** |
||
48 | * Server connection scheme. http or https. |
||
49 | * |
||
50 | * @var string |
||
51 | */ |
||
52 | protected $_scheme = self::SCHEME_HTTP; |
||
53 | |||
54 | /** |
||
55 | * Constructed servlet URL for Luke |
||
56 | * |
||
57 | * @var string |
||
58 | */ |
||
59 | protected $_lukeUrl; |
||
60 | |||
61 | /** |
||
62 | * Constructed servlet URL for plugin information |
||
63 | * |
||
64 | * @var string |
||
65 | */ |
||
66 | protected $_pluginsUrl; |
||
67 | |||
68 | protected $_coresUrl; |
||
69 | |||
70 | protected $_extractUrl; |
||
71 | |||
72 | protected $_synonymsUrl; |
||
73 | |||
74 | protected $_stopWordsUrl; |
||
75 | |||
76 | protected $_schemaUrl; |
||
77 | |||
78 | protected $debug; |
||
79 | |||
80 | /** |
||
81 | * @var \Apache_Solr_Response |
||
82 | */ |
||
83 | protected $responseCache = null; |
||
84 | protected $hasSearched = false; |
||
85 | |||
86 | protected $lukeData = array(); |
||
87 | protected $systemData = null; |
||
88 | protected $pluginsData = null; |
||
89 | |||
90 | protected $schemaName = null; |
||
91 | protected $solrconfigName = null; |
||
92 | |||
93 | /** |
||
94 | * @var array |
||
95 | */ |
||
96 | protected $configuration; |
||
97 | |||
98 | /** |
||
99 | * Constructor |
||
100 | * |
||
101 | * @param string $host Solr host |
||
102 | * @param string $port Solr port |
||
103 | * @param string $path Solr path |
||
104 | * @param string $scheme Scheme, defaults to http, can be https |
||
105 | */ |
||
106 | 54 | public function __construct( |
|
117 | |||
118 | /** |
||
119 | * Creates a string representation of the Solr connection. Specifically |
||
120 | * will return the Solr URL. |
||
121 | * |
||
122 | * @return string The Solr URL. |
||
123 | */ |
||
124 | 4 | public function __toString() |
|
128 | |||
129 | /** |
||
130 | * Returns the current time in milliseconds. |
||
131 | * |
||
132 | * @return int |
||
133 | */ |
||
134 | protected function getMilliseconds() |
||
138 | |||
139 | /** |
||
140 | * Performs a search. |
||
141 | * |
||
142 | * @param string $query query string / search term |
||
143 | * @param int $offset result offset for pagination |
||
144 | * @param int $limit number of results to retrieve |
||
145 | * @param array $params additional HTTP GET parameters |
||
146 | * @param string $method The HTTP method (Apache_Solr_Service::METHOD_GET or Apache_Solr_Service::METHOD::POST) |
||
147 | * @return \Apache_Solr_Response Solr response |
||
148 | * @throws \RuntimeException if Solr returns a HTTP status code other than 200 |
||
149 | */ |
||
150 | 25 | public function search($query, $offset = 0, $limit = 10, $params = array(), $method = self::METHOD_GET) |
|
168 | |||
169 | /** |
||
170 | * Call the /admin/ping servlet, can be used to quickly tell if a connection to the |
||
171 | * server is available. |
||
172 | * |
||
173 | * Simply overrides the SolrPhpClient implementation, changing ping from a |
||
174 | * HEAD to a GET request, see http://forge.typo3.org/issues/44167 |
||
175 | * |
||
176 | * Also does not report the time, see https://forge.typo3.org/issues/64551 |
||
177 | * |
||
178 | * @param float|int $timeout maximum time to wait for ping in seconds, -1 for unlimited (default is 2) |
||
179 | * @return bool TRUE if Solr can be reached, FALSE if not |
||
180 | */ |
||
181 | 35 | public function ping($timeout = 2) |
|
186 | |||
187 | /** |
||
188 | * Call the /admin/ping servlet, can be used to get the runtime of a ping request. |
||
189 | * |
||
190 | * @param float|int $timeout maximum time to wait for ping in seconds, -1 for unlimited (default is 2) |
||
191 | * @return int runtime in milliseconds |
||
192 | * @throws \ApacheSolrForTypo3\Solr\PingFailedException |
||
193 | */ |
||
194 | public function getPingRoundTripRuntime($timeout = 2) |
||
210 | |||
211 | /** |
||
212 | * Performs a ping request and returns the result. |
||
213 | * |
||
214 | * @param int $timeout |
||
215 | * @return \Apache_Solr_HttpTransport_Response |
||
216 | */ |
||
217 | 35 | protected function performPingRequest($timeout = 2) |
|
221 | |||
222 | /** |
||
223 | * Performs a content and meta data extraction request. |
||
224 | * |
||
225 | * @param ExtractingQuery $query An extraction query |
||
226 | * @return array An array containing the extracted content [0] and meta data [1] |
||
227 | */ |
||
228 | 1 | public function extractByQuery(ExtractingQuery $query) |
|
229 | { |
||
230 | $headers = array( |
||
231 | 1 | 'Content-Type' => 'multipart/form-data; boundary=' . $query->getMultiPartPostDataBoundary() |
|
232 | ); |
||
233 | |||
234 | try { |
||
235 | 1 | $response = $this->requestServlet( |
|
236 | 1 | self::EXTRACT_SERVLET, |
|
237 | 1 | $query->getQueryParameters(), |
|
238 | 1 | 'POST', |
|
239 | $headers, |
||
240 | 1 | $query->getRawPostFileData() |
|
241 | ); |
||
242 | } catch (\Exception $e) { |
||
243 | GeneralUtility::devLog('Extracting text and meta data through Solr Cell over HTTP POST', |
||
244 | 'solr', 3, array( |
||
245 | 'query' => (array)$query, |
||
246 | 'parameters' => $query->getQueryParameters(), |
||
247 | 'file' => $query->getFile(), |
||
248 | 'headers' => $headers, |
||
249 | 'query url' => self::EXTRACT_SERVLET, |
||
250 | 'exception' => $e->getMessage() |
||
251 | )); |
||
252 | } |
||
253 | |||
254 | return array( |
||
255 | 1 | $response->extracted, |
|
256 | 1 | (array)$response->extracted_metadata |
|
257 | ); |
||
258 | } |
||
259 | |||
260 | /** |
||
261 | * Make a request to a servlet (a path) that's not a standard path. |
||
262 | * |
||
263 | * @param string $servlet Path to be added to the base Solr path. |
||
264 | * @param array $parameters Optional, additional request parameters when constructing the URL. |
||
265 | * @param string $method HTTP method to use, defaults to GET. |
||
266 | * @param array $requestHeaders Key value pairs of header names and values. Should include 'Content-Type' for POST and PUT. |
||
267 | * @param string $rawPost Must be an empty string unless method is POST or PUT. |
||
268 | * @param float|bool $timeout Read timeout in seconds, defaults to FALSE. |
||
269 | * @return \Apache_Solr_Response Response object |
||
270 | * @throws \Apache_Solr_HttpTransportException if returned HTTP status is other than 200 |
||
271 | */ |
||
272 | 1 | public function requestServlet( |
|
273 | $servlet, |
||
274 | $parameters = array(), |
||
275 | $method = 'GET', |
||
276 | $requestHeaders = array(), |
||
277 | $rawPost = '', |
||
278 | $timeout = false |
||
279 | ) { |
||
280 | 1 | $httpTransport = $this->getHttpTransport(); |
|
281 | 1 | $solrResponse = null; |
|
282 | |||
283 | 1 | if ($method == 'GET' || $method == 'HEAD') { |
|
284 | // Make sure we are not sending a request body. |
||
285 | $rawPost = ''; |
||
286 | } |
||
287 | |||
288 | // Add default parameters |
||
289 | 1 | $parameters['wt'] = self::SOLR_WRITER; |
|
290 | 1 | $parameters['json.nl'] = $this->_namedListTreatment; |
|
291 | 1 | $url = $this->_constructUrl($servlet, $parameters); |
|
292 | |||
293 | 1 | if ($method == self::METHOD_GET) { |
|
294 | $httpResponse = $httpTransport->performGetRequest($url, $timeout); |
||
295 | 1 | } elseif ($method == self::METHOD_POST) { |
|
296 | // FIXME should respect all headers, not only Content-Type |
||
297 | 1 | $httpResponse = $httpTransport->performPostRequest($url, $rawPost, |
|
298 | 1 | $requestHeaders['Content-Type'], $timeout); |
|
299 | } |
||
300 | |||
301 | 1 | $solrResponse = new \Apache_Solr_Response($httpResponse, |
|
302 | 1 | $this->_createDocuments, $this->_collapseSingleValueArrays); |
|
303 | |||
304 | 1 | if ($solrResponse->getHttpStatus() != 200) { |
|
305 | throw new \Apache_Solr_HttpTransportException($solrResponse); |
||
306 | } |
||
307 | |||
308 | 1 | return $solrResponse; |
|
309 | } |
||
310 | |||
311 | /** |
||
312 | * Return a valid http URL given this server's scheme, host, port, and path |
||
313 | * and a provided servlet name. |
||
314 | * |
||
315 | * @param string $servlet Servlet name |
||
316 | * @param array $params Additional URL parameters to attach to the end of the URL |
||
317 | * @return string Servlet URL |
||
318 | */ |
||
319 | 53 | protected function _constructUrl($servlet, $params = array()) |
|
320 | { |
||
321 | 53 | $url = parent::_constructUrl($servlet, $params); |
|
322 | |||
323 | 53 | if (!GeneralUtility::isFirstPartOfStr($url, $this->_scheme)) { |
|
324 | 1 | $parsedUrl = parse_url($url); |
|
325 | |||
326 | // unfortunately can't use str_replace as it replace all |
||
327 | // occurrences of $needle and can't be limited to replace only once |
||
328 | 1 | $url = $this->_scheme . substr($url, strlen($parsedUrl['scheme'])); |
|
329 | } |
||
330 | |||
331 | 53 | return $url; |
|
332 | } |
||
333 | |||
334 | /** |
||
335 | * Returns the set scheme |
||
336 | * |
||
337 | * @return string |
||
338 | */ |
||
339 | public function getScheme() |
||
343 | |||
344 | /** |
||
345 | * Set the scheme used. If empty will fallback to constants |
||
346 | * |
||
347 | * @param string $scheme Either http or https |
||
348 | * @throws \UnexpectedValueException |
||
349 | */ |
||
350 | 54 | public function setScheme($scheme) |
|
351 | { |
||
352 | // Use the provided scheme or use the default |
||
353 | 54 | if (empty($scheme)) { |
|
354 | 1 | throw new \UnexpectedValueException('Scheme parameter is empty', |
|
355 | 1 | 1380756390); |
|
356 | } else { |
||
357 | 53 | if (in_array($scheme, |
|
358 | 53 | array(self::SCHEME_HTTP, self::SCHEME_HTTPS))) { |
|
359 | 53 | $this->_scheme = $scheme; |
|
360 | } else { |
||
361 | throw new \UnexpectedValueException('Unsupported scheme parameter, scheme must be http or https', |
||
362 | 1380756442); |
||
363 | } |
||
364 | } |
||
365 | |||
366 | 53 | if ($this->_urlsInited) { |
|
367 | $this->_initUrls(); |
||
368 | } |
||
369 | 53 | } |
|
370 | |||
371 | /** |
||
372 | * get field meta data for the index |
||
373 | * |
||
374 | * @param int $numberOfTerms Number of top terms to fetch for each field |
||
375 | * @return array |
||
376 | */ |
||
377 | public function getFieldsMetaData($numberOfTerms = 0) |
||
381 | |||
382 | /** |
||
383 | * Retrieves meta data about the index from the luke request handler |
||
384 | * |
||
385 | * @param int $numberOfTerms Number of top terms to fetch for each field |
||
386 | * @return \Apache_Solr_Response Index meta data |
||
387 | */ |
||
388 | public function getLukeMetaData($numberOfTerms = 0) |
||
389 | { |
||
390 | if (!isset($this->lukeData[$numberOfTerms])) { |
||
391 | $lukeUrl = $this->_constructUrl( |
||
392 | self::LUKE_SERVLET, |
||
393 | array( |
||
394 | 'numTerms' => $numberOfTerms, |
||
395 | 'wt' => self::SOLR_WRITER, |
||
396 | 'fl' => '*' |
||
397 | ) |
||
398 | ); |
||
399 | |||
400 | $this->lukeData[$numberOfTerms] = $this->_sendRawGet($lukeUrl); |
||
401 | } |
||
402 | |||
403 | return $this->lukeData[$numberOfTerms]; |
||
404 | } |
||
405 | |||
406 | /** |
||
407 | * Central method for making a get operation against this Solr Server |
||
408 | * |
||
409 | * @param string $url |
||
410 | * @param float|bool $timeout Read timeout in seconds |
||
411 | * @return \Apache_Solr_Response |
||
412 | */ |
||
413 | 53 | protected function _sendRawGet($url, $timeout = false) |
|
414 | { |
||
415 | 53 | $logSeverity = 0; // info |
|
416 | |||
417 | try { |
||
418 | 53 | $response = parent::_sendRawGet($url, $timeout); |
|
419 | 1 | } catch (\Apache_Solr_HttpTransportException $e) { |
|
420 | 1 | $logSeverity = 3; // fatal error |
|
421 | 1 | $response = $e->getResponse(); |
|
422 | } |
||
423 | |||
424 | 53 | if ($this->configuration->getLoggingQueryRawGet() || $response->getHttpStatus() != 200) { |
|
425 | $logData = array( |
||
426 | 1 | 'query url' => $url, |
|
427 | 1 | 'response' => (array)$response |
|
428 | ); |
||
429 | |||
430 | 1 | if (!empty($e)) { |
|
431 | 1 | $logData['exception'] = $e->__toString(); |
|
432 | } else { |
||
433 | // trigger data parsing |
||
434 | $response->response; |
||
435 | $logData['response data'] = print_r($response, true); |
||
436 | } |
||
437 | |||
438 | 1 | GeneralUtility::devLog('Querying Solr using GET', 'solr', |
|
439 | $logSeverity, $logData); |
||
440 | } |
||
441 | |||
442 | 53 | return $response; |
|
443 | } |
||
444 | |||
445 | /** |
||
446 | * Returns whether a search has been executed or not. |
||
447 | * |
||
448 | * @return bool TRUE if a search has been executed, FALSE otherwise |
||
449 | */ |
||
450 | public function hasSearched() |
||
454 | |||
455 | /** |
||
456 | * Gets the most recent response (if any) |
||
457 | * |
||
458 | * @return \Apache_Solr_Response Most recent response, or NULL if a search has not been executed yet. |
||
459 | */ |
||
460 | public function getResponse() |
||
464 | |||
465 | /** |
||
466 | * Enable/Disable debug mode |
||
467 | * |
||
468 | * @param bool $debug TRUE to enable debug mode, FALSE to turn off, off by default |
||
469 | */ |
||
470 | public function setDebug($debug) |
||
474 | |||
475 | /** |
||
476 | * Gets information about the plugins installed in Solr |
||
477 | * |
||
478 | * @return array A nested array of plugin data. |
||
479 | */ |
||
480 | public function getPluginsInformation() |
||
481 | { |
||
482 | if (empty($this->pluginsData)) { |
||
483 | $pluginsInformation = $this->_sendRawGet($this->_pluginsUrl); |
||
484 | |||
485 | // access a random property to trigger response parsing |
||
486 | $pluginsInformation->responseHeader; |
||
487 | $this->pluginsData = $pluginsInformation; |
||
488 | } |
||
489 | |||
490 | return $this->pluginsData; |
||
491 | } |
||
492 | |||
493 | /** |
||
494 | * Gets the name of the schema.xml file installed and in use on the Solr |
||
495 | * server. |
||
496 | * |
||
497 | * @return string Name of the active schema.xml |
||
498 | */ |
||
499 | 1 | public function getSchemaName() |
|
500 | { |
||
501 | 1 | if (is_null($this->schemaName)) { |
|
502 | 1 | $systemInformation = $this->getSystemInformation(); |
|
503 | 1 | $this->schemaName = $systemInformation->core->schema; |
|
504 | } |
||
505 | |||
506 | 1 | return $this->schemaName; |
|
507 | } |
||
508 | |||
509 | /** |
||
510 | * Gets information about the Solr server |
||
511 | * |
||
512 | * @return array A nested array of system data. |
||
513 | */ |
||
514 | 2 | public function getSystemInformation() |
|
515 | { |
||
516 | 2 | if (empty($this->systemData)) { |
|
517 | 2 | $systemInformation = $this->system(); |
|
518 | |||
519 | // access a random property to trigger response parsing |
||
520 | 2 | $systemInformation->responseHeader; |
|
521 | 2 | $this->systemData = $systemInformation; |
|
522 | } |
||
523 | |||
524 | 2 | return $this->systemData; |
|
525 | } |
||
526 | |||
527 | /** |
||
528 | * Gets the name of the solrconfig.xml file installed and in use on the Solr |
||
529 | * server. |
||
530 | * |
||
531 | * @return string Name of the active solrconfig.xml |
||
532 | */ |
||
533 | 1 | public function getSolrconfigName() |
|
534 | { |
||
535 | 1 | if (is_null($this->solrconfigName)) { |
|
536 | 1 | $solrconfigXmlUrl = $this->_scheme . '://' |
|
537 | 1 | . $this->_host . ':' . $this->_port |
|
538 | 1 | . $this->_path . 'admin/file/?file=solrconfig.xml'; |
|
539 | |||
540 | 1 | $solrconfigXml = simplexml_load_file($solrconfigXmlUrl); |
|
541 | 1 | if ($solrconfigXml === false) { |
|
542 | throw new \InvalidArgumentException('No valid xml response from schema file: ' . $solrconfigXmlUrl); |
||
543 | } |
||
544 | 1 | $this->solrconfigName = (string)$solrconfigXml->attributes()->name; |
|
545 | } |
||
546 | |||
547 | 1 | return $this->solrconfigName; |
|
548 | } |
||
549 | |||
550 | /** |
||
551 | * Gets the Solr server's version number. |
||
552 | * |
||
553 | * @return string Solr version number |
||
554 | */ |
||
555 | 1 | public function getSolrServerVersion() |
|
556 | { |
||
557 | 1 | $systemInformation = $this->getSystemInformation(); |
|
558 | |||
559 | // don't know why $systemInformation->lucene->solr-spec-version won't work |
||
560 | 1 | $luceneInformation = (array)$systemInformation->lucene; |
|
561 | 1 | return $luceneInformation['solr-spec-version']; |
|
562 | } |
||
563 | |||
564 | /** |
||
565 | * Deletes all index documents of a certain type and does a commit |
||
566 | * afterwards. |
||
567 | * |
||
568 | * @param string $type The type of documents to delete, usually a table name. |
||
569 | * @param bool $commit Will commit immediately after deleting the documents if set, defaults to TRUE |
||
570 | */ |
||
571 | public function deleteByType($type, $commit = true) |
||
572 | { |
||
573 | $this->deleteByQuery('type:' . trim($type)); |
||
574 | |||
575 | if ($commit) { |
||
576 | $this->commit(false, false, false); |
||
577 | } |
||
578 | } |
||
579 | |||
580 | /** |
||
581 | * Raw Delete Method. Takes a raw post body and sends it to the update service. Body should be |
||
582 | * a complete and well formed "delete" xml document |
||
583 | * |
||
584 | * @param string $rawPost Expected to be utf-8 encoded xml document |
||
585 | * @param float|int $timeout Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception) |
||
586 | * @return \Apache_Solr_Response |
||
587 | */ |
||
588 | 5 | public function delete($rawPost, $timeout = 3600) |
|
589 | { |
||
590 | 5 | $response = $this->_sendRawPost($this->_updateUrl, $rawPost, $timeout); |
|
591 | |||
592 | 5 | GeneralUtility::devLog( |
|
593 | 5 | 'Delete Query sent.', |
|
594 | 5 | 'solr', |
|
595 | 5 | 1, |
|
596 | array( |
||
597 | 5 | 'query' => $rawPost, |
|
598 | 5 | 'query url' => $this->_updateUrl, |
|
599 | 5 | 'response' => (array)$response |
|
600 | ) |
||
601 | ); |
||
602 | |||
603 | 5 | return $response; |
|
604 | } |
||
605 | |||
606 | /** |
||
607 | * Central method for making a post operation against this Solr Server |
||
608 | * |
||
609 | * @param string $url |
||
610 | * @param string $rawPost |
||
611 | * @param float|bool $timeout Read timeout in seconds |
||
612 | * @param string $contentType |
||
613 | * @return \Apache_Solr_Response |
||
614 | */ |
||
615 | 46 | protected function _sendRawPost( |
|
616 | $url, |
||
617 | $rawPost, |
||
618 | $timeout = false, |
||
619 | $contentType = 'text/xml; charset=UTF-8' |
||
620 | ) { |
||
621 | 46 | $logSeverity = 0; // info |
|
622 | |||
623 | try { |
||
624 | 46 | $response = parent::_sendRawPost($url, $rawPost, $timeout, |
|
625 | $contentType); |
||
626 | } catch (\Apache_Solr_HttpTransportException $e) { |
||
627 | $logSeverity = 3; // fatal error |
||
628 | $response = $e->getResponse(); |
||
629 | } |
||
630 | |||
631 | 46 | if ($this->configuration->getLoggingQueryRawPost() || $response->getHttpStatus() != 200) { |
|
632 | $logData = array( |
||
633 | 'query url' => $url, |
||
634 | 'content' => $rawPost, |
||
635 | 'response' => (array)$response |
||
636 | ); |
||
637 | |||
638 | if (!empty($e)) { |
||
639 | $logData['exception'] = $e->__toString(); |
||
640 | } |
||
641 | |||
642 | GeneralUtility::devLog('Querying Solr using POST', 'solr', |
||
643 | $logSeverity, $logData); |
||
644 | } |
||
645 | |||
646 | 46 | return $response; |
|
647 | } |
||
648 | |||
649 | /** |
||
650 | * Get currently configured synonyms |
||
651 | * |
||
652 | * @param string $baseWord If given a base word, retrieves the synonyms for that word only |
||
653 | * @return array |
||
654 | */ |
||
655 | public function getSynonyms($baseWord = '') |
||
656 | { |
||
657 | $synonymsUrl = $this->_synonymsUrl; |
||
658 | if (!empty($baseWord)) { |
||
659 | $synonymsUrl .= '/' . $baseWord; |
||
660 | } |
||
661 | |||
662 | $response = $this->_sendRawGet($synonymsUrl); |
||
663 | $decodedResponse = json_decode($response->getRawResponse()); |
||
664 | |||
665 | $synonyms = array(); |
||
666 | if (!empty($baseWord)) { |
||
667 | if (is_array($decodedResponse->{$baseWord})) { |
||
668 | $synonyms = $decodedResponse->{$baseWord}; |
||
669 | } |
||
670 | } else { |
||
671 | if (isset($decodedResponse->synonymMappings->managedMap)) { |
||
672 | $synonyms = (array)$decodedResponse->synonymMappings->managedMap; |
||
673 | } |
||
674 | } |
||
675 | |||
676 | return $synonyms; |
||
677 | } |
||
678 | |||
679 | /** |
||
680 | * Add list of synonyms for base word to managed synonyms map |
||
681 | * |
||
682 | * @param $baseWord |
||
683 | * @param array $synonyms |
||
684 | * |
||
685 | * @return \Apache_Solr_Response |
||
686 | * |
||
687 | * @throws \Apache_Solr_InvalidArgumentException If $baseWord or $synonyms are empty |
||
688 | */ |
||
689 | public function addSynonym($baseWord, array $synonyms) |
||
699 | |||
700 | /** |
||
701 | * Remove a synonym from the synonyms map |
||
702 | * |
||
703 | * @param $baseWord |
||
704 | * @return \Apache_Solr_Response |
||
705 | * @throws \Apache_Solr_InvalidArgumentException |
||
706 | */ |
||
707 | public function deleteSynonym($baseWord) |
||
715 | |||
716 | /** |
||
717 | * Central method for making a HTTP DELETE operation against the Solr server |
||
718 | * |
||
719 | * @param $url |
||
720 | * @param bool|float $timeout Read timeout in seconds |
||
721 | * @return \Apache_Solr_Response |
||
722 | */ |
||
723 | protected function _sendRawDelete($url, $timeout = false) |
||
724 | { |
||
725 | $logSeverity = 0; // info |
||
726 | |||
727 | try { |
||
728 | $httpTransport = $this->getHttpTransport(); |
||
729 | |||
730 | $httpResponse = $httpTransport->performDeleteRequest($url, |
||
731 | $timeout); |
||
732 | $solrResponse = new \Apache_Solr_Response($httpResponse, |
||
733 | $this->_createDocuments, $this->_collapseSingleValueArrays); |
||
734 | |||
735 | if ($solrResponse->getHttpStatus() != 200) { |
||
736 | throw new \Apache_Solr_HttpTransportException($solrResponse); |
||
737 | } |
||
738 | } catch (\Apache_Solr_HttpTransportException $e) { |
||
739 | $logSeverity = 3; // fatal error |
||
740 | $solrResponse = $e->getResponse(); |
||
741 | } |
||
742 | |||
743 | if ($this->configuration->getLoggingQueryRawDelete() || $solrResponse->getHttpStatus() != 200) { |
||
744 | $logData = array( |
||
745 | 'query url' => $url, |
||
746 | 'response' => (array)$solrResponse |
||
747 | ); |
||
748 | |||
749 | if (!empty($e)) { |
||
750 | $logData['exception'] = $e->__toString(); |
||
751 | } else { |
||
752 | // trigger data parsing |
||
753 | $solrResponse->response; |
||
754 | $logData['response data'] = print_r($solrResponse, true); |
||
755 | } |
||
756 | |||
757 | GeneralUtility::devLog('Querying Solr using DELETE', 'solr', |
||
758 | $logSeverity, $logData); |
||
759 | } |
||
760 | |||
761 | return $solrResponse; |
||
762 | } |
||
763 | |||
764 | /** |
||
765 | * Get currently configured stop words |
||
766 | * |
||
767 | * @return array |
||
768 | */ |
||
769 | public function getStopWords() |
||
770 | { |
||
771 | $stopWords = array(); |
||
772 | |||
773 | $response = $this->_sendRawGet($this->_stopWordsUrl); |
||
774 | $decodedResponse = json_decode($response->getRawResponse()); |
||
775 | |||
776 | if (isset($decodedResponse->wordSet->managedList)) { |
||
777 | $stopWords = (array)$decodedResponse->wordSet->managedList; |
||
778 | } |
||
779 | |||
780 | return $stopWords; |
||
781 | } |
||
782 | |||
783 | /** |
||
784 | * Adds stop words to the managed stop word list |
||
785 | * |
||
786 | * @param array|string $stopWords string for a single word, array for multiple words |
||
787 | * @return \Apache_Solr_Response |
||
788 | * @throws \Apache_Solr_InvalidArgumentException If $stopWords is empty |
||
789 | */ |
||
790 | public function addStopWords($stopWords) |
||
791 | { |
||
792 | if (empty($stopWords)) { |
||
793 | throw new \Apache_Solr_InvalidArgumentException('Must provide stop word.'); |
||
794 | } |
||
795 | |||
796 | if (is_string($stopWords)) { |
||
797 | $stopWords = array($stopWords); |
||
798 | } |
||
799 | |||
800 | $stopWords = array_values($stopWords); |
||
801 | $rawPut = json_encode($stopWords); |
||
802 | return $this->_sendRawPost($this->_stopWordsUrl, $rawPut, |
||
803 | $this->getHttpTransport()->getDefaultTimeout(), 'application/json'); |
||
804 | } |
||
805 | |||
806 | /** |
||
807 | * Deletes a words from the managed stop word list |
||
808 | * |
||
809 | * @param string $stopWord stop word to delete |
||
810 | * @return \Apache_Solr_Response |
||
811 | * @throws \Apache_Solr_InvalidArgumentException If $stopWords is empty |
||
812 | */ |
||
813 | public function deleteStopWord($stopWord) |
||
821 | |||
822 | /** |
||
823 | * Reloads the current core |
||
824 | * |
||
825 | * @return \Apache_Solr_Response |
||
826 | */ |
||
827 | public function reloadCore() |
||
834 | |||
835 | /** |
||
836 | * initializes various URLs, including the Luke URL |
||
837 | * |
||
838 | * @return void |
||
839 | */ |
||
840 | 53 | protected function _initUrls() |
|
875 | |||
876 | /** |
||
877 | * Get the language map name for the text field. |
||
878 | * This is necessary to select the correct synonym map. |
||
879 | * |
||
880 | * @return string |
||
881 | */ |
||
882 | 53 | protected function getManagedLanguage() |
|
883 | { |
||
884 | 53 | $language = 'english'; |
|
885 | |||
886 | 53 | $schema = $this->getSchema(); |
|
887 | |||
888 | 53 | if (is_object($schema) && isset($schema->fieldTypes)) { |
|
889 | 52 | foreach ($schema->fieldTypes as $fieldType) { |
|
890 | 52 | if ($fieldType->name === 'text') { |
|
891 | 52 | foreach ($fieldType->queryAnalyzer->filters as $filter) { |
|
892 | 52 | if ($filter->class === 'solr.ManagedSynonymFilterFactory') { |
|
893 | 52 | $language = $filter->managed; |
|
894 | } |
||
895 | } |
||
896 | } |
||
897 | } |
||
898 | } |
||
899 | |||
900 | 53 | return $language; |
|
901 | } |
||
902 | |||
903 | /** |
||
904 | * Get the configured schema for the current core |
||
905 | * |
||
906 | * @return \stdClass |
||
907 | */ |
||
908 | 53 | protected function getSchema() |
|
913 | } |
||
914 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..