private function testSolrConnection() { $client = new SolariumClient($this->getSolrConfig()); $ping = $client->createPing(); try { $client->ping($ping); return true; } catch (Exception $e) { return false; } }
/** * Gets summary information about the Solr Core. * * @return array */ public function getStatsSummary() { $summary = array('@pending_docs' => '', '@autocommit_time_seconds' => '', '@autocommit_time' => '', '@deletes_by_id' => '', '@deletes_by_query' => '', '@deletes_total' => '', '@schema_version' => '', '@core_name' => '', '@index_size' => ''); $solr_version = $this->getSolrVersion(); $query = $this->solr->createPing(); $query->setResponseWriter(Query::WT_PHPS); if (version_compare($solr_version, '4', '>=')) { $query->setHandler('admin/mbeans?stats=true'); } else { $query->setHandler('admin/stats.jsp'); } $stats = $this->solr->execute($query)->getData(); if (!empty($stats)) { if (version_compare($solr_version, '3', '<=')) { // @todo Needs to be updated by someone who has a Solr 3.x setup. /* $docs_pending_xpath = $stats->xpath('//stat[@name="docsPending"]'); $summary['@pending_docs'] = (int) trim(current($docs_pending_xpath)); $max_time_xpath = $stats->xpath('//stat[@name="autocommit maxTime"]'); $max_time = (int) trim(current($max_time_xpath)); // Convert to seconds. $summary['@autocommit_time_seconds'] = $max_time / 1000; $summary['@autocommit_time'] = \Drupal::service('date')->formatInterval($max_time / 1000); $deletes_id_xpath = $stats->xpath('//stat[@name="deletesById"]'); $summary['@deletes_by_id'] = (int) trim(current($deletes_id_xpath)); $deletes_query_xpath = $stats->xpath('//stat[@name="deletesByQuery"]'); $summary['@deletes_by_query'] = (int) trim(current($deletes_query_xpath)); $summary['@deletes_total'] = $summary['@deletes_by_id'] + $summary['@deletes_by_query']; $schema = $stats->xpath('/solr/schema[1]'); $summary['@schema_version'] = trim($schema[0]); $core = $stats->xpath('/solr/core[1]'); $summary['@core_name'] = trim($core[0]); $size_xpath = $stats->xpath('//stat[@name="indexSize"]'); $summary['@index_size'] = trim(current($size_xpath)); */ } else { $update_handler_stats = $stats['solr-mbeans']['UPDATEHANDLER']['updateHandler']['stats']; $summary['@pending_docs'] = (int) $update_handler_stats['docsPending']; $max_time = (int) $update_handler_stats['autocommit maxTime']; // Convert to seconds. $summary['@autocommit_time_seconds'] = $max_time / 1000; $summary['@autocommit_time'] = \Drupal::service('date.formatter')->formatInterval($max_time / 1000); $summary['@deletes_by_id'] = (int) $update_handler_stats['deletesById']; $summary['@deletes_by_query'] = (int) $update_handler_stats['deletesByQuery']; $summary['@deletes_total'] = $summary['@deletes_by_id'] + $summary['@deletes_by_query']; $summary['@schema_version'] = $this->getSystemInfo()['core']['schema']; $summary['@core_name'] = $stats['solr-mbeans']['CORE']['core']['stats']['coreName']; $summary['@index_size'] = $stats['solr-mbeans']['QUERYHANDLER']['/replication']['stats']['indexSize']; } } return $summary; }
public function ping() { $config = $this->getConfig(); $solr = new Solarium\Client($config); $ping = $solr->createPing(); try { $ping = $solr->ping($ping); $ping = $ping->getData(); $alive = false; if (isset($ping['status']) && $ping['status'] === "OK") { $alive = true; } } catch (\Solarium\Exception $e) { return false; } return $alive; }
/** * Ping Solr to test if it is working. * * @return bool - True on success */ public function ping() { /** * This function should not check the $this->_working variable, * because it is used to check if everything is working. */ $result = false; try { $query = $this->_client->createPing(); // Not 100% sure if this setTimeAllowed works. $query->setTimeAllowed(intval($this->getConf('server/search_timeout'))); $solariumResult = $this->_client->ping($query); $this->debugQuery($query); $resultData = $solariumResult->getData(); if (!empty($resultData['status']) && 'OK' === $resultData['status']) { $result = true; } } catch (Exception $e) { $this->_lastError = $e; Mage::log(sprintf('%s->%s: %s', __CLASS__, __FUNCTION__, $e->getMessage()), Zend_Log::ERR); } return $result; }
/** * Retrieves a config file or file list from the Solr server. * * Uses the admin/file request handler. * * @param string|null $file * (optional) The name of the file to retrieve. If the file is a directory, * the directory contents are instead listed and returned. NULL represents * the root config directory. * * @return \Solarium\Core\Client\Response * A Solarium response object containing either the file contents or a file * list. */ public function getFile($file = NULL) { $this->connect(); $query = $this->solr->createPing(); $query->setHandler('admin/file'); $query->addParam('contentType', 'text/xml;charset=utf-8'); if ($file) { $query->addParam('file', $file); } return $this->solr->execute($query)->getResponse(); }