| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | namespace ApacheSolrForTypo3\Solr\ViewHelpers\Debug; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * This file is part of the TYPO3 CMS project. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * It is free software; you can redistribute it and/or modify it under | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * the terms of the GNU General Public License, either version 2 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * of the License, or any later version. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * For the full copyright and license information, please read the | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * LICENSE.txt file that was distributed with this source code. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * The TYPO3 project - inspiring people to share! | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use ApacheSolrForTypo3\Solr\Domain\Search\Score\ScoreCalculationService; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\SearchResultSet; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | use ApacheSolrForTypo3\Solr\ViewHelpers\AbstractSolrFrontendViewHelper; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | use TYPO3\CMS\Core\Utility\GeneralUtility; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  * Class DocumentScoreAnalyzerViewHelper | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  * @author Frans Saris <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  * @author Timo Hund <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  * @package ApacheSolrForTypo3\Solr\ViewHelpers\Debug | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | class DocumentScoreAnalyzerViewHelper extends AbstractSolrFrontendViewHelper | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     use CompileWithRenderStatic; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |      * @var ScoreCalculationService | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     protected static $scoreService; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |      * @var bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     protected $escapeOutput = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |      * Initializes the arguments | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     public function initializeArguments() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         parent::initializeArguments(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         $this->registerArgument('document', \Apache_Solr_Document::class, 'The solr document', true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |      * @param array $arguments | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |      * @param \Closure $renderChildrenClosure | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |      * @param RenderingContextInterface $renderingContext | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |      * @return string | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 59 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |     public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |         $content = ''; | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |         // only check whether a BE user is logged in, don't need to check | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |         // for enabled score analysis as we wouldn't be here if it was disabled | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |         if (empty($GLOBALS['TSFE']->beUserLogin)) { | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |             return $content; | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  |         $document = $arguments['document']; | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  |         /** @var $resultSet SearchResultSet */ | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  |         $resultSet = self::getUsedSearchResultSetFromRenderingContext($renderingContext); | 
            
                                                                        
                            
            
                                    
            
            
                | 73 |  |  |         $debugData = $resultSet->getUsedSearch()->getDebugResponse()->explain->{$document->getId()}; | 
            
                                                                        
                            
            
                                    
            
            
                | 74 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 75 |  |  |         /** @var $scoreService ScoreCalculationService */ | 
            
                                                                        
                            
            
                                    
            
            
                | 76 |  |  |         $scoreService = self::getScoreService(); | 
            
                                                                        
                            
            
                                    
            
            
                | 77 |  |  |         $queryFields = $resultSet->getUsedSearchRequest()->getContextTypoScriptConfiguration()->getSearchQueryQueryFields(); | 
            
                                                                        
                            
            
                                    
            
            
                | 78 |  |  |         $content = $scoreService->getRenderedScores($debugData, $queryFields); | 
            
                                                                        
                            
            
                                    
            
            
                | 79 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 80 |  |  |         return '<div class="document-score-analysis">' . $content . '</div>'; | 
            
                                                                        
                            
            
                                    
            
            
                | 81 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |      * @return ScoreCalculationService | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |     protected static function getScoreService() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |         if (isset(self::$scoreService)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |             return self::$scoreService; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |         self::$scoreService = GeneralUtility::makeInstance(ScoreCalculationService::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |         return self::$scoreService; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 95 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 96 |  |  |  |