Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method to return connection parameters #177

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions Classes/Domain/Model/Connection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php

declare(strict_types=1);

namespace Subugoe\Find\Domain\Model;

class Connection
{
private string $searchProvider;

private string $host;

private int $port;

private string $scheme;

private string $core;

private string $path;

public function getSearchProvider(): string
{
return $this->searchProvider;
}

public function setSearchProvider(string $searchProvider): Connection
{
$this->searchProvider = $searchProvider;

return $this;
}

public function getHost(): string
{
return $this->host;
}

public function setHost(string $host): Connection
{
$this->host = $host;

return $this;
}

public function getPort(): int
{
return $this->port;
}

public function setPort(int $port): Connection
{
$this->port = $port;

return $this;
}

public function getScheme(): string
{
return $this->scheme;
}

public function setScheme(string $scheme): Connection
{
$this->scheme = $scheme;

return $this;
}

public function getCore(): string
{
return $this->core;
}

public function setCore(string $core): Connection
{
$this->core = $core;

return $this;
}

public function getPath(): string
{
return $this->path;
}

public function setPath(string $path): Connection
{
$this->path = $path;

return $this;
}
}
4 changes: 4 additions & 0 deletions Classes/Service/ServiceProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
* This copyright notice MUST APPEAR in all copies of the script!
* ************************************************************* */

use Subugoe\Find\Domain\Model\Connection;

/**
* Interface for search engine provider.
*/
Expand All @@ -38,6 +40,8 @@ public function connect();

public function getConfiguration();

public function getConnectionSettings(): Connection;

public function getDefaultQuery();

public function getDocumentById(string $id);
Expand Down
67 changes: 49 additions & 18 deletions Classes/Service/SolrServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use Solarium\Core\Client\Adapter\Http;
use Solarium\Exception\HttpException;
use Solarium\QueryType\Select\Query\Query;
use Subugoe\Find\Domain\Model\Connection;
use Subugoe\Find\Utility\FrontendUtility;
use Subugoe\Find\Utility\LoggerUtility;
use Subugoe\Find\Utility\SettingsUtility;
Expand All @@ -52,6 +53,8 @@ class SolrServiceProvider extends AbstractServiceProvider

protected ?string $controllerExtensionKey = null;

protected Connection $connectionSettings;

protected Query $query;

public function connect()
Expand All @@ -62,14 +65,22 @@ public function connect()
$currentConnectionSettings = UpgradeUtility::handleSolariumUpgrade($currentConnectionSettings);
}

$this->connectionSettings = (new Connection())
->setCore($currentConnectionSettings['core'])
->setHost($currentConnectionSettings['host'])
->setPort((int) $currentConnectionSettings['port'])
->setScheme($currentConnectionSettings['scheme'])
->setPath($currentConnectionSettings['path'])
->setSearchProvider(__CLASS__);

$connectionSettings = [
'endpoint' => [
$this->connectionName => [
'host' => $currentConnectionSettings['host'],
'port' => (int) $currentConnectionSettings['port'],
'path' => $currentConnectionSettings['path'],
'scheme' => $currentConnectionSettings['scheme'],
'core' => $currentConnectionSettings['core'],
'host' => $this->connectionSettings->getHost(),
'port' => $this->connectionSettings->getPort(),
'path' => $this->connectionSettings->getPath(),
'scheme' => $this->connectionSettings->getScheme(),
'core' => $this->connectionSettings->getCore(),
],
],
];
Expand All @@ -78,6 +89,7 @@ public function connect()
$adapter = new Curl();
$eventDispatcher = new EventDispatcher();
$adapter->setTimeout((int) $currentConnectionSettings['timeout']);

// create a client instance
$client = new Client($adapter, $eventDispatcher, $connectionSettings);

Expand Down Expand Up @@ -338,7 +350,8 @@ protected function addFacetQueries(): void
if (array_key_exists('id', $facetQuery) && array_key_exists('query', $facetQuery)) {
$queryForFacet->createQuery($facetQuery['id'], $facetQuery['query']);
} else {
$this->logger->error(sprintf('TypoScript facet »%s«, facetQuery %s does not have the required keys »id« and »query«. Ignoring this facetQuery.', $facetID, $facetQueryIndex),
$this->logger->error(sprintf('TypoScript facet »%s«, facetQuery %s does not have the required keys »id« and »query«. Ignoring this facetQuery.',
$facetID, $facetQueryIndex),
[
'facetQuery' => $facetQuery,
'facetConfiguration' => $facetConfiguration,
Expand All @@ -358,7 +371,8 @@ protected function addFacetQueries(): void
->setSort($facet['sortOrder']);
}
} else {
$this->logger->warning(sprintf('TypoScript facet %s does not have the required key »id«. Ignoring this facet.', $key),
$this->logger->warning(sprintf('TypoScript facet %s does not have the required key »id«. Ignoring this facet.',
$key),
[
'facet' => $facet,
'facetConfiguration' => $facetConfiguration,
Expand Down Expand Up @@ -542,7 +556,8 @@ protected function addSortOrdersToTemplate(array $arguments): void
$sortOptions['default'] = $sortOption['sortCriteria'];
}
} else {
$this->logger->warning(sprintf('TypoScript sort option »%s« does not have the required keys »id« and »sortCriteria. Ignoring this setting.', $sortOptionIndex),
$this->logger->warning(sprintf('TypoScript sort option »%s« does not have the required keys »id« and »sortCriteria. Ignoring this setting.',
$sortOptionIndex),
[
'sortOption' => $sortOption,
]
Expand Down Expand Up @@ -576,13 +591,15 @@ protected function addSortStringForQuery(string $sortString): void
if ('desc' === $sortCriterionParts[1]) {
$sortDirection = Query::SORT_DESC;
} elseif ('asc' !== $sortCriterionParts[1]) {
$this->logger->warning(sprintf('sort criterion »%s«’s sort direction is »%s« It should be »asc« or »desc«. Ignoring it.', $sortCriterion, $sortCriterionParts[1]));
$this->logger->warning(sprintf('sort criterion »%s«’s sort direction is »%s« It should be »asc« or »desc«. Ignoring it.',
$sortCriterion, $sortCriterionParts[1]));
continue;
}

$this->query->addSort($sortCriterionParts[0], $sortDirection);
} else {
$this->logger->warning('sort criterion »%s« does not have the required form »fieldName [asc|desc]«. Ignoring it.', $sortCriterion);
$this->logger->warning('sort criterion »%s« does not have the required form »fieldName [asc|desc]«. Ignoring it.',
$sortCriterion);
}
}
}
Expand Down Expand Up @@ -794,7 +811,8 @@ protected function getFacetQuery(array $facetConfig, string $queryTerm): ?string
}

if (null === $queryString) {
$this->logger->info(sprintf('Results for Facet »%s« with facetQuery ID »%s« were requested, but this facetQuery is not configured. Building a generic facet query instead.', $facetConfig['id'], $queryTerm),
$this->logger->info(sprintf('Results for Facet »%s« with facetQuery ID »%s« were requested, but this facetQuery is not configured. Building a generic facet query instead.',
$facetConfig['id'], $queryTerm),
[
'requestArguments' => $this->requestArguments,
'facetConfig' => $facetConfig,
Expand Down Expand Up @@ -881,12 +899,14 @@ protected function getRecordsWithUnderlyingQuery(array $assignments, array $inde
$assignments['document-next-number'] = $index['nextIndex'] + 1;
}
} else {
$this->logger->error(sprintf('»detail« action query with underlying query could not retrieve record id »%d«.', $id),
$this->logger->error(sprintf('»detail« action query with underlying query could not retrieve record id »%d«.',
$id),
['arguments' => $arguments]
);
}
} else {
$this->logger->error('»detail« action query with underlying query returned no results.', ['arguments' => $arguments]);
$this->logger->error('»detail« action query with underlying query returned no results.',
['arguments' => $arguments]);
}
} catch (HttpException $httpException) {
$this->logger->error('Solr Exception (Timeout?)',
Expand Down Expand Up @@ -922,7 +942,8 @@ protected function getTheRecordSpecified($id, $assignments)
$resultSet = $selectResults->getDocuments();
$assignments['document'] = $resultSet[0];
} else {
$this->logger->error(sprintf('»detail« action query for id »%d« returned no results.', $id), ['arguments' => $this->getRequestArguments()]);
$this->logger->error(sprintf('»detail« action query for id »%d« returned no results.', $id),
['arguments' => $this->getRequestArguments()]);
}
} catch (HttpException $httpException) {
$this->logger->error('Solr Exception (Timeout?)',
Expand Down Expand Up @@ -956,7 +977,8 @@ protected function queryComponentsForQueryParameters(array $queryParameters): ar
$queryArguments = $queryParameters[$fieldID];
$queryAlternate = null;
$queryTerms = null;
if (is_array($queryArguments) && array_key_exists('alternate', $queryArguments) && array_key_exists('queryAlternate', $fieldInfo)) {
if (is_array($queryArguments) && array_key_exists('alternate',
$queryArguments) && array_key_exists('queryAlternate', $fieldInfo)) {
$queryAlternate = $queryArguments['alternate'];
if (array_key_exists('term', $queryArguments)) {
$queryTerms = $queryArguments['term'];
Expand Down Expand Up @@ -1015,15 +1037,19 @@ protected function queryComponentsForQueryParameters(array $queryParameters): ar

$magicFieldPrefix = '';

if ((array_key_exists('luceneMatchVersionNumber', $this->settings) && (int) $this->settings['luceneMatchVersionNumber'] < 8) || (!array_key_exists('luceneMatchVersionNumber', $this->settings))) {
if ((array_key_exists('luceneMatchVersionNumber',
$this->settings) && (int) $this->settings['luceneMatchVersionNumber'] < 8) || (!array_key_exists('luceneMatchVersionNumber',
$this->settings))) {
$magicFieldPrefix = '_query_:';
}

if ($this->settings['features']['eDisMax']) {
$queryPart = $magicFieldPrefix.'{!edismax}'.$this->query->getHelper()->escapePhrase(vsprintf($queryFormat, $queryTerms));
$queryPart = $magicFieldPrefix.'{!edismax}'.$this->query->getHelper()->escapePhrase(vsprintf($queryFormat,
$queryTerms));
$queryPart = str_replace('"', '', $queryPart);
} else {
$queryPart = $magicFieldPrefix.$this->query->getHelper()->escapePhrase(vsprintf($queryFormat, $queryTerms));
$queryPart = $magicFieldPrefix.$this->query->getHelper()->escapePhrase(vsprintf($queryFormat,
$queryTerms));
}

if ('' !== $queryPart && '0' !== $queryPart) {
Expand Down Expand Up @@ -1149,4 +1175,9 @@ protected function tagForFacet(string $facetID): string
{
return 'facet-'.$facetID;
}

public function getConnectionSettings(): Connection
{
return $this->connectionSettings;
}
}