first commit
This commit is contained in:
@@ -25,14 +25,14 @@ namespace WapplerSystems\Meilisearch;
|
||||
***************************************************************/
|
||||
|
||||
use WapplerSystems\Meilisearch\Access\Rootline;
|
||||
use WapplerSystems\Meilisearch\Domain\Search\ApacheSolrDocument\Builder;
|
||||
use WapplerSystems\Meilisearch\Domain\Search\ApacheMeilisearchDocument\Builder;
|
||||
use WapplerSystems\Meilisearch\FieldProcessor\Service;
|
||||
use WapplerSystems\Meilisearch\IndexQueue\FrontendHelper\PageFieldMappingIndexer;
|
||||
use WapplerSystems\Meilisearch\IndexQueue\Item;
|
||||
use WapplerSystems\Meilisearch\System\Configuration\TypoScriptConfiguration;
|
||||
use WapplerSystems\Meilisearch\System\Logging\SolrLogManager;
|
||||
use WapplerSystems\Meilisearch\System\Solr\Document\Document;
|
||||
use WapplerSystems\Meilisearch\System\Solr\SolrConnection;
|
||||
use WapplerSystems\Meilisearch\System\Logging\MeilisearchLogManager;
|
||||
use WapplerSystems\Meilisearch\System\Meilisearch\Document\Document;
|
||||
use WapplerSystems\Meilisearch\System\Meilisearch\MeilisearchConnection;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
|
||||
|
||||
@@ -47,17 +47,17 @@ class Typo3PageIndexer
|
||||
{
|
||||
|
||||
/**
|
||||
* ID of the current page's Solr document.
|
||||
* ID of the current page's Meilisearch document.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $pageSolrDocumentId = '';
|
||||
protected static $pageMeilisearchDocumentId = '';
|
||||
/**
|
||||
* The Solr document generated for the current page.
|
||||
* The Meilisearch document generated for the current page.
|
||||
*
|
||||
* @var Document
|
||||
*/
|
||||
protected static $pageSolrDocument = null;
|
||||
protected static $pageMeilisearchDocument = null;
|
||||
/**
|
||||
* The mount point parameter used in the Frontend controller.
|
||||
*
|
||||
@@ -65,11 +65,11 @@ class Typo3PageIndexer
|
||||
*/
|
||||
protected $mountPointParameter;
|
||||
/**
|
||||
* Solr server connection.
|
||||
* Meilisearch server connection.
|
||||
*
|
||||
* @var SolrConnection
|
||||
* @var MeilisearchConnection
|
||||
*/
|
||||
protected $solrConnection = null;
|
||||
protected $meilisearchConnection = null;
|
||||
/**
|
||||
* Frontend page object (TSFE).
|
||||
*
|
||||
@@ -95,11 +95,11 @@ class Typo3PageIndexer
|
||||
*/
|
||||
protected $pageAccessRootline = null;
|
||||
/**
|
||||
* Documents that have been sent to Solr
|
||||
* Documents that have been sent to Meilisearch
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $documentsSentToSolr = [];
|
||||
protected $documentsSentToMeilisearch = [];
|
||||
|
||||
/**
|
||||
* @var TypoScriptConfiguration
|
||||
@@ -112,7 +112,7 @@ class Typo3PageIndexer
|
||||
protected $indexQueueItem;
|
||||
|
||||
/**
|
||||
* @var \WapplerSystems\Meilisearch\System\Logging\SolrLogManager
|
||||
* @var \WapplerSystems\Meilisearch\System\Logging\MeilisearchLogManager
|
||||
*/
|
||||
protected $logger = null;
|
||||
|
||||
@@ -123,24 +123,24 @@ class Typo3PageIndexer
|
||||
*/
|
||||
public function __construct(TypoScriptFrontendController $page)
|
||||
{
|
||||
$this->logger = GeneralUtility::makeInstance(SolrLogManager::class, /** @scrutinizer ignore-type */ __CLASS__);
|
||||
$this->logger = GeneralUtility::makeInstance(MeilisearchLogManager::class, /** @scrutinizer ignore-type */ __CLASS__);
|
||||
|
||||
$this->page = $page;
|
||||
$this->pageUrl = GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL');
|
||||
$this->configuration = Util::getSolrConfiguration();
|
||||
$this->configuration = Util::getMeilisearchConfiguration();
|
||||
|
||||
try {
|
||||
$this->initializeSolrConnection();
|
||||
$this->initializeMeilisearchConnection();
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->log(
|
||||
SolrLogManager::ERROR,
|
||||
MeilisearchLogManager::ERROR,
|
||||
$e->getMessage() . ' Error code: ' . $e->getCode()
|
||||
);
|
||||
|
||||
// TODO extract to a class "ExceptionLogger"
|
||||
if ($this->configuration->getLoggingExceptions()) {
|
||||
$this->logger->log(
|
||||
SolrLogManager::ERROR,
|
||||
MeilisearchLogManager::ERROR,
|
||||
'Exception while trying to index a page',
|
||||
[
|
||||
$e->__toString()
|
||||
@@ -161,62 +161,62 @@ class Typo3PageIndexer
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the Solr server connection.
|
||||
* Initializes the Meilisearch server connection.
|
||||
*
|
||||
* @throws \Exception when no Solr connection can be established.
|
||||
* @throws \Exception when no Meilisearch connection can be established.
|
||||
*/
|
||||
protected function initializeSolrConnection()
|
||||
protected function initializeMeilisearchConnection()
|
||||
{
|
||||
$solr = GeneralUtility::makeInstance(ConnectionManager::class)->getConnectionByPageId($this->page->id, Util::getLanguageUid());
|
||||
$meilisearch = GeneralUtility::makeInstance(ConnectionManager::class)->getConnectionByPageId($this->page->id, Util::getLanguageUid());
|
||||
|
||||
// do not continue if no server is available
|
||||
if (!$solr->getWriteService()->ping()) {
|
||||
if (!$meilisearch->getWriteService()->ping()) {
|
||||
throw new \Exception(
|
||||
'No Solr instance available while trying to index a page.',
|
||||
'No Meilisearch instance available while trying to index a page.',
|
||||
1234790825
|
||||
);
|
||||
}
|
||||
|
||||
$this->solrConnection = $solr;
|
||||
$this->meilisearchConnection = $meilisearch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current page's Solr document ID.
|
||||
* Gets the current page's Meilisearch document ID.
|
||||
*
|
||||
* @return string|NULL The page's Solr document ID or NULL in case no document was generated yet.
|
||||
* @return string|NULL The page's Meilisearch document ID or NULL in case no document was generated yet.
|
||||
*/
|
||||
public static function getPageSolrDocumentId()
|
||||
public static function getPageMeilisearchDocumentId()
|
||||
{
|
||||
return self::$pageSolrDocumentId;
|
||||
return self::$pageMeilisearchDocumentId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Solr document generated for the current page.
|
||||
* Gets the Meilisearch document generated for the current page.
|
||||
*
|
||||
* @return Document|NULL The page's Solr document or NULL if it has not been generated yet.
|
||||
* @return Document|NULL The page's Meilisearch document or NULL if it has not been generated yet.
|
||||
*/
|
||||
public static function getPageSolrDocument()
|
||||
public static function getPageMeilisearchDocument()
|
||||
{
|
||||
return self::$pageSolrDocument;
|
||||
return self::$pageMeilisearchDocument;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows to provide a Solr server connection other than the one
|
||||
* Allows to provide a Meilisearch server connection other than the one
|
||||
* initialized by the constructor.
|
||||
*
|
||||
* @param SolrConnection $solrConnection Solr connection
|
||||
* @throws \Exception if the Solr server cannot be reached
|
||||
* @param MeilisearchConnection $meilisearchConnection Meilisearch connection
|
||||
* @throws \Exception if the Meilisearch server cannot be reached
|
||||
*/
|
||||
public function setSolrConnection(SolrConnection $solrConnection)
|
||||
public function setMeilisearchConnection(MeilisearchConnection $meilisearchConnection)
|
||||
{
|
||||
if (!$solrConnection->getWriteService()->ping()) {
|
||||
if (!$meilisearchConnection->getWriteService()->ping()) {
|
||||
throw new \Exception(
|
||||
'Could not connect to Solr server.',
|
||||
'Could not connect to Meilisearch server.',
|
||||
1323946472
|
||||
);
|
||||
}
|
||||
|
||||
$this->solrConnection = $solrConnection;
|
||||
$this->meilisearchConnection = $meilisearchConnection;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -230,9 +230,9 @@ class Typo3PageIndexer
|
||||
$pageIndexed = false;
|
||||
$documents = []; // this will become useful as soon as when starting to index individual records instead of whole pages
|
||||
|
||||
if (is_null($this->solrConnection)) {
|
||||
if (is_null($this->meilisearchConnection)) {
|
||||
// intended early return as it doesn't make sense to continue
|
||||
// and waste processing time if the solr server isn't available
|
||||
// and waste processing time if the meilisearch server isn't available
|
||||
// anyways
|
||||
// FIXME use an exception
|
||||
return $pageIndexed;
|
||||
@@ -243,13 +243,13 @@ class Typo3PageIndexer
|
||||
|
||||
$this->applyIndexPagePostProcessors($pageDocument);
|
||||
|
||||
self::$pageSolrDocument = $pageDocument;
|
||||
self::$pageMeilisearchDocument = $pageDocument;
|
||||
$documents[] = $pageDocument;
|
||||
$documents = $this->getAdditionalDocuments($pageDocument, $documents);
|
||||
$this->processDocuments($documents);
|
||||
|
||||
$pageIndexed = $this->addDocumentsToSolrIndex($documents);
|
||||
$this->documentsSentToSolr = $documents;
|
||||
$pageIndexed = $this->addDocumentsToMeilisearchIndex($documents);
|
||||
$this->documentsSentToMeilisearch = $documents;
|
||||
|
||||
return $pageIndexed;
|
||||
}
|
||||
@@ -261,11 +261,11 @@ class Typo3PageIndexer
|
||||
*/
|
||||
protected function applyIndexPagePostProcessors($pageDocument)
|
||||
{
|
||||
if (!is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['Indexer']['indexPagePostProcessPageDocument'])) {
|
||||
if (!is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['meilisearch']['Indexer']['indexPagePostProcessPageDocument'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['Indexer']['indexPagePostProcessPageDocument'] as $classReference) {
|
||||
foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['meilisearch']['Indexer']['indexPagePostProcessPageDocument'] as $classReference) {
|
||||
$postProcessor = GeneralUtility::makeInstance($classReference);
|
||||
if (!$postProcessor instanceof PageDocumentPostProcessor) {
|
||||
throw new \UnexpectedValueException(get_class($pageDocument) . ' must implement interface ' . PageDocumentPostProcessor::class, 1397739154);
|
||||
@@ -276,7 +276,7 @@ class Typo3PageIndexer
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the Solr document for the current page.
|
||||
* Builds the Meilisearch document for the current page.
|
||||
*
|
||||
* @return Document A document representing the page
|
||||
*/
|
||||
@@ -285,7 +285,7 @@ class Typo3PageIndexer
|
||||
$documentBuilder = GeneralUtility::makeInstance(Builder::class);
|
||||
$document = $documentBuilder->fromPage($this->page, $this->pageUrl, $this->pageAccessRootline, (string)$this->mountPointParameter);
|
||||
|
||||
self::$pageSolrDocumentId = $document['id'];
|
||||
self::$pageMeilisearchDocumentId = $document['id'];
|
||||
|
||||
return $document;
|
||||
}
|
||||
@@ -321,16 +321,16 @@ class Typo3PageIndexer
|
||||
* created by this indexer.
|
||||
*
|
||||
* @param Document $pageDocument The page document created by this indexer.
|
||||
* @return Document An Apache Solr document representing the currently indexed page
|
||||
* @return Document An Meilisearch document representing the currently indexed page
|
||||
*/
|
||||
protected function substitutePageDocument(Document $pageDocument)
|
||||
{
|
||||
if (!is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['Indexer']['indexPageSubstitutePageDocument'])) {
|
||||
if (!is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['meilisearch']['Indexer']['indexPageSubstitutePageDocument'])) {
|
||||
return $pageDocument;
|
||||
}
|
||||
|
||||
$indexConfigurationName = $this->getIndexConfigurationNameForCurrentPage();
|
||||
foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['Indexer']['indexPageSubstitutePageDocument'] as $classReference) {
|
||||
foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['meilisearch']['Indexer']['indexPageSubstitutePageDocument'] as $classReference) {
|
||||
$substituteIndexer = GeneralUtility::makeInstance($classReference);
|
||||
|
||||
if (!$substituteIndexer instanceof SubstitutePageIndexer) {
|
||||
@@ -375,11 +375,11 @@ class Typo3PageIndexer
|
||||
{
|
||||
$documents = $existingDocuments;
|
||||
|
||||
if (!is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['Indexer']['indexPageAddDocuments'])) {
|
||||
if (!is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['meilisearch']['Indexer']['indexPageAddDocuments'])) {
|
||||
return $documents;
|
||||
}
|
||||
|
||||
foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['Indexer']['indexPageAddDocuments'] as $classReference) {
|
||||
foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['meilisearch']['Indexer']['indexPageAddDocuments'] as $classReference) {
|
||||
$additionalIndexer = GeneralUtility::makeInstance($classReference);
|
||||
|
||||
if (!$additionalIndexer instanceof AdditionalPageIndexer) {
|
||||
@@ -412,12 +412,12 @@ class Typo3PageIndexer
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the collected documents to the Solr index.
|
||||
* Adds the collected documents to the Meilisearch index.
|
||||
*
|
||||
* @param array $documents An array of Document objects.
|
||||
* @return bool TRUE if documents were added successfully, FALSE otherwise
|
||||
*/
|
||||
protected function addDocumentsToSolrIndex(array $documents)
|
||||
protected function addDocumentsToMeilisearchIndex(array $documents)
|
||||
{
|
||||
$documentsAdded = false;
|
||||
|
||||
@@ -426,23 +426,23 @@ class Typo3PageIndexer
|
||||
}
|
||||
|
||||
try {
|
||||
$this->logger->log(SolrLogManager::INFO, 'Adding ' . count($documents) . ' documents.', $documents);
|
||||
$this->logger->log(MeilisearchLogManager::INFO, 'Adding ' . count($documents) . ' documents.', $documents);
|
||||
|
||||
// chunk adds by 20
|
||||
$documentChunks = array_chunk($documents, 20);
|
||||
foreach ($documentChunks as $documentChunk) {
|
||||
$response = $this->solrConnection->getWriteService()->addDocuments($documentChunk);
|
||||
$response = $this->meilisearchConnection->getWriteService()->addDocuments($documentChunk);
|
||||
if ($response->getHttpStatus() != 200) {
|
||||
throw new \RuntimeException('Solr Request failed.', 1331834983);
|
||||
throw new \RuntimeException('Meilisearch Request failed.', 1331834983);
|
||||
}
|
||||
}
|
||||
|
||||
$documentsAdded = true;
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->log(SolrLogManager::ERROR, $e->getMessage() . ' Error code: ' . $e->getCode());
|
||||
$this->logger->log(MeilisearchLogManager::ERROR, $e->getMessage() . ' Error code: ' . $e->getCode());
|
||||
|
||||
if ($this->configuration->getLoggingExceptions()) {
|
||||
$this->logger->log(SolrLogManager::ERROR, 'Exception while adding documents', [$e->__toString()]);
|
||||
$this->logger->log(MeilisearchLogManager::ERROR, 'Exception while adding documents', [$e->__toString()]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -490,12 +490,12 @@ class Typo3PageIndexer
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the documents that have been sent to Solr
|
||||
* Gets the documents that have been sent to Meilisearch
|
||||
*
|
||||
* @return array An array of Document objects
|
||||
*/
|
||||
public function getDocumentsSentToSolr()
|
||||
public function getDocumentsSentToMeilisearch()
|
||||
{
|
||||
return $this->documentsSentToSolr;
|
||||
return $this->documentsSentToMeilisearch;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user