/** * @test */ public function canExtractByQuery() { $testFilePath = $this->getFixturePath('testpdf.pdf'); /** @var $extractQuery \ApacheSolrForTypo3\Solr\ExtractingQuery */ $extractQuery = GeneralUtility::makeInstance('ApacheSolrForTypo3\\Solr\\ExtractingQuery', $testFilePath); $extractQuery->setExtractOnly(); $response = $this->solrService->extractByQuery($extractQuery); $this->assertContains('PDF Test', $response[0], 'Could not extract text'); }
/** * Adds the collected documents to the Solr index. * * @param array $documents An array of \Apache_Solr_Document objects. * @return boolean TRUE if documents were added successfully, FALSE otherwise */ 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) { $response = $this->solrConnection->addDocuments($documentChunk); if ($response->getHttpStatus() != 200) { $transportException = new \Apache_Solr_HttpTransportException($response); throw new \RuntimeException('Solr Request failed.', 1331834983, $transportException); } } $documentsAdded = TRUE; } catch (\Exception $e) { $this->log($e->getMessage() . ' Error code: ' . $e->getCode(), 2); if ($GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_solr.']['logging.']['exceptions']) { GeneralUtility::devLog('Exception while adding documents', 'solr', 3, array($e->__toString())); } } return $documentsAdded; }
/** * Creates a single Solr Document for an item in a specific language. * * @param Item $item An index queue item to index. * @param integer $language The language to use. * @return boolean TRUE if item was indexed successfully, FALSE on failure */ protected function indexItem(Item $item, $language = 0) { $itemIndexed = FALSE; $documents = array(); $itemDocument = $this->itemToDocument($item, $language); if (is_null($itemDocument)) { /* * If there is no itemDocument, this means there was no translation * for this record. This should not stop the current item to count as * being valid because not-indexing not-translated items is perfectly * fine. */ return TRUE; } $documents[] = $itemDocument; $documents = array_merge($documents, $this->getAdditionalDocuments($item, $language, $itemDocument)); $documents = $this->processDocuments($item, $documents); $documents = $this->preAddModifyDocuments($item, $language, $documents); $response = $this->solr->addDocuments($documents); if ($response->getHttpStatus() == 200) { $itemIndexed = TRUE; } $this->log($item, $documents, $response); return $itemIndexed; }
/** * Sends a ping to the solr server to see whether it is available. * * @return boolean Returns TRUE on successful ping. * @throws \Exception Throws an exception in case ping was not successful. */ public function ping() { $solrAvailable = FALSE; try { if (!$this->solr->ping()) { throw new \Exception('Solr Server not responding.', 1237475791); } $solrAvailable = TRUE; } catch (\Exception $e) { if ($GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_solr.']['logging.']['exceptions']) { GeneralUtility::devLog('exception while trying to ping the solr server', 'solr', 3, array($e->__toString())); } } return $solrAvailable; }
/** * Sends a ping to the solr server to see whether it is available. * * @return boolean Returns TRUE on successful ping. * @throws \Exception Throws an exception in case ping was not successful. */ public function ping() { $solrAvailable = false; try { if (!$this->solr->ping()) { throw new \Exception('Solr Server not responding.', 1237475791); } $solrAvailable = true; } catch (\Exception $e) { if ($this->configuration->getLoggingExceptions()) { GeneralUtility::devLog('exception while trying to ping the solr server', 'solr', 3, array($e->__toString())); } } return $solrAvailable; }
/** * Checks the solr schema name and adds it to the report. * * @param SolrService $solr */ protected function checkSolrSchemaName(SolrService $solr) { try { $solrSchemaMessage = $solr->getSchemaName(); } catch (\Exception $e) { $this->responseStatus = Status::ERROR; $solrSchemaMessage = 'Error determining schema name: ' . $e->getMessage(); } $this->responseMessage = $this->replaceMarkerInResponse($this->responseMessage, 'SOLR_SCHEMA', $solrSchemaMessage); }
/** * Gets the Tika version * * @return string Apache Solr server version string */ public function getTikaVersion() { // TODO add patch for endpoint on Apache Solr to return Tika version // for now returns the Solr version string f.e. "Apache Solr 5.2.0" (for now) return $this->solr->getSolrServerVersion(); }
/** * Reloads a single Solr core. * * @param SolrService $solrServer A Solr server connection * @param string $coreName Name of the core to reload * @return bool TRUE if reloading the core was successful, FALSE otherwise */ protected function reloadCore(SolrService $solrServer, $coreName) { $coreReloaded = FALSE; $path = $solrServer->getPath(); $pathElements = explode('/', trim($path, '/')); $coreAdminReloadUrl = $solrServer->getScheme() . '://' . $solrServer->getHost() . ':' . $solrServer->getPort() . '/' . $pathElements[0] . '/' . 'admin/cores?action=reload&core=' . $coreName; $httpTransport = $solrServer->getHttpTransport(); $httpResponse = $httpTransport->performGetRequest($coreAdminReloadUrl); $solrResponse = new \Apache_Solr_Response($httpResponse, $solrServer->getCreateDocuments(), $solrServer->getCollapseSingleValueArrays()); if ($solrResponse->getHttpStatus() == 200) { $coreReloaded = TRUE; } return $coreReloaded; }
/** * Gets the version of the installed plugin. * * @param SolrService $solrConnection Solr connection to check for the plugin. * @return string The installed plugin's version number. */ public function getInstalledPluginVersion(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; }