zwischenstand

This commit is contained in:
Sven Wappler
2021-04-29 18:33:05 +02:00
parent 2c9e27b3b7
commit 0ee2fae261
264 changed files with 263 additions and 21253 deletions

View File

@@ -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
*

View File

@@ -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;
}
}

View File

@@ -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
*

View File

@@ -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);
}
}