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

[MAINTENANCE] Fix and move Solr classes #982

Merged
merged 9 commits into from
Jul 20, 2023
5 changes: 3 additions & 2 deletions Classes/Common/Indexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace Kitodo\Dlf\Common;

use Kitodo\Dlf\Common\Solr\Solr;
use Kitodo\Dlf\Domain\Repository\DocumentRepository;
use Kitodo\Dlf\Domain\Model\Document;
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
Expand Down Expand Up @@ -74,9 +75,9 @@ class Indexer
protected static $processedDocs = [];

/**
* Instance of \Kitodo\Dlf\Common\Solr class
* Instance of \Kitodo\Dlf\Common\Solr\Solr class
*
* @var \Kitodo\Dlf\Common\Solr
* @var Solr
* @access protected
*/
protected static $solr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* LICENSE.txt file that was distributed with this source code.
*/

namespace Kitodo\Dlf\Common\SolrSearchResult;
namespace Kitodo\Dlf\Common\Solr\SearchResult;

/**
* Highlight class for the 'dlf' extension. It keeps highlight for found search phrase.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* LICENSE.txt file that was distributed with this source code.
*/

namespace Kitodo\Dlf\Common\SolrSearchResult;
namespace Kitodo\Dlf\Common\Solr\SearchResult;

/**
* Page class for the 'dlf' extension. It keeps page in which search phrase was found.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* LICENSE.txt file that was distributed with this source code.
*/

namespace Kitodo\Dlf\Common\SolrSearchResult;
namespace Kitodo\Dlf\Common\Solr\SearchResult;

/**
* Region class for the 'dlf' extension. It keeps region in which search phrase was found.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@
* LICENSE.txt file that was distributed with this source code.
*/

namespace Kitodo\Dlf\Common\SolrSearchResult;

use Kitodo\Dlf\Common\SolrSearchResult\Highlight;
use Kitodo\Dlf\Common\SolrSearchResult\Page;
use Kitodo\Dlf\Common\SolrSearchResult\Region;
namespace Kitodo\Dlf\Common\Solr\SearchResult;

/**
* ResultDocument class for the 'dlf' extension. It keeps the result of the search in the SOLR index.
Expand Down Expand Up @@ -202,7 +198,7 @@ public function getSnippets()
}

/**
* Get the thumnail URL
* Get the thumbnail URL
*
* @access public
*
Expand Down
10 changes: 5 additions & 5 deletions Classes/Common/Solr.php → Classes/Common/Solr/Solr.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
* LICENSE.txt file that was distributed with this source code.
*/

namespace Kitodo\Dlf\Common;
namespace Kitodo\Dlf\Common\Solr;

use Kitodo\Dlf\Common\Helper;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use TYPO3\CMS\Core\Cache\CacheManager;
Expand Down Expand Up @@ -115,7 +116,7 @@ class Solr implements LoggerAwareInterface
/**
* This holds the singleton search objects with their core as array key
*
* @var array (\Kitodo\Dlf\Common\Solr)
* @var array (\Kitodo\Dlf\Common\Solr\Solr)
* @access protected
*/
protected static $registry = [];
Expand Down Expand Up @@ -187,8 +188,7 @@ public static function createCore($core = '')
*/
public static function escapeQuery($query)
{
$helper = GeneralUtility::makeInstance(\Solarium\Core\Query\Helper::class);
// Escape query by dissallowing range and field operators
// Escape query by disallowing range and field operators
// Permit operators: wildcard, boolean, fuzzy, proximity, boost, grouping
// https://solr.apache.org/guide/solr/latest/query-guide/standard-query-parser.html
return preg_replace('/(\{|}|\[|]|:|\/|\\\)/', '\\\$1', $query);
Expand Down Expand Up @@ -298,7 +298,7 @@ public static function getFields()
*
* @param mixed $core: Name or UID of the core to load or null to get core admin endpoint
*
* @return \Kitodo\Dlf\Common\Solr Instance of this class
* @return \Kitodo\Dlf\Common\Solr\Solr Instance of this class
*/
public static function getInstance($core = null)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?php

namespace Kitodo\Dlf\Common;
namespace Kitodo\Dlf\Common\Solr;

use Kitodo\Dlf\Common\SolrSearchResult\ResultDocument;
use Kitodo\Dlf\Common\Solr\SearchResult\ResultDocument;
use Kitodo\Dlf\Common\Doc;
use Kitodo\Dlf\Common\Helper;
use Kitodo\Dlf\Common\Indexer;
use Kitodo\Dlf\Domain\Model\Collection;
use Kitodo\Dlf\Domain\Repository\DocumentRepository;
use TYPO3\CMS\Core\Cache\CacheManager;
Expand Down Expand Up @@ -276,24 +278,24 @@ public function prepare()
$virtualCollectionsQueryString = '';
foreach ($this->collection as $collectionEntry) {
// check for virtual collections query string
if($collectionEntry->getIndexSearch()) {
if ($collectionEntry->getIndexSearch()) {
$virtualCollectionsQueryString .= empty($virtualCollectionsQueryString) ? '(' . $collectionEntry->getIndexSearch() . ')' : ' OR ('. $collectionEntry->getIndexSearch() . ')' ;
} else {
$collectionsQueryString .= empty($collectionsQueryString) ? '"' . $collectionEntry->getIndexName() . '"' : ' OR "' . $collectionEntry->getIndexName() . '"';
}
}

// distinguish between simple collection browsing and actual searching within the collection(s)
if(!empty($collectionsQueryString)) {
if(empty($query)) {
if (!empty($collectionsQueryString)) {
if (empty($query)) {
$collectionsQueryString = '(collection_faceting:(' . $collectionsQueryString . ') AND toplevel:true AND partof:0)';
} else {
$collectionsQueryString = '(collection_faceting:(' . $collectionsQueryString . '))';
}
}

// virtual collections might query documents that are neither toplevel:true nor partof:0 and need to be searched separatly
if(!empty($virtualCollectionsQueryString)) {
if (!empty($virtualCollectionsQueryString)) {
$virtualCollectionsQueryString = '(' . $virtualCollectionsQueryString . ')';
}

Expand Down Expand Up @@ -372,9 +374,9 @@ public function submit($start, $rows, $processResults = true)
}
if ($documents[$doc['uid']]) {
// translate language code if applicable
if($doc['metadata']['language']) {
foreach($doc['metadata']['language'] as $indexName => $language) {
$doc['metadata']['language'][$indexName] = Helper::getLanguageName($doc['metadata']['language'][$indexName]);
if ($doc['metadata']['language']) {
foreach ($doc['metadata']['language'] as $indexName => $language) {
$doc['metadata']['language'][$indexName] = Helper::getLanguageName($language);
}
}
if ($doc['toplevel'] === false) {
Expand Down Expand Up @@ -558,7 +560,7 @@ protected function searchSolr($parameters = [], $enableCache = true)
// Perform search for all documents with the same uid that either fit to the search or marked as toplevel.
$response = $solr->service->executeRequest($solrRequest);
// return empty resultSet on error-response
if ($response->getStatusCode() == "400") {
if ($response->getStatusCode() == 400) {
return $resultSet;
}
$result = $solr->service->createResult($selectQuery, $response);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Kitodo\Dlf\Common;
namespace Kitodo\Dlf\Common\Solr;

use TYPO3\CMS\Extbase\Persistence\QueryInterface;
use TYPO3\CMS\Extbase\Persistence\Generic\Qom\ConstraintInterface;
Expand All @@ -12,6 +12,24 @@
*/
class SolrSearchQuery implements QueryInterface
{
/**
* @var SolrSearch
* @access private
*/
private $solrSearch;

/**
* @var int
* @access private
*/
private $limit;

/**
* @var int
* @access private
*/
private $offset;

public function __construct($solrSearch)
{
$this->solrSearch = $solrSearch;
Expand Down
2 changes: 1 addition & 1 deletion Classes/Controller/Backend/NewTenantController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Kitodo\Dlf\Controller\Backend;

use Kitodo\Dlf\Common\Solr;
use Kitodo\Dlf\Common\Solr\Solr;
use Kitodo\Dlf\Controller\AbstractController;
use Kitodo\Dlf\Domain\Model\Format;
use Kitodo\Dlf\Domain\Model\Metadata;
Expand Down
2 changes: 1 addition & 1 deletion Classes/Controller/CollectionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Kitodo\Dlf\Controller;

use Kitodo\Dlf\Common\Solr;
use Kitodo\Dlf\Common\Solr\Solr;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
use Kitodo\Dlf\Domain\Repository\CollectionRepository;
Expand Down
2 changes: 1 addition & 1 deletion Classes/Controller/OaiPmhController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace Kitodo\Dlf\Controller;

use TYPO3\CMS\Core\Utility\GeneralUtility;
use Kitodo\Dlf\Common\Solr;
use Kitodo\Dlf\Common\Solr\Solr;
use Kitodo\Dlf\Domain\Model\Token;
use Kitodo\Dlf\Domain\Repository\CollectionRepository;
use Kitodo\Dlf\Domain\Repository\LibraryRepository;
Expand Down
4 changes: 2 additions & 2 deletions Classes/Controller/SearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use Kitodo\Dlf\Common\Helper;
use Kitodo\Dlf\Common\Indexer;
use Kitodo\Dlf\Common\Solr;
use Kitodo\Dlf\Common\Solr\Solr;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Information\Typo3Version;
use TYPO3\CMS\Core\Utility\GeneralUtility;
Expand Down Expand Up @@ -326,7 +326,7 @@ public function makeFacetsMenuArray($facets)
$solrRequest = $solr->service->createRequest($selectQuery);
$response = $solr->service->executeRequest($solrRequest);
// return empty facet on solr error
if ($response->getStatusCode() == "400") {
if ($response->getStatusCode() == 400) {
return [];
}
$results = $solr->service->select($selectQuery);
Expand Down
2 changes: 1 addition & 1 deletion Classes/Domain/Repository/DocumentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use Kitodo\Dlf\Common\Doc;
use Kitodo\Dlf\Common\Helper;
use Kitodo\Dlf\Common\SolrSearch;
use Kitodo\Dlf\Common\Solr\SolrSearch;
use Kitodo\Dlf\Domain\Model\Collection;
use Kitodo\Dlf\Domain\Model\Document;
use TYPO3\CMS\Core\Database\ConnectionPool;
Expand Down
4 changes: 2 additions & 2 deletions Classes/Eid/SearchInDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
namespace Kitodo\Dlf\Eid;

use Kitodo\Dlf\Common\Helper;
use Kitodo\Dlf\Common\Solr;
use Kitodo\Dlf\Common\SolrSearchResult\ResultDocument;
use Kitodo\Dlf\Common\Solr\Solr;
use Kitodo\Dlf\Common\Solr\SearchResult\ResultDocument;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Http\Response;
Expand Down
2 changes: 1 addition & 1 deletion Classes/Eid/SearchSuggest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace Kitodo\Dlf\Eid;

use Kitodo\Dlf\Common\Solr;
use Kitodo\Dlf\Common\Solr\Solr;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Core\Environment;
Expand Down
2 changes: 1 addition & 1 deletion Classes/Hooks/ConfigurationForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
namespace Kitodo\Dlf\Hooks;

use Kitodo\Dlf\Common\Helper;
use Kitodo\Dlf\Common\Solr;
use Kitodo\Dlf\Common\Solr\Solr;
use TYPO3\CMS\Core\Core\Bootstrap;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Localization\LanguageService;
Expand Down
2 changes: 1 addition & 1 deletion Classes/Hooks/DataHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use Kitodo\Dlf\Common\Doc;
use Kitodo\Dlf\Common\Helper;
use Kitodo\Dlf\Common\Indexer;
use Kitodo\Dlf\Common\Solr;
use Kitodo\Dlf\Common\Solr\Solr;
use Kitodo\Dlf\Domain\Repository\DocumentRepository;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
Expand Down
2 changes: 1 addition & 1 deletion Classes/Hooks/Form/FieldInformation/SolrCoreStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
namespace Kitodo\Dlf\Hooks\Form\FieldInformation;

use Kitodo\Dlf\Common\Helper;
use Kitodo\Dlf\Common\Solr;
use Kitodo\Dlf\Common\Solr\Solr;
use TYPO3\CMS\Backend\Form\AbstractNode;

/**
Expand Down
2 changes: 1 addition & 1 deletion Tests/Functional/Api/OaiPmhTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use DateTime;
use GuzzleHttp\Client as HttpClient;
use Kitodo\Dlf\Common\Solr;
use Kitodo\Dlf\Common\Solr\Solr;
use Kitodo\Dlf\Domain\Repository\SolrCoreRepository;
use Kitodo\Dlf\Tests\Functional\FunctionalTestCase;
use Phpoaipmh\Endpoint;
Expand Down
2 changes: 1 addition & 1 deletion Tests/Functional/Common/SolrIndexingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Kitodo\Dlf\Common\Doc;
use Kitodo\Dlf\Common\Indexer;
use Kitodo\Dlf\Common\Solr;
use Kitodo\Dlf\Common\Solr\Solr;
use Kitodo\Dlf\Domain\Model\Collection;
use Kitodo\Dlf\Domain\Model\SolrCore;
use Kitodo\Dlf\Domain\Repository\CollectionRepository;
Expand Down
2 changes: 1 addition & 1 deletion Tests/Functional/FunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Kitodo\Dlf\Tests\Functional;

use GuzzleHttp\Client as HttpClient;
use Kitodo\Dlf\Common\Solr;
use Kitodo\Dlf\Common\Solr\Solr;
use Symfony\Component\Yaml\Yaml;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Utility\ArrayUtility;
Expand Down