Last active
June 28, 2023 08:04
-
-
Save spoonerWeb/f0393fbf393c2e5c351af555c3aca1fb to your computer and use it in GitHub Desktop.
Get result count of Solr search without facets in TYPO3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$signalSlotDispatcher = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\SignalSlot\Dispatcher::class); | |
$signalSlotDispatcher->connect( | |
\ApacheSolrForTypo3\Solr\Controller\SearchController::class, | |
'resultsAction', | |
\Vendor\ExtensionName\Slot\Solr::class, | |
'addResultsWithoutFacets' | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Vendor\ExtensionName\Slot; | |
/* | |
* This file is part of a TYPO3 extension. | |
* | |
* It is free software; you can redistribute it and/or modify it under | |
* the terms of the GNU General Public License, either version 2 | |
* of the License, or any later version. | |
* | |
* For the full copyright and license information, please read the | |
* LICENSE.txt file that was distributed with this source code. | |
* | |
* The TYPO3 project - inspiring people to share! | |
*/ | |
class Solr | |
{ | |
public function addResultsWithoutFacets(array $values): array | |
{ | |
// remove filter queries of facets | |
$filterQueries = $values['resultSet']->getUsedQuery()->getFilterQueries(); | |
unset($filterQueries['type']); | |
$values['resultSet']->getUsedQuery()->setFilterQueries($filterQueries); | |
// get result count on search without filter queries | |
$allValuesFoundWithoutFacet = (int)$values['resultSet']->getUsedSearch()->search($values['resultSet']->getUsedQuery())->getParsedData()->response->numFound; | |
// set the default result count into variable | |
$values['allResultCountWithoutFacets'] = $values['resultSet']->getAllResultCount(); | |
// save value from search without facet into variable | |
if ($allValuesFoundWithoutFacet > 0) { | |
$values['allResultCountWithoutFacets'] = $allValuesFoundWithoutFacet; | |
} | |
return [$values]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks a bunch @spoonerWeb that is exactly what I have been looking for. Works like a charm!