zwischenstand
This commit is contained in:
@@ -258,7 +258,7 @@ abstract class AbstractModuleController extends ActionController
|
||||
);
|
||||
$menuItem->setHref($uri);
|
||||
|
||||
if ($coreAdmin->getCorePath() == $this->selectedMeilisearchCoreConnection->getAdminService()->getCorePath()) {
|
||||
if ($coreAdmin->getCorePath() == $this->selectedMeilisearchCoreConnection->getService()->getCorePath()) {
|
||||
$menuItem->setActive(true);
|
||||
}
|
||||
$this->coreSelectorMenu->addMenuItem($menuItem);
|
||||
@@ -308,7 +308,7 @@ abstract class AbstractModuleController extends ActionController
|
||||
}
|
||||
if (!$this->selectedMeilisearchCoreConnection instanceof MeilisearchCoreConnection && count($meilisearchCoreConnections) > 0) {
|
||||
$this->initializeFirstAvailableMeilisearchCoreConnection($meilisearchCoreConnections, $moduleData);
|
||||
$message = LocalizationUtility::translate('coreselector_switched_to_default_core', 'meilisearch', [$currentMeilisearchCorePath, $this->selectedSite->getLabel(), $this->selectedMeilisearchCoreConnection->getAdminService()->getCorePath()]);
|
||||
$message = LocalizationUtility::translate('coreselector_switched_to_default_core', 'meilisearch', [$currentMeilisearchCorePath, $this->selectedSite->getLabel(), $this->selectedMeilisearchCoreConnection->getService()->getCorePath()]);
|
||||
$this->addFlashMessage($message, '', AbstractMessage::NOTICE);
|
||||
}
|
||||
}
|
||||
@@ -322,7 +322,7 @@ abstract class AbstractModuleController extends ActionController
|
||||
return;
|
||||
}
|
||||
$this->selectedMeilisearchCoreConnection = $meilisearchCoreConnections[0];
|
||||
$moduleData->setCore($this->selectedMeilisearchCoreConnection->getAdminService()->getCorePath());
|
||||
$moduleData->setCore($this->selectedMeilisearchCoreConnection->getService()->getCorePath());
|
||||
$this->moduleDataStorageService->persistModuleData($moduleData);
|
||||
}
|
||||
}
|
||||
|
@@ -138,7 +138,7 @@ class IndexAdministrationModuleController extends AbstractModuleController
|
||||
|
||||
foreach ($meilisearchServers as $meilisearchServer) {
|
||||
/* @var $meilisearchServer MeilisearchConnection */
|
||||
$coreAdmin = $meilisearchServer->getAdminService();
|
||||
$coreAdmin = $meilisearchServer->getService();
|
||||
$coreReloaded = $coreAdmin->reloadCore()->getHttpStatus() === 200;
|
||||
|
||||
$coreName = $coreAdmin->getPrimaryEndpoint()->getCore();
|
||||
|
@@ -24,19 +24,13 @@ namespace WapplerSystems\Meilisearch\Controller\Backend\Search;
|
||||
* This copyright notice MUST APPEAR in all copies of the script!
|
||||
***************************************************************/
|
||||
|
||||
use TYPO3\CMS\Core\Utility\DebugUtility;
|
||||
use WapplerSystems\Meilisearch\Api;
|
||||
use WapplerSystems\Meilisearch\ConnectionManager;
|
||||
use WapplerSystems\Meilisearch\Domain\Search\Statistics\StatisticsRepository;
|
||||
use WapplerSystems\Meilisearch\Domain\Search\MeilisearchDocument\Repository;
|
||||
use WapplerSystems\Meilisearch\System\Meilisearch\ResponseAdapter;
|
||||
use WapplerSystems\Meilisearch\System\Validator\Path;
|
||||
use TYPO3\CMS\Backend\Template\ModuleTemplate;
|
||||
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
|
||||
use TYPO3\CMS\Core\Messaging\FlashMessage;
|
||||
use TYPO3\CMS\Core\Registry;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Extbase\Mvc\Exception\StopActionException;
|
||||
use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
|
||||
|
||||
/**
|
||||
@@ -121,7 +115,6 @@ class InfoModuleController extends AbstractModuleController
|
||||
{
|
||||
$connectedHosts = [];
|
||||
$missingHosts = [];
|
||||
$invalidPaths = [];
|
||||
|
||||
$connection = $this->meilisearchConnectionManager->getConnectionBySite($this->selectedSite);
|
||||
|
||||
@@ -130,12 +123,12 @@ class InfoModuleController extends AbstractModuleController
|
||||
return;
|
||||
}
|
||||
|
||||
$coreAdmin = $connection->getAdminService();
|
||||
$service = $connection->getService();
|
||||
|
||||
if ($coreAdmin->ping()) {
|
||||
$connectedHosts[] = $coreAdmin;
|
||||
if ($service->ping()) {
|
||||
$connectedHosts[] = $service;
|
||||
} else {
|
||||
$missingHosts[] = $coreAdmin;
|
||||
$missingHosts[] = $service;
|
||||
}
|
||||
|
||||
|
||||
@@ -144,7 +137,6 @@ class InfoModuleController extends AbstractModuleController
|
||||
'apiKey' => Api::getApiKey(),
|
||||
'connectedHosts' => $connectedHosts,
|
||||
'missingHosts' => $missingHosts,
|
||||
'invalidPaths' => $invalidPaths
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -211,7 +203,7 @@ class InfoModuleController extends AbstractModuleController
|
||||
|
||||
$this->addFlashMessage(
|
||||
'',
|
||||
'Unable to contact Meilisearch server: ' . $this->selectedSite->getLabel() . ' ' . $coreAdmin->getCorePath(),
|
||||
'Unable to contact Meilisearch server: ' . $this->selectedSite->getLabel(),
|
||||
FlashMessage::ERROR
|
||||
);
|
||||
}
|
||||
@@ -248,49 +240,4 @@ class InfoModuleController extends AbstractModuleController
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets field metrics.
|
||||
*
|
||||
* @param ResponseAdapter $lukeData Luke index data
|
||||
* @param string $limitNote Note to display if there are too many documents in the index to show number of terms for a field
|
||||
*
|
||||
* @return array An array of field metrics
|
||||
*/
|
||||
protected function getFields(ResponseAdapter $lukeData, $limitNote)
|
||||
{
|
||||
$rows = [];
|
||||
|
||||
$fields = (array)$lukeData->fields;
|
||||
foreach ($fields as $name => $field) {
|
||||
$rows[$name] = [
|
||||
'name' => $name,
|
||||
'type' => $field->type,
|
||||
'docs' => isset($field->docs) ? $field->docs : 0,
|
||||
'terms' => isset($field->distinct) ? $field->distinct : $limitNote
|
||||
];
|
||||
}
|
||||
ksort($rows);
|
||||
|
||||
return $rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets general core metrics.
|
||||
*
|
||||
* @param ResponseAdapter $lukeData Luke index data
|
||||
* @param array $fields Fields metrics
|
||||
*
|
||||
* @return array An array of core metrics
|
||||
*/
|
||||
protected function getCoreMetrics(ResponseAdapter $lukeData, array $fields)
|
||||
{
|
||||
$coreMetrics = [
|
||||
'numberOfDocuments' => $lukeData->index->numDocs,
|
||||
'numberOfDeletedDocuments' => $lukeData->index->deletedDocs,
|
||||
'numberOfTerms' => $lukeData->index->numTerms,
|
||||
'numberOfFields' => count($fields)
|
||||
];
|
||||
|
||||
return $coreMetrics;
|
||||
}
|
||||
}
|
||||
|
@@ -25,6 +25,7 @@ namespace WapplerSystems\Meilisearch\Domain\Index;
|
||||
* This copyright notice MUST APPEAR in all copies of the script!
|
||||
***************************************************************/
|
||||
|
||||
use TYPO3\CMS\Core\Utility\DebugUtility;
|
||||
use WapplerSystems\Meilisearch\ConnectionManager;
|
||||
use WapplerSystems\Meilisearch\IndexQueue\Indexer;
|
||||
use WapplerSystems\Meilisearch\IndexQueue\Item;
|
||||
|
@@ -130,9 +130,7 @@ class Builder
|
||||
*/
|
||||
public function fromRecord(array $itemRecord, string $type, int $rootPageUid, string $accessRootLine): array
|
||||
{
|
||||
/* @var $document Document */
|
||||
$document = GeneralUtility::makeInstance(Document::class);
|
||||
|
||||
$document = [];
|
||||
$site = $this->getSiteByPageId($rootPageUid);
|
||||
|
||||
$documentId = $this->getDocumentId($type, $site->getRootPageId(), $itemRecord['uid']);
|
||||
@@ -174,7 +172,7 @@ class Builder
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TypoScriptFrontendController $page
|
||||
* @param TypoScriptFrontendController $frontendController
|
||||
* @param string $accessGroups
|
||||
* @param string $mountPointParameter
|
||||
* @return string
|
||||
|
@@ -33,7 +33,6 @@ use TYPO3\CMS\Backend\Utility\BackendUtility;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
|
||||
/**
|
||||
* Base Clas for Typo3ManagedSite and LegacySite
|
||||
*/
|
||||
abstract class Site implements SiteInterface
|
||||
{
|
||||
@@ -42,6 +41,11 @@ abstract class Site implements SiteInterface
|
||||
*/
|
||||
protected $configuration;
|
||||
|
||||
/**
|
||||
* @var \TYPO3\CMS\Core\Site\Entity\Site
|
||||
*/
|
||||
protected $site;
|
||||
|
||||
/**
|
||||
* Root page record.
|
||||
*
|
||||
@@ -63,16 +67,6 @@ abstract class Site implements SiteInterface
|
||||
*/
|
||||
protected $pagesRepository;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $defaultLanguageId = 0;
|
||||
|
||||
/**
|
||||
* @var int[] Available language ids
|
||||
*/
|
||||
protected $availableLanguageIds = [];
|
||||
|
||||
/**
|
||||
* Takes an pagerecord and checks whether the page is marked as root page.
|
||||
*
|
||||
@@ -100,14 +94,14 @@ abstract class Site implements SiteInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets available language id's for this site
|
||||
*
|
||||
* @return int[] array or language id's
|
||||
* @return \TYPO3\CMS\Core\Site\Entity\Site
|
||||
*/
|
||||
public function getAvailableLanguageIds(): array {
|
||||
return $this->availableLanguageIds;
|
||||
public function getSite(): \TYPO3\CMS\Core\Site\Entity\Site
|
||||
{
|
||||
return $this->site;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the site's label. The label is build from the the site title and root
|
||||
* page ID (uid).
|
||||
@@ -137,17 +131,6 @@ abstract class Site implements SiteInterface
|
||||
return $this->configuration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the site's default language as configured in
|
||||
* config.sys_language_uid. If sys_language_uid is not set, 0 is assumed to
|
||||
* be the default.
|
||||
*
|
||||
* @return int The site's default language.
|
||||
*/
|
||||
public function getDefaultLanguage()
|
||||
{
|
||||
return $this->defaultLanguageId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a list of page IDs in this site. Attention, this includes
|
||||
|
@@ -36,13 +36,6 @@ interface SiteInterface
|
||||
*/
|
||||
public function getRootPageId();
|
||||
|
||||
/**
|
||||
* Gets available language id's for this site
|
||||
*
|
||||
* @return int[] array or language id's
|
||||
*/
|
||||
public function getAvailableLanguageIds(): array;
|
||||
|
||||
/**
|
||||
* Gets the site's label. The label is build from the the site title and root
|
||||
* page ID (uid).
|
||||
@@ -58,15 +51,6 @@ interface SiteInterface
|
||||
*/
|
||||
public function getMeilisearchConfiguration();
|
||||
|
||||
/**
|
||||
* Gets the site's default language as configured in
|
||||
* config.sys_language_uid. If sys_language_uid is not set, 0 is assumed to
|
||||
* be the default.
|
||||
*
|
||||
* @return int The site's default language.
|
||||
*/
|
||||
public function getDefaultLanguage();
|
||||
|
||||
/**
|
||||
* Generates a list of page IDs in this site. Attention, this includes
|
||||
* all page types! Deleted pages are not included.
|
||||
|
@@ -290,6 +290,7 @@ class SiteRepository
|
||||
|
||||
return GeneralUtility::makeInstance(
|
||||
Typo3ManagedSite::class,
|
||||
$typo3Site,
|
||||
/** @scrutinizer ignore-type */
|
||||
$meilisearchConfiguration,
|
||||
/** @scrutinizer ignore-type */
|
||||
|
@@ -51,9 +51,11 @@ class Typo3ManagedSite extends Site
|
||||
|
||||
|
||||
public function __construct(
|
||||
$site,
|
||||
TypoScriptConfiguration $configuration,
|
||||
array $page, $domain, $siteHash, PagesRepository $pagesRepository = null, array $meilisearchConnectionConfiguration = [], Typo3Site $typo3SiteObject = null)
|
||||
{
|
||||
$this->site = $site;
|
||||
$this->configuration = $configuration;
|
||||
$this->rootPage = $page;
|
||||
$this->domain = $domain;
|
||||
|
@@ -27,7 +27,6 @@ namespace WapplerSystems\Meilisearch\IndexQueue;
|
||||
use WapplerSystems\Meilisearch\ContentObject\Classification;
|
||||
use WapplerSystems\Meilisearch\ContentObject\Multivalue;
|
||||
use WapplerSystems\Meilisearch\ContentObject\Relation;
|
||||
use WapplerSystems\Meilisearch\System\Meilisearch\Document\Document;
|
||||
use TYPO3\CMS\Core\Core\Environment;
|
||||
use TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
|
@@ -300,7 +300,7 @@ class PageIndexer extends AbstractFrontendHelper implements SingletonInterface
|
||||
$this->responseData['meilisearchConnection'] = [
|
||||
'rootPage' => $indexQueueItem->getRootPageUid(),
|
||||
'sys_language_uid' => Util::getLanguageUid(),
|
||||
'meilisearch' => (string)$meilisearchConnection->getNode('write')
|
||||
'meilisearch' => (string)$meilisearchConnection
|
||||
];
|
||||
|
||||
$documentsSentToMeilisearch = $indexer->getDocumentsSentToMeilisearch();
|
||||
|
@@ -24,6 +24,7 @@ namespace WapplerSystems\Meilisearch\IndexQueue;
|
||||
* This copyright notice MUST APPEAR in all copies of the script!
|
||||
***************************************************************/
|
||||
|
||||
use TYPO3\CMS\Core\Utility\DebugUtility;
|
||||
use WapplerSystems\Meilisearch\ConnectionManager;
|
||||
use WapplerSystems\Meilisearch\Domain\Search\MeilisearchDocument\Builder;
|
||||
use WapplerSystems\Meilisearch\FieldProcessor\Service;
|
||||
@@ -145,11 +146,13 @@ class Indexer extends AbstractIndexer
|
||||
$this->type = $item->getType();
|
||||
$this->setLogging($item);
|
||||
|
||||
$meilisearchConnections = $this->getMeilisearchConnectionByItem($item);
|
||||
foreach ($meilisearchConnections as $systemLanguageUid => $meilisearchConnection) {
|
||||
$this->meilisearch = $meilisearchConnection;
|
||||
$this->meilisearch = $this->getMeilisearchConnectionByItem($item);
|
||||
|
||||
if (!$this->indexItem($item, $systemLanguageUid)) {
|
||||
$languages = $item->getSite()->getSite()->getLanguages();
|
||||
|
||||
foreach ($languages as $language) {
|
||||
|
||||
if (!$this->indexItem($item, $language->getLanguageId())) {
|
||||
/*
|
||||
* A single language voting for "not indexed" should make the whole
|
||||
* item count as being not indexed, even if all other languages are
|
||||
@@ -511,7 +514,7 @@ class Indexer extends AbstractIndexer
|
||||
* for translations of an 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 \WapplerSystems\Meilisearch\System\Meilisearch\MeilisearchConnection
|
||||
*/
|
||||
protected function getMeilisearchConnectionByItem(Item $item)
|
||||
{
|
||||
@@ -525,7 +528,7 @@ class Indexer extends AbstractIndexer
|
||||
|
||||
// Meilisearch configurations possible for this item
|
||||
$site = $item->getSite();
|
||||
return $site->getMeilisearchConnectionConfiguration();
|
||||
return $this->connectionManager->getConnectionBySite($site);
|
||||
|
||||
|
||||
$defaultLanguageUid = $this->getDefaultLanguageUid($item, $site->getRootPage(), $siteLanguages);
|
||||
|
@@ -29,6 +29,7 @@ use WapplerSystems\Meilisearch\Access\Rootline;
|
||||
use WapplerSystems\Meilisearch\Access\RootlineElement;
|
||||
use WapplerSystems\Meilisearch\Domain\Index\PageIndexer\Helper\UriBuilder\AbstractUriStrategy;
|
||||
use WapplerSystems\Meilisearch\Domain\Index\PageIndexer\Helper\UriStrategyFactory;
|
||||
use WapplerSystems\Meilisearch\Domain\Search\MeilisearchDocument\Builder;
|
||||
use WapplerSystems\Meilisearch\System\Logging\MeilisearchLogManager;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
|
||||
@@ -58,13 +59,19 @@ class PageIndexer extends Indexer
|
||||
return false;
|
||||
}
|
||||
|
||||
//$meilisearchConnection = $this->getMeilisearchConnectionByItem($item);
|
||||
$this->meilisearch = $this->getMeilisearchConnectionByItem($item);
|
||||
|
||||
$site = $item->getSite();
|
||||
$languageUids = $site->getAvailableLanguageIds();
|
||||
$languages = $site->getSite()->getLanguages();
|
||||
|
||||
foreach ($languageUids as $systemLanguageUid) {
|
||||
$contentAccessGroups = $this->getAccessGroupsFromContent($item, $systemLanguageUid);
|
||||
foreach ($languages as $language) {
|
||||
|
||||
$this->indexPage($item, $language->getLanguageId());
|
||||
|
||||
// TODO: Versions for usergroups
|
||||
continue;
|
||||
|
||||
$contentAccessGroups = $this->getAccessGroupsFromContent($item, $language->getLanguageId());
|
||||
|
||||
if (empty($contentAccessGroups)) {
|
||||
// might be an empty page w/no content elements or some TYPO3 error / bug
|
||||
@@ -73,7 +80,7 @@ class PageIndexer extends Indexer
|
||||
}
|
||||
|
||||
foreach ($contentAccessGroups as $userGroup) {
|
||||
$this->indexPage($item, $systemLanguageUid, $userGroup);
|
||||
$this->indexPage($item, $language->getLanguageId(), $userGroup);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -191,46 +198,6 @@ class PageIndexer extends Indexer
|
||||
return $accessGroupsCache[$accessGroupsCacheEntryId];
|
||||
}
|
||||
|
||||
// Utility methods
|
||||
|
||||
/**
|
||||
* Builds a base page indexer request with configured headers and other
|
||||
* parameters.
|
||||
*
|
||||
* @return PageIndexerRequest Base page indexer request
|
||||
*/
|
||||
protected function buildBasePageIndexerRequest()
|
||||
{
|
||||
$request = $this->getPageIndexerRequest();
|
||||
$request->setParameter('loggingEnabled', $this->loggingEnabled);
|
||||
|
||||
if (!empty($this->options['authorization.'])) {
|
||||
$request->setAuthorizationCredentials(
|
||||
$this->options['authorization.']['username'],
|
||||
$this->options['authorization.']['password']
|
||||
);
|
||||
}
|
||||
|
||||
if (!empty($this->options['frontendDataHelper.']['headers.'])) {
|
||||
foreach ($this->options['frontendDataHelper.']['headers.'] as $headerValue) {
|
||||
$request->addHeader($headerValue);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($this->options['frontendDataHelper.']['requestTimeout'])) {
|
||||
$request->setTimeout((float)$this->options['frontendDataHelper.']['requestTimeout']);
|
||||
}
|
||||
|
||||
return $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return PageIndexerRequest
|
||||
*/
|
||||
protected function getPageIndexerRequest()
|
||||
{
|
||||
return GeneralUtility::makeInstance(PageIndexerRequest::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines a page ID's URL.
|
||||
@@ -248,9 +215,7 @@ class PageIndexer extends Indexer
|
||||
$pageId = $item->getRecordUid();
|
||||
$strategy = $this->getUriStrategy($pageId);
|
||||
$mountPointParameter = $this->getMountPageDataUrlParameter($item);
|
||||
$dataUrl = $strategy->getPageIndexingUriFromPageItemAndLanguageId($item, $language, $mountPointParameter, $this->options);
|
||||
|
||||
return $dataUrl;
|
||||
return $strategy->getPageIndexingUriFromPageItemAndLanguageId($item, $language, $mountPointParameter, $this->options);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -294,16 +259,16 @@ class PageIndexer extends Indexer
|
||||
*/
|
||||
protected function indexPage(Item $item, $language = 0, $userGroup = 0)
|
||||
{
|
||||
DebugUtility::debug('dededede');
|
||||
$accessRootline = $this->getAccessRootline($item, $language, $userGroup);
|
||||
$request = $this->buildBasePageIndexerRequest();
|
||||
$request->setIndexQueueItem($item);
|
||||
$request->addAction('indexPage');
|
||||
$request->setParameter('accessRootline', (string)$accessRootline);
|
||||
|
||||
$indexRequestUrl = $this->getDataUrl($item, $language);
|
||||
$response = $request->send($indexRequestUrl);
|
||||
$indexActionResult = $response->getActionResult('indexPage');
|
||||
|
||||
//$this->meilisearch->getService()->getClient()->index($item->getType())->addDocuments();
|
||||
|
||||
$result = false;
|
||||
|
||||
DebugUtility::debug('PageIndexer');
|
||||
exit();
|
||||
|
||||
|
||||
if ($this->loggingEnabled) {
|
||||
$logSeverity = MeilisearchLogManager::INFO;
|
||||
@@ -404,4 +369,21 @@ class PageIndexer extends Indexer
|
||||
return Rootline::getAccessRootlineByPageId($pageId, $mountPointParameter);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Builds the Meilisearch document for the current page.
|
||||
*
|
||||
* @return array A document representing the page
|
||||
*/
|
||||
protected function getPageDocument()
|
||||
{
|
||||
/** @var Builder $documentBuilder */
|
||||
$documentBuilder = GeneralUtility::makeInstance(Builder::class);
|
||||
$document = $documentBuilder->fromPage($this->page, $this->pageUrl, $this->pageAccessRootline, (string)$this->mountPointParameter);
|
||||
|
||||
self::$pageMeilisearchDocumentId = $document['id'];
|
||||
|
||||
return $document;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -40,7 +40,7 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
class PageIndexerRequest
|
||||
{
|
||||
|
||||
const SOLR_INDEX_HEADER = 'X-Tx-Meilisearch-Iq';
|
||||
const MEILISEARCH_INDEX_HEADER = 'X-Tx-Meilisearch-Iq';
|
||||
|
||||
/**
|
||||
* List of actions to perform during page rendering.
|
||||
@@ -248,7 +248,7 @@ class PageIndexerRequest
|
||||
];
|
||||
|
||||
$indexerRequestData = array_merge($indexerRequestData, $this->parameters);
|
||||
$headers[] = self::SOLR_INDEX_HEADER . ': ' . json_encode($indexerRequestData, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT | JSON_UNESCAPED_SLASHES);
|
||||
$headers[] = self::MEILISEARCH_INDEX_HEADER . ': ' . json_encode($indexerRequestData, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT | JSON_UNESCAPED_SLASHES);
|
||||
|
||||
return $headers;
|
||||
}
|
||||
|
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
namespace WapplerSystems\Meilisearch;
|
||||
|
||||
namespace WapplerSystems\Meilisearch\IndexQueue;
|
||||
|
||||
/***************************************************************
|
||||
* Copyright notice
|
||||
@@ -25,16 +26,21 @@ namespace WapplerSystems\Meilisearch;
|
||||
***************************************************************/
|
||||
|
||||
use WapplerSystems\Meilisearch\Access\Rootline;
|
||||
use WapplerSystems\Meilisearch\AdditionalPageIndexer;
|
||||
use WapplerSystems\Meilisearch\ConnectionManager;
|
||||
use WapplerSystems\Meilisearch\Domain\Search\MeilisearchDocument\Builder;
|
||||
use WapplerSystems\Meilisearch\FieldProcessor\Service;
|
||||
use WapplerSystems\Meilisearch\IndexQueue\FrontendHelper\PageFieldMappingIndexer;
|
||||
use WapplerSystems\Meilisearch\IndexQueue\Item;
|
||||
use WapplerSystems\Meilisearch\SubstitutePageIndexer;
|
||||
use WapplerSystems\Meilisearch\System\Configuration\TypoScriptConfiguration;
|
||||
use WapplerSystems\Meilisearch\System\Logging\MeilisearchLogManager;
|
||||
use WapplerSystems\Meilisearch\System\Meilisearch\Document\Document;
|
||||
use WapplerSystems\Meilisearch\System\Meilisearch\MeilisearchConnection;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
|
||||
use WapplerSystems\Meilisearch\Typo3PageContentExtractor;
|
||||
use WapplerSystems\Meilisearch\Util;
|
||||
|
||||
/**
|
||||
* Page Indexer to index TYPO3 pages used by the Index Queue.
|
||||
@@ -52,12 +58,12 @@ class Typo3PageIndexer
|
||||
* @var string
|
||||
*/
|
||||
protected static $pageMeilisearchDocumentId = '';
|
||||
|
||||
/**
|
||||
* The Meilisearch document generated for the current page.
|
||||
*
|
||||
* @var Document
|
||||
* @var array
|
||||
*/
|
||||
protected static $pageMeilisearchDocument = null;
|
||||
private static $pageMeilisearchDocument;
|
||||
|
||||
/**
|
||||
* The mount point parameter used in the Frontend controller.
|
||||
*
|
||||
@@ -193,7 +199,7 @@ class Typo3PageIndexer
|
||||
/**
|
||||
* Gets the Meilisearch document generated for the current page.
|
||||
*
|
||||
* @return Document|NULL The page's Meilisearch document or NULL if it has not been generated yet.
|
||||
* @return array|NULL The page's Meilisearch document or NULL if it has not been generated yet.
|
||||
*/
|
||||
public static function getPageMeilisearchDocument()
|
||||
{
|
||||
@@ -209,7 +215,7 @@ class Typo3PageIndexer
|
||||
*/
|
||||
public function setMeilisearchConnection(MeilisearchConnection $meilisearchConnection)
|
||||
{
|
||||
if (!$meilisearchConnection->getWriteService()->ping()) {
|
||||
if (!$meilisearchConnection->getService()->ping()) {
|
||||
throw new \Exception(
|
||||
'Could not connect to Meilisearch server.',
|
||||
1323946472
|
||||
@@ -257,7 +263,7 @@ class Typo3PageIndexer
|
||||
/**
|
||||
* Applies the configured post processors (indexPagePostProcessPageDocument)
|
||||
*
|
||||
* @param Document $pageDocument
|
||||
* @param array $pageDocument
|
||||
*/
|
||||
protected function applyIndexPagePostProcessors($pageDocument)
|
||||
{
|
||||
@@ -278,10 +284,11 @@ class Typo3PageIndexer
|
||||
/**
|
||||
* Builds the Meilisearch document for the current page.
|
||||
*
|
||||
* @return Document A document representing the page
|
||||
* @return array A document representing the page
|
||||
*/
|
||||
protected function getPageDocument()
|
||||
{
|
||||
/** @var Builder $documentBuilder */
|
||||
$documentBuilder = GeneralUtility::makeInstance(Builder::class);
|
||||
$document = $documentBuilder->fromPage($this->page, $this->pageUrl, $this->pageAccessRootline, (string)$this->mountPointParameter);
|
||||
|
||||
@@ -431,7 +438,7 @@ class Typo3PageIndexer
|
||||
// chunk adds by 20
|
||||
$documentChunks = array_chunk($documents, 20);
|
||||
foreach ($documentChunks as $documentChunk) {
|
||||
$response = $this->meilisearchConnection->getWriteService()->addDocuments($documentChunk);
|
||||
$response = $this->meilisearchConnection->getService()->addDocuments($documentChunk);
|
||||
if ($response->getHttpStatus() != 200) {
|
||||
throw new \RuntimeException('Meilisearch Request failed.', 1331834983);
|
||||
}
|
@@ -76,13 +76,13 @@ class FrontendUserAuthenticator implements MiddlewareInterface
|
||||
*/
|
||||
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
|
||||
{
|
||||
if (!$request->hasHeader(PageIndexerRequest::SOLR_INDEX_HEADER)) {
|
||||
if (!$request->hasHeader(PageIndexerRequest::MEILISEARCH_INDEX_HEADER)) {
|
||||
return $handler->handle($request);
|
||||
}
|
||||
|
||||
// disable TSFE cache for TYPO3 v10
|
||||
$request = $request->withAttribute('noCache', true);
|
||||
$jsonEncodedParameters = $request->getHeader(PageIndexerRequest::SOLR_INDEX_HEADER)[0];
|
||||
$jsonEncodedParameters = $request->getHeader(PageIndexerRequest::MEILISEARCH_INDEX_HEADER)[0];
|
||||
|
||||
/* @var PageIndexerRequestHandler $pageIndexerRequestHandler */
|
||||
$pageIndexerRequestHandler = GeneralUtility::makeInstance(PageIndexerRequestHandler::class, $jsonEncodedParameters);
|
||||
|
@@ -52,7 +52,7 @@ class PageIndexerFinisher implements MiddlewareInterface
|
||||
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
|
||||
{
|
||||
$response = $handler->handle($request);
|
||||
if ($request->hasHeader(PageIndexerRequest::SOLR_INDEX_HEADER)) {
|
||||
if ($request->hasHeader(PageIndexerRequest::MEILISEARCH_INDEX_HEADER)) {
|
||||
/* @var PageIndexerRequestHandler $pageIndexerRequestHandler */
|
||||
$pageIndexerRequestHandler = GeneralUtility::makeInstance(PageIndexerRequestHandler::class);
|
||||
$pageIndexerRequestHandler->shutdown();
|
||||
|
@@ -51,10 +51,10 @@ class PageIndexerInitialization implements MiddlewareInterface
|
||||
*/
|
||||
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
|
||||
{
|
||||
if ($request->hasHeader(PageIndexerRequest::SOLR_INDEX_HEADER)) {
|
||||
if ($request->hasHeader(PageIndexerRequest::MEILISEARCH_INDEX_HEADER)) {
|
||||
// disable TSFE cache for TYPO3 v10
|
||||
$request = $request->withAttribute('noCache', true);
|
||||
$jsonEncodedParameters = $request->getHeader(PageIndexerRequest::SOLR_INDEX_HEADER)[0];
|
||||
$jsonEncodedParameters = $request->getHeader(PageIndexerRequest::MEILISEARCH_INDEX_HEADER)[0];
|
||||
/* @var PageIndexerRequestHandler $pageIndexerRequestHandler */
|
||||
$pageIndexerRequestHandler = GeneralUtility::makeInstance(PageIndexerRequestHandler::class, $jsonEncodedParameters);
|
||||
|
||||
|
@@ -25,7 +25,7 @@ namespace WapplerSystems\Meilisearch\Report;
|
||||
***************************************************************/
|
||||
|
||||
use WapplerSystems\Meilisearch\ConnectionManager;
|
||||
use WapplerSystems\Meilisearch\System\Meilisearch\Service\MeilisearchAdminService;
|
||||
use WapplerSystems\Meilisearch\System\Meilisearch\Service\MeilisearchService;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Reports\Status;
|
||||
|
||||
@@ -87,10 +87,10 @@ class AccessFilterPluginInstalledStatus extends AbstractMeilisearchStatus
|
||||
/**
|
||||
* Checks whether the Meilisearch plugin is installed.
|
||||
*
|
||||
* @param MeilisearchAdminService $adminService
|
||||
* @param MeilisearchService $adminService
|
||||
* @return null|\TYPO3\CMS\Reports\Status
|
||||
*/
|
||||
protected function checkPluginInstallationStatus(MeilisearchAdminService $adminService)
|
||||
protected function checkPluginInstallationStatus(MeilisearchService $adminService)
|
||||
{
|
||||
if ($this->isPluginInstalled($adminService)) {
|
||||
return null;
|
||||
@@ -111,10 +111,10 @@ class AccessFilterPluginInstalledStatus extends AbstractMeilisearchStatus
|
||||
/**
|
||||
* Checks whether the Meilisearch plugin version is up to date.
|
||||
*
|
||||
* @param MeilisearchAdminService $adminService
|
||||
* @param MeilisearchService $adminService
|
||||
* @return null|\TYPO3\CMS\Reports\Status
|
||||
*/
|
||||
protected function checkPluginVersion(MeilisearchAdminService $adminService)
|
||||
protected function checkPluginVersion(MeilisearchService $adminService)
|
||||
{
|
||||
if (!($this->isPluginInstalled($adminService) && $this->isPluginOutdated($adminService))) {
|
||||
return null;
|
||||
@@ -137,10 +137,10 @@ class AccessFilterPluginInstalledStatus extends AbstractMeilisearchStatus
|
||||
* Checks whether the Access Filter Query Parser Plugin is installed for
|
||||
* the given Meilisearch server instance.
|
||||
*
|
||||
* @param MeilisearchAdminService $adminService
|
||||
* @param MeilisearchService $adminService
|
||||
* @return bool True if the plugin is installed, FALSE otherwise.
|
||||
*/
|
||||
protected function isPluginInstalled(MeilisearchAdminService $adminService)
|
||||
protected function isPluginInstalled(MeilisearchService $adminService)
|
||||
{
|
||||
$accessFilterQueryParserPluginInstalled = false;
|
||||
|
||||
@@ -155,10 +155,10 @@ class AccessFilterPluginInstalledStatus extends AbstractMeilisearchStatus
|
||||
/**
|
||||
* Checks whether the installed plugin is current.
|
||||
*
|
||||
* @param MeilisearchAdminService $adminService
|
||||
* @param MeilisearchService $adminService
|
||||
* @return bool True if the plugin is outdated, FALSE if it meets the current version recommendation.
|
||||
*/
|
||||
protected function isPluginOutdated(MeilisearchAdminService $adminService)
|
||||
protected function isPluginOutdated(MeilisearchService $adminService)
|
||||
{
|
||||
$pluginVersion = $this->getInstalledPluginVersion($adminService);
|
||||
$pluginVersionOutdated = version_compare($pluginVersion, self::RECOMMENDED_PLUGIN_VERSION, '<');
|
||||
@@ -169,10 +169,10 @@ class AccessFilterPluginInstalledStatus extends AbstractMeilisearchStatus
|
||||
/**
|
||||
* Gets the version of the installed plugin.
|
||||
*
|
||||
* @param MeilisearchAdminService $adminService
|
||||
* @param MeilisearchService $adminService
|
||||
* @return string The installed plugin's version number.
|
||||
*/
|
||||
public function getInstalledPluginVersion(MeilisearchAdminService $adminService)
|
||||
public function getInstalledPluginVersion(MeilisearchService $adminService)
|
||||
{
|
||||
$pluginsInformation = $adminService->getPluginsInformation();
|
||||
|
||||
|
@@ -27,7 +27,7 @@ namespace WapplerSystems\Meilisearch\Report;
|
||||
use WapplerSystems\Meilisearch\ConnectionManager;
|
||||
use WapplerSystems\Meilisearch\Domain\Site\SiteRepository;
|
||||
use WapplerSystems\Meilisearch\PingFailedException;
|
||||
use WapplerSystems\Meilisearch\System\Meilisearch\Service\MeilisearchAdminService;
|
||||
use WapplerSystems\Meilisearch\System\Meilisearch\Service\MeilisearchService;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Fluid\View\StandaloneView;
|
||||
use TYPO3\CMS\Reports\Status;
|
||||
@@ -111,7 +111,7 @@ class MeilisearchStatus extends AbstractMeilisearchStatus
|
||||
|
||||
$meilisearchAdmin = $this->connectionManager
|
||||
->getMeilisearchConnectionForNode($meilisearchConnection['read'], $meilisearchConnection['write'])
|
||||
->getAdminService();
|
||||
->getService();
|
||||
|
||||
$meilisearchVersion = $this->checkMeilisearchVersion($meilisearchAdmin);
|
||||
$accessFilter = $this->checkAccessFilter($meilisearchAdmin);
|
||||
@@ -147,10 +147,10 @@ class MeilisearchStatus extends AbstractMeilisearchStatus
|
||||
/**
|
||||
* Checks the meilisearch version and adds it to the report.
|
||||
*
|
||||
* @param MeilisearchAdminService $meilisearch
|
||||
* @param MeilisearchService $meilisearch
|
||||
* @return string meilisearch version
|
||||
*/
|
||||
protected function checkMeilisearchVersion(MeilisearchAdminService $meilisearch)
|
||||
protected function checkMeilisearchVersion(MeilisearchService $meilisearch)
|
||||
{
|
||||
try {
|
||||
$meilisearchVersion = $this->formatMeilisearchVersion($meilisearch->getMeilisearchServerVersion());
|
||||
@@ -165,10 +165,10 @@ class MeilisearchStatus extends AbstractMeilisearchStatus
|
||||
/**
|
||||
* Checks the access filter setup and adds it to the report.
|
||||
*
|
||||
* @param MeilisearchAdminService $meilisearchAdminService
|
||||
* @param MeilisearchService $meilisearchAdminService
|
||||
* @return string
|
||||
*/
|
||||
protected function checkAccessFilter(MeilisearchAdminService $meilisearchAdminService)
|
||||
protected function checkAccessFilter(MeilisearchService $meilisearchAdminService)
|
||||
{
|
||||
try {
|
||||
$accessFilterPluginStatus = GeneralUtility::makeInstance(AccessFilterPluginInstalledStatus::class);
|
||||
@@ -184,10 +184,10 @@ class MeilisearchStatus extends AbstractMeilisearchStatus
|
||||
/**
|
||||
* Checks the ping time and adds it to the report.
|
||||
*
|
||||
* @param MeilisearchAdminService $meilisearchAdminService
|
||||
* @param MeilisearchService $meilisearchAdminService
|
||||
* @return string
|
||||
*/
|
||||
protected function checkPingTime(MeilisearchAdminService $meilisearchAdminService)
|
||||
protected function checkPingTime(MeilisearchService $meilisearchAdminService)
|
||||
{
|
||||
try {
|
||||
$pingQueryTime = $meilisearchAdminService->getPingRoundTripRuntime();
|
||||
@@ -202,10 +202,10 @@ class MeilisearchStatus extends AbstractMeilisearchStatus
|
||||
/**
|
||||
* Checks the meilisearch config name and adds it to the report.
|
||||
*
|
||||
* @param MeilisearchAdminService $meilisearchAdminService
|
||||
* @param MeilisearchService $meilisearchAdminService
|
||||
* @return string
|
||||
*/
|
||||
protected function checkMeilisearchConfigName(MeilisearchAdminService $meilisearchAdminService)
|
||||
protected function checkMeilisearchConfigName(MeilisearchService $meilisearchAdminService)
|
||||
{
|
||||
try {
|
||||
$meilisearchConfigMessage = $meilisearchAdminService->getMeilisearchconfigName();
|
||||
@@ -220,10 +220,10 @@ class MeilisearchStatus extends AbstractMeilisearchStatus
|
||||
/**
|
||||
* Checks the meilisearch schema name and adds it to the report.
|
||||
*
|
||||
* @param MeilisearchAdminService $meilisearchAdminService
|
||||
* @param MeilisearchService $meilisearchAdminService
|
||||
* @return string
|
||||
*/
|
||||
protected function checkMeilisearchSchemaName(MeilisearchAdminService $meilisearchAdminService)
|
||||
protected function checkMeilisearchSchemaName(MeilisearchService $meilisearchAdminService)
|
||||
{
|
||||
try {
|
||||
$meilisearchSchemaMessage = $meilisearchAdminService->getSchema()->getName();
|
||||
|
@@ -65,7 +65,7 @@ class SchemaStatus extends AbstractMeilisearchStatus
|
||||
$meilisearchConnections = $connectionManager->getAllConnections();
|
||||
|
||||
foreach ($meilisearchConnections as $meilisearchConnection) {
|
||||
$adminService = $meilisearchConnection->getAdminService();
|
||||
$adminService = $meilisearchConnection->getService();
|
||||
/** @var $meilisearchConnection MeilisearchConnection */
|
||||
if (!$adminService->ping()) {
|
||||
$url = $adminService->__toString();
|
||||
|
@@ -1,50 +0,0 @@
|
||||
<?php
|
||||
namespace WapplerSystems\Meilisearch\System\Meilisearch\Document;
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* Document representing the update query document
|
||||
*
|
||||
* @author Timo Hund <timo.hund@dkd.de>
|
||||
*/
|
||||
class Document
|
||||
{
|
||||
/**
|
||||
* Magic call method used to emulate getters as used by the template engine.
|
||||
*
|
||||
* @param string $name method name
|
||||
* @param array $arguments method arguments
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call($name, $arguments)
|
||||
{
|
||||
if (substr($name, 0, 3) === 'get') {
|
||||
$field = substr($name, 3);
|
||||
$field = strtolower($field[0]) . substr($field, 1);
|
||||
return $this->fields[$field] ?? null;
|
||||
}
|
||||
throw new RuntimeException('Call to undefined method. Supports magic getters only.', 1311006605);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getFieldNames()
|
||||
{
|
||||
return array_keys($this->fields);
|
||||
}
|
||||
}
|
@@ -30,9 +30,7 @@ use WapplerSystems\Meilisearch\System\Logging\MeilisearchLogManager;
|
||||
use WapplerSystems\Meilisearch\System\Meilisearch\Parser\SchemaParser;
|
||||
use WapplerSystems\Meilisearch\System\Meilisearch\Parser\StopWordParser;
|
||||
use WapplerSystems\Meilisearch\System\Meilisearch\Parser\SynonymParser;
|
||||
use WapplerSystems\Meilisearch\System\Meilisearch\Service\MeilisearchAdminService;
|
||||
use WapplerSystems\Meilisearch\System\Meilisearch\Service\MeilisearchReadService;
|
||||
use WapplerSystems\Meilisearch\System\Meilisearch\Service\MeilisearchWriteService;
|
||||
use WapplerSystems\Meilisearch\System\Meilisearch\Service\MeilisearchService;
|
||||
use WapplerSystems\Meilisearch\Util;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
@@ -50,19 +48,9 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
class MeilisearchConnection
|
||||
{
|
||||
/**
|
||||
* @var MeilisearchAdminService
|
||||
* @var MeilisearchService
|
||||
*/
|
||||
protected $adminService;
|
||||
|
||||
/**
|
||||
* @var MeilisearchReadService
|
||||
*/
|
||||
protected $readService;
|
||||
|
||||
/**
|
||||
* @var MeilisearchWriteService
|
||||
*/
|
||||
protected $writeService;
|
||||
protected $service;
|
||||
|
||||
/**
|
||||
* @var TypoScriptConfiguration
|
||||
@@ -157,66 +145,24 @@ class MeilisearchConnection
|
||||
|
||||
|
||||
/**
|
||||
* @return MeilisearchAdminService
|
||||
* @return MeilisearchService
|
||||
*/
|
||||
public function getAdminService(): MeilisearchAdminService
|
||||
public function getService(): MeilisearchService
|
||||
{
|
||||
if ($this->adminService === null) {
|
||||
$this->adminService = $this->buildAdminService();
|
||||
if ($this->service === null) {
|
||||
$this->service = $this->buildService();
|
||||
}
|
||||
|
||||
return $this->adminService;
|
||||
return $this->service;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MeilisearchAdminService
|
||||
* @return MeilisearchService
|
||||
* @noinspection PhpIncompatibleReturnTypeInspection
|
||||
*/
|
||||
protected function buildAdminService(): MeilisearchAdminService
|
||||
protected function buildService(): MeilisearchService
|
||||
{
|
||||
return GeneralUtility::makeInstance(MeilisearchAdminService::class, $this, $this->client, $this->configuration, $this->logger, $this->synonymParser, $this->stopWordParser, $this->schemaParser);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MeilisearchReadService
|
||||
*/
|
||||
public function getReadService(): MeilisearchReadService
|
||||
{
|
||||
if ($this->readService === null) {
|
||||
$this->readService = $this->buildReadService();
|
||||
}
|
||||
|
||||
return $this->readService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MeilisearchReadService
|
||||
* @noinspection PhpIncompatibleReturnTypeInspection
|
||||
*/
|
||||
protected function buildReadService(): MeilisearchReadService
|
||||
{
|
||||
return GeneralUtility::makeInstance(MeilisearchReadService::class, $this->client);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MeilisearchWriteService
|
||||
*/
|
||||
public function getWriteService(): MeilisearchWriteService
|
||||
{
|
||||
if ($this->writeService === null) {
|
||||
$this->writeService = $this->buildWriteService();
|
||||
}
|
||||
|
||||
return $this->writeService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MeilisearchWriteService
|
||||
* @noinspection PhpIncompatibleReturnTypeInspection
|
||||
*/
|
||||
protected function buildWriteService(): MeilisearchWriteService
|
||||
{
|
||||
return GeneralUtility::makeInstance(MeilisearchWriteService::class, $this->client);
|
||||
return GeneralUtility::makeInstance(MeilisearchService::class, $this, $this->client, $this->configuration, $this->logger, $this->synonymParser, $this->stopWordParser, $this->schemaParser);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -1,34 +0,0 @@
|
||||
<?php
|
||||
namespace WapplerSystems\Meilisearch\System\Meilisearch;
|
||||
|
||||
/**
|
||||
* This class provides static helper functions that are helpful during the result parsing for meilisearch.
|
||||
*/
|
||||
class ParsingUtil
|
||||
{
|
||||
/**
|
||||
* This method is used to covert a array structure with json.nl=flat to have it as return with json.nl=map.
|
||||
*
|
||||
* @param $options
|
||||
* @return array
|
||||
*/
|
||||
public static function getMapArrayFromFlatArray(array $options): array
|
||||
{
|
||||
$keyValueMap = [];
|
||||
$valueFromKeyNode = -1;
|
||||
foreach($options as $key => $value) {
|
||||
$isKeyNode = (($key % 2) == 0);
|
||||
if ($isKeyNode) {
|
||||
$valueFromKeyNode = $value;
|
||||
} else {
|
||||
if($valueFromKeyNode == -1) {
|
||||
throw new \UnexpectedValueException('No optionValue before count value');
|
||||
}
|
||||
//we have a countNode
|
||||
$keyValueMap[$valueFromKeyNode] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $keyValueMap;
|
||||
}
|
||||
}
|
@@ -1,44 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
namespace WapplerSystems\Meilisearch\System\Meilisearch;
|
||||
|
||||
use GuzzleHttp\Client as GuzzleClient;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use TYPO3\CMS\Core\Http\RequestFactory as CoreRequestFactory;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
|
||||
class RequestFactory extends CoreRequestFactory
|
||||
{
|
||||
protected $clientOptions = [];
|
||||
|
||||
/**
|
||||
* RequestFactory constructor.
|
||||
* @param array $clientOptions
|
||||
*/
|
||||
public function __construct(array $clientOptions)
|
||||
{
|
||||
$this->clientOptions = $clientOptions;
|
||||
}
|
||||
|
||||
public function request(string $uri, string $method = 'GET', array $options = []): ResponseInterface
|
||||
{
|
||||
/* @var GuzzleClient $client */
|
||||
$client = GeneralUtility::makeInstance(GuzzleClient::class, $this->clientOptions);
|
||||
return $client->request($method, $uri, $options);
|
||||
}
|
||||
}
|
@@ -1,150 +0,0 @@
|
||||
<?php
|
||||
namespace WapplerSystems\Meilisearch\System\Meilisearch;
|
||||
use WapplerSystems\Meilisearch\System\Meilisearch\Document\Document;
|
||||
use Countable;
|
||||
|
||||
/**
|
||||
* In EXT:meilisearch 9 we have switched from the MeilisearchPhpClient to the solarium api.
|
||||
*
|
||||
* In many places of the code the class Apache_Meilisearch_Response and the property Apache_Meilisearch_Response::reponse is used.
|
||||
* To be able to refactor this we need to have a replacement for Apache_Meilisearch_Response that behaves like the original class,
|
||||
* to keep the old code working. This allows us to drop the old code of MeilisearchPhpClient and refactore the other parts step by step.
|
||||
*
|
||||
* Class ResponseAdapter
|
||||
*
|
||||
* Search response
|
||||
*
|
||||
* @property \stdClass facet_counts
|
||||
* @property \stdClass facets
|
||||
* @property \stdClass spellcheck
|
||||
* @property \stdClass response
|
||||
* @property \stdClass responseHeader
|
||||
* @property \stdClass highlighting
|
||||
* @property \stdClass debug
|
||||
* @property \stdClass lucene
|
||||
* @property string file
|
||||
* @property array file_metadata
|
||||
*
|
||||
* Luke response
|
||||
*
|
||||
* @property \stdClass index
|
||||
* @property \stdClass fields
|
||||
*/
|
||||
class ResponseAdapter implements Countable
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $responseBody;
|
||||
|
||||
/**
|
||||
* @var \stdClass
|
||||
*/
|
||||
protected $data = null;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $httpStatus = 200;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $httpStatusMessage = '';
|
||||
|
||||
/**
|
||||
* ResponseAdapter constructor.
|
||||
*
|
||||
* @param string $responseBody
|
||||
* @param int $httpStatus
|
||||
* @param string $httpStatusMessage
|
||||
*/
|
||||
public function __construct($responseBody, $httpStatus = 500, $httpStatusMessage = '')
|
||||
{
|
||||
$this->data = json_decode($responseBody);
|
||||
$this->responseBody = $responseBody;
|
||||
$this->httpStatus = $httpStatus;
|
||||
$this->httpStatusMessage = $httpStatusMessage;
|
||||
|
||||
// @extensionScannerIgnoreLine
|
||||
if (isset($this->data->response) && is_array($this->data->response->docs)) {
|
||||
$documents = array();
|
||||
|
||||
// @extensionScannerIgnoreLine
|
||||
foreach ($this->data->response->docs as $originalDocument) {
|
||||
$fields = get_object_vars($originalDocument);
|
||||
$document = new Document($fields);
|
||||
$documents[] = $document;
|
||||
}
|
||||
|
||||
// @extensionScannerIgnoreLine
|
||||
$this->data->response->docs = $documents;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic get to expose the parsed data and to lazily load it
|
||||
*
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function __get($key)
|
||||
{
|
||||
if (isset($this->data->$key)) {
|
||||
return $this->data->$key;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic function for isset function on parsed data
|
||||
*
|
||||
* @param string $key
|
||||
* @return boolean
|
||||
*/
|
||||
public function __isset($key)
|
||||
{
|
||||
return isset($this->data->$key);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getParsedData()
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getRawResponse()
|
||||
{
|
||||
return $this->responseBody;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getHttpStatus(): int
|
||||
{
|
||||
return $this->httpStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getHttpStatusMessage(): string
|
||||
{
|
||||
return $this->httpStatusMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Counts the elements of
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
return count(get_object_vars($this->data));
|
||||
}
|
||||
}
|
@@ -29,7 +29,6 @@ use MeiliSearch\Exceptions\CommunicationException;
|
||||
use WapplerSystems\Meilisearch\System\Configuration\TypoScriptConfiguration;
|
||||
use WapplerSystems\Meilisearch\System\Logging\MeilisearchLogManager;
|
||||
use WapplerSystems\Meilisearch\System\Meilisearch\MeilisearchConnection;
|
||||
use WapplerSystems\Meilisearch\System\Meilisearch\ResponseAdapter;
|
||||
use WapplerSystems\Meilisearch\Util;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
|
||||
@@ -93,15 +92,14 @@ abstract class AbstractMeilisearchService
|
||||
{
|
||||
|
||||
$siteConfiguration = $this->meilisearchConnection->getSiteConfiguration();
|
||||
$strConnection = $siteConfiguration['schema'].$siteConfiguration['host'];
|
||||
$strConnection = $siteConfiguration['scheme'].'://'.$siteConfiguration['host'].':'.$siteConfiguration['port'];
|
||||
|
||||
if (!$this->ping()) return $strConnection;
|
||||
|
||||
return $strConnection . ', ' . implode(',',$this->client->version());
|
||||
return $strConnection . ', Version: ' . $this->client->version()['pkgVersion'];
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Build the log data and writes the message to the log
|
||||
*
|
||||
|
@@ -1,98 +0,0 @@
|
||||
<?php
|
||||
namespace WapplerSystems\Meilisearch\System\Meilisearch\Service;
|
||||
|
||||
/***************************************************************
|
||||
* Copyright notice
|
||||
*
|
||||
* (c) 2009-2017 Timo Hund <timo.hund@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\System\Meilisearch\ResponseAdapter;
|
||||
use WapplerSystems\Meilisearch\System\Meilisearch\MeilisearchCommunicationException;
|
||||
use WapplerSystems\Meilisearch\System\Meilisearch\MeilisearchInternalServerErrorException;
|
||||
use WapplerSystems\Meilisearch\System\Meilisearch\MeilisearchUnavailableException;
|
||||
|
||||
/**
|
||||
* Class MeilisearchReadService
|
||||
*/
|
||||
class MeilisearchReadService extends AbstractMeilisearchService
|
||||
{
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $hasSearched = false;
|
||||
|
||||
/**
|
||||
* @var ResponseAdapter
|
||||
*/
|
||||
protected $responseCache = null;
|
||||
|
||||
/**
|
||||
* Returns whether a search has been executed or not.
|
||||
*
|
||||
* @return bool TRUE if a search has been executed, FALSE otherwise
|
||||
*/
|
||||
public function hasSearched()
|
||||
{
|
||||
return $this->hasSearched;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the most recent response (if any)
|
||||
*
|
||||
* @return ResponseAdapter Most recent response, or NULL if a search has not been executed yet.
|
||||
*/
|
||||
public function getResponse()
|
||||
{
|
||||
return $this->responseCache;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method maps the failed meilisearch requests to a meaningful exception.
|
||||
*
|
||||
* @param HttpException $exception
|
||||
* @throws MeilisearchCommunicationException
|
||||
* @return HttpException
|
||||
*/
|
||||
protected function handleErrorResponses(HttpException $exception)
|
||||
{
|
||||
$status = $exception->getCode();
|
||||
$message = $exception->getStatusMessage();
|
||||
$meilisearchRespone = new ResponseAdapter($exception->getBody());
|
||||
|
||||
if ($status === 0 || $status === 502) {
|
||||
$e = new MeilisearchUnavailableException('Meilisearch Server not available: ' . $message, 1505989391);
|
||||
$e->setMeilisearchResponse($meilisearchRespone);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
if ($status === 500) {
|
||||
$e = new MeilisearchInternalServerErrorException('Internal Server error during search: ' . $message, 1505989897);
|
||||
$e->setMeilisearchResponse($meilisearchRespone);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$e = new MeilisearchCommunicationException('Invalid query. Meilisearch returned an error: ' . $status . ' ' . $message, 1293109870);
|
||||
$e->setMeilisearchResponse($meilisearchRespone);
|
||||
|
||||
throw $e;
|
||||
}
|
||||
}
|
@@ -31,14 +31,13 @@ use WapplerSystems\Meilisearch\System\Meilisearch\MeilisearchConnection;
|
||||
use WapplerSystems\Meilisearch\System\Meilisearch\Parser\SchemaParser;
|
||||
use WapplerSystems\Meilisearch\System\Meilisearch\Parser\StopWordParser;
|
||||
use WapplerSystems\Meilisearch\System\Meilisearch\Parser\SynonymParser;
|
||||
use WapplerSystems\Meilisearch\System\Meilisearch\ResponseAdapter;
|
||||
use WapplerSystems\Meilisearch\System\Meilisearch\Schema\Schema;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
|
||||
/**
|
||||
* Class MeilisearchAdminService
|
||||
*/
|
||||
class MeilisearchAdminService extends AbstractMeilisearchService
|
||||
class MeilisearchService extends AbstractMeilisearchService
|
||||
{
|
||||
|
||||
protected $systemData = null;
|
||||
@@ -101,25 +100,6 @@ class MeilisearchAdminService extends AbstractMeilisearchService
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets information about the Meilisearch server
|
||||
*
|
||||
* @return ResponseAdapter
|
||||
*/
|
||||
public function getSystemInformation()
|
||||
{
|
||||
if (empty($this->systemData)) {
|
||||
$systemInformation = $this->system();
|
||||
|
||||
// access a random property to trigger response parsing
|
||||
$this->systemData = $systemInformation;
|
||||
}
|
||||
|
||||
return $this->systemData;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get currently configured synonyms
|
||||
*
|
@@ -1,120 +0,0 @@
|
||||
<?php
|
||||
namespace WapplerSystems\Meilisearch\System\Meilisearch\Service;
|
||||
|
||||
/***************************************************************
|
||||
* Copyright notice
|
||||
*
|
||||
* (c) 2009-2017 Timo Hund <timo.hund@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\System\Logging\MeilisearchLogManager;
|
||||
use WapplerSystems\Meilisearch\System\Meilisearch\ResponseAdapter;
|
||||
|
||||
/**
|
||||
* Class MeilisearchWriteService
|
||||
*/
|
||||
class MeilisearchWriteService extends AbstractMeilisearchService
|
||||
{
|
||||
const EXTRACT_SERVLET = 'update/extract';
|
||||
|
||||
/**
|
||||
* Performs a content and meta data extraction request.
|
||||
*
|
||||
* @param Query $query An extraction query
|
||||
* @return array An array containing the extracted content [0] and meta data [1]
|
||||
*/
|
||||
public function extractByQuery(Query $query)
|
||||
{
|
||||
try {
|
||||
$response = $this->createAndExecuteRequest($query);
|
||||
return [$response->file, (array)$response->file_metadata];
|
||||
} catch (\Exception $e) {
|
||||
$param = $query->getRequestBuilder()->build($query)->getParams();
|
||||
$this->logger->log(
|
||||
MeilisearchLogManager::ERROR,
|
||||
'Extracting text and meta data through Meilisearch Cell over HTTP POST',
|
||||
[
|
||||
'query' => (array)$query,
|
||||
'parameters' => $param,
|
||||
'file' => $query->getFile(),
|
||||
'query url' => self::EXTRACT_SERVLET,
|
||||
'exception' => $e->getMessage()
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes all index documents of a certain type and does a commit
|
||||
* afterwards.
|
||||
*
|
||||
* @param string $type The type of documents to delete, usually a table name.
|
||||
* @param bool $commit Will commit immediately after deleting the documents if set, defaults to TRUE
|
||||
*/
|
||||
public function deleteByType($type, $commit = true)
|
||||
{
|
||||
$this->deleteByQuery('type:' . trim($type));
|
||||
|
||||
if ($commit) {
|
||||
$this->commit(false, false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a delete document based on a query and submit it
|
||||
*
|
||||
* @param string $rawQuery Expected to be utf-8 encoded
|
||||
* @return ResponseAdapter
|
||||
*/
|
||||
public function deleteByQuery($rawQuery) {
|
||||
$query = $this->client->createUpdate();
|
||||
$query->addDeleteQuery($rawQuery);
|
||||
return $this->createAndExecuteRequest($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an array of Meilisearch Documents to the index all at once
|
||||
*
|
||||
* @param array $documents Should be an array of \WapplerSystems\Meilisearch\System\Meilisearch\Document\Document instances
|
||||
* @return ResponseAdapter
|
||||
*/
|
||||
public function addDocuments($documents)
|
||||
{
|
||||
$update = $this->client->createUpdate();
|
||||
$update->addDocuments($documents);
|
||||
return $this->createAndExecuteRequest($update);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a commit command. Will be synchronous unless both wait parameters are set to false.
|
||||
*
|
||||
* @param boolean $expungeDeletes Defaults to false, merge segments with deletes away
|
||||
* @param boolean $waitSearcher Defaults to true, block until a new searcher is opened and registered as the main query searcher, making the changes visible
|
||||
* @return ResponseAdapter
|
||||
*/
|
||||
public function commit($expungeDeletes = false, $waitSearcher = true)
|
||||
{
|
||||
$update = $this->client->createUpdate();
|
||||
$update->addCommit(false, $waitSearcher, $expungeDeletes);
|
||||
return $this->createAndExecuteRequest($update);
|
||||
}
|
||||
}
|
@@ -145,7 +145,7 @@ class FlexFormUserFunctions
|
||||
*/
|
||||
protected function getFieldNamesFromMeilisearchMetaDataForPage(array $pageRecord)
|
||||
{
|
||||
return array_keys((array)$this->getConnection($pageRecord)->getAdminService()->getFieldsMetaData());
|
||||
return array_keys((array)$this->getConnection($pageRecord)->getService()->getFieldsMetaData());
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user