first commit

This commit is contained in:
Sven Wappler
2021-04-17 00:26:33 +02:00
commit 866c63cc63
813 changed files with 100696 additions and 0 deletions

View File

@@ -0,0 +1,51 @@
<?php
namespace WapplerSystems\Meilisearch\Search;
/***************************************************************
* Copyright notice
*
* (c) 2012-2015 Ingo Renner <ingo@typo3.org>
* 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!
***************************************************************/
/**
* Abstract search component
*
* @author Ingo Renner <ingo@typo3.org>
*/
abstract class AbstractComponent implements SearchComponent
{
/**
* Search configuration - plugin.tx_meilisearch.search
*
* @var array
*/
protected $searchConfiguration = [];
/**
* Sets the plugin's search configuration.
*
* @param array $configuration Configuration
*/
public function setSearchConfiguration(array $configuration)
{
$this->searchConfiguration = $configuration;
}
}

View File

@@ -0,0 +1,82 @@
<?php
namespace WapplerSystems\Meilisearch\Search;
/***************************************************************
* Copyright notice
*
* (c) 2012-2015 Ingo Renner <ingo@typo3.org>
* 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\Domain\Search\Query\QueryBuilder;
use WapplerSystems\Meilisearch\Domain\Search\Query\Query;
use WapplerSystems\Meilisearch\Util;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Access search component
*
* @author Ingo Renner <ingo@typo3.org>
*/
class AccessComponent extends AbstractComponent implements QueryAware
{
/**
* Solr query
*
* @var Query
*/
protected $query;
/**
* @var QueryBuilder
*/
protected $queryBuilder;
/**
* AccessComponent constructor.
* @param QueryBuilder|null
*/
public function __construct(QueryBuilder $queryBuilder = null)
{
$this->queryBuilder = $queryBuilder ?? GeneralUtility::makeInstance(QueryBuilder::class);
}
/**
* Initializes the search component.
*/
public function initializeSearchComponent()
{
$this->query = $this->queryBuilder
->startFrom($this->query)
->useSiteHashFromTypoScript($GLOBALS['TSFE']->id)
->useUserAccessGroups(Util::getFrontendUserGroups())
->getQuery();
}
/**
* Provides the extension component with an instance of the current query.
*
* @param Query $query Current query
*/
public function setQuery(Query $query)
{
$this->query = $query;
}
}

View File

@@ -0,0 +1,81 @@
<?php
namespace WapplerSystems\Meilisearch\Search;
/***************************************************************
* Copyright notice
*
* (c) 2012-2015 Ingo Renner <ingo@typo3.org>
* 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\Domain\Search\Query\QueryBuilder;
use WapplerSystems\Meilisearch\Domain\Search\Query\Query;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Analysis search component
*
* @author Ingo Renner <ingo@typo3.org>
*/
class AnalysisComponent extends AbstractComponent implements QueryAware
{
/**
* Solr query
*
* @var Query
*/
protected $query;
/**
* QueryBuilder
*
* @var QueryBuilder|object
*/
protected $queryBuilder;
/**
* AccessComponent constructor.
* @param QueryBuilder|null
*/
public function __construct(QueryBuilder $queryBuilder = null)
{
$this->queryBuilder = $queryBuilder ?? GeneralUtility::makeInstance(QueryBuilder::class);
}
/**
* Initializes the search component.
*/
public function initializeSearchComponent()
{
if ($this->searchConfiguration['results.']['showDocumentScoreAnalysis']) {
$this->queryBuilder->startFrom($this->query)->useDebug(true);
}
}
/**
* Provides the extension component with an instance of the current query.
*
* @param Query $query Current query
*/
public function setQuery(Query $query)
{
$this->query = $query;
}
}

View File

@@ -0,0 +1,102 @@
<?php
namespace WapplerSystems\Meilisearch\Search;
/***************************************************************
* Copyright notice
*
* (c) 2012-2015 Ingo Renner <ingo@typo3.org>
* 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\Domain\Search\Query\QueryBuilder;
use WapplerSystems\Meilisearch\Domain\Search\Query\Query;
use WapplerSystems\Meilisearch\Domain\Search\SearchRequest;
use WapplerSystems\Meilisearch\Domain\Search\SearchRequestAware;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Debug search component
*
*
* @author Ingo Renner <ingo@typo3.org>
*/
class DebugComponent extends AbstractComponent implements QueryAware, SearchRequestAware
{
/**
* Solr query
*
* @var Query
*/
protected $query;
/**
* @var SearchRequest
*/
protected $seachRequest;
/**
* QueryBuilder
*
* @var QueryBuilder|object
*/
protected $queryBuilder;
/**
* AccessComponent constructor.
* @param QueryBuilder|null
*/
public function __construct(QueryBuilder $queryBuilder = null)
{
$this->queryBuilder = $queryBuilder ?? GeneralUtility::makeInstance(QueryBuilder::class);
}
/**
* Provides a component that is aware of the current SearchRequest
*
* @param SearchRequest $searchRequest
*/
public function setSearchRequest(SearchRequest $searchRequest)
{
$this->seachRequest = $searchRequest;
}
/**
* Initializes the search component.
*
* Sets the debug query parameter
*
*/
public function initializeSearchComponent()
{
if ($this->seachRequest->getContextTypoScriptConfiguration()->getEnabledDebugMode()) {
$this->queryBuilder->startFrom($this->query)->useDebug(true);
}
}
/**
* Provides the extension component with an instance of the current query.
*
* @param Query $query Current query
*/
public function setQuery(Query $query)
{
$this->query = $query;
}
}

View File

@@ -0,0 +1,45 @@
<?php
namespace WapplerSystems\Meilisearch\Search;
/***************************************************************
* Copyright notice
*
* (c) 2014-2015 Ingo Renner <ingo@typo3.org>
* 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\Query\Modifier\Elevation;
/**
* Elevation search component
*
* @author Ingo Renner <ingo@typo3.org>
*/
class ElevationComponent extends AbstractComponent
{
/**
* Initializes the search component.
*
*/
public function initializeSearchComponent()
{
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['modifySearchQuery']['elevation'] = Elevation::class;
}
}

View File

@@ -0,0 +1,47 @@
<?php
namespace WapplerSystems\Meilisearch\Search;
/***************************************************************
* Copyright notice
*
* (c) 2012-2015 Ingo Renner <ingo@typo3.org>
* 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\Query\Modifier\Faceting;
/**
* Faceting search component
*
* @author Ingo Renner <ingo@typo3.org>
*/
class FacetingComponent extends AbstractComponent
{
/**
* Initializes the search component.
*
*/
public function initializeSearchComponent()
{
if ($this->searchConfiguration['faceting']) {
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['modifySearchQuery']['faceting'] = Faceting::class;
}
}
}

View File

@@ -0,0 +1,46 @@
<?php
namespace WapplerSystems\Meilisearch\Search;
/***************************************************************
* Copyright notice
*
* (c) 2010-2011 Markus Goldbach <markus.goldbach@dkd.de>
* (c) 2012-2015 Ingo Renner <ingo@typo3.org>
* 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.
* A copy is found in the textfile GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
*
* 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!
***************************************************************/
/**
* FacetsModifier interface, allows to modify facet fields and their counts.
*
* @author Markus Goldbach <markus.goldbach@dkd.de>
*/
interface FacetsModifier
{
/**
* Modifies the given facets and returns the modified facets as array
*
* @param array $facets
* @return array The facets with fields as array
*/
public function modifyFacets($facets);
}

View File

@@ -0,0 +1,77 @@
<?php
namespace WapplerSystems\Meilisearch\Search;
/***************************************************************
* Copyright notice
*
* (c) 2012-2015 Ingo Renner <ingo@typo3.org>
* 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\Domain\Search\Query\QueryBuilder;
use WapplerSystems\Meilisearch\Domain\Search\Query\Query;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Highlighting search component
*
* @author Ingo Renner <ingo@typo3.org>
*/
class HighlightingComponent extends AbstractComponent implements QueryAware
{
/**
* Solr query
*
* @var Query
*/
protected $query;
/**
* @var QueryBuilder
*/
protected $queryBuilder;
/**
* AccessComponent constructor.
* @param QueryBuilder|null
*/
public function __construct(QueryBuilder $queryBuilder = null)
{
$this->queryBuilder = $queryBuilder ?? GeneralUtility::makeInstance(QueryBuilder::class);
}
/**
* Initializes the search component.
*/
public function initializeSearchComponent()
{
$this->query = $this->queryBuilder->startFrom($this->query)->useHighlightingFromTypoScript()->getQuery();
}
/**
* Provides the extension component with an instance of the current query.
*
* @param Query $query Current query
*/
public function setQuery(Query $query)
{
$this->query = $query;
}
}

View File

@@ -0,0 +1,47 @@
<?php
namespace WapplerSystems\Meilisearch\Search;
/***************************************************************
* Copyright notice
*
* (c) 2012-2015 Ingo Renner <ingo@typo3.org>
* 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\Domain\Search\LastSearches\LastSearchesWriterProcessor;
/**
* Last searches search component
*
* @author Ingo Renner <ingo@typo3.org>
*/
class LastSearchesComponent extends AbstractComponent
{
/**
* Initializes the search component.
*
*/
public function initializeSearchComponent()
{
if ($this->searchConfiguration['lastSearches']) {
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['afterSearch']['lastSearches'] = LastSearchesWriterProcessor::class;
}
}
}

View File

@@ -0,0 +1,46 @@
<?php
namespace WapplerSystems\Meilisearch\Search;
/***************************************************************
* Copyright notice
*
* (c) 2012-2015 Ingo Renner <ingo@typo3.org>
* 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.
* A copy is found in the textfile GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
*
* 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\Domain\Search\Query\Query;
/**
* Query awareness interface for extension components.
*
* @author Ingo Renner <ingo@typo3.org>
*/
interface QueryAware
{
/**
* Provides the extension component with an instance of the current query.
*
* @param Query $query Current query
*/
public function setQuery(Query $query);
}

View File

@@ -0,0 +1,88 @@
<?php
namespace WapplerSystems\Meilisearch\Search;
/***************************************************************
* Copyright notice
*
* (c) 2012-2015 Ingo Renner <ingo@typo3.org>
* 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\Domain\Search\Query\QueryBuilder;
use WapplerSystems\Meilisearch\Domain\Search\Query\Query;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Boosting search component
*
* @author Ingo Renner <ingo@typo3.org>
*/
class RelevanceComponent extends AbstractComponent implements QueryAware
{
/**
* Solr query
*
* @var Query
*/
protected $query;
/**
* QueryBuilder
*
* @var QueryBuilder|object
*/
protected $queryBuilder;
/**
* AccessComponent constructor.
* @param QueryBuilder|null
*/
public function __construct(QueryBuilder $queryBuilder = null)
{
$this->queryBuilder = $queryBuilder ?? GeneralUtility::makeInstance(QueryBuilder::class);
}
/**
* Initializes the search component.
*
* Sets minimum match, boost function, boost query and tie breaker.
*
*/
public function initializeSearchComponent()
{
$this->query = $this->queryBuilder->startFrom($this->query)
->useMinimumMatchFromTypoScript()
->useBoostFunctionFromTypoScript()
->useSlopsFromTypoScript()
->useBoostQueriesFromTypoScript()
->useTieParameterFromTypoScript()
->getQuery();
}
/**
* Provides the extension component with an instance of the current query.
*
* @param Query $query Current query
*/
public function setQuery(Query $query)
{
$this->query = $query;
}
}

View File

@@ -0,0 +1,47 @@
<?php
namespace WapplerSystems\Meilisearch\Search;
/***************************************************************
* Copyright notice
*
* (c) 2012-2015 Ingo Renner <ingo@typo3.org>
* 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.
* A copy is found in the textfile GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
*
* 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\Solr\ResponseAdapter;
/**
* ResponseModifier interface, allows to modify the search response
*
* @author Ingo Renner <ingo@typo3.org>
*/
interface ResponseModifier
{
/**
* Modifies the given response and returns the modified response as result
*
* @param ResponseAdapter $response The response to modify
* @return ResponseAdapter The modified response
*/
public function modifyResponse(ResponseAdapter $response);
}

View File

@@ -0,0 +1,47 @@
<?php
namespace WapplerSystems\Meilisearch\Search;
/***************************************************************
* Copyright notice
*
* (c) 2012-2015 Ingo Renner <ingo@typo3.org>
* 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.
* A copy is found in the textfile GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
*
* 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\Search;
/**
* Search awareness interface for extension components.
*
* @author Ingo Renner <ingo@typo3.org>
*/
interface SearchAware
{
/**
* Provides the extension component with an instance of the currently
* active search.
*
* @param Search $search Currently active search instance
*/
public function setSearch(Search $search);
}

View File

@@ -0,0 +1,50 @@
<?php
namespace WapplerSystems\Meilisearch\Search;
/***************************************************************
* Copyright notice
*
* (c) 2012-2015 Ingo Renner <ingo@typo3.org>
* 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.
* A copy is found in the textfile GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
*
* 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!
***************************************************************/
/**
* Search component interface.
*
* @author Ingo Renner <ingo@typo3.org>
*/
interface SearchComponent
{
/**
* Provides the plugin's search configuration from plugin.tx_meilisearch.search
*
* @param array $configuration Configuration
*/
public function setSearchConfiguration(array $configuration);
/**
* Initializes the search component.
*
*/
public function initializeSearchComponent();
}

View File

@@ -0,0 +1,116 @@
<?php
namespace WapplerSystems\Meilisearch\Search;
/***************************************************************
* Copyright notice
*
* (c) 2012-2015 Ingo Renner <ingo@typo3.org>
* 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\Search\SearchComponent;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Search components manager, registration and stuff...
*
* @author Ingo Renner <ingo@typo3.org>
*/
class SearchComponentManager
{
/**
* Search component registry.
*
* @var array
*/
protected static $searchComponents = [];
/**
* Registers a search component.
*
* @param string $componentName Search component name
* @param string $componentClassName Component class
*/
public static function registerSearchComponent(
$componentName,
$componentClassName
) {
self::$searchComponents[$componentName] = $componentClassName;
}
/**
* Returns all currently registered search components.
*
* @return array An array of search component instances
*/
public function getSearchComponents()
{
$searchComponents = [];
foreach (self::$searchComponents as $componentName => $componentClass) {
$searchComponents[$componentName] = $this->getSearchComponent($componentName);
}
return $searchComponents;
}
/**
* Instanciates a registered search component
*
* @param string $componentName Search component name
* @return SearchComponent Instance of the requested search component
* @throws \InvalidArgumentException if $componentName is not a registered search component
* @throws \RuntimeException if the class registered for $componentName is not an implementation of WapplerSystems\Meilisearch\Search\SearchComponent
*/
public function getSearchComponent($componentName)
{
if (!array_key_exists($componentName, self::$searchComponents)) {
throw new \InvalidArgumentException(
'No search component registered named ' . $componentName,
1343398440
);
}
$searchComponent = GeneralUtility::makeInstance(self::$searchComponents[$componentName]);
if (!($searchComponent instanceof SearchComponent)) {
throw new \RuntimeException(
'Class ' . self::$searchComponents[$componentName] . ' must implement interface ' . SearchComponent::class,
1343398621
);
}
return $searchComponent;
}
/**
* Unregisters a search component
*
* @param string $componentName Search component name
*/
public function removeSearchComponent($componentName)
{
if (!array_key_exists($componentName, self::$searchComponents)) {
return;
}
unset(self::$searchComponents[$componentName]);
}
}

View File

@@ -0,0 +1,135 @@
<?php
namespace WapplerSystems\Meilisearch\Search;
/***************************************************************
* Copyright notice
*
* (c) 2012-2015 Ingo Renner <ingo@typo3.org>
* 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\Domain\Search\Query\ParameterBuilder\Sortings;
use WapplerSystems\Meilisearch\Domain\Search\Query\QueryBuilder;
use WapplerSystems\Meilisearch\Domain\Search\ResultSet\Sorting\SortingHelper;
use WapplerSystems\Meilisearch\Domain\Search\Query\Query;
use WapplerSystems\Meilisearch\Domain\Search\SearchRequest;
use WapplerSystems\Meilisearch\Domain\Search\SearchRequestAware;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Sorting search component
*
* TODO maybe merge WapplerSystems\Meilisearch\Sorting into WapplerSystems\Meilisearch\Search\SortingComponent
*
* @author Ingo Renner <ingo@typo3.org>
*/
class SortingComponent extends AbstractComponent implements QueryAware, SearchRequestAware
{
/**
* Solr query
*
* @var Query
*/
protected $query;
/**
* @var SearchRequest
*/
protected $searchRequest;
/**
* QueryBuilder
*
* @var QueryBuilder|object
*/
protected $queryBuilder;
/**
* AccessComponent constructor.
* @param QueryBuilder|null
*/
public function __construct(QueryBuilder $queryBuilder = null)
{
$this->queryBuilder = $queryBuilder ?? GeneralUtility::makeInstance(QueryBuilder::class);
}
/**
* Initializes the search component.
*
* Sets the sorting query parameters
*/
public function initializeSearchComponent()
{
$this->queryBuilder->startFrom($this->query);
if (!empty($this->searchConfiguration['query.']['sortBy'])) {
$this->queryBuilder->useSortings(Sortings::fromString($this->searchConfiguration['query.']['sortBy']));
$this->query = $this->queryBuilder->getQuery();
}
$isSortingEnabled = !empty($this->searchConfiguration['sorting']) && ((int)$this->searchConfiguration['sorting']) === 1;
if(!$isSortingEnabled) {
return;
}
$arguments = $this->searchRequest->getArguments();
$isSortingPassedAsArgument = !empty($arguments['sort']) && preg_match('/^([a-z0-9_]+ (asc|desc)[, ]*)*([a-z0-9_]+ (asc|desc))+$/i', $arguments['sort']);
if (!$isSortingPassedAsArgument) {
return;
}
// a passed sorting has allways priority an overwrites the configured initial sorting
$this->query->clearSorts();
/** @var $sortHelper SortingHelper */
$sortHelper = GeneralUtility::makeInstance(SortingHelper::class, $this->searchConfiguration['sorting.']['options.']);
$sortFields = $sortHelper->getSortFieldFromUrlParameter($arguments['sort']);
$this->queryBuilder->useSortings(Sortings::fromString($sortFields));
$this->query = $this->queryBuilder->getQuery();
}
/**
* Checks if the arguments array has a valid sorting.
*
* @param array $arguments
* @return bool
*/
protected function hasValidSorting(array $arguments)
{
return !empty($arguments['sort']) && preg_match('/^([a-z0-9_]+ (asc|desc)[, ]*)*([a-z0-9_]+ (asc|desc))+$/i', $arguments['sort']);
}
/**
* Provides the extension component with an instance of the current query.
*
* @param Query $query Current query
*/
public function setQuery(Query $query)
{
$this->query = $query;
}
/**
* @param SearchRequest $searchRequest
*/
public function setSearchRequest(SearchRequest $searchRequest)
{
$this->searchRequest = $searchRequest;
}
}

View File

@@ -0,0 +1,83 @@
<?php
namespace WapplerSystems\Meilisearch\Search;
/***************************************************************
* Copyright notice
*
* (c) 2012-2015 Ingo Renner <ingo@typo3.org>
* 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\Domain\Search\Query\QueryBuilder;
use WapplerSystems\Meilisearch\Domain\Search\Query\Query;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Spellchecking search component
*
* @author Ingo Renner <ingo@typo3.org>
*/
class SpellcheckingComponent extends AbstractComponent implements QueryAware
{
/**
* Solr query
*
* @var Query
*/
protected $query;
/**
* QueryBuilder
*
* @var QueryBuilder|object
*/
protected $queryBuilder;
/**
* AccessComponent constructor.
* @param QueryBuilder|null
*/
public function __construct(QueryBuilder $queryBuilder = null)
{
$this->queryBuilder = $queryBuilder ?? GeneralUtility::makeInstance(QueryBuilder::class);
}
/**
* Initializes the search component.
*
*
*/
public function initializeSearchComponent()
{
if ($this->searchConfiguration['spellchecking']) {
$this->query = $this->queryBuilder->startFrom($this->query)->useSpellcheckingFromTypoScript()->getQuery();
}
}
/**
* Provides the extension component with an instance of the current query.
*
* @param Query $query Current query
*/
public function setQuery(Query $query)
{
$this->query = $query;
}
}

View File

@@ -0,0 +1,72 @@
<?php
namespace WapplerSystems\Meilisearch\Search;
/***************************************************************
* Copyright notice
*
* (c) 2012-2015 Ingo Renner <ingo@typo3.org>
* 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\Domain\Search\SearchRequest;
use WapplerSystems\Meilisearch\Domain\Search\SearchRequestAware;
use WapplerSystems\Meilisearch\Domain\Search\Statistics\StatisticsWriterProcessor;
use WapplerSystems\Meilisearch\Query\Modifier\Statistics;
/**
* Statistics search component
*
* @author Ingo Renner <ingo@typo3.org>
*/
class StatisticsComponent extends AbstractComponent implements SearchRequestAware
{
/**
* @var SearchRequest
*/
protected $seachRequest;
/**
* Provides a component that is aware of the current SearchRequest
*
* @param SearchRequest $searchRequest
*/
public function setSearchRequest(SearchRequest $searchRequest)
{
$this->seachRequest = $searchRequest;
}
/**
* Initializes the search component.
*
*/
public function initializeSearchComponent()
{
$solrConfiguration = $this->seachRequest->getContextTypoScriptConfiguration();
if ($solrConfiguration->getStatistics()) {
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['afterSearch']['statistics'] = StatisticsWriterProcessor::class;
// Only if addDebugData is enabled add Query modifier
if ($solrConfiguration->getStatisticsAddDebugData()) {
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['modifySearchQuery']['statistics'] = Statistics::class;
}
}
}
}