first commit

This commit is contained in:
Sven Wappler 2021-04-24 04:44:44 +02:00
parent cadcc8edb4
commit 2c9e27b3b7
55 changed files with 333 additions and 3877 deletions

View File

@ -1,4 +1,5 @@
<?php <?php
namespace WapplerSystems\Meilisearch; namespace WapplerSystems\Meilisearch;
/*************************************************************** /***************************************************************
@ -66,9 +67,9 @@ class ConnectionManager implements SingletonInterface
/** /**
* @param SystemLanguageRepository $systemLanguageRepository * @param SystemLanguageRepository|null $systemLanguageRepository
* @param PagesRepositoryAtExtMeilisearch|null $pagesRepositoryAtExtMeilisearch * @param PagesRepositoryAtExtMeilisearch|null $pagesRepositoryAtExtMeilisearch
* @param SiteRepository $siteRepository * @param SiteRepository|null $siteRepository
*/ */
public function __construct( public function __construct(
SystemLanguageRepository $systemLanguageRepository = null, SystemLanguageRepository $systemLanguageRepository = null,
@ -84,17 +85,15 @@ class ConnectionManager implements SingletonInterface
/** /**
* Creates a meilisearch connection for read and write endpoints * Creates a meilisearch connection for read and write endpoints
* *
* @param array $readNodeConfiguration * @param array $siteConfiguration
* @param array $writeNodeConfiguration
* @return MeilisearchConnection|object * @return MeilisearchConnection|object
*/ */
public function getMeilisearchConnectionForNodes(array $readNodeConfiguration, array $writeNodeConfiguration) public function getMeilisearchConnectionForNode(array $siteConfiguration)
{ {
$connectionHash = md5(json_encode($readNodeConfiguration) . json_encode($writeNodeConfiguration)); $connectionHash = md5(json_encode($siteConfiguration));
if (!isset(self::$connections[$connectionHash])) { if (!isset(self::$connections[$connectionHash])) {
$readNode = $this->createClientFromArray($readNodeConfiguration); $node = $this->createClientFromArray($siteConfiguration);
$writeNode = $this->createClientFromArray($writeNodeConfiguration); self::$connections[$connectionHash] = GeneralUtility::makeInstance(MeilisearchConnection::class, $node, $siteConfiguration);
self::$connections[$connectionHash] = GeneralUtility::makeInstance(MeilisearchConnection::class, $readNode, $writeNode);
} }
return self::$connections[$connectionHash]; return self::$connections[$connectionHash];
} }
@ -107,11 +106,11 @@ class ConnectionManager implements SingletonInterface
*/ */
public function getConnectionFromConfiguration(array $config) public function getConnectionFromConfiguration(array $config)
{ {
if(empty($config['read']) && !empty($config['meilisearchHost'])) { if (empty($config) && !empty($config['meilisearchHost'])) {
throw new InvalidArgumentException('Invalid registry data please re-initialize your meilisearch connections'); throw new InvalidArgumentException('Invalid registry data please re-initialize your meilisearch connections');
} }
return $this->getMeilisearchConnectionForNodes($config['read'], $config['write']); return $this->getMeilisearchConnectionForNode($config);
} }
/** /**
@ -131,7 +130,7 @@ class ConnectionManager implements SingletonInterface
$config = $site->getMeilisearchConnectionConfiguration($language); $config = $site->getMeilisearchConnectionConfiguration($language);
$meilisearchConnection = $this->getConnectionFromConfiguration($config); $meilisearchConnection = $this->getConnectionFromConfiguration($config);
return $meilisearchConnection; return $meilisearchConnection;
} catch(InvalidArgumentException $e) { } catch (InvalidArgumentException $e) {
$noMeilisearchConnectionException = $this->buildNoConnectionExceptionForPageAndLanguage($pageId, $language); $noMeilisearchConnectionException = $this->buildNoConnectionExceptionForPageAndLanguage($pageId, $language);
throw $noMeilisearchConnectionException; throw $noMeilisearchConnectionException;
} }
@ -170,7 +169,7 @@ class ConnectionManager implements SingletonInterface
{ {
$meilisearchConnections = []; $meilisearchConnections = [];
foreach ($this->siteRepository->getAvailableSites() as $site) { foreach ($this->siteRepository->getAvailableSites() as $site) {
foreach ($site->getAllMeilisearchConnectionConfigurations() as $meilisearchConfiguration) { foreach ($site->getMeilisearchConnectionConfigurations() as $meilisearchConfiguration) {
$meilisearchConnections[] = $this->getConnectionFromConfiguration($meilisearchConfiguration); $meilisearchConnections[] = $this->getConnectionFromConfiguration($meilisearchConfiguration);
} }
} }
@ -182,18 +181,11 @@ class ConnectionManager implements SingletonInterface
* Gets all connections configured for a given site. * Gets all connections configured for a given site.
* *
* @param Site $site A TYPO3 site * @param Site $site A TYPO3 site
* @return MeilisearchConnection[] An array of Meilisearch connection objects (WapplerSystems\Meilisearch\System\Meilisearch\MeilisearchConnection) * @return MeilisearchConnection An array of Meilisearch connection objects (WapplerSystems\Meilisearch\System\Meilisearch\MeilisearchConnection)
* @throws NoMeilisearchConnectionFoundException
*/ */
public function getConnectionsBySite(Site $site) public function getConnectionBySite(Site $site)
{ {
$connections = []; return $this->getConnectionFromConfiguration($site->getMeilisearchConnectionConfiguration());
foreach ($site->getAllMeilisearchConnectionConfigurations() as $languageId => $meilisearchConnectionConfiguration) {
$connections[$languageId] = $this->getConnectionFromConfiguration($meilisearchConnectionConfiguration);
}
return $connections;
} }
/** /**
@ -211,7 +203,7 @@ class ConnectionManager implements SingletonInterface
. $connection['read']['host'] . ':' . $connection['read']['host'] . ':'
. $connection['read']['port'] . $connection['read']['port']
. $connection['read']['path'] . $connection['read']['path']
.' - Write node: ' . ' - Write node: '
. $connection['write']['host'] . ':' . $connection['write']['host'] . ':'
. $connection['write']['port'] . $connection['write']['port']
. $connection['write']['path']; . $connection['write']['path'];
@ -266,8 +258,9 @@ class ConnectionManager implements SingletonInterface
} }
private function createClientFromArray(array $configuration) { private function createClientFromArray(array $configuration)
return new Client(($configuration['scheme'] ?? 'http') . '://'.$configuration['host'].':'.$configuration['port'], $configuration['apiKey'] ?? null, new \TYPO3\CMS\Core\Http\Client(\TYPO3\CMS\Core\Http\Client\GuzzleClientFactory::getClient())); {
return new Client(($configuration['scheme'] ?? 'http') . '://' . $configuration['host'] . ':' . $configuration['port'], $configuration['apiKey'] ?? null, new \TYPO3\CMS\Core\Http\Client(\TYPO3\CMS\Core\Http\Client\GuzzleClientFactory::getClient()));
} }

View File

@ -245,7 +245,7 @@ abstract class AbstractModuleController extends ActionController
} }
$this->initializeSelectedMeilisearchCoreConnection(); $this->initializeSelectedMeilisearchCoreConnection();
$cores = $this->meilisearchConnectionManager->getConnectionsBySite($site); $cores = $this->meilisearchConnectionManager->getConnectionBySite($site);
foreach ($cores as $core) { foreach ($cores as $core) {
$coreAdmin = $core->getAdminService(); $coreAdmin = $core->getAdminService();
$menuItem = $this->coreSelectorMenu->makeMenuItem(); $menuItem = $this->coreSelectorMenu->makeMenuItem();
@ -295,7 +295,7 @@ abstract class AbstractModuleController extends ActionController
{ {
$moduleData = $this->moduleDataStorageService->loadModuleData(); $moduleData = $this->moduleDataStorageService->loadModuleData();
$meilisearchCoreConnections = $this->meilisearchConnectionManager->getConnectionsBySite($this->selectedSite); $meilisearchCoreConnections = $this->meilisearchConnectionManager->getConnectionBySite($this->selectedSite);
$currentMeilisearchCorePath = $moduleData->getCore(); $currentMeilisearchCorePath = $moduleData->getCore();
if (empty($currentMeilisearchCorePath)) { if (empty($currentMeilisearchCorePath)) {
$this->initializeFirstAvailableMeilisearchCoreConnection($meilisearchCoreConnections, $moduleData); $this->initializeFirstAvailableMeilisearchCoreConnection($meilisearchCoreConnections, $moduleData);

View File

@ -1,386 +0,0 @@
<?php
namespace WapplerSystems\Meilisearch\Controller\Backend\Search;
/***************************************************************
* Copyright notice
*
* (c) 2010-2017 dkd Internet Service GmbH <meilisearchs-support@dkd.de>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use WapplerSystems\Meilisearch\Utility\ManagedResourcesUtility;
use TYPO3\CMS\Backend\Template\ModuleTemplate;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
/**
* Manage Synonyms and Stop words in Backend Module
* @property \TYPO3\CMS\Extbase\Mvc\Web\Response $response
*/
class CoreOptimizationModuleController extends AbstractModuleController
{
/**
* Set up the doc header properly here
*
* @param ViewInterface $view
* @return void
*/
protected function initializeView(ViewInterface $view)
{
parent::initializeView($view);
$this->generateCoreSelectorMenuUsingPageTree();
/* @var ModuleTemplate $module */ // holds the state of chosen tab
$module = $this->objectManager->get(ModuleTemplate::class);
$coreOptimizationTabs = $module->getDynamicTabMenu([], 'coreOptimization');
$this->view->assign('tabs', $coreOptimizationTabs);
}
/**
* Gets synonyms and stopwords for the currently selected core
*
* @return void
*/
public function indexAction()
{
if ($this->selectedMeilisearchCoreConnection === null) {
$this->view->assign('can_not_proceed', true);
return;
}
$synonyms = [];
$coreAdmin = $this->selectedMeilisearchCoreConnection->getAdminService();
$rawSynonyms = $coreAdmin->getSynonyms();
foreach ($rawSynonyms as $baseWord => $synonymList) {
$synonyms[$baseWord] = implode(', ', $synonymList);
}
$stopWords = $coreAdmin->getStopWords();
$this->view->assignMultiple([
'synonyms' => $synonyms,
'stopWords' => implode(PHP_EOL, $stopWords),
'stopWordsCount' => count($stopWords)
]);
}
/**
* Add synonyms to selected core
*
* @param string $baseWord
* @param string $synonyms
* @param bool $overrideExisting
* @return void
*/
public function addSynonymsAction(string $baseWord, string $synonyms, $overrideExisting)
{
if (empty($baseWord) || empty($synonyms)) {
$this->addFlashMessage(
'Please provide a base word and synonyms.',
'Missing parameter',
FlashMessage::ERROR
);
} else {
$baseWord = mb_strtolower($baseWord);
$synonyms = mb_strtolower($synonyms);
$coreAdmin = $this->selectedMeilisearchCoreConnection->getAdminService();
if ($overrideExisting && $coreAdmin->getSynonyms($baseWord)) {
$coreAdmin->deleteSynonym($baseWord);
}
$coreAdmin->addSynonym($baseWord, GeneralUtility::trimExplode(',', $synonyms, true));
$coreAdmin->reloadCore();
$this->addFlashMessage(
'"' . $synonyms . '" added as synonyms for base word "' . $baseWord . '"'
);
}
$this->redirect('index');
}
/**
* @param string $fileFormat
* @return void
*/
public function exportStopWordsAction($fileFormat = 'txt')
{
$coreAdmin = $this->selectedMeilisearchCoreConnection->getAdminService();
$this->exportFile(
implode(PHP_EOL, $coreAdmin->getStopWords()),
'stopwords',
$fileFormat
);
}
/**
* Exports synonyms to a download file.
*
* @param string $fileFormat
* @return string
*/
public function exportSynonymsAction($fileFormat = 'txt')
{
$coreAdmin = $this->selectedMeilisearchCoreConnection->getAdminService();
$synonyms = $coreAdmin->getSynonyms();
return $this->exportFile(ManagedResourcesUtility::exportSynonymsToTxt($synonyms), 'synonyms', $fileFormat);
}
/**
* @param array $synonymFileUpload
* @param bool $overrideExisting
* @param bool $deleteSynonymsBefore
* @return void
*/
public function importSynonymListAction(array $synonymFileUpload, $overrideExisting, $deleteSynonymsBefore)
{
if ($deleteSynonymsBefore) {
$this->deleteAllSynonyms();
}
$fileLines = ManagedResourcesUtility::importSynonymsFromPlainTextContents($synonymFileUpload);
$synonymCount = 0;
$coreAdmin = $this->selectedMeilisearchCoreConnection->getAdminService();
foreach ($fileLines as $baseWord => $synonyms) {
if (!isset($baseWord) || empty($synonyms)) {
continue;
}
$this->deleteExistingSynonym($overrideExisting, $deleteSynonymsBefore, $baseWord);
$coreAdmin->addSynonym($baseWord, $synonyms);
$synonymCount++;
}
$coreAdmin->reloadCore();
$this->addFlashMessage(
$synonymCount . ' synonyms imported.'
);
$this->redirect('index');
}
/**
* @param array $stopwordsFileUpload
* @param bool $replaceStopwords
* @return void
*/
public function importStopWordListAction(array $stopwordsFileUpload, $replaceStopwords)
{
$this->saveStopWordsAction(
ManagedResourcesUtility::importStopwordsFromPlainTextContents($stopwordsFileUpload),
$replaceStopwords
);
}
/**
* Delete complete synonym list
*
* @return void
*/
public function deleteAllSynonymsAction()
{
$allSynonymsCouldBeDeleted = $this->deleteAllSynonyms();
$coreAdmin = $this->selectedMeilisearchCoreConnection->getAdminService();
$reloadResponse = $coreAdmin->reloadCore();
if ($allSynonymsCouldBeDeleted
&& $reloadResponse->getHttpStatus() == 200
) {
$this->addFlashMessage(
'All synonym removed.'
);
} else {
$this->addFlashMessage(
'Failed to remove all synonyms.',
'An error occurred',
FlashMessage::ERROR
);
}
$this->redirect('index');
}
/**
* Deletes a synonym mapping by its base word.
*
* @param string $baseWord Synonym mapping base word
*/
public function deleteSynonymsAction($baseWord)
{
$coreAdmin = $this->selectedMeilisearchCoreConnection->getAdminService();
$deleteResponse = $coreAdmin->deleteSynonym($baseWord);
$reloadResponse = $coreAdmin->reloadCore();
if ($deleteResponse->getHttpStatus() == 200
&& $reloadResponse->getHttpStatus() == 200
) {
$this->addFlashMessage(
'Synonym removed.'
);
} else {
$this->addFlashMessage(
'Failed to remove synonym.',
'An error occurred',
FlashMessage::ERROR
);
}
$this->redirect('index');
}
/**
* Saves the edited stop word list to Meilisearch
*
* @param string $stopWords
* @param bool $replaceStopwords
* @return void
*/
public function saveStopWordsAction(string $stopWords, $replaceStopwords = true)
{
// lowercase stopword before saving because terms get lowercased before stopword filtering
$newStopWords = mb_strtolower($stopWords);
$newStopWords = GeneralUtility::trimExplode("\n", $newStopWords, true);
$coreAdmin = $this->selectedMeilisearchCoreConnection->getAdminService();
$oldStopWords = $coreAdmin->getStopWords();
if ($replaceStopwords) {
$removedStopWords = array_diff($oldStopWords, $newStopWords);
$wordsRemoved = $this->removeStopsWordsFromIndex($removedStopWords);
} else {
$wordsRemoved = true;
}
$wordsAdded = true;
$addedStopWords = array_diff($newStopWords, $oldStopWords);
if (!empty($addedStopWords)) {
$wordsAddedResponse = $coreAdmin->addStopWords($addedStopWords);
$wordsAdded = ($wordsAddedResponse->getHttpStatus() == 200);
}
$reloadResponse = $coreAdmin->reloadCore();
if ($wordsRemoved && $wordsAdded && $reloadResponse->getHttpStatus() == 200) {
$this->addFlashMessage(
'Stop Words Updated.'
);
}
$this->redirect('index');
}
/**
* @param string $content
* @param string $type
* @param string $fileExtension
* @return string
*/
protected function exportFile($content, $type = 'synonyms', $fileExtension = 'txt') : string
{
$coreAdmin = $this->selectedMeilisearchCoreConnection->getAdminService();
$this->response->setHeader('Content-type', 'text/plain', true);
$this->response->setHeader('Cache-control', 'public', true);
$this->response->setHeader('Content-Description', 'File transfer', true);
$this->response->setHeader(
'Content-disposition',
'attachment; filename =' . $type . '_' .
$coreAdmin->getPrimaryEndpoint()->getCore() . '.' . $fileExtension,
true
);
$this->response->setContent($content);
$this->sendFileResponse();
}
/**
* This method send the headers and content and does an exit, since without the exit TYPO3 produces and error.
* @return void
*/
protected function sendFileResponse()
{
$this->response->sendHeaders();
$this->response->send();
$this->response->shutdown();
exit();
}
/**
* Delete complete synonym list form meilisearch
*
* @return bool
*/
protected function deleteAllSynonyms() : bool
{
$coreAdmin = $this->selectedMeilisearchCoreConnection->getAdminService();
$synonyms = $coreAdmin->getSynonyms();
$allSynonymsCouldBeDeleted = true;
foreach ($synonyms as $baseWord => $synonym) {
$deleteResponse = $coreAdmin->deleteSynonym($baseWord);
$allSynonymsCouldBeDeleted = $allSynonymsCouldBeDeleted && $deleteResponse->getHttpStatus() == 200;
}
return $allSynonymsCouldBeDeleted;
}
/**
* @param $stopwordsToRemove
* @return bool
*/
protected function removeStopsWordsFromIndex($stopwordsToRemove) : bool
{
$wordsRemoved = true;
$coreAdmin = $this->selectedMeilisearchCoreConnection->getAdminService();
foreach ($stopwordsToRemove as $word) {
$response = $coreAdmin->deleteStopWord($word);
if ($response->getHttpStatus() != 200) {
$wordsRemoved = false;
$this->addFlashMessage(
'Failed to remove stop word "' . $word . '".',
'An error occurred',
FlashMessage::ERROR
);
break;
}
}
return $wordsRemoved;
}
/**
* Delete synonym entry if selceted before
* @param bool $overrideExisting
* @param bool $deleteSynonymsBefore
* @param string $baseWord
*/
protected function deleteExistingSynonym($overrideExisting, $deleteSynonymsBefore, $baseWord)
{
$coreAdmin = $this->selectedMeilisearchCoreConnection->getAdminService();
if (!$deleteSynonymsBefore &&
$overrideExisting &&
$coreAdmin->getSynonyms($baseWord)
) {
$coreAdmin->deleteSynonym($baseWord);
}
}
}

View File

@ -77,7 +77,7 @@ class IndexAdministrationModuleController extends AbstractModuleController
*/ */
public function indexAction() public function indexAction()
{ {
if ($this->selectedSite === null || empty($this->meilisearchConnectionManager->getConnectionsBySite($this->selectedSite))) { if ($this->selectedSite === null || empty($this->meilisearchConnectionManager->getConnectionBySite($this->selectedSite))) {
$this->view->assign('can_not_proceed', true); $this->view->assign('can_not_proceed', true);
} }
} }
@ -93,7 +93,7 @@ class IndexAdministrationModuleController extends AbstractModuleController
try { try {
$affectedCores = []; $affectedCores = [];
$meilisearchServers = $this->meilisearchConnectionManager->getConnectionsBySite($this->selectedSite); $meilisearchServers = $this->meilisearchConnectionManager->getConnectionBySite($this->selectedSite);
foreach ($meilisearchServers as $meilisearchServer) { foreach ($meilisearchServers as $meilisearchServer) {
$writeService = $meilisearchServer->getWriteService(); $writeService = $meilisearchServer->getWriteService();
/* @var $meilisearchServer MeilisearchConnection */ /* @var $meilisearchServer MeilisearchConnection */
@ -134,7 +134,7 @@ class IndexAdministrationModuleController extends AbstractModuleController
{ {
$coresReloaded = true; $coresReloaded = true;
$reloadedCores = []; $reloadedCores = [];
$meilisearchServers = $this->meilisearchConnectionManager->getConnectionsBySite($this->selectedSite); $meilisearchServers = $this->meilisearchConnectionManager->getConnectionBySite($this->selectedSite);
foreach ($meilisearchServers as $meilisearchServer) { foreach ($meilisearchServers as $meilisearchServer) {
/* @var $meilisearchServer MeilisearchConnection */ /* @var $meilisearchServer MeilisearchConnection */

View File

@ -114,7 +114,7 @@ class IndexQueueModuleController extends AbstractModuleController
*/ */
protected function canQueueSelectedSite() protected function canQueueSelectedSite()
{ {
if ($this->selectedSite === null || empty($this->meilisearchConnectionManager->getConnectionsBySite($this->selectedSite))) { if ($this->selectedSite === null || empty($this->meilisearchConnectionManager->getConnectionBySite($this->selectedSite))) {
return false; return false;
} }
$enabledIndexQueueConfigurationNames = $this->selectedSite->getMeilisearchConfiguration()->getEnabledIndexQueueConfigurationNames(); $enabledIndexQueueConfigurationNames = $this->selectedSite->getMeilisearchConfiguration()->getEnabledIndexQueueConfigurationNames();

View File

@ -24,10 +24,11 @@ namespace WapplerSystems\Meilisearch\Controller\Backend\Search;
* This copyright notice MUST APPEAR in all copies of the script! * This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/ ***************************************************************/
use TYPO3\CMS\Core\Utility\DebugUtility;
use WapplerSystems\Meilisearch\Api; use WapplerSystems\Meilisearch\Api;
use WapplerSystems\Meilisearch\ConnectionManager; use WapplerSystems\Meilisearch\ConnectionManager;
use WapplerSystems\Meilisearch\Domain\Search\Statistics\StatisticsRepository; use WapplerSystems\Meilisearch\Domain\Search\Statistics\StatisticsRepository;
use WapplerSystems\Meilisearch\Domain\Search\ApacheMeilisearchDocument\Repository; use WapplerSystems\Meilisearch\Domain\Search\MeilisearchDocument\Repository;
use WapplerSystems\Meilisearch\System\Meilisearch\ResponseAdapter; use WapplerSystems\Meilisearch\System\Meilisearch\ResponseAdapter;
use WapplerSystems\Meilisearch\System\Validator\Path; use WapplerSystems\Meilisearch\System\Validator\Path;
use TYPO3\CMS\Backend\Template\ModuleTemplate; use TYPO3\CMS\Backend\Template\ModuleTemplate;
@ -93,8 +94,8 @@ class InfoModuleController extends AbstractModuleController
$this->collectConnectionInfos(); $this->collectConnectionInfos();
$this->collectStatistics(); $this->collectStatistics();
$this->collectIndexFieldsInfo(); //$this->collectIndexFieldsInfo();
$this->collectIndexInspectorInfo(); //$this->collectIndexInspectorInfo();
} }
/** /**
@ -122,29 +123,21 @@ class InfoModuleController extends AbstractModuleController
$missingHosts = []; $missingHosts = [];
$invalidPaths = []; $invalidPaths = [];
/* @var Path $path */ $connection = $this->meilisearchConnectionManager->getConnectionBySite($this->selectedSite);
$path = GeneralUtility::makeInstance(Path::class);
$connections = $this->meilisearchConnectionManager->getConnectionsBySite($this->selectedSite);
if (empty($connections)) { if (empty($connection)) {
$this->view->assign('can_not_proceed', true); $this->view->assign('can_not_proceed', true);
return; return;
} }
foreach ($connections as $connection) {
$coreAdmin = $connection->getAdminService(); $coreAdmin = $connection->getAdminService();
$coreUrl = (string)$coreAdmin;
if ($coreAdmin->ping()) { if ($coreAdmin->ping()) {
$connectedHosts[] = $coreUrl; $connectedHosts[] = $coreAdmin;
} else { } else {
$missingHosts[] = $coreUrl; $missingHosts[] = $coreAdmin;
} }
if (!$path->isValidMeilisearchPath($coreAdmin->getCorePath())) {
$invalidPaths[] = $coreAdmin->getCorePath();
}
}
$this->view->assignMultiple([ $this->view->assignMultiple([
'site' => $this->selectedSite, 'site' => $this->selectedSite,
@ -204,36 +197,15 @@ class InfoModuleController extends AbstractModuleController
{ {
$indexFieldsInfoByCorePaths = []; $indexFieldsInfoByCorePaths = [];
$meilisearchCoreConnections = $this->meilisearchConnectionManager->getConnectionsBySite($this->selectedSite); $meilisearchCoreConnections = $this->meilisearchConnectionManager->getConnectionBySite($this->selectedSite);
foreach ($meilisearchCoreConnections as $meilisearchCoreConnection) { foreach ($meilisearchCoreConnections as $i => $meilisearchCoreConnection) {
$coreAdmin = $meilisearchCoreConnection->getAdminService(); $coreAdmin = $meilisearchCoreConnection->getAdminService();
$indexFieldsInfo = [
'corePath' => $coreAdmin->getCorePath()
];
if ($coreAdmin->ping()) { if ($coreAdmin->ping()) {
$lukeData = $coreAdmin->getLukeMetaData();
/* @var Registry $registry */
$registry = GeneralUtility::makeInstance(Registry::class);
$limit = $registry->get('tx_meilisearch', 'luke.limit', 20000);
$limitNote = '';
if (isset($lukeData->index->numDocs) && $lukeData->index->numDocs > $limit) {
$limitNote = '<em>Too many terms</em>';
} elseif (isset($lukeData->index->numDocs)) {
$limitNote = 'Nothing indexed';
// below limit, so we can get more data
// Note: we use 2 since 1 fails on Ubuntu Hardy.
$lukeData = $coreAdmin->getLukeMetaData(2);
}
$fields = $this->getFields($lukeData, $limitNote);
$coreMetrics = $this->getCoreMetrics($lukeData, $fields);
$indexFieldsInfo['noError'] = 'OK'; $indexFieldsInfo['noError'] = 'OK';
$indexFieldsInfo['fields'] = $fields; $indexFieldsInfo['coreMetrics'] = 'dedede';
$indexFieldsInfo['coreMetrics'] = $coreMetrics;
} else { } else {
$indexFieldsInfo['noError'] = null; $indexFieldsInfo['noError'] = null;
@ -243,7 +215,7 @@ class InfoModuleController extends AbstractModuleController
FlashMessage::ERROR FlashMessage::ERROR
); );
} }
$indexFieldsInfoByCorePaths[$coreAdmin->getCorePath()] = $indexFieldsInfo; $indexFieldsInfoByCorePaths[$i] = $indexFieldsInfo;
} }
$this->view->assign('indexFieldsInfoByCorePaths', $indexFieldsInfoByCorePaths); $this->view->assign('indexFieldsInfoByCorePaths', $indexFieldsInfoByCorePaths);
} }
@ -255,7 +227,7 @@ class InfoModuleController extends AbstractModuleController
*/ */
protected function collectIndexInspectorInfo() protected function collectIndexInspectorInfo()
{ {
$meilisearchCoreConnections = $this->meilisearchConnectionManager->getConnectionsBySite($this->selectedSite); $meilisearchCoreConnections = $this->meilisearchConnectionManager->getConnectionBySite($this->selectedSite);
$documentsByCoreAndType = []; $documentsByCoreAndType = [];
foreach ($meilisearchCoreConnections as $languageId => $meilisearchCoreConnection) { foreach ($meilisearchCoreConnections as $languageId => $meilisearchCoreConnection) {
$coreAdmin = $meilisearchCoreConnection->getAdminService(); $coreAdmin = $meilisearchCoreConnection->getAdminService();

View File

@ -33,8 +33,6 @@ use WapplerSystems\Meilisearch\Domain\Site\Site;
use WapplerSystems\Meilisearch\System\Configuration\TypoScriptConfiguration; use WapplerSystems\Meilisearch\System\Configuration\TypoScriptConfiguration;
use WapplerSystems\Meilisearch\System\Logging\MeilisearchLogManager; use WapplerSystems\Meilisearch\System\Logging\MeilisearchLogManager;
use WapplerSystems\Meilisearch\Task\IndexQueueWorkerTask; use WapplerSystems\Meilisearch\Task\IndexQueueWorkerTask;
use Solarium\Exception\HttpException;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\SignalSlot\Dispatcher; use TYPO3\CMS\Extbase\SignalSlot\Dispatcher;
@ -140,7 +138,7 @@ class IndexService
$this->emitSignal('afterIndexItems', [$itemsToIndex, $this->getContextTask(), $indexRunId]); $this->emitSignal('afterIndexItems', [$itemsToIndex, $this->getContextTask(), $indexRunId]);
if ($enableCommitsSetting && count($itemsToIndex) > 0) { if ($enableCommitsSetting && count($itemsToIndex) > 0) {
$meilisearchServers = GeneralUtility::makeInstance(ConnectionManager::class)->getConnectionsBySite($this->site); $meilisearchServers = GeneralUtility::makeInstance(ConnectionManager::class)->getConnectionBySite($this->site);
foreach ($meilisearchServers as $meilisearchServer) { foreach ($meilisearchServers as $meilisearchServer) {
try { try {
$meilisearchServer->getWriteService()->commit(false, false, false); $meilisearchServer->getWriteService()->commit(false, false, false);

View File

@ -121,7 +121,7 @@ abstract class AbstractStrategy
$enableCommitsSetting = $site->getMeilisearchConfiguration()->getEnableCommits(); $enableCommitsSetting = $site->getMeilisearchConfiguration()->getEnableCommits();
$siteHash = $site->getSiteHash(); $siteHash = $site->getSiteHash();
// a site can have multiple connections (cores / languages) // a site can have multiple connections (cores / languages)
$meilisearchConnections = $this->connectionManager->getConnectionsBySite($site); $meilisearchConnections = $this->connectionManager->getConnectionBySite($site);
if ($language > 0) { if ($language > 0) {
$meilisearchConnections = [$language => $meilisearchConnections[$language]]; $meilisearchConnections = [$language => $meilisearchConnections[$language]];
} }

View File

@ -1,5 +1,5 @@
<?php <?php
namespace WapplerSystems\Meilisearch\Domain\Search\ApacheMeilisearchDocument; namespace WapplerSystems\Meilisearch\Domain\Search\MeilisearchDocument;
/*************************************************************** /***************************************************************
* Copyright notice * Copyright notice
@ -35,7 +35,7 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
/** /**
* Builder class to build an ApacheMeilisearchDocument * Builder class to build an MeilisearchDocument
* *
* Responsible to build \WapplerSystems\Meilisearch\System\Meilisearch\Document\Document * Responsible to build \WapplerSystems\Meilisearch\System\Meilisearch\Document\Document
* *
@ -64,38 +64,37 @@ class Builder
* @param string $url * @param string $url
* @param Rootline $pageAccessRootline * @param Rootline $pageAccessRootline
* @param string $mountPointParameter * @param string $mountPointParameter
* @return Document|object * @return array
*/ */
public function fromPage(TypoScriptFrontendController $page, $url, Rootline $pageAccessRootline, $mountPointParameter): Document public function fromPage(TypoScriptFrontendController $page, $url, Rootline $pageAccessRootline, $mountPointParameter): array
{ {
/* @var $document Document */ $document = [];
$document = GeneralUtility::makeInstance(Document::class);
$site = $this->getSiteByPageId($page->id); $site = $this->getSiteByPageId($page->id);
$pageRecord = $page->page; $pageRecord = $page->page;
$accessGroups = $this->getDocumentIdGroups($pageAccessRootline); $accessGroups = $this->getDocumentIdGroups($pageAccessRootline);
$documentId = $this->getPageDocumentId($page, $accessGroups, $mountPointParameter); $documentId = $this->getPageDocumentId($page, $accessGroups, $mountPointParameter);
$document->setField('id', $documentId); $document['id'] = $documentId;
$document->setField('site', $site->getDomain()); $document['site'] = $site->getDomain();
$document->setField('siteHash', $site->getSiteHash()); $document['siteHash'] = $site->getSiteHash();
$document->setField('appKey', 'EXT:meilisearch'); $document['appKey'] = 'EXT:meilisearch';
$document->setField('type', 'pages'); $document['type'] = 'pages';
// system fields // system fields
$document->setField('uid', $page->id); $document['uid'] = $page->id;
$document->setField('pid', $pageRecord['pid']); $document['pid'] = $pageRecord['pid'];
// variantId // variantId
$variantId = $this->variantIdBuilder->buildFromTypeAndUid('pages', $page->id); $variantId = $this->variantIdBuilder->buildFromTypeAndUid('pages', $page->id);
$document->setField('variantId', $variantId); $document['variantId'] = $variantId;
$document->setField('typeNum', $page->type); $document['typeNum'] = $page->type;
$document->setField('created', $pageRecord['crdate']); $document['created'] = $pageRecord['crdate'];
$document->setField('changed', $pageRecord['SYS_LASTCHANGED']); $document['changed'] = $pageRecord['SYS_LASTCHANGED'];
$rootline = $this->getRootLineFieldValue($page->id, $mountPointParameter); $rootline = $this->getRootLineFieldValue($page->id, $mountPointParameter);
$document->setField('rootline', $rootline); $document['rootline'] = $rootline;
// access // access
$this->addAccessField($document, $pageAccessRootline); $this->addAccessField($document, $pageAccessRootline);
@ -104,14 +103,14 @@ class Builder
// content // content
// @extensionScannerIgnoreLine // @extensionScannerIgnoreLine
$contentExtractor = $this->getExtractorForPageContent($page->content); $contentExtractor = $this->getExtractorForPageContent($page->content);
$document->setField('title', $contentExtractor->getPageTitle()); $document['title'] = $contentExtractor->getPageTitle();
$document->setField('subTitle', $pageRecord['subtitle']); $document['subTitle'] = $pageRecord['subtitle'];
$document->setField('navTitle', $pageRecord['nav_title']); $document['navTitle'] = $pageRecord['nav_title'];
$document->setField('author', $pageRecord['author']); $document['author'] = $pageRecord['author'];
$document->setField('description', $pageRecord['description']); $document['description'] = $pageRecord['description'];
$document->setField('abstract', $pageRecord['abstract']); $document['abstract'] = $pageRecord['abstract'];
$document->setField('content', $contentExtractor->getIndexableContent()); $document['content'] = $contentExtractor->getIndexableContent();
$document->setField('url', $url); $document['url'] = $url;
$this->addKeywordsField($document, $pageRecord); $this->addKeywordsField($document, $pageRecord);
$this->addTagContentFields($document, $contentExtractor->getTagContent()); $this->addTagContentFields($document, $contentExtractor->getTagContent());
@ -127,9 +126,9 @@ class Builder
* @param string $type * @param string $type
* @param int $rootPageUid * @param int $rootPageUid
* @param string $accessRootLine * @param string $accessRootLine
* @return Document * @return array
*/ */
public function fromRecord(array $itemRecord, string $type, int $rootPageUid, string $accessRootLine): Document public function fromRecord(array $itemRecord, string $type, int $rootPageUid, string $accessRootLine): array
{ {
/* @var $document Document */ /* @var $document Document */
$document = GeneralUtility::makeInstance(Document::class); $document = GeneralUtility::makeInstance(Document::class);
@ -139,36 +138,36 @@ class Builder
$documentId = $this->getDocumentId($type, $site->getRootPageId(), $itemRecord['uid']); $documentId = $this->getDocumentId($type, $site->getRootPageId(), $itemRecord['uid']);
// required fields // required fields
$document->setField('id', $documentId); $document['id'] = $documentId;
$document->setField('type', $type); $document['type'] = $type;
$document->setField('appKey', 'EXT:meilisearch'); $document['appKey'] = 'EXT:meilisearch';
// site, siteHash // site, siteHash
$document->setField('site', $site->getDomain()); $document['site'] = $site->getDomain();
$document->setField('siteHash', $site->getSiteHash()); $document['siteHash'] = $site->getSiteHash();
// uid, pid // uid, pid
$document->setField('uid', $itemRecord['uid']); $document['uid'] = $itemRecord['uid'];
$document->setField('pid', $itemRecord['pid']); $document['pid'] = $itemRecord['pid'];
// variantId // variantId
$variantId = $this->variantIdBuilder->buildFromTypeAndUid($type, $itemRecord['uid']); $variantId = $this->variantIdBuilder->buildFromTypeAndUid($type, $itemRecord['uid']);
$document->setField('variantId', $variantId); $document['variantId'] = $variantId;
// created, changed // created, changed
if (!empty($GLOBALS['TCA'][$type]['ctrl']['crdate'])) { if (!empty($GLOBALS['TCA'][$type]['ctrl']['crdate'])) {
$document->setField('created', $itemRecord[$GLOBALS['TCA'][$type]['ctrl']['crdate']]); $document['created'] = $itemRecord[$GLOBALS['TCA'][$type]['ctrl']['crdate']];
} }
if (!empty($GLOBALS['TCA'][$type]['ctrl']['tstamp'])) { if (!empty($GLOBALS['TCA'][$type]['ctrl']['tstamp'])) {
$document->setField('changed', $itemRecord[$GLOBALS['TCA'][$type]['ctrl']['tstamp']]); $document['changed'] = $itemRecord[$GLOBALS['TCA'][$type]['ctrl']['tstamp']];
} }
// access, endtime // access, endtime
$document->setField('access', $accessRootLine); $document['access'] = $accessRootLine;
if (!empty($GLOBALS['TCA'][$type]['ctrl']['enablecolumns']['endtime']) if (!empty($GLOBALS['TCA'][$type]['ctrl']['enablecolumns']['endtime'])
&& $itemRecord[$GLOBALS['TCA'][$type]['ctrl']['enablecolumns']['endtime']] != 0 && $itemRecord[$GLOBALS['TCA'][$type]['ctrl']['enablecolumns']['endtime']] != 0
) { ) {
$document->setField('endtime', $itemRecord[$GLOBALS['TCA'][$type]['ctrl']['enablecolumns']['endtime']]); $document['endtime'] = $itemRecord[$GLOBALS['TCA'][$type]['ctrl']['enablecolumns']['endtime']];
} }
return $document; return $document;
@ -255,37 +254,37 @@ class Builder
/** /**
* Adds the access field to the document if needed. * Adds the access field to the document if needed.
* *
* @param Document $document * @param array $document
* @param Rootline $pageAccessRootline * @param Rootline $pageAccessRootline
*/ */
protected function addAccessField(Document $document, Rootline $pageAccessRootline) protected function addAccessField(array &$document, Rootline $pageAccessRootline)
{ {
$access = (string)$pageAccessRootline; $access = (string)$pageAccessRootline;
if (trim($access) !== '') { if (trim($access) !== '') {
$document->setField('access', $access); $document['access'] = $access;
} }
} }
/** /**
* Adds the endtime field value to the Document. * Adds the endtime field value to the Document.
* *
* @param Document $document * @param array $document
* @param array $pageRecord * @param array $pageRecord
*/ */
protected function addEndtimeField(Document $document, $pageRecord) protected function addEndtimeField(array &$document, $pageRecord)
{ {
if ($pageRecord['endtime']) { if ($pageRecord['endtime']) {
$document->setField('endtime', $pageRecord['endtime']); $document['endtime'] = $pageRecord['endtime'];
} }
} }
/** /**
* Adds keywords, multi valued. * Adds keywords, multi valued.
* *
* @param Document $document * @param array $document
* @param array $pageRecord * @param array $pageRecord
*/ */
protected function addKeywordsField(Document $document, $pageRecord) protected function addKeywordsField(array &$document, $pageRecord)
{ {
if (!isset($pageRecord['keywords'])) { if (!isset($pageRecord['keywords'])) {
return; return;
@ -293,20 +292,20 @@ class Builder
$keywords = array_unique(GeneralUtility::trimExplode(',', $pageRecord['keywords'], true)); $keywords = array_unique(GeneralUtility::trimExplode(',', $pageRecord['keywords'], true));
foreach ($keywords as $keyword) { foreach ($keywords as $keyword) {
$document->addField('keywords', $keyword); $document['keywords'] = $keyword;
} }
} }
/** /**
* Add content from several tags like headers, anchors, ... * Add content from several tags like headers, anchors, ...
* *
* @param Document $document * @param array $document
* @param array $tagContent * @param array $tagContent
*/ */
protected function addTagContentFields(Document $document, $tagContent = []) protected function addTagContentFields(array &$document, $tagContent = [])
{ {
foreach ($tagContent as $fieldName => $fieldValue) { foreach ($tagContent as $fieldName => $fieldValue) {
$document->setField($fieldName, $fieldValue); $document[$fieldName] = $fieldValue;
} }
} }
} }

View File

@ -1,5 +1,5 @@
<?php <?php
namespace WapplerSystems\Meilisearch\Domain\Search\ApacheMeilisearchDocument; namespace WapplerSystems\Meilisearch\Domain\Search\MeilisearchDocument;
/*************************************************************** /***************************************************************
* Copyright notice * Copyright notice

View File

@ -1,47 +0,0 @@
<?php
namespace WapplerSystems\Meilisearch\Domain\Search\Query;
/***************************************************************
* Copyright notice
*
* (c) 2010-2015 Ingo Renner <ingo@typo3.org>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use Solarium\QueryType\Extract\Query as SolariumExtractQuery;
/**
* Specialized query for content extraction using Meilisearch Cell
*
*/
class ExtractingQuery extends SolariumExtractQuery
{
/**
* Constructor
*
* @param string $file Absolute path to the file to extract content and meta data from.
*/
public function __construct($file)
{
parent::__construct();
$this->setFile($file);
$this->addParam('extractFormat', 'text');
}
}

View File

@ -1,47 +0,0 @@
<?php
namespace WapplerSystems\Meilisearch\Domain\Search\Query;
/***************************************************************
* Copyright notice
*
* (c) 2009-2015 Ingo Renner <ingo@typo3.org>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use Solarium\QueryType\Select\Query\Query as SolariumQuery;
class Query extends SolariumQuery {
/**
* Returns the query parameters that should be used.
*
* @return array
*/
public function getQueryParameters() {
return $this->getParams();
}
/**
* @return string
*/
public function __toString()
{
return $this->getQuery();
}
}

View File

@ -62,7 +62,7 @@ class DefaultResultParser extends AbstractResultParser {
} }
foreach ($documents as $searchResult) { foreach ($documents as $searchResult) {
$searchResultObject = $this->searchResultBuilder->fromApacheMeilisearchDocument($searchResult); $searchResultObject = $this->searchResultBuilder->fromMeilisearchDocument($searchResult);
$searchResults[] = $searchResultObject; $searchResults[] = $searchResultObject;
} }

View File

@ -42,7 +42,7 @@ class SearchResultBuilder {
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
* @return SearchResult * @return SearchResult
*/ */
public function fromApacheMeilisearchDocument(Document $originalDocument) public function fromMeilisearchDocument(Document $originalDocument)
{ {
$searchResultClassName = $this->getResultClassName(); $searchResultClassName = $this->getResultClassName();

View File

@ -431,7 +431,7 @@ class SearchResultSetService
throw new \UnexpectedValueException("Response did not contain a valid Document object"); throw new \UnexpectedValueException("Response did not contain a valid Document object");
} }
return $this->searchResultBuilder->fromApacheMeilisearchDocument($resultDocument); return $this->searchResultBuilder->fromMeilisearchDocument($resultDocument);
} }
/** /**

View File

@ -239,28 +239,14 @@ abstract class Site implements SiteInterface
return $rootPageIds; return $rootPageIds;
} }
/**
* @return array
* @throws NoMeilisearchConnectionFoundException
*/
public function getAllMeilisearchConnectionConfigurations(): array {
$configs = [];
foreach ($this->getAvailableLanguageIds() as $languageId) {
try {
$configs[$languageId] = $this->getMeilisearchConnectionConfiguration($languageId);
} catch (NoMeilisearchConnectionFoundException $e) {}
}
return $configs;
}
public function isEnabled(): bool public function isEnabled(): bool
{ {
return !empty($this->getAllMeilisearchConnectionConfigurations()); return !empty($this->getMeilisearchConnectionConfiguration());
} }
/** /**
* @param int $languageId
* @return array * @return array
*/ */
abstract function getMeilisearchConnectionConfiguration(int $language = 0): array; abstract function getMeilisearchConnectionConfiguration(): array;
} }

View File

@ -110,19 +110,12 @@ interface SiteInterface
*/ */
public function getTitle(); public function getTitle();
/**
* @param int $language
* @return array
* @throws NoMeilisearchConnectionFoundException
*/
public function getMeilisearchConnectionConfiguration(int $language = 0): array;
/** /**
* @return array * @return array
* @throws NoMeilisearchConnectionFoundException * @throws NoMeilisearchConnectionFoundException
*/ */
public function getAllMeilisearchConnectionConfigurations(): array; public function getMeilisearchConnectionConfiguration(): array;
public function isEnabled(): bool; public function isEnabled(): bool;
} }

View File

@ -85,7 +85,7 @@ class SiteRepository
* @param TwoLevelCache|null $twoLevelCache * @param TwoLevelCache|null $twoLevelCache
* @param Registry|null $registry * @param Registry|null $registry
* @param SiteFinder|null $siteFinder * @param SiteFinder|null $siteFinder
* @param ExtensionConfiguration| null * @param ExtensionConfiguration|null
*/ */
public function __construct( public function __construct(
RootPageResolver $rootPageResolver = null, RootPageResolver $rootPageResolver = null,
@ -230,8 +230,7 @@ class SiteRepository
{ {
/** @var $siteHashService SiteHashService */ /** @var $siteHashService SiteHashService */
$siteHashService = GeneralUtility::makeInstance(SiteHashService::class); $siteHashService = GeneralUtility::makeInstance(SiteHashService::class);
$siteHash = $siteHashService->getSiteHashForDomain($domain); return $siteHashService->getSiteHashForDomain($domain);
return $siteHash;
} }
/** /**
@ -272,38 +271,22 @@ class SiteRepository
$domain = $typo3Site->getBase()->getHost(); $domain = $typo3Site->getBase()->getHost();
$siteHash = $this->getSiteHashForDomain($domain); $siteHash = $this->getSiteHashForDomain($domain);
$defaultLanguage = $typo3Site->getDefaultLanguage()->getLanguageId();
$pageRepository = GeneralUtility::makeInstance(PagesRepository::class); $pageRepository = GeneralUtility::makeInstance(PagesRepository::class);
$availableLanguageIds = array_map(function($language) {
return $language->getLanguageId();
}, $typo3Site->getLanguages());
$meilisearchConnectionConfigurations = []; $meilisearchConnectionConfiguration = [];
foreach ($availableLanguageIds as $languageUid) { $meilisearchEnabled = SiteUtility::getConnectionProperty($typo3Site, 'enabled', true);
$meilisearchEnabled = SiteUtility::getConnectionProperty($typo3Site, 'enabled', $languageUid, 'read', true);
if ($meilisearchEnabled) { if ($meilisearchEnabled) {
$meilisearchConnectionConfigurations[$languageUid] = [ $meilisearchConnectionConfiguration = [
'connectionKey' => $rootPageRecord['uid'] . '|' . $languageUid, 'connectionKey' => $rootPageRecord['uid'] . '|',
'rootPageTitle' => $rootPageRecord['title'], 'rootPageTitle' => $rootPageRecord['title'],
'rootPageUid' => $rootPageRecord['uid'], 'rootPageUid' => $rootPageRecord['uid'],
'read' => [ 'scheme' => SiteUtility::getConnectionProperty($typo3Site, 'scheme', 'http'),
'scheme' => SiteUtility::getConnectionProperty($typo3Site, 'scheme', $languageUid, 'read', 'http'), 'host' => SiteUtility::getConnectionProperty($typo3Site, 'host', 'localhost'),
'host' => SiteUtility::getConnectionProperty($typo3Site, 'host', $languageUid, 'read', 'localhost'), 'port' => (int)SiteUtility::getConnectionProperty($typo3Site, 'port',7700),
'port' => (int)SiteUtility::getConnectionProperty($typo3Site, 'port', $languageUid, 'read', 7700), 'apiKey' => SiteUtility::getConnectionProperty($typo3Site, 'apiKey', ''),
'apiKey' => SiteUtility::getConnectionProperty($typo3Site, 'apiKey', $languageUid, 'read', ''),
],
'write' => [
'scheme' => SiteUtility::getConnectionProperty($typo3Site, 'scheme', $languageUid, 'write', 'http'),
'host' => SiteUtility::getConnectionProperty($typo3Site, 'host', $languageUid, 'write', 'localhost'),
'port' => (int)SiteUtility::getConnectionProperty($typo3Site, 'port', $languageUid, 'write', 7700),
'apiKey' => SiteUtility::getConnectionProperty($typo3Site, 'apiKey', $languageUid, 'write', ''),
],
'language' => $languageUid
]; ];
} }
}
return GeneralUtility::makeInstance( return GeneralUtility::makeInstance(
Typo3ManagedSite::class, Typo3ManagedSite::class,
@ -318,11 +301,7 @@ class SiteRepository
/** @scrutinizer ignore-type */ /** @scrutinizer ignore-type */
$pageRepository, $pageRepository,
/** @scrutinizer ignore-type */ /** @scrutinizer ignore-type */
$defaultLanguage, $meilisearchConnectionConfiguration,
/** @scrutinizer ignore-type */
$availableLanguageIds,
/** @scrutinizer ignore-type */
$meilisearchConnectionConfigurations,
/** @scrutinizer ignore-type */ /** @scrutinizer ignore-type */
$typo3Site $typo3Site
); );

View File

@ -47,32 +47,29 @@ class Typo3ManagedSite extends Site
/** /**
* @var array * @var array
*/ */
protected $meilisearchConnectionConfigurations; protected $meilisearchConnectionConfiguration;
public function __construct( public function __construct(
TypoScriptConfiguration $configuration, TypoScriptConfiguration $configuration,
array $page, $domain, $siteHash, PagesRepository $pagesRepository = null, $defaultLanguageId = 0, $availableLanguageIds = [], array $meilisearchConnectionConfigurations = [], Typo3Site $typo3SiteObject = null) array $page, $domain, $siteHash, PagesRepository $pagesRepository = null, array $meilisearchConnectionConfiguration = [], Typo3Site $typo3SiteObject = null)
{ {
$this->configuration = $configuration; $this->configuration = $configuration;
$this->rootPage = $page; $this->rootPage = $page;
$this->domain = $domain; $this->domain = $domain;
$this->siteHash = $siteHash; $this->siteHash = $siteHash;
$this->pagesRepository = $pagesRepository ?? GeneralUtility::makeInstance(PagesRepository::class); $this->pagesRepository = $pagesRepository ?? GeneralUtility::makeInstance(PagesRepository::class);
$this->defaultLanguageId = $defaultLanguageId; $this->meilisearchConnectionConfiguration = $meilisearchConnectionConfiguration;
$this->availableLanguageIds = $availableLanguageIds;
$this->meilisearchConnectionConfigurations = $meilisearchConnectionConfigurations;
$this->typo3SiteObject = $typo3SiteObject; $this->typo3SiteObject = $typo3SiteObject;
} }
/** /**
* @param int $language
* @return array * @return array
* @throws NoMeilisearchConnectionFoundException * @throws NoMeilisearchConnectionFoundException
*/ */
public function getMeilisearchConnectionConfiguration(int $language = 0): array public function getMeilisearchConnectionConfiguration(): array
{ {
if (!is_array($this->meilisearchConnectionConfigurations[$language])) { if (!is_array($this->meilisearchConnectionConfiguration)) {
/* @var $noMeilisearchConnectionException NoMeilisearchConnectionFoundException */ /* @var $noMeilisearchConnectionException NoMeilisearchConnectionFoundException */
$noMeilisearchConnectionException = GeneralUtility::makeInstance( $noMeilisearchConnectionException = GeneralUtility::makeInstance(
NoMeilisearchConnectionFoundException::class, NoMeilisearchConnectionFoundException::class,
@ -80,12 +77,11 @@ class Typo3ManagedSite extends Site
/** @scrutinizer ignore-type */ 1552491117 /** @scrutinizer ignore-type */ 1552491117
); );
$noMeilisearchConnectionException->setRootPageId($this->getRootPageId()); $noMeilisearchConnectionException->setRootPageId($this->getRootPageId());
$noMeilisearchConnectionException->setLanguageId($language);
throw $noMeilisearchConnectionException; throw $noMeilisearchConnectionException;
} }
return $this->meilisearchConnectionConfigurations[$language]; return $this->meilisearchConnectionConfiguration;
} }
/** /**
@ -97,4 +93,5 @@ class Typo3ManagedSite extends Site
{ {
return $this->typo3SiteObject; return $this->typo3SiteObject;
} }
} }

View File

@ -114,7 +114,7 @@ class VariantsProcessor implements SearchResultSetProcessor
$fields = get_object_vars($variantDocumentArray); $fields = get_object_vars($variantDocumentArray);
$variantDocument = new SearchResult($fields); $variantDocument = new SearchResult($fields);
$variantSearchResult = $this->resultBuilder->fromApacheMeilisearchDocument($variantDocument); $variantSearchResult = $this->resultBuilder->fromMeilisearchDocument($variantDocument);
$variantSearchResult->setIsVariant(true); $variantSearchResult->setIsVariant(true);
$variantSearchResult->setVariantParent($resultDocument); $variantSearchResult->setVariantParent($resultDocument);

View File

@ -25,7 +25,7 @@ namespace WapplerSystems\Meilisearch\IndexQueue;
***************************************************************/ ***************************************************************/
use WapplerSystems\Meilisearch\ConnectionManager; use WapplerSystems\Meilisearch\ConnectionManager;
use WapplerSystems\Meilisearch\Domain\Search\ApacheMeilisearchDocument\Builder; use WapplerSystems\Meilisearch\Domain\Search\MeilisearchDocument\Builder;
use WapplerSystems\Meilisearch\FieldProcessor\Service; use WapplerSystems\Meilisearch\FieldProcessor\Service;
use WapplerSystems\Meilisearch\FrontendEnvironment; use WapplerSystems\Meilisearch\FrontendEnvironment;
use WapplerSystems\Meilisearch\NoMeilisearchConnectionFoundException; use WapplerSystems\Meilisearch\NoMeilisearchConnectionFoundException;
@ -37,7 +37,6 @@ use WapplerSystems\Meilisearch\System\Meilisearch\ResponseAdapter;
use WapplerSystems\Meilisearch\System\Meilisearch\MeilisearchConnection; use WapplerSystems\Meilisearch\System\Meilisearch\MeilisearchConnection;
use Exception; use Exception;
use RuntimeException; use RuntimeException;
use Solarium\Exception\HttpException;
use TYPO3\CMS\Core\Context\LanguageAspectFactory; use TYPO3\CMS\Core\Context\LanguageAspectFactory;
use TYPO3\CMS\Core\Error\Http\ServiceUnavailableException; use TYPO3\CMS\Core\Error\Http\ServiceUnavailableException;
use TYPO3\CMS\Core\Exception\SiteNotFoundException; use TYPO3\CMS\Core\Exception\SiteNotFoundException;
@ -146,7 +145,7 @@ class Indexer extends AbstractIndexer
$this->type = $item->getType(); $this->type = $item->getType();
$this->setLogging($item); $this->setLogging($item);
$meilisearchConnections = $this->getMeilisearchConnectionsByItem($item); $meilisearchConnections = $this->getMeilisearchConnectionByItem($item);
foreach ($meilisearchConnections as $systemLanguageUid => $meilisearchConnection) { foreach ($meilisearchConnections as $systemLanguageUid => $meilisearchConnection) {
$this->meilisearch = $meilisearchConnection; $this->meilisearch = $meilisearchConnection;
@ -504,7 +503,6 @@ class Indexer extends AbstractIndexer
return $documents; return $documents;
} }
// Initialization
/** /**
* Gets the Meilisearch connections applicable for an item. * Gets the Meilisearch connections applicable for an item.
@ -515,9 +513,8 @@ class Indexer extends AbstractIndexer
* @param Item $item An index queue item * @param Item $item An index queue item
* @return array An array of WapplerSystems\Meilisearch\System\Meilisearch\MeilisearchConnection connections, the array's keys are the sys_language_uid of the language of the connection * @return array An array of WapplerSystems\Meilisearch\System\Meilisearch\MeilisearchConnection connections, the array's keys are the sys_language_uid of the language of the connection
*/ */
protected function getMeilisearchConnectionsByItem(Item $item) protected function getMeilisearchConnectionByItem(Item $item)
{ {
$meilisearchConnections = [];
$rootPageId = $item->getRootPageUid(); $rootPageId = $item->getRootPageUid();
if ($item->getType() === 'pages') { if ($item->getType() === 'pages') {
@ -528,11 +525,8 @@ class Indexer extends AbstractIndexer
// Meilisearch configurations possible for this item // Meilisearch configurations possible for this item
$site = $item->getSite(); $site = $item->getSite();
$meilisearchConfigurationsBySite = $site->getAllMeilisearchConnectionConfigurations(); return $site->getMeilisearchConnectionConfiguration();
$siteLanguages = [];
foreach ($meilisearchConfigurationsBySite as $meilisearchConfiguration) {
$siteLanguages[] = $meilisearchConfiguration['language'];
}
$defaultLanguageUid = $this->getDefaultLanguageUid($item, $site->getRootPage(), $siteLanguages); $defaultLanguageUid = $this->getDefaultLanguageUid($item, $site->getRootPage(), $siteLanguages);
$translationOverlays = $this->getTranslationOverlaysWithConfiguredSite((int)$pageId, $site, (array)$siteLanguages); $translationOverlays = $this->getTranslationOverlaysWithConfiguredSite((int)$pageId, $site, (array)$siteLanguages);

View File

@ -24,6 +24,7 @@ namespace WapplerSystems\Meilisearch\IndexQueue;
* This copyright notice MUST APPEAR in all copies of the script! * This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/ ***************************************************************/
use TYPO3\CMS\Core\Utility\DebugUtility;
use WapplerSystems\Meilisearch\Access\Rootline; use WapplerSystems\Meilisearch\Access\Rootline;
use WapplerSystems\Meilisearch\Access\RootlineElement; use WapplerSystems\Meilisearch\Access\RootlineElement;
use WapplerSystems\Meilisearch\Domain\Index\PageIndexer\Helper\UriBuilder\AbstractUriStrategy; use WapplerSystems\Meilisearch\Domain\Index\PageIndexer\Helper\UriBuilder\AbstractUriStrategy;
@ -57,8 +58,12 @@ class PageIndexer extends Indexer
return false; return false;
} }
$meilisearchConnections = $this->getMeilisearchConnectionsByItem($item); //$meilisearchConnection = $this->getMeilisearchConnectionByItem($item);
foreach ($meilisearchConnections as $systemLanguageUid => $meilisearchConnection) {
$site = $item->getSite();
$languageUids = $site->getAvailableLanguageIds();
foreach ($languageUids as $systemLanguageUid) {
$contentAccessGroups = $this->getAccessGroupsFromContent($item, $systemLanguageUid); $contentAccessGroups = $this->getAccessGroupsFromContent($item, $systemLanguageUid);
if (empty($contentAccessGroups)) { if (empty($contentAccessGroups)) {
@ -108,9 +113,9 @@ class PageIndexer extends Indexer
* @param Item $item An index queue item * @param Item $item An index queue item
* @return array An array of WapplerSystems\Meilisearch\System\Meilisearch\MeilisearchConnection connections, the array's keys are the sys_language_uid of the language of the connection * @return array An array of WapplerSystems\Meilisearch\System\Meilisearch\MeilisearchConnection connections, the array's keys are the sys_language_uid of the language of the connection
*/ */
protected function getMeilisearchConnectionsByItem(Item $item) protected function getMeilisearchConnectionByItem(Item $item)
{ {
$meilisearchConnections = parent::getMeilisearchConnectionsByItem($item); $meilisearchConnections = parent::getMeilisearchConnectionByItem($item);
$page = $item->getRecord(); $page = $item->getRecord();
// may use \TYPO3\CMS\Core\Utility\GeneralUtility::hideIfDefaultLanguage($page['l18n_cfg']) with TYPO3 4.6 // may use \TYPO3\CMS\Core\Utility\GeneralUtility::hideIfDefaultLanguage($page['l18n_cfg']) with TYPO3 4.6
@ -289,6 +294,7 @@ class PageIndexer extends Indexer
*/ */
protected function indexPage(Item $item, $language = 0, $userGroup = 0) protected function indexPage(Item $item, $language = 0, $userGroup = 0)
{ {
DebugUtility::debug('dededede');
$accessRootline = $this->getAccessRootline($item, $language, $userGroup); $accessRootline = $this->getAccessRootline($item, $language, $userGroup);
$request = $this->buildBasePageIndexerRequest(); $request = $this->buildBasePageIndexerRequest();
$request->setIndexQueueItem($item); $request->setIndexQueueItem($item);

View File

@ -90,7 +90,7 @@ class MeilisearchStatus extends AbstractMeilisearchStatus
{ {
$reports = []; $reports = [];
foreach ($this->siteRepository->getAvailableSites() as $site) { foreach ($this->siteRepository->getAvailableSites() as $site) {
foreach ($site->getAllMeilisearchConnectionConfigurations() as $meilisearchConfiguration) { foreach ($site->getMeilisearchConnectionConfigurations() as $meilisearchConfiguration) {
$reports[] = $this->getConnectionStatus($meilisearchConfiguration); $reports[] = $this->getConnectionStatus($meilisearchConfiguration);
} }
} }
@ -110,7 +110,7 @@ class MeilisearchStatus extends AbstractMeilisearchStatus
$this->responseStatus = Status::OK; $this->responseStatus = Status::OK;
$meilisearchAdmin = $this->connectionManager $meilisearchAdmin = $this->connectionManager
->getMeilisearchConnectionForNodes($meilisearchConnection['read'], $meilisearchConnection['write']) ->getMeilisearchConnectionForNode($meilisearchConnection['read'], $meilisearchConnection['write'])
->getAdminService(); ->getAdminService();
$meilisearchVersion = $this->checkMeilisearchVersion($meilisearchAdmin); $meilisearchVersion = $this->checkMeilisearchVersion($meilisearchAdmin);

View File

@ -15,14 +15,13 @@ namespace WapplerSystems\Meilisearch\System\Meilisearch\Document;
*/ */
use RuntimeException; use RuntimeException;
use Solarium\QueryType\Update\Query\Document as SolariumDocument;
/** /**
* Document representing the update query document * Document representing the update query document
* *
* @author Timo Hund <timo.hund@dkd.de> * @author Timo Hund <timo.hund@dkd.de>
*/ */
class Document extends SolariumDocument class Document
{ {
/** /**
* Magic call method used to emulate getters as used by the template engine. * Magic call method used to emulate getters as used by the template engine.
@ -33,13 +32,12 @@ class Document extends SolariumDocument
*/ */
public function __call($name, $arguments) public function __call($name, $arguments)
{ {
if (substr($name, 0, 3) == 'get') { if (substr($name, 0, 3) === 'get') {
$field = substr($name, 3); $field = substr($name, 3);
$field = strtolower($field[0]) . substr($field, 1); $field = strtolower($field[0]) . substr($field, 1);
return $this->fields[$field] ?? null; return $this->fields[$field] ?? null;
} else {
throw new RuntimeException('Call to undefined method. Supports magic getters only.', 1311006605);
} }
throw new RuntimeException('Call to undefined method. Supports magic getters only.', 1311006605);
} }
/** /**

View File

@ -69,6 +69,11 @@ class MeilisearchConnection
*/ */
protected $configuration; protected $configuration;
/**
* @var array
*/
protected $siteConfiguration;
/** /**
* @var SynonymParser * @var SynonymParser
*/ */
@ -85,9 +90,9 @@ class MeilisearchConnection
protected $schemaParser = null; protected $schemaParser = null;
/** /**
* @var Client[] * @var Client
*/ */
protected $nodes = []; protected $client ;
/** /**
* @var MeilisearchLogManager * @var MeilisearchLogManager
@ -104,15 +109,6 @@ class MeilisearchConnection
*/ */
protected $psr7Client; protected $psr7Client;
/**
* @var RequestFactoryInterface
*/
protected $requestFactory;
/**
* @var StreamFactoryInterface
*/
protected $streamFactory;
/** /**
* @var EventDispatcherInterface * @var EventDispatcherInterface
@ -122,8 +118,8 @@ class MeilisearchConnection
/** /**
* Constructor * Constructor
* *
* @param Client $readNode * @param Client $client
* @param Client $writeNode * @param array $siteConfiguration
* @param ?TypoScriptConfiguration $configuration * @param ?TypoScriptConfiguration $configuration
* @param ?SynonymParser $synonymParser * @param ?SynonymParser $synonymParser
* @param ?StopWordParser $stopWordParser * @param ?StopWordParser $stopWordParser
@ -138,8 +134,8 @@ class MeilisearchConnection
* @throws NotFoundExceptionInterface * @throws NotFoundExceptionInterface
*/ */
public function __construct( public function __construct(
Client $readNode, Client $client,
Client $writeNode, array $siteConfiguration,
TypoScriptConfiguration $configuration = null, TypoScriptConfiguration $configuration = null,
SynonymParser $synonymParser = null, SynonymParser $synonymParser = null,
StopWordParser $stopWordParser = null, StopWordParser $stopWordParser = null,
@ -148,9 +144,8 @@ class MeilisearchConnection
ClientInterface $psr7Client = null, ClientInterface $psr7Client = null,
EventDispatcherInterface $eventDispatcher = null EventDispatcherInterface $eventDispatcher = null
) { ) {
$this->nodes['read'] = $readNode; $this->client = $client;
$this->nodes['write'] = $writeNode; $this->siteConfiguration = $siteConfiguration;
$this->nodes['admin'] = $writeNode;
$this->configuration = $configuration ?? Util::getMeilisearchConfiguration(); $this->configuration = $configuration ?? Util::getMeilisearchConfiguration();
$this->synonymParser = $synonymParser; $this->synonymParser = $synonymParser;
$this->stopWordParser = $stopWordParser; $this->stopWordParser = $stopWordParser;
@ -160,14 +155,6 @@ class MeilisearchConnection
$this->eventDispatcher = $eventDispatcher ?? GeneralUtility::getContainer()->get(EventDispatcherInterface::class); $this->eventDispatcher = $eventDispatcher ?? GeneralUtility::getContainer()->get(EventDispatcherInterface::class);
} }
/**
* @param string $key
* @return Client
*/
public function getNode(string $key): Client
{
return $this->nodes[$key];
}
/** /**
* @return MeilisearchAdminService * @return MeilisearchAdminService
@ -187,9 +174,7 @@ class MeilisearchConnection
*/ */
protected function buildAdminService(): MeilisearchAdminService protected function buildAdminService(): MeilisearchAdminService
{ {
$endpointKey = 'admin'; return GeneralUtility::makeInstance(MeilisearchAdminService::class, $this, $this->client, $this->configuration, $this->logger, $this->synonymParser, $this->stopWordParser, $this->schemaParser);
$client = $this->getClient($endpointKey);
return GeneralUtility::makeInstance(MeilisearchAdminService::class, $client, $this->configuration, $this->logger, $this->synonymParser, $this->stopWordParser, $this->schemaParser);
} }
/** /**
@ -210,9 +195,7 @@ class MeilisearchConnection
*/ */
protected function buildReadService(): MeilisearchReadService protected function buildReadService(): MeilisearchReadService
{ {
$endpointKey = 'read'; return GeneralUtility::makeInstance(MeilisearchReadService::class, $this->client);
$client = $this->getClient($endpointKey);
return GeneralUtility::makeInstance(MeilisearchReadService::class, $client);
} }
/** /**
@ -233,9 +216,7 @@ class MeilisearchConnection
*/ */
protected function buildWriteService(): MeilisearchWriteService protected function buildWriteService(): MeilisearchWriteService
{ {
$endpointKey = 'write'; return GeneralUtility::makeInstance(MeilisearchWriteService::class, $this->client);
$client = $this->getClient($endpointKey);
return GeneralUtility::makeInstance(MeilisearchWriteService::class, $client);
} }
@ -247,4 +228,13 @@ class MeilisearchConnection
{ {
$this->clients[$endpointKey] = $client; $this->clients[$endpointKey] = $client;
} }
/**
* @return array
*/
public function getSiteConfiguration(): array
{
return $this->siteConfiguration;
}
} }

View File

@ -24,27 +24,18 @@ namespace WapplerSystems\Meilisearch\System\Meilisearch\Service;
* This copyright notice MUST APPEAR in all copies of the script! * This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/ ***************************************************************/
use WapplerSystems\Meilisearch\PingFailedException; use MeiliSearch\Client;
use MeiliSearch\Exceptions\CommunicationException;
use WapplerSystems\Meilisearch\System\Configuration\TypoScriptConfiguration; use WapplerSystems\Meilisearch\System\Configuration\TypoScriptConfiguration;
use WapplerSystems\Meilisearch\System\Logging\MeilisearchLogManager; use WapplerSystems\Meilisearch\System\Logging\MeilisearchLogManager;
use WapplerSystems\Meilisearch\System\Meilisearch\MeilisearchConnection;
use WapplerSystems\Meilisearch\System\Meilisearch\ResponseAdapter; use WapplerSystems\Meilisearch\System\Meilisearch\ResponseAdapter;
use WapplerSystems\Meilisearch\Util; use WapplerSystems\Meilisearch\Util;
use Solarium\Client;
use Solarium\Core\Client\Endpoint;
use Solarium\Core\Client\Request;
use Solarium\Core\Query\QueryInterface;
use Solarium\Exception\HttpException;
use TYPO3\CMS\Core\Http\Uri;
use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\GeneralUtility;
abstract class AbstractMeilisearchService abstract class AbstractMeilisearchService
{ {
/**
* @var array
*/
protected static $pingCache = [];
/** /**
* @var TypoScriptConfiguration * @var TypoScriptConfiguration
*/ */
@ -60,26 +51,22 @@ abstract class AbstractMeilisearchService
*/ */
protected $client = null; protected $client = null;
/**
* @var MeilisearchConnection
*/
protected $meilisearchConnection = null;
/** /**
* MeilisearchReadService constructor. * MeilisearchReadService constructor.
*/ */
public function __construct(Client $client, $typoScriptConfiguration = null, $logManager = null) public function __construct(MeilisearchConnection $meilisearchConnection, Client $client, $typoScriptConfiguration = null, $logManager = null)
{ {
$this->meilisearchConnection = $meilisearchConnection;
$this->client = $client; $this->client = $client;
$this->configuration = $typoScriptConfiguration ?? Util::getMeilisearchConfiguration(); $this->configuration = $typoScriptConfiguration ?? Util::getMeilisearchConfiguration();
$this->logger = $logManager ?? GeneralUtility::makeInstance(MeilisearchLogManager::class, /** @scrutinizer ignore-type */ __CLASS__); $this->logger = $logManager ?? GeneralUtility::makeInstance(MeilisearchLogManager::class, /** @scrutinizer ignore-type */ __CLASS__);
} }
/**
* Returns the path to the core meilisearch path + core path.
*
* @return string
*/
public function getCorePath()
{
$endpoint = $this->getPrimaryEndpoint();
return is_null($endpoint) ? '' : $endpoint->getPath() .'/'. $endpoint->getCore();
}
/** /**
* Returns the Solarium client * Returns the Solarium client
@ -92,158 +79,28 @@ abstract class AbstractMeilisearchService
} }
/** /**
* Return a valid http URL given this server's host, port and path and a provided servlet name * @return MeilisearchConnection
*
* @param string $servlet
* @param array $params
* @return string
*/ */
protected function _constructUrl($servlet, $params = []) public function getMeilisearchConnection(): ?MeilisearchConnection
{ {
$queryString = count($params) ? '?' . http_build_query($params, null, '&') : ''; return $this->meilisearchConnection;
return $this->__toString() . $servlet . $queryString;
} }
/** /**
* Creates a string representation of the Meilisearch connection. Specifically
* will return the Meilisearch URL.
* *
* @return string The Meilisearch URL.
* @TODO: Add support for API version 2
*/ */
public function __toString() public function __toString()
{ {
$endpoint = $this->getPrimaryEndpoint();
if (!$endpoint instanceof Endpoint) { $siteConfiguration = $this->meilisearchConnection->getSiteConfiguration();
return ''; $strConnection = $siteConfiguration['schema'].$siteConfiguration['host'];
if (!$this->ping()) return $strConnection;
return $strConnection . ', ' . implode(',',$this->client->version());
} }
try {
return $endpoint->getCoreBaseUri();
} catch (\Exception $exception) {
}
return $endpoint->getScheme(). '://' . $endpoint->getHost() . ':' . $endpoint->getPort() . $endpoint->getPath() . '/' . $endpoint->getCore() . '/';
}
/**
* @return Endpoint|null
*/
public function getPrimaryEndpoint()
{
return is_array($this->client->getEndpoints()) ? reset($this->client->getEndpoints()) : null;
}
/**
* Central method for making a get operation against this Meilisearch Server
*
* @param string $url
* @return ResponseAdapter
*/
protected function _sendRawGet($url)
{
return $this->_sendRawRequest($url, Request::METHOD_GET);
}
/**
* Central method for making a HTTP DELETE operation against the Meilisearch server
*
* @param string $url
* @return ResponseAdapter
*/
protected function _sendRawDelete($url)
{
return $this->_sendRawRequest($url, Request::METHOD_DELETE);
}
/**
* Central method for making a post operation against this Meilisearch Server
*
* @param string $url
* @param string $rawPost
* @param string $contentType
* @return ResponseAdapter
*/
protected function _sendRawPost($url, $rawPost, $contentType = 'text/xml; charset=UTF-8')
{
$initializeRequest = function(Request $request) use ($rawPost, $contentType) {
$request->setRawData($rawPost);
$request->addHeader('Content-Type: ' . $contentType);
return $request;
};
return $this->_sendRawRequest($url, Request::METHOD_POST, $rawPost, $initializeRequest);
}
/**
* Method that performs an http request with the solarium client.
*
* @param string $url
* @param string $method
* @param string $body
* @param ?\Closure $initializeRequest
* @return ResponseAdapter
*/
protected function _sendRawRequest(
string $url,
$method = Request::METHOD_GET,
$body = '',
\Closure $initializeRequest = null
) {
$logSeverity = MeilisearchLogManager::INFO;
$exception = null;
$url = $this->reviseUrl($url);
try {
$request = $this->buildSolariumRequestFromUrl($url, $method);
if($initializeRequest !== null) {
$request = $initializeRequest($request);
}
$response = $this->executeRequest($request);
} catch (HttpException $exception) {
$logSeverity = MeilisearchLogManager::ERROR;
$response = new ResponseAdapter($exception->getBody(), $exception->getCode(), $exception->getMessage());
}
if ($this->configuration->getLoggingQueryRawPost() || $response->getHttpStatus() != 200) {
$message = 'Querying Meilisearch using '.$method;
$this->writeLog($logSeverity, $message, $url, $response, $exception, $body);
}
return $response;
}
/**
* Revise url
* - Resolve relative paths
*
* @param string $url
* @return string
*/
protected function reviseUrl(string $url): string
{
/* @var Uri $uri */
$uri = GeneralUtility::makeInstance(Uri::class, $url);
if ((string)$uri->getPath() === '') {
return $url;
}
$path = trim($uri->getPath(), '/');
$pathsCurrent = explode('/', $path);
$pathNew = [];
foreach ($pathsCurrent as $pathCurrent) {
if ($pathCurrent === '..') {
array_pop($pathNew);
continue;
}
if ($pathCurrent === '.') {
continue;
}
$pathNew[] = $pathCurrent;
}
$uri = $uri->withPath(implode('/', $pathNew));
return (string)$uri;
}
/** /**
* Build the log data and writes the message to the log * Build the log data and writes the message to the log
@ -281,90 +138,29 @@ abstract class AbstractMeilisearchService
if (!empty($e)) { if (!empty($e)) {
$logData['exception'] = $e->__toString(); $logData['exception'] = $e->__toString();
return $logData; return $logData;
} else { }
// trigger data parsing // trigger data parsing
// @extensionScannerIgnoreLine // @extensionScannerIgnoreLine
$meilisearchResponse->response; $meilisearchResponse->response;
$logData['response data'] = print_r($meilisearchResponse, true); $logData['response data'] = print_r($meilisearchResponse, true);
return $logData; return $logData;
}
} }
/** /**
* Call the /admin/ping servlet, can be used to quickly tell if a connection to the * @return bool
* server is available.
*
* Simply overrides the MeilisearchPhpClient implementation, changing ping from a
* HEAD to a GET request, see http://forge.typo3.org/issues/44167
*
* Also does not report the time, see https://forge.typo3.org/issues/64551
*
* @param boolean $useCache indicates if the ping result should be cached in the instance or not
* @return bool TRUE if Meilisearch can be reached, FALSE if not
*/ */
public function ping($useCache = true) public function ping()
{ {
try { try {
$httpResponse = $this->performPingRequest($useCache); $health = $this->client->health();
} catch (HttpException $exception) { } catch (CommunicationException $ex) {
return false; return false;
} }
return is_array($health) && $health['status'] === 'available';
return ($httpResponse->getHttpStatus() === 200);
} }
/**
* Call the /admin/ping servlet, can be used to get the runtime of a ping request.
*
* @param boolean $useCache indicates if the ping result should be cached in the instance or not
* @return double runtime in milliseconds
* @throws \WapplerSystems\Meilisearch\PingFailedException
*/
public function getPingRoundTripRuntime($useCache = true)
{
try {
$start = $this->getMilliseconds();
$httpResponse = $this->performPingRequest($useCache);
$end = $this->getMilliseconds();
} catch (HttpException $e) {
$message = 'Meilisearch ping failed with unexpected response code: ' . $e->getCode();
/** @var $exception \WapplerSystems\Meilisearch\PingFailedException */
$exception = GeneralUtility::makeInstance(PingFailedException::class, /** @scrutinizer ignore-type */ $message);
throw $exception;
}
if ($httpResponse->getHttpStatus() !== 200) {
$message = 'Meilisearch ping failed with unexpected response code: ' . $httpResponse->getHttpStatus();
/** @var $exception \WapplerSystems\Meilisearch\PingFailedException */
$exception = GeneralUtility::makeInstance(PingFailedException::class, /** @scrutinizer ignore-type */ $message);
throw $exception;
}
return $end - $start;
}
/**
* Performs a ping request and returns the result.
*
* @param boolean $useCache indicates if the ping result should be cached in the instance or not
* @return ResponseAdapter
*/
protected function performPingRequest($useCache = true)
{
$cacheKey = (string)($this);
if ($useCache && isset(static::$pingCache[$cacheKey])) {
return static::$pingCache[$cacheKey];
}
$pingQuery = $this->client->createPing();
$pingResult = $this->createAndExecuteRequest($pingQuery);
if ($useCache) {
static::$pingCache[$cacheKey] = $pingResult;
}
return $pingResult;
}
/** /**
* Returns the current time in milliseconds. * Returns the current time in milliseconds.
@ -376,76 +172,5 @@ abstract class AbstractMeilisearchService
return GeneralUtility::milliseconds(); return GeneralUtility::milliseconds();
} }
/**
* @param QueryInterface $query
* @return ResponseAdapter
*/
protected function createAndExecuteRequest(QueryInterface $query): ResponseAdapter
{
$request = $this->client->createRequest($query);
return $this->executeRequest($request);
}
/**
* @param $request
* @return ResponseAdapter
*/
protected function executeRequest($request): ResponseAdapter
{
$result = $this->client->executeRequest($request);
return new ResponseAdapter($result->getBody(), $result->getStatusCode(), $result->getStatusMessage());
}
/**
* Build the request for Solarium.
*
* Important: The endpoint already contains the API information.
* The internal Solarium will append the information including the core if set.
*
* @param string $url
* @param string $httpMethod
* @return Request
*/
protected function buildSolariumRequestFromUrl(string $url, $httpMethod = Request::METHOD_GET): Request
{
$params = [];
parse_str(parse_url($url, PHP_URL_QUERY), $params);
$request = new Request();
$path = parse_url($url, PHP_URL_PATH);
$endpoint = $this->getPrimaryEndpoint();
$api = $request->getApi() === Request::API_V1 ? 'meilisearch' : 'api';
$coreBasePath = $endpoint->getPath() . '/' . $api . '/' . $endpoint->getCore() . '/';
$handler = $this->buildRelativePath($coreBasePath, $path);
$request->setMethod($httpMethod);
$request->setParams($params);
$request->setHandler($handler);
return $request;
}
/**
* Build a relative path from base path to target path.
* Required since Solarium contains the core information
*
* @param string $basePath
* @param string $targetPath
* @return string
*/
protected function buildRelativePath(string $basePath, string $targetPath): string
{
$basePath = trim($basePath, '/');
$targetPath = trim($targetPath, '/');
$baseElements = explode('/', $basePath);
$targetElements = explode('/', $targetPath);
$targetSegment = array_pop($targetElements);
foreach ($baseElements as $i => $segment) {
if (isset($targetElements[$i]) && $segment === $targetElements[$i]) {
unset($baseElements[$i], $targetElements[$i]);
} else {
break;
}
}
$targetElements[] = $targetSegment;
return str_repeat('../', count($baseElements)) . implode('/', $targetElements);
}
} }

View File

@ -24,14 +24,15 @@ namespace WapplerSystems\Meilisearch\System\Meilisearch\Service;
* This copyright notice MUST APPEAR in all copies of the script! * This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/ ***************************************************************/
use MeiliSearch\Client;
use WapplerSystems\Meilisearch\System\Configuration\TypoScriptConfiguration; use WapplerSystems\Meilisearch\System\Configuration\TypoScriptConfiguration;
use WapplerSystems\Meilisearch\System\Logging\MeilisearchLogManager; use WapplerSystems\Meilisearch\System\Logging\MeilisearchLogManager;
use WapplerSystems\Meilisearch\System\Meilisearch\MeilisearchConnection;
use WapplerSystems\Meilisearch\System\Meilisearch\Parser\SchemaParser; use WapplerSystems\Meilisearch\System\Meilisearch\Parser\SchemaParser;
use WapplerSystems\Meilisearch\System\Meilisearch\Parser\StopWordParser; use WapplerSystems\Meilisearch\System\Meilisearch\Parser\StopWordParser;
use WapplerSystems\Meilisearch\System\Meilisearch\Parser\SynonymParser; use WapplerSystems\Meilisearch\System\Meilisearch\Parser\SynonymParser;
use WapplerSystems\Meilisearch\System\Meilisearch\ResponseAdapter; use WapplerSystems\Meilisearch\System\Meilisearch\ResponseAdapter;
use WapplerSystems\Meilisearch\System\Meilisearch\Schema\Schema; use WapplerSystems\Meilisearch\System\Meilisearch\Schema\Schema;
use Solarium\Client;
use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\GeneralUtility;
/** /**
@ -39,30 +40,9 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
*/ */
class MeilisearchAdminService extends AbstractMeilisearchService class MeilisearchAdminService extends AbstractMeilisearchService
{ {
const PLUGINS_SERVLET = 'admin/plugins';
const LUKE_SERVLET = 'admin/luke';
const SYSTEM_SERVLET = 'admin/system';
const CORES_SERVLET = '../admin/cores';
const FILE_SERVLET = 'admin/file';
const SCHEMA_SERVLET = 'schema';
const SYNONYMS_SERVLET = 'schema/analysis/synonyms/';
const STOPWORDS_SERVLET = 'schema/analysis/stopwords/';
/**
* @var array
*/
protected $lukeData = [];
protected $systemData = null; protected $systemData = null;
protected $pluginsData = [];
/**
* @var string|null
*/
protected $meilisearchconfigName;
/** /**
* @var SchemaParser * @var SchemaParser
*/ */
@ -95,13 +75,16 @@ class MeilisearchAdminService extends AbstractMeilisearchService
/** /**
* Constructor * Constructor
* *
* @param TypoScriptConfiguration $typoScriptConfiguration * @param MeilisearchConnection $meilisearchConnection
* @param SynonymParser $synonymParser * @param Client $client
* @param StopWordParser $stopWordParser * @param TypoScriptConfiguration|null $typoScriptConfiguration
* @param SchemaParser $schemaParser * @param MeilisearchLogManager|null $logManager
* @param MeilisearchLogManager $logManager * @param SynonymParser|null $synonymParser
* @param StopWordParser|null $stopWordParser
* @param SchemaParser|null $schemaParser
*/ */
public function __construct( public function __construct(
MeilisearchConnection $meilisearchConnection,
Client $client, Client $client,
TypoScriptConfiguration $typoScriptConfiguration = null, TypoScriptConfiguration $typoScriptConfiguration = null,
MeilisearchLogManager $logManager = null, MeilisearchLogManager $logManager = null,
@ -110,71 +93,13 @@ class MeilisearchAdminService extends AbstractMeilisearchService
SchemaParser $schemaParser = null SchemaParser $schemaParser = null
) )
{ {
parent::__construct($client, $typoScriptConfiguration); parent::__construct($meilisearchConnection, $client, $typoScriptConfiguration);
$this->synonymParser = $synonymParser ?? GeneralUtility::makeInstance(SynonymParser::class); $this->synonymParser = $synonymParser ?? GeneralUtility::makeInstance(SynonymParser::class);
$this->stopWordParser = $stopWordParser ?? GeneralUtility::makeInstance(StopWordParser::class); $this->stopWordParser = $stopWordParser ?? GeneralUtility::makeInstance(StopWordParser::class);
$this->schemaParser = $schemaParser ?? GeneralUtility::makeInstance(SchemaParser::class); $this->schemaParser = $schemaParser ?? GeneralUtility::makeInstance(SchemaParser::class);
} }
/**
* Call the /admin/system servlet and retrieve system information about Meilisearch
*
* @return ResponseAdapter
*/
public function system()
{
return $this->_sendRawGet($this->_constructUrl(self::SYSTEM_SERVLET, ['wt' => 'json']));
}
/**
* Gets information about the plugins installed in Meilisearch
*
* @return array A nested array of plugin data.
*/
public function getPluginsInformation()
{
if (count($this->pluginsData) == 0) {
$url = $this->_constructUrl(self::PLUGINS_SERVLET, ['wt' => 'json']);
$pluginsInformation = $this->_sendRawGet($url);
// access a random property to trigger response parsing
$pluginsInformation->responseHeader;
$this->pluginsData = $pluginsInformation;
}
return $this->pluginsData;
}
/**
* get field meta data for the index
*
* @param int $numberOfTerms Number of top terms to fetch for each field
* @return \stdClass
*/
public function getFieldsMetaData($numberOfTerms = 0)
{
return $this->getLukeMetaData($numberOfTerms)->fields;
}
/**
* Retrieves meta data about the index from the luke request handler
*
* @param int $numberOfTerms Number of top terms to fetch for each field
* @return ResponseAdapter Index meta data
*/
public function getLukeMetaData($numberOfTerms = 0)
{
if (!isset($this->lukeData[$numberOfTerms])) {
$lukeUrl = $this->_constructUrl(
self::LUKE_SERVLET, ['numTerms' => $numberOfTerms, 'wt' => 'json', 'fl' => '*']
);
$this->lukeData[$numberOfTerms] = $this->_sendRawGet($lukeUrl);
}
return $this->lukeData[$numberOfTerms];
}
/** /**
* Gets information about the Meilisearch server * Gets information about the Meilisearch server
@ -187,86 +112,13 @@ class MeilisearchAdminService extends AbstractMeilisearchService
$systemInformation = $this->system(); $systemInformation = $this->system();
// access a random property to trigger response parsing // access a random property to trigger response parsing
$systemInformation->responseHeader;
$this->systemData = $systemInformation; $this->systemData = $systemInformation;
} }
return $this->systemData; return $this->systemData;
} }
/**
* Gets the name of the meilisearchconfig.xml file installed and in use on the Meilisearch
* server.
*
* @return string Name of the active meilisearchconfig.xml
*/
public function getMeilisearchconfigName()
{
if (is_null($this->meilisearchconfigName)) {
$meilisearchconfigXmlUrl = $this->_constructUrl(self::FILE_SERVLET, ['file' => 'meilisearchconfig.xml']);
$response = $this->_sendRawGet($meilisearchconfigXmlUrl);
$meilisearchconfigXml = simplexml_load_string($response->getRawResponse());
if ($meilisearchconfigXml === false) {
throw new \InvalidArgumentException('No valid xml response from schema file: ' . $meilisearchconfigXmlUrl);
}
$this->meilisearchconfigName = (string)$meilisearchconfigXml->attributes()->name;
}
return $this->meilisearchconfigName;
}
/**
* Gets the Meilisearch server's version number.
*
* @return string Meilisearch version number
*/
public function getMeilisearchServerVersion()
{
$systemInformation = $this->getSystemInformation();
// don't know why $systemInformation->lucene->meilisearch-spec-version won't work
$luceneInformation = (array)$systemInformation->lucene;
return $luceneInformation['meilisearch-spec-version'];
}
/**
* Reloads the current core
*
* @return ResponseAdapter
*/
public function reloadCore()
{
$response = $this->reloadCoreByName($this->getPrimaryEndpoint()->getCore());
return $response;
}
/**
* Reloads a core of the connection by a given corename.
*
* @param string $coreName
* @return ResponseAdapter
*/
public function reloadCoreByName($coreName)
{
$coreAdminReloadUrl = $this->_constructUrl(self::CORES_SERVLET) . '?action=reload&core=' . $coreName;
$response = $this->_sendRawGet($coreAdminReloadUrl);
return $response;
}
/**
* Get the configured schema for the current core.
*
* @return Schema
*/
public function getSchema()
{
if ($this->schema !== null) {
return $this->schema;
}
$response = $this->_sendRawGet($this->_constructUrl(self::SCHEMA_SERVLET));
$this->schema = $this->schemaParser->parseJson($response->getRawResponse());
return $this->schema;
}
/** /**
* Get currently configured synonyms * Get currently configured synonyms
@ -300,8 +152,7 @@ class MeilisearchAdminService extends AbstractMeilisearchService
{ {
$this->initializeSynonymsUrl(); $this->initializeSynonymsUrl();
$json = $this->synonymParser->toJson($baseWord, $synonyms); $json = $this->synonymParser->toJson($baseWord, $synonyms);
$response = $this->_sendRawPost($this->_synonymsUrl, $json, 'application/json'); return $this->_sendRawPost($this->_synonymsUrl, $json, 'application/json');
return $response;
} }
/** /**
@ -318,8 +169,7 @@ class MeilisearchAdminService extends AbstractMeilisearchService
throw new \InvalidArgumentException('Must provide base word.'); throw new \InvalidArgumentException('Must provide base word.');
} }
$response = $this->_sendRawDelete($this->_synonymsUrl . '/' . urlencode($baseWord)); return $this->_sendRawDelete($this->_synonymsUrl . '/' . urlencode($baseWord));
return $response;
} }
/** /**

View File

@ -24,12 +24,10 @@ namespace WapplerSystems\Meilisearch\System\Meilisearch\Service;
* This copyright notice MUST APPEAR in all copies of the script! * This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/ ***************************************************************/
use WapplerSystems\Meilisearch\Domain\Search\Query\Query;
use WapplerSystems\Meilisearch\System\Meilisearch\ResponseAdapter; use WapplerSystems\Meilisearch\System\Meilisearch\ResponseAdapter;
use WapplerSystems\Meilisearch\System\Meilisearch\MeilisearchCommunicationException; use WapplerSystems\Meilisearch\System\Meilisearch\MeilisearchCommunicationException;
use WapplerSystems\Meilisearch\System\Meilisearch\MeilisearchInternalServerErrorException; use WapplerSystems\Meilisearch\System\Meilisearch\MeilisearchInternalServerErrorException;
use WapplerSystems\Meilisearch\System\Meilisearch\MeilisearchUnavailableException; use WapplerSystems\Meilisearch\System\Meilisearch\MeilisearchUnavailableException;
use Solarium\Exception\HttpException;
/** /**
* Class MeilisearchReadService * Class MeilisearchReadService
@ -47,26 +45,6 @@ class MeilisearchReadService extends AbstractMeilisearchService
*/ */
protected $responseCache = null; protected $responseCache = null;
/**
* Performs a search.
*
* @param Query $query
* @return ResponseAdapter Meilisearch response
* @throws \RuntimeException if Meilisearch returns a HTTP status code other than 200
*/
public function search($query)
{
try {
$request = $this->client->createRequest($query);
$response = $this->executeRequest($request);
$this->hasSearched = true;
$this->responseCache = $response;
} catch (HttpException $e) {
$this->handleErrorResponses($e);
}
return $response;
}
/** /**
* Returns whether a search has been executed or not. * Returns whether a search has been executed or not.
* *

View File

@ -26,7 +26,6 @@ namespace WapplerSystems\Meilisearch\System\Meilisearch\Service;
use WapplerSystems\Meilisearch\System\Logging\MeilisearchLogManager; use WapplerSystems\Meilisearch\System\Logging\MeilisearchLogManager;
use WapplerSystems\Meilisearch\System\Meilisearch\ResponseAdapter; use WapplerSystems\Meilisearch\System\Meilisearch\ResponseAdapter;
use Solarium\QueryType\Extract\Query;
/** /**
* Class MeilisearchWriteService * Class MeilisearchWriteService

View File

@ -58,30 +58,16 @@ class SiteUtility
} }
/** /**
* This method is used to retrieve the connection configuration from the TYPO3 site configuration.
* *
* Note: Language context properties have precedence over global settings.
*
* The configuration is done in the globals configuration of a site, and be extended in the language specific configuration
* of a site.
*
* Typically everything except the core name is configured on the global level and the core name differs for each language.
*
* In addition every property can be defined for the ```read``` and ```write``` scope.
*
* The convention for property keys is "meilisearch_{propertyName}_{scope}". With the configuration "meilisearch_host_read" you define the host
* for the meilisearch read connection.
* *
* @param Site $typo3Site * @param Site $typo3Site
* @param string $property * @param string $property
* @param int $languageId
* @param string $scope
* @param string $defaultValue * @param string $defaultValue
* @return string * @return string
*/ */
public static function getConnectionProperty(Site $typo3Site, string $property, int $languageId, string $scope, string $defaultValue = null): string public static function getConnectionProperty(Site $typo3Site, string $property, string $defaultValue = null): string
{ {
$value = self::getConnectionPropertyOrFallback($typo3Site, $property, $languageId, $scope); $value = self::getConnectionPropertyOrFallback($typo3Site, $property);
if ($value === null) { if ($value === null) {
return $defaultValue; return $defaultValue;
} }
@ -94,72 +80,31 @@ class SiteUtility
* *
* @param Site $typo3Site * @param Site $typo3Site
* @param string $property * @param string $property
* @param int $languageId
* @param string $scope
* @return mixed * @return mixed
*/ */
protected static function getConnectionPropertyOrFallback(Site $typo3Site, string $property, int $languageId, string $scope) protected static function getConnectionPropertyOrFallback(Site $typo3Site, string $property)
{ {
if ($scope === 'write' && !self::writeConnectionIsEnabled($typo3Site, $languageId)) {
$scope = 'read';
}
// convention key meilisearch_$property_$scope // convention key meilisearch_$property_$scope
$keyToCheck = 'meilisearch_' . $property . '_' . $scope; $keyToCheck = 'meilisearch_' . $property;
// convention fallback key meilisearch_$property_read
$fallbackKey = 'meilisearch_' . $property . '_read';
// try to find language specific setting if found return it
$languageSpecificConfiguration = $typo3Site->getLanguageById($languageId)->toArray();
$value = self::getValueOrFallback($languageSpecificConfiguration, $keyToCheck, $fallbackKey);
if ($value !== null) {
return $value;
}
// if not found check global configuration // if not found check global configuration
$siteBaseConfiguration = $typo3Site->getConfiguration(); $siteBaseConfiguration = $typo3Site->getConfiguration();
return self::getValueOrFallback($siteBaseConfiguration, $keyToCheck, $fallbackKey); return self::getValueOrFallback($siteBaseConfiguration, $keyToCheck);
} }
/**
* Checks whether write connection is enabled.
* Language context properties have precedence over global settings.
*
* @param Site $typo3Site
* @param int $languageId
* @return bool
*/
protected static function writeConnectionIsEnabled(Site $typo3Site, int $languageId): bool
{
$languageSpecificConfiguration = $typo3Site->getLanguageById($languageId)->toArray();
$value = self::getValueOrFallback($languageSpecificConfiguration, 'meilisearch_use_write_connection', 'meilisearch_use_write_connection');
if ($value !== null) {
return $value;
}
$siteBaseConfiguration = $typo3Site->getConfiguration();
$value = self::getValueOrFallback($siteBaseConfiguration, 'meilisearch_use_write_connection', 'meilisearch_use_write_connection');
if ($value !== null) {
return $value;
}
return false;
}
/** /**
* @param array $data * @param array $data
* @param string $keyToCheck * @param string $keyToCheck
* @param string $fallbackKey
* @return string|bool|null * @return string|bool|null
*/ */
protected static function getValueOrFallback(array $data, string $keyToCheck, string $fallbackKey) protected static function getValueOrFallback(array $data, string $keyToCheck)
{ {
$value = $data[$keyToCheck] ?? null; $value = $data[$keyToCheck] ?? null;
if ($value === '0' || $value === 0 || !empty($value)) { if ($value === '0' || $value === 0 || !empty($value)) {
return self::evaluateConfigurationData($value); return self::evaluateConfigurationData($value);
} }
return null;
return self::evaluateConfigurationData($data[$fallbackKey] ?? null);
} }
/** /**
@ -176,7 +121,8 @@ class SiteUtility
{ {
if ($value === 'true') { if ($value === 'true') {
return true; return true;
} elseif ($value === 'false') { }
if ($value === 'false') {
return false; return false;
} }

View File

@ -75,7 +75,7 @@ class ReIndexTask extends AbstractMeilisearchTask
{ {
$cleanUpResult = true; $cleanUpResult = true;
$meilisearchConfiguration = $this->getSite()->getMeilisearchConfiguration(); $meilisearchConfiguration = $this->getSite()->getMeilisearchConfiguration();
$meilisearchServers = GeneralUtility::makeInstance(ConnectionManager::class)->getConnectionsBySite($this->getSite()); $meilisearchServers = GeneralUtility::makeInstance(ConnectionManager::class)->getConnectionBySite($this->getSite());
$typesToCleanUp = []; $typesToCleanUp = [];
$enableCommitsSetting = $meilisearchConfiguration->getEnableCommits(); $enableCommitsSetting = $meilisearchConfiguration->getEnableCommits();

View File

@ -25,7 +25,7 @@ namespace WapplerSystems\Meilisearch;
***************************************************************/ ***************************************************************/
use WapplerSystems\Meilisearch\Access\Rootline; use WapplerSystems\Meilisearch\Access\Rootline;
use WapplerSystems\Meilisearch\Domain\Search\ApacheMeilisearchDocument\Builder; use WapplerSystems\Meilisearch\Domain\Search\MeilisearchDocument\Builder;
use WapplerSystems\Meilisearch\FieldProcessor\Service; use WapplerSystems\Meilisearch\FieldProcessor\Service;
use WapplerSystems\Meilisearch\IndexQueue\FrontendHelper\PageFieldMappingIndexer; use WapplerSystems\Meilisearch\IndexQueue\FrontendHelper\PageFieldMappingIndexer;
use WapplerSystems\Meilisearch\IndexQueue\Item; use WapplerSystems\Meilisearch\IndexQueue\Item;

View File

@ -2,13 +2,11 @@
// TypoScript // TypoScript
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile('meilisearch', \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile('meilisearch',
'Configuration/TypoScript/Meilisearch/', 'Search - Base Configuration'); 'Configuration/TypoScript/Meilisearch/', 'Meilisearch');
// StyleSheets // StyleSheets
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile('meilisearch', \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile('meilisearch',
'Configuration/TypoScript/BootstrapCss/', 'Search - Bootstrap CSS Framework'); 'Configuration/TypoScript/BootstrapCSS/', 'Meilisearch - Bootstrap CSS');
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile('meilisearch',
'Configuration/TypoScript/StyleSheets/', 'Search - Default Stylesheets');
// OpenSearch++ // OpenSearch++
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile('meilisearch', \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile('meilisearch',

View File

@ -1,2 +0,0 @@
# Important: This file is deprecated and will removed with EXT:meilisearch 12.x
@import 'EXT:meilisearch/Configuration/TypoScript/BootstrapCss/setup.typoscript'

View File

@ -0,0 +1,28 @@
plugin.tx_meilisearch {
# cat=meilisearch: basic/10/enable; type=boolean; label=Enable/disable Meilisearch extension: EXT:meilisearch should only be enabled for relevant sys_languages, to avoid unnecessary connections and overwritten contents.
enabled = 1
view {
# cat=plugin.tx_meilisearch/file; type=string; label=Path to template root (FE)
templateRootPath = EXT:meilisearch/Resources/Private/Templates/
# cat=plugin.tx_meilisearch/file; type=string; label=Path to template partials (FE)
partialRootPath = EXT:meilisearch/Resources/Private/Partials/
# cat=plugin.tx_meilisearch/file; type=string; label=Path to template layouts (FE)
layoutRootPath = EXT:meilisearch/Resources/Private/Layouts/
}
meilisearch {
scheme = http
host = localhost
port = 7700
apiKey =
}
search {
targetPage = 0
results {
resultsPerPage = 10
}
}
}

View File

@ -8,21 +8,32 @@ plugin.tx_meilisearch {
dateFormat.date = d.m.Y H:i dateFormat.date = d.m.Y H:i
} }
meilisearch { view {
read { pluginNamespace = tx_meilisearch
scheme = {$plugin.tx_meilisearch.meilisearch.scheme}
host = {$plugin.tx_meilisearch.meilisearch.host} templateRootPaths {
port = {$plugin.tx_meilisearch.meilisearch.port} 0 = EXT:meilisearch/Resources/Private/Templates/
apiKey = {$plugin.tx_meilisearch.meilisearch.apiKey} 10 = {$plugin.tx_meilisearch.view.templateRootPath}
} }
write { partialRootPaths {
0 = EXT:meilisearch/Resources/Private/Partials/
10 = {$plugin.tx_meilisearch.view.partialRootPath}
}
layoutRootPaths {
0 = EXT:meilisearch/Resources/Private/Layouts/
10 = {$plugin.tx_meilisearch.view.layoutRootPath}
}
}
meilisearch {
scheme = {$plugin.tx_meilisearch.meilisearch.scheme} scheme = {$plugin.tx_meilisearch.meilisearch.scheme}
host = {$plugin.tx_meilisearch.meilisearch.host} host = {$plugin.tx_meilisearch.meilisearch.host}
port = {$plugin.tx_meilisearch.meilisearch.port} port = {$plugin.tx_meilisearch.meilisearch.port}
apiKey = {$plugin.tx_meilisearch.meilisearch.apiKey} apiKey = {$plugin.tx_meilisearch.meilisearch.apiKey}
} }
}
index { index {
additionalFields { additionalFields {
@ -39,8 +50,6 @@ plugin.tx_meilisearch {
queue { queue {
// mapping tableName.fields.MeilisearchFieldName => TableFieldName (+ cObj processing)
pages = 1 pages = 1
pages { pages {
initialization = WapplerSystems\Meilisearch\IndexQueue\Initializer\Page initialization = WapplerSystems\Meilisearch\IndexQueue\Initializer\Page
@ -116,9 +125,6 @@ plugin.tx_meilisearch {
sortBy = sortBy =
// https://www.hathitrust.org/blogs/large-scale-search/slow-queries-and-common-words-part-2
// http://blog.thedigitalgroup.com/vijaym/understanding-phrasequery-and-slop-in-meilisearch/
// https://meilisearch.pl/en/2010/07/14/meilisearch-and-phrasequery-phrase-bonus-in-query-stage/
// see https://lucene.apache.org/meilisearch/guide/7_0/the-dismax-query-parser.html#TheDisMaxQueryParser-Thepf_PhraseFields_Parameter // see https://lucene.apache.org/meilisearch/guide/7_0/the-dismax-query-parser.html#TheDisMaxQueryParser-Thepf_PhraseFields_Parameter
// EXT:Meilisearch configures Schemas from Meilisearch to use content field with boost of 2.0 per default. // EXT:Meilisearch configures Schemas from Meilisearch to use content field with boost of 2.0 per default.
@ -313,47 +319,6 @@ plugin.tx_meilisearch {
anonymizeIP = 1 anonymizeIP = 1
} }
view {
pluginNamespace = tx_meilisearch
templateRootPaths {
0 = EXT:meilisearch/Resources/Private/Templates/
10 = {$plugin.tx_meilisearch.view.templateRootPath}
}
partialRootPaths {
0 = EXT:meilisearch/Resources/Private/Partials/
10 = {$plugin.tx_meilisearch.view.partialRootPath}
}
layoutRootPaths {
0 = EXT:meilisearch/Resources/Private/Layouts/
10 = {$plugin.tx_meilisearch.view.layoutRootPath}
}
// By convention the templates is loaded from EXT:meilisearch/Resources/Private/Templates/Frontend/Search/(ActionName).html
// If you want to define a different entry template, you can do this here to overwrite the conventional default template
// if you want to use FLUID fallbacks you can just configure the template name, otherwise you could also use a full reference EXT:/.../
// The templates that you configure in availableTemplate can be used in the flexform by the editor to select a template for the concrete plugin instance.
templateFiles {
// results = Results
// results.availableTemplates {
// default {
// label = Default Searchresults Template
// file = Results
// }
// }
// form = Form
// form.availableTemplates {
// default {
// label = Default Searchform Template
// file = Form
// }
// }
// frequentSearched = FrequentlySearched
}
}
logging { logging {
exceptions = 1 exceptions = 1
debugOutput = 0 debugOutput = 0

View File

@ -1,2 +0,0 @@
# Important: This file is deprecated and will removed with EXT:meilisearch 12.x
@import 'EXT:meilisearch/Configuration/TypoScript/OpenSearch/constants.typoscript'

View File

@ -1,4 +1,3 @@
plugin.tx_meilisearch.OpenSearch { plugin.tx_meilisearch.OpenSearch {
# cat=plugin.meilisearch: OpenSearch/10; type=text; label=Short Name: Brief title of the search, up to 16 characters. # cat=plugin.meilisearch: OpenSearch/10; type=text; label=Short Name: Brief title of the search, up to 16 characters.

View File

@ -1,2 +0,0 @@
# Important: This file is deprecated and will removed with EXT:meilisearch 12.x
@import 'EXT:meilisearch/Configuration/TypoScript/OpenSearch/setup.typoscript'

View File

@ -1,4 +1,3 @@
// 7567 = SOLR as vanity number // 7567 = SOLR as vanity number
page { page {
@ -53,7 +52,6 @@ OpenSearch {
) )
# link to this description file for automatic updates # link to this description file for automatic updates
20 = TEXT 20 = TEXT
20.insertData = 1 20.insertData = 1
@ -64,7 +62,6 @@ OpenSearch {
) )
# link the search page # link the search page
30 = TEXT 30 = TEXT
30.insertData = 1 30.insertData = 1
@ -79,7 +76,6 @@ OpenSearch {
31.wrap = &amp;|={searchTerms}" /> 31.wrap = &amp;|={searchTerms}" />
# link to auto suggestion provider # link to auto suggestion provider
40 = TEXT 40 = TEXT
40.insertData = 1 40.insertData = 1
@ -94,7 +90,6 @@ OpenSearch {
41.wrap = &amp;|={searchTerms}" /> 41.wrap = &amp;|={searchTerms}" />
500 = TEXT 500 = TEXT
500.value ( 500.value (

View File

@ -1,2 +0,0 @@
# Important: This file is deprecated and will removed with EXT:meilisearch 12.x
@import 'EXT:meilisearch/Configuration/TypoScript/Meilisearch/constants.typoscript'

View File

@ -1,27 +0,0 @@
plugin.tx_meilisearch {
# cat=meilisearch: basic/10/enable; type=boolean; label=Enable/disable Meilisearch extension: EXT:meilisearch should only be enabled for relevant sys_languages, to avoid unnecessary connections and overwritten contents.
enabled = 1
view {
templateRootPath =
partialRootPath =
layoutRootPath =
}
meilisearch {
scheme = http
host = localhost
port = 7700
path = /meilisearch/core_en/
username =
password =
}
search {
targetPage = 0
results {
resultsPerPage = 10
}
}
}

View File

@ -1,2 +0,0 @@
# Important: This file is deprecated and will removed with EXT:meilisearch 12.x
@import 'EXT:meilisearch/Configuration/TypoScript/Meilisearch/setup.typoscript'

View File

@ -1,2 +0,0 @@
# Important: This file is deprecated and will removed with EXT:meilisearch 12.x
@import 'EXT:meilisearch/Configuration/TypoScript/StyleSheets/setup.typoscript'

View File

@ -102,7 +102,6 @@
<hr class="double" /> <hr class="double" />
No meilisearch server running? You can use <strong><a href="http://www.hosted-meilisearch.com/" target="_blank">hosted-meilisearch.com</a></strong> to setup a meilisearch core with just a few clicks.
</f:section> </f:section>
<f:section name="Statistics"> <f:section name="Statistics">

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -1,13 +0,0 @@
// This file is autogenerated via the `commonjs` Grunt task. You can require() this file in a CommonJS environment.
require('../../js/transition.js')
require('../../js/alert.js')
require('../../js/button.js')
require('../../js/carousel.js')
require('../../js/collapse.js')
require('../../js/dropdown.js')
require('../../js/modal.js')
require('../../js/tooltip.js')
require('../../js/popover.js')
require('../../js/scrollspy.js')
require('../../js/tab.js')
require('../../js/affix.js')

View File

@ -63,21 +63,6 @@ defined('TYPO3_MODE') || die();
] ]
); );
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerModule(
'WapplerSystems.meilisearch',
'searchbackend',
'CoreOptimization',
'',
[
'Backend\\Search\\CoreOptimizationModule' => 'index, addSynonyms, importSynonymList, deleteAllSynonyms, exportSynonyms, deleteSynonyms, saveStopWords, importStopWordList, exportStopWords, switchSite, switchCore'
],
[
'access' => 'user,group',
'icon' => 'EXT:meilisearch/Resources/Public/Images/Icons/ModuleCoreOptimization.svg',
'labels' => 'LLL:EXT:meilisearch/Resources/Private/Language/locallang_mod_coreoptimize.xlf',
'navigationComponentId' => $treeComponentId
]
);
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerModule( \TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerModule(
'WapplerSystems.meilisearch', 'WapplerSystems.meilisearch',