first commit
This commit is contained in:
@@ -26,14 +26,14 @@ namespace WapplerSystems\Meilisearch;
|
||||
|
||||
use WapplerSystems\Meilisearch\Domain\Search\Query\Query;
|
||||
use WapplerSystems\Meilisearch\System\Configuration\TypoScriptConfiguration;
|
||||
use WapplerSystems\Meilisearch\System\Logging\SolrLogManager;
|
||||
use WapplerSystems\Meilisearch\System\Solr\ResponseAdapter;
|
||||
use WapplerSystems\Meilisearch\System\Solr\SolrCommunicationException;
|
||||
use WapplerSystems\Meilisearch\System\Solr\SolrConnection;
|
||||
use WapplerSystems\Meilisearch\System\Logging\MeilisearchLogManager;
|
||||
use WapplerSystems\Meilisearch\System\Meilisearch\ResponseAdapter;
|
||||
use WapplerSystems\Meilisearch\System\Meilisearch\MeilisearchCommunicationException;
|
||||
use WapplerSystems\Meilisearch\System\Meilisearch\MeilisearchConnection;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
|
||||
/**
|
||||
* Class to handle solr search requests
|
||||
* Class to handle meilisearch search requests
|
||||
*
|
||||
* @author Ingo Renner <ingo@typo3.org>
|
||||
*/
|
||||
@@ -41,11 +41,11 @@ class Search
|
||||
{
|
||||
|
||||
/**
|
||||
* An instance of the Solr service
|
||||
* An instance of the Meilisearch service
|
||||
*
|
||||
* @var SolrConnection
|
||||
* @var MeilisearchConnection
|
||||
*/
|
||||
protected $solr = null;
|
||||
protected $meilisearch = null;
|
||||
|
||||
/**
|
||||
* The search query
|
||||
@@ -69,56 +69,56 @@ class Search
|
||||
// TODO Override __clone to reset $response and $hasSearched
|
||||
|
||||
/**
|
||||
* @var \WapplerSystems\Meilisearch\System\Logging\SolrLogManager
|
||||
* @var \WapplerSystems\Meilisearch\System\Logging\MeilisearchLogManager
|
||||
*/
|
||||
protected $logger = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param SolrConnection $solrConnection The Solr connection to use for searching
|
||||
* @param MeilisearchConnection $meilisearchConnection The Meilisearch connection to use for searching
|
||||
*/
|
||||
public function __construct(SolrConnection $solrConnection = null)
|
||||
public function __construct(MeilisearchConnection $meilisearchConnection = null)
|
||||
{
|
||||
$this->logger = GeneralUtility::makeInstance(SolrLogManager::class, /** @scrutinizer ignore-type */ __CLASS__);
|
||||
$this->logger = GeneralUtility::makeInstance(MeilisearchLogManager::class, /** @scrutinizer ignore-type */ __CLASS__);
|
||||
|
||||
$this->solr = $solrConnection;
|
||||
$this->meilisearch = $meilisearchConnection;
|
||||
|
||||
if (is_null($solrConnection)) {
|
||||
if (is_null($meilisearchConnection)) {
|
||||
/** @var $connectionManager ConnectionManager */
|
||||
$connectionManager = GeneralUtility::makeInstance(ConnectionManager::class);
|
||||
$this->solr = $connectionManager->getConnectionByPageId($GLOBALS['TSFE']->id, Util::getLanguageUid());
|
||||
$this->meilisearch = $connectionManager->getConnectionByPageId($GLOBALS['TSFE']->id, Util::getLanguageUid());
|
||||
}
|
||||
|
||||
$this->configuration = Util::getSolrConfiguration();
|
||||
$this->configuration = Util::getMeilisearchConfiguration();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Solr connection used by this search.
|
||||
* Gets the Meilisearch connection used by this search.
|
||||
*
|
||||
* @return SolrConnection Solr connection
|
||||
* @return MeilisearchConnection Meilisearch connection
|
||||
*/
|
||||
public function getSolrConnection()
|
||||
public function getMeilisearchConnection()
|
||||
{
|
||||
return $this->solr;
|
||||
return $this->meilisearch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Solr connection used by this search.
|
||||
* Sets the Meilisearch connection used by this search.
|
||||
*
|
||||
* Since WapplerSystems\Meilisearch\Search is a \TYPO3\CMS\Core\SingletonInterface, this is needed to
|
||||
* be able to switch between multiple cores/connections during
|
||||
* one request
|
||||
*
|
||||
* @param SolrConnection $solrConnection
|
||||
* @param MeilisearchConnection $meilisearchConnection
|
||||
*/
|
||||
public function setSolrConnection(SolrConnection $solrConnection)
|
||||
public function setMeilisearchConnection(MeilisearchConnection $meilisearchConnection)
|
||||
{
|
||||
$this->solr = $solrConnection;
|
||||
$this->meilisearch = $meilisearchConnection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a query against a Solr server.
|
||||
* Executes a query against a Meilisearch server.
|
||||
*
|
||||
* 1) Gets the query string
|
||||
* 2) Conducts the actual search
|
||||
@@ -127,7 +127,7 @@ class Search
|
||||
* @param Query $query The query with keywords, filters, and so on.
|
||||
* @param int $offset Result offset for pagination.
|
||||
* @param int $limit Maximum number of results to return. If set to NULL, this value is taken from the query object.
|
||||
* @return ResponseAdapter Solr response
|
||||
* @return ResponseAdapter Meilisearch response
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function search(Query $query, $offset = 0, $limit = 10)
|
||||
@@ -140,10 +140,10 @@ class Search
|
||||
$query->setStart($offset);
|
||||
|
||||
try {
|
||||
$response = $this->solr->getReadService()->search($query);
|
||||
$response = $this->meilisearch->getReadService()->search($query);
|
||||
if ($this->configuration->getLoggingQueryQueryString()) {
|
||||
$this->logger->log(SolrLogManager::INFO,
|
||||
'Querying Solr, getting result',
|
||||
$this->logger->log(MeilisearchLogManager::INFO,
|
||||
'Querying Meilisearch, getting result',
|
||||
[
|
||||
'query string' => $query->getQuery(),
|
||||
'query parameters' => $query->getRequestBuilder()->build($query)->getParams(),
|
||||
@@ -151,11 +151,11 @@ class Search
|
||||
]
|
||||
);
|
||||
}
|
||||
} catch (SolrCommunicationException $e) {
|
||||
} catch (MeilisearchCommunicationException $e) {
|
||||
if ($this->configuration->getLoggingExceptions()) {
|
||||
$this->logger->log(
|
||||
SolrLogManager::ERROR,
|
||||
'Exception while querying Solr',
|
||||
MeilisearchLogManager::ERROR,
|
||||
'Exception while querying Meilisearch',
|
||||
[
|
||||
'exception' => $e->__toString(),
|
||||
'query' => (array)$query,
|
||||
@@ -174,7 +174,7 @@ class Search
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a ping to the solr server to see whether it is available.
|
||||
* Sends a ping to the meilisearch server to see whether it is available.
|
||||
*
|
||||
* @param bool $useCache Set to true if the cache should be used.
|
||||
* @return bool Returns TRUE on successful ping.
|
||||
@@ -182,19 +182,19 @@ class Search
|
||||
*/
|
||||
public function ping($useCache = true)
|
||||
{
|
||||
$solrAvailable = false;
|
||||
$meilisearchAvailable = false;
|
||||
|
||||
try {
|
||||
if (!$this->solr->getReadService()->ping($useCache)) {
|
||||
throw new \Exception('Solr Server not responding.', 1237475791);
|
||||
if (!$this->meilisearch->getReadService()->ping($useCache)) {
|
||||
throw new \Exception('Meilisearch Server not responding.', 1237475791);
|
||||
}
|
||||
|
||||
$solrAvailable = true;
|
||||
$meilisearchAvailable = true;
|
||||
} catch (\Exception $e) {
|
||||
if ($this->configuration->getLoggingExceptions()) {
|
||||
$this->logger->log(
|
||||
SolrLogManager::ERROR,
|
||||
'Exception while trying to ping the solr server',
|
||||
MeilisearchLogManager::ERROR,
|
||||
'Exception while trying to ping the meilisearch server',
|
||||
[
|
||||
$e->__toString()
|
||||
]
|
||||
@@ -202,7 +202,7 @@ class Search
|
||||
}
|
||||
}
|
||||
|
||||
return $solrAvailable;
|
||||
return $meilisearchAvailable;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -216,7 +216,7 @@ class Search
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Solr response
|
||||
* Gets the Meilisearch response
|
||||
*
|
||||
* @return ResponseAdapter
|
||||
*/
|
||||
@@ -242,7 +242,7 @@ class Search
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the time Solr took to execute the query and return the result.
|
||||
* Gets the time Meilisearch took to execute the query and return the result.
|
||||
*
|
||||
* @return int Query time in milliseconds
|
||||
*/
|
||||
|
Reference in New Issue
Block a user