/** * Executes the commit task and returns TRUE if the execution was * succesfull * * @return boolean returns TRUE on success, FALSE on failure */ public function execute() { $result = FALSE; if (is_null($this->solr)) { $this->initializeSolr(); } $response = $this->solr->commit(); if ($response->responseHeader->status === 0) { $result = TRUE; } return $result; }
public function getSpellcheckingSuggestions() { $spellcheckingSuggestions = FALSE; $suggestions = (array) $this->solr->getResponse()->spellcheck->suggestions; if (!empty($suggestions)) { $spellcheckingSuggestions = $suggestions; } return $spellcheckingSuggestions; }
/** * Checks whether a Solr server is available and provides some information. * * @param tx_solr_SolrService Solr connection * @return tx_reports_reports_status_Status Status of the Solr connection */ protected function getConnectionStatus(tx_solr_SolrService $solr) { $value = 'Your site was unable to contact the Apache Solr server.'; $severity = tx_reports_reports_status_Status::ERROR; $message = '<ul>' . '<li>Host: ' . $solr->getHost() . '</li>' . '<li>Port: ' . $solr->getPort() . '</li>' . '<li style="padding-bottom: 10px;">Path: ' . $solr->getPath() . '</li>'; if ($solr->ping()) { $severity = tx_reports_reports_status_Status::OK; $value = 'Your site has contacted the Apache Solr server.'; $solrVersion = $this->formatSolrVersion($solr->getSolrServerVersion()); $message .= '<li>Apache Solr: ' . $solrVersion . '</li>'; $message .= '<li>schema.xml: ' . $solr->getSchemaName() . '</li>'; $message .= '<li>solrconfig.xml: ' . $solr->getSolrconfigName() . '</li>'; $accessFilterPluginStatus = t3lib_div::makeInstance('tx_solr_report_AccessFilterPluginInstalledStatus'); $accessFilterPluginVersion = $accessFilterPluginStatus->getInstalledPluginVersion($solr); $message .= '<li>Access Filter Plugin: ' . $accessFilterPluginVersion . '</li>'; } $message .= '</ul>'; return t3lib_div::makeInstance('tx_reports_reports_status_Status', 'Apache Solr', $value, $message, $severity); }
/** * Indexes Redmine projects * * @param array $projects An array of Redmine project objects * @return boolean TRUE if projects are successfully indexed, FALSE otherwise */ protected function indexProjects(array $projects) { $projectDocuments = array(); $projectsIndexed = FALSE; foreach ($projects as $project) { $projectDocuments[] = $this->projectToDocument($project); } try { $response = $this->solrConnection->addDocuments($projectDocuments); if ($response->getHttpStatus() == 200) { $projectsIndexed = TRUE; } } catch (Exception $e) { foreach ($projectDocuments as $index => $projectDocument) { $projectDocuments[$index] = (array) $projectDocument; } t3lib_div::devLog('Failed to index Redmine projects', 'solr_redmine', 3, array('documents' => $projectDocuments, 'response' => (array) $response)); } return $projectsIndexed; }
/** * Adds the collected documents to the Solr index. * * @param array $documents An array of Apache_Solr_Document objects. */ protected function addDocumentsToSolrIndex(array $documents) { $documentsAdded = FALSE; if (!count($documents)) { return $documentsAdded; } try { $this->log('Adding ' . count($documents) . ' documents.', 0, $documents); // chunk adds by 20 $documentChunks = array_chunk($documents, 20); foreach ($documentChunks as $documentChunk) { $this->solrConnection->addDocuments($documentChunk); } $documentsAdded = TRUE; } catch (Exception $e) { $this->log($e->getMessage() . ' Error code: ' . $e->getCode(), 2); if ($GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_solr.']['logging.']['exceptions']) { t3lib_div::devLog('Exception while adding documents', 'tx_solr', 3, array($e->__toString())); } } return $documentsAdded; }
/** * Renders the index field table. * * Acknowledgement: Some of the code is taken from Drupal's apachesolr module * * @param $data * @return unknown_type */ protected function renderData(Apache_Solr_Response $data) { $content = ''; $registry = t3lib_div::makeInstance('t3lib_Registry'); $limit = $registry->get('tx_solr', 'luke.limit', 20000); $numberOfDocuments = $data->index->numDocs; $content .= '<p>Number of documents in index: ' . $numberOfDocuments . '</p>'; if (isset($data->index->numDocs) && $data->index->numDocs > $limit) { $notFound = '<em>Omitted</em>'; $content .= '<p>You have more than ' . $limit . ' documents, so term frequencies are being omitted for performance reasons.</p>'; } elseif (isset($data->index->numDocs)) { $notFound = 'Not indexed'; // below limit, so we get more data // Note: we use 2 since 1 fails on Ubuntu Hardy. $data = $this->solr->getLukeMetaData(2); $content .= '<p>Number of terms in index: ' . $data->index->numTerms . '</p>'; } $fields = (array) $data->fields; $content .= '<p>Number of fields in index: ' . count($fields) . '</p>'; // getting fields, sorting $rows = array(); foreach ($fields as $name => $field) { $rows[$name] = array($name, $field->type, isset($field->distinct) ? $field->distinct : $notFound); } ksort($rows); // Initialise table layout $tableLayout = array('table' => array('<table border="0" cellspacing="0" cellpadding="2" class="tx_solr_index_list">', '</table>'), '0' => array('tr' => array('<tr class="bgColor2" valign="top">', '</tr>'), 'defCol' => array('<td>', '</td>')), 'defRowOdd' => array('tr' => array('<tr class="bgColor3-20">', '</tr>'), 'defCol' => array('<td>', '</td>')), 'defRowEven' => array('tr' => array('<tr>', '</tr>'), 'defCol' => array('<td>', '</td>'))); $table = array(); // header row $table[] = array('Field Name', 'Index Type', 'Distinct Terms'); foreach ($rows as $row) { $table[] = $row; } // Render table $content .= $this->reportsModule->doc->table($table, $tableLayout); return $content; }
/** * Gets the version of the installed plugin. * * @param tx_solr_SolrService Solr connection to check for the plugin. * @return string The installed plugin's version number. */ public function getInstalledPluginVersion(tx_solr_SolrService $solrConnection) { $version = '0.0.0'; $pluginsInformation = $solrConnection->getPluginsInformation(); $rawVersion = $pluginsInformation->plugins->OTHER->{self::PLUGIN_CLASS_NAME}->version; $explodedRawVersion = explode('-', $rawVersion); $version = $explodedRawVersion[0]; return $version; }