first commit
This commit is contained in:
@@ -24,14 +24,15 @@ namespace WapplerSystems\Meilisearch\System\Meilisearch\Service;
|
||||
* This copyright notice MUST APPEAR in all copies of the script!
|
||||
***************************************************************/
|
||||
|
||||
use MeiliSearch\Client;
|
||||
use WapplerSystems\Meilisearch\System\Configuration\TypoScriptConfiguration;
|
||||
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\StopWordParser;
|
||||
use WapplerSystems\Meilisearch\System\Meilisearch\Parser\SynonymParser;
|
||||
use WapplerSystems\Meilisearch\System\Meilisearch\ResponseAdapter;
|
||||
use WapplerSystems\Meilisearch\System\Meilisearch\Schema\Schema;
|
||||
use Solarium\Client;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
|
||||
/**
|
||||
@@ -39,30 +40,9 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
*/
|
||||
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 $pluginsData = [];
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
protected $meilisearchconfigName;
|
||||
|
||||
/**
|
||||
* @var SchemaParser
|
||||
*/
|
||||
@@ -95,13 +75,16 @@ class MeilisearchAdminService extends AbstractMeilisearchService
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param TypoScriptConfiguration $typoScriptConfiguration
|
||||
* @param SynonymParser $synonymParser
|
||||
* @param StopWordParser $stopWordParser
|
||||
* @param SchemaParser $schemaParser
|
||||
* @param MeilisearchLogManager $logManager
|
||||
* @param MeilisearchConnection $meilisearchConnection
|
||||
* @param Client $client
|
||||
* @param TypoScriptConfiguration|null $typoScriptConfiguration
|
||||
* @param MeilisearchLogManager|null $logManager
|
||||
* @param SynonymParser|null $synonymParser
|
||||
* @param StopWordParser|null $stopWordParser
|
||||
* @param SchemaParser|null $schemaParser
|
||||
*/
|
||||
public function __construct(
|
||||
MeilisearchConnection $meilisearchConnection,
|
||||
Client $client,
|
||||
TypoScriptConfiguration $typoScriptConfiguration = null,
|
||||
MeilisearchLogManager $logManager = null,
|
||||
@@ -110,71 +93,13 @@ class MeilisearchAdminService extends AbstractMeilisearchService
|
||||
SchemaParser $schemaParser = null
|
||||
)
|
||||
{
|
||||
parent::__construct($client, $typoScriptConfiguration);
|
||||
parent::__construct($meilisearchConnection, $client, $typoScriptConfiguration);
|
||||
|
||||
$this->synonymParser = $synonymParser ?? GeneralUtility::makeInstance(SynonymParser::class);
|
||||
$this->stopWordParser = $stopWordParser ?? GeneralUtility::makeInstance(StopWordParser::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
|
||||
@@ -187,86 +112,13 @@ class MeilisearchAdminService extends AbstractMeilisearchService
|
||||
$systemInformation = $this->system();
|
||||
|
||||
// access a random property to trigger response parsing
|
||||
$systemInformation->responseHeader;
|
||||
$this->systemData = $systemInformation;
|
||||
}
|
||||
|
||||
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
|
||||
@@ -300,8 +152,7 @@ class MeilisearchAdminService extends AbstractMeilisearchService
|
||||
{
|
||||
$this->initializeSynonymsUrl();
|
||||
$json = $this->synonymParser->toJson($baseWord, $synonyms);
|
||||
$response = $this->_sendRawPost($this->_synonymsUrl, $json, 'application/json');
|
||||
return $response;
|
||||
return $this->_sendRawPost($this->_synonymsUrl, $json, 'application/json');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -318,8 +169,7 @@ class MeilisearchAdminService extends AbstractMeilisearchService
|
||||
throw new \InvalidArgumentException('Must provide base word.');
|
||||
}
|
||||
|
||||
$response = $this->_sendRawDelete($this->_synonymsUrl . '/' . urlencode($baseWord));
|
||||
return $response;
|
||||
return $this->_sendRawDelete($this->_synonymsUrl . '/' . urlencode($baseWord));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user