Passed
Push — master ( 4485bc...42e507 )
by Timo
18:39
created

StatisticsComponent::setSearchRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1.4218

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 1
cts 4
cp 0.25
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1.4218
1
<?php
2
namespace ApacheSolrForTypo3\Solr\Search;
3
4
/***************************************************************
5
 *  Copyright notice
6
 *
7
 *  (c) 2012-2015 Ingo Renner <[email protected]>
8
 *  All rights reserved
9
 *
10
 *  This script is part of the TYPO3 project. The TYPO3 project is
11
 *  free software; you can redistribute it and/or modify
12
 *  it under the terms of the GNU General Public License as published by
13
 *  the Free Software Foundation; either version 2 of the License, or
14
 *  (at your option) any later version.
15
 *
16
 *  The GNU General Public License can be found at
17
 *  http://www.gnu.org/copyleft/gpl.html.
18
 *
19
 *  This script is distributed in the hope that it will be useful,
20
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
21
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
 *  GNU General Public License for more details.
23
 *
24
 *  This copyright notice MUST APPEAR in all copies of the script!
25
 ***************************************************************/
26
27
use ApacheSolrForTypo3\Solr\Domain\Search\SearchRequest;
28
use ApacheSolrForTypo3\Solr\Domain\Search\SearchRequestAware;
29
use ApacheSolrForTypo3\Solr\Domain\Search\Statistics\StatisticsWriterProcessor;
30
use ApacheSolrForTypo3\Solr\Query\Modifier\Statistics;
31
32
/**
33
 * Statistics search component
34
 *
35
 * @author Ingo Renner <[email protected]>
36
 */
37
class StatisticsComponent extends AbstractComponent implements SearchRequestAware
38
{
39
40
    /**
41
     * @var SearchRequest
42
     */
43 26
    protected $seachRequest;
44
45 26
    /**
46
     * Provides a component that is aware of the current SearchRequest
47 26
     *
48 22
     * @param SearchRequest $searchRequest
49
     */
50 22
    public function setSearchRequest(SearchRequest $searchRequest)
51
    {
52
        $this->seachRequest = $searchRequest;
53
    }
54 26
55
    /**
56
     * Initializes the search component.
57
     *
58
     */
59
    public function initializeSearchComponent()
60
    {
61
        $solrConfiguration = $this->seachRequest->getContextTypoScriptConfiguration();
62
63
        if ($solrConfiguration->getStatistics()) {
64
            $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['afterSearch']['statistics'] = StatisticsWriterProcessor::class;
65
            // Only if addDebugData is enabled add Query modifier
66
            if ($solrConfiguration->getStatisticsAddDebugData()) {
67
                $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['modifySearchQuery']['statistics'] = Statistics::class;
68
            }
69
        }
70
    }
71
72
}
73