Completed
Pull Request — master (#840)
by Timo
13:12
created

PluginBase::initializeSearch()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 1.0046

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 10
cts 12
cp 0.8333
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 0
crap 1.0046
1
<?php
2
namespace ApacheSolrForTypo3\Solr\Plugin;
3
4
/***************************************************************
5
 *  Copyright notice
6
 *
7
 *  (c) 2010-2015 Timo Schmidt <[email protected]>
8
 *  (c) 2012-2015 Ingo Renner <[email protected]>
9
 *  All rights reserved
10
 *
11
 *  This script is part of the TYPO3 project. The TYPO3 project is
12
 *  free software; you can redistribute it and/or modify
13
 *  it under the terms of the GNU General Public License as published by
14
 *  the Free Software Foundation; either version 2 of the License, or
15
 *  (at your option) any later version.
16
 *
17
 *  The GNU General Public License can be found at
18
 *  http://www.gnu.org/copyleft/gpl.html.
19
 *
20
 *  This script is distributed in the hope that it will be useful,
21
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 *  GNU General Public License for more details.
24
 *
25
 *  This copyright notice MUST APPEAR in all copies of the script!
26
 ***************************************************************/
27
28
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\SearchResultSetService;
29
use ApacheSolrForTypo3\Solr\JavascriptManager;
30
use ApacheSolrForTypo3\Solr\Query;
31
use ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration;
32
use ApacheSolrForTypo3\Solr\Template;
33
use ApacheSolrForTypo3\Solr\ViewHelper\ViewHelperProvider;
34
use TYPO3\CMS\Core\Utility\ArrayUtility;
35
use TYPO3\CMS\Core\Utility\GeneralUtility;
36
use TYPO3\CMS\Frontend\Plugin\AbstractPlugin;
37
38
/**
39
 * Abstract base class for all solr plugins.
40
 *
41
 * Implements a main method and several abstract methods which
42
 * need to be implemented by an inheriting plugin.
43
 *
44
 * @author Ingo Renner <[email protected]>
45
 * @author Timo Schmidt <[email protected]>
46
 */
47
abstract class PluginBase extends AbstractPlugin
48
{
49
    /**
50
     * @var string
51
     */
52
    public $prefixId = 'tx_solr';
53
54
    /**
55
     * @var string
56
     */
57
    public $extKey = 'solr';
58
59
    /**
60
     * An instance of ApacheSolrForTypo3\Solr\Template
61
     *
62
     * @var Template
63
     */
64
    protected $template;
65
66
    /**
67
     * An instance of ApacheSolrForTypo3\Solr\JavascriptManager
68
     *
69
     * @var JavascriptManager
70
     */
71
    protected $javascriptManager;
72
73
    /**
74
     * An instance of the localization factory
75
     *
76
     * @var \TYPO3\CMS\Core\Localization\LocalizationFactory
77
     */
78
    protected $languageFactory;
79
80
    /**
81
     * The user's raw query.
82
     *
83
     * Private to enforce API usage.
84
     *
85
     * @var string
86
     */
87
    private $rawUserQuery;
88
89
    // Main
90
91
    /**
92
     * @var TypoScriptConfiguration
93
     */
94
    public $typoScriptConfiguration;
95
96
    /**
97
     * @var SearchResultSetService
98
     */
99
    private $searchResultsSetService;
100
101
    /**
102
     * The main method of the plugin
103
     *
104
     * @param string $content The plugin content
105
     * @param array $configuration The plugin configuration
106
     * @return string The content that is displayed on the website
107
     */
108 25
    public function main($content, $configuration)
0 ignored issues
show
Unused Code introduced by
The parameter $content is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
109
    {
110
        /** @noinspection PhpUnusedLocalVariableInspection */
111 25
        $content = '';
112
113
        try {
114 25
            $this->initialize($configuration);
115 25
            $this->preRender();
116
117 25
            $actionResult = $this->performAction();
118
119 25
            if ($this->getSearchResultSetService()->getIsSolrAvailable()) {
120 25
                $content = $this->render($actionResult);
121
            } else {
122
                $content = $this->renderError();
123
            }
124
125 25
            $content = $this->postRender($content);
126
        } catch (\Exception $e) {
127
            if ($this->typoScriptConfiguration->getLoggingExceptions()) {
128
                GeneralUtility::devLog(
129
                    $e->getCode() . ': ' . $e->__toString(),
130
                    'solr',
131
                    3,
132
                    (array)$e
133
                );
134
            }
135
136
            $this->initializeTemplateEngine();
137
            $content = $this->renderException();
138
        }
139
140 25
        return $this->baseWrap($content);
141
    }
142
143
    /**
144
     * Adds the possibility to use stdWrap on the plugins content instead of wrapInBaseClass.
145
     * Defaults to wrapInBaseClass to ensure downward compatibility.
146
     *
147
     * @param string $content The plugin content
148
     * @return string
149
     */
150 25
    protected function baseWrap($content)
151
    {
152 25
        $baseWrap = $this->typoScriptConfiguration->getObjectByPath('plugin.tx_solr.general.baseWrap.');
153 25
        if (isset($baseWrap)) {
154 25
            return $this->cObj->stdWrap($content,
155
                $baseWrap);
156
        } else {
157
            return $this->pi_wrapInBaseClass($content);
158
        }
159
    }
160
161
    /**
162
     * Implements the action logic. The result of this method is passed to the
163
     * render method.
164
     *
165
     * @return string Action result
166
     */
167
    abstract protected function performAction();
168
169
    // Initialization
170
171
    /**
172
     * Initializes the plugin - configuration, language, caching, search...
173
     *
174
     * @param array $configuration configuration array as provided by the TYPO3 core
175
     */
176 25
    protected function initialize($configuration)
177
    {
178
        /** @var $configurationManager \ApacheSolrForTypo3\Solr\System\Configuration\ConfigurationManager */
179 25
        $configurationManager = GeneralUtility::makeInstance('ApacheSolrForTypo3\\Solr\\System\\Configuration\\ConfigurationManager');
180 25
        $typoScriptConfiguration = $configurationManager->getTypoScriptConfiguration()->mergeSolrConfiguration($configuration);
181 25
        $this->typoScriptConfiguration = $typoScriptConfiguration;
182
183 25
        $this->initializeLanguageFactory();
184 25
        $this->pi_setPiVarDefaults();
185 25
        $this->pi_loadLL();
186 25
        $this->pi_initPIflexForm();
187
188 25
        $this->overrideTyposcriptWithFlexformSettings();
189
190 25
        $this->initializeQuery();
191 25
        $this->initializeSearch();
192 25
        $this->initializeTemplateEngine();
193 25
        $this->initializeJavascriptManager();
194
195 25
        $this->postInitialize();
196 25
    }
197
198
    /**
199
     * Overwrites pi_setPiVarDefaults to add stdWrap-functionality to _DEFAULT_PI_VARS
200
     *
201
     * @author Grigori Prokhorov <[email protected]>
202
     * @author Ivan Kartolo <[email protected]>
203
     * @return void
204
     */
205 25
    public function pi_setPiVarDefaults()
206
    {
207 25
        if (is_array($this->conf['_DEFAULT_PI_VARS.'])) {
208
            foreach ($this->conf['_DEFAULT_PI_VARS.'] as $key => $defaultValue) {
209
                $this->conf['_DEFAULT_PI_VARS.'][$key] = $this->cObj->cObjGetSingle($this->conf['_DEFAULT_PI_VARS.'][$key],
210
                    $this->conf['_DEFAULT_PI_VARS.'][$key . '.']);
211
            }
212
213
            $piVars = is_array($this->piVars) ? $this->piVars : array();
214
            $this->piVars = $this->conf['_DEFAULT_PI_VARS.'];
215
            ArrayUtility::mergeRecursiveWithOverrule(
216
                $this->piVars,
217
                $piVars
218
            );
219
        }
220 25
    }
221
222
    /**
223
     * Overwrites pi_loadLL() to handle custom location of language files.
224
     *
225
     * Loads local-language values by looking for a "locallang" file in the
226
     * plugin class directory ($this->scriptRelPath) and if found includes it.
227
     * Also locallang values set in the TypoScript property "_LOCAL_LANG" are
228
     * merged onto the values found in the "locallang" file.
229
     * Supported file extensions xlf, xml, php
230
     *
231
     * @param string $languageFilePath path to the plugin language file in format EXT:....
232
     * @return void
233
     */
234 25
    public function pi_loadLL($languageFilePath = '')
235
    {
236 25
        if (!$this->LOCAL_LANG_loaded && $this->scriptRelPath) {
237 25
            $basePath = 'EXT:' . $this->extKey . '/Resources/Private/Language/locallang.xlf';
238
            // Read the strings in the required charset (since TYPO3 4.2)
239 25
            $this->LOCAL_LANG = $this->languageFactory->getParsedData($basePath,
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->languageFactory->...FE']->renderCharset, 3) can also be of type boolean. However, the property $LOCAL_LANG is declared as type array. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
240 25
                $this->LLkey, $GLOBALS['TSFE']->renderCharset, 3);
241
242 25
            $alternativeLanguageKeys = GeneralUtility::trimExplode(',',
243 25
                $this->altLLkey, true);
244 25
            foreach ($alternativeLanguageKeys as $languageKey) {
245
                $tempLL = $this->languageFactory->getParsedData($basePath, $languageKey, $GLOBALS['TSFE']->renderCharset, 3);
246
                if ($this->LLkey !== 'default' && isset($tempLL[$languageKey])) {
247
                    $this->LOCAL_LANG[$languageKey] = $tempLL[$languageKey];
248
                }
249
            }
250
            // Overlaying labels from TypoScript (including fictitious language keys for non-system languages!):
251 25
            $translationInTypoScript = $this->typoScriptConfiguration->getLocalLangConfiguration();
252
253 25
            if (count($translationInTypoScript) == 0) {
254 24
                return;
255
            }
256
257
            // Clear the "unset memory"
258 1
            $this->LOCAL_LANG_UNSET = array();
259 1
            foreach ($translationInTypoScript as $languageKey => $languageArray) {
260
                // Remove the dot after the language key
261 1
                $languageKey = substr($languageKey, 0, -1);
262
                // Don't process label if the language is not loaded
263 1
                if (is_array($languageArray) && isset($this->LOCAL_LANG[$languageKey])) {
264 1
                    foreach ($languageArray as $labelKey => $labelValue) {
265 1
                        if (!is_array($labelValue)) {
266 1
                            $this->LOCAL_LANG[$languageKey][$labelKey][0]['target'] = $labelValue;
267 1
                            $this->LOCAL_LANG_charset[$languageKey][$labelKey] = 'utf-8';
0 ignored issues
show
Bug introduced by
The property LOCAL_LANG_charset does not seem to exist. Did you mean LOCAL_LANG?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
268
269 1
                            if ($labelValue === '') {
270 1
                                $this->LOCAL_LANG_UNSET[$languageKey][$labelKey] = '';
271
                            }
272
                        }
273
                    }
274
                }
275
            }
276
        }
277 1
        $this->LOCAL_LANG_loaded = 1;
0 ignored issues
show
Documentation Bug introduced by
The property $LOCAL_LANG_loaded was declared of type boolean, but 1 is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
278 1
    }
279
280
    /**
281
     * Allows to override TypoScript settings with Flexform values.
282
     *
283
     */
284 3
    protected function overrideTyposcriptWithFlexformSettings()
285
    {
286 3
    }
287
288
    /**
289
     * Initializes the query from the GET query parameter.
290
     *
291
     */
292 25
    protected function initializeQuery()
293
    {
294 25
        $this->rawUserQuery = GeneralUtility::_GET('q');
0 ignored issues
show
Documentation Bug introduced by
It seems like \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('q') can also be of type array. However, the property $rawUserQuery is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
295 25
    }
296
297
    /**
298
     * Initializes the Solr connection and tests the connection through a ping.
299
     *
300
     */
301 25
    protected function initializeSearch()
302
    {
303 25
        $solrConnection = GeneralUtility::makeInstance('ApacheSolrForTypo3\\Solr\\ConnectionManager')->getConnectionByPageId(
304 25
            $GLOBALS['TSFE']->id,
305 25
            $GLOBALS['TSFE']->sys_language_uid,
306 25
            $GLOBALS['TSFE']->MP
307
        );
308
309 25
        $search = GeneralUtility::makeInstance('ApacheSolrForTypo3\\Solr\\Search', $solrConnection);
310
        /** @var $this->searchService ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\SearchResultSetService */
311 25
        $this->searchResultsSetService = GeneralUtility::makeInstance('ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\SearchResultSetService', $this->typoScriptConfiguration, $search, $this);
312 25
        $this->solrAvailable = $this->searchResultsSetService->getIsSolrAvailable();
0 ignored issues
show
Bug introduced by
The property solrAvailable does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
313 25
        $this->search = $this->searchResultsSetService->getSearch();
0 ignored issues
show
Bug introduced by
The property search does not seem to exist. Did you mean searchResultsSetService?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
314 25
    }
315
316
    /**
317
     * @return SearchResultSetService
318
     */
319 25
    public function getSearchResultSetService()
320
    {
321 25
        return $this->searchResultsSetService;
322
    }
323
324
    /**
325
     * Initializes the template engine and returns the initialized instance.
326
     *
327
     * @throws \UnexpectedValueException if a view helper provider fails to implement interface ApacheSolrForTypo3\Solr\ViewHelper\ViewHelperProvider
328
     */
329 25
    protected function initializeTemplateEngine()
330
    {
331 25
        $templateFile = $this->getTemplateFile();
332 25
        $subPart = $this->getSubpart();
333
334 25
        $flexformTemplateFile = $this->pi_getFFvalue(
335 25
            $this->cObj->data['pi_flexform'],
336 25
            'templateFile',
337 25
            'sOptions'
338
        );
339 25
        if (!empty($flexformTemplateFile)) {
340
            $templateFile = $flexformTemplateFile;
341
        }
342
343
        /** @var Template $template */
344 25
        $template = GeneralUtility::makeInstance(
345 25
            'ApacheSolrForTypo3\\Solr\\Template',
346 25
            $this->cObj,
347
            $templateFile,
348
            $subPart
349
        );
350 25
        $template->addViewHelperIncludePath($this->extKey,
351 25
            'Classes/ViewHelper/');
352 25
        $template->addViewHelper('LLL', array(
353 25
            'languageFile' => 'EXT:solr/Resources/Private/Language/locallang.xlf',
354 25
            'llKey' => $this->LLkey
355
        ));
356
357
        // can be used for view helpers that need configuration during initialization
358 25
        if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr'][$this->getPluginKey()]['addViewHelpers'])) {
359
            foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr'][$this->getPluginKey()]['addViewHelpers'] as $classReference) {
360
                $viewHelperProvider = &GeneralUtility::getUserObj($classReference);
361
362
                if ($viewHelperProvider instanceof ViewHelperProvider) {
363
                    $viewHelpers = $viewHelperProvider->getViewHelpers();
364
                    foreach ($viewHelpers as $helperName => $helperObject) {
365
                        // TODO check whether $helperAdded is TRUE, throw an exception if not
366
                        $helperAdded = $template->addViewHelperObject($helperName,
0 ignored issues
show
Unused Code introduced by
$helperAdded is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
367
                            $helperObject);
368
                    }
369
                } else {
370
                    throw new \UnexpectedValueException(
371
                        get_class($viewHelperProvider) . ' must implement interface ApacheSolrForTypo3\Solr\ViewHelper\ViewHelperProvider',
372
                        1310387296
373
                    );
374
                }
375
            }
376
        }
377
378 25
        $template = $this->postInitializeTemplateEngine($template);
379
380 25
        $this->template = $template;
381 25
    }
382
383
    /**
384
     * Initializes the javascript manager.
385
     *
386
     */
387 25
    protected function initializeJavascriptManager()
388
    {
389 25
        $this->javascriptManager = GeneralUtility::makeInstance('ApacheSolrForTypo3\\Solr\\JavascriptManager');
390 25
    }
391
392
    /**
393
     * Initializes the language factory;
394
     */
395 25
    protected function initializeLanguageFactory()
396
    {
397 25
        $this->languageFactory = GeneralUtility::makeInstance('TYPO3\CMS\Core\Localization\LocalizationFactory');
398 25
    }
399
400
    /**
401
     * This method is called after initializing in the initialize method.
402
     * Overwrite this method to do your own initialization.
403
     *
404
     * @return void
405
     */
406 3
    protected function postInitialize()
407
    {
408 3
    }
409
410
    /**
411
     * Overwrite this method to do own initialisations  of the template.
412
     *
413
     * @param Template $template Template
414
     * @return Template
415
     */
416
    protected function postInitializeTemplateEngine(Template $template)
417
    {
418
        return $template;
419
    }
420
421
    // Rendering
422
423
    /**
424
     * This method executes the requested commands and applies the changes to
425
     * the template.
426
     *
427
     * @param $actionResult
428
     * @return string Rendered plugin content
429
     */
430
    abstract protected function render($actionResult);
431
432
    /**
433
     * Renders a solr error.
434
     *
435
     * @return string A representation of the error that should be understandable for the user.
436
     */
437
    protected function renderError()
438
    {
439
        $this->template->workOnSubpart('solr_search_unavailable');
440
441
        return $this->template->render();
442
    }
443
444
    /**
445
     * Renders a solr exception.
446
     *
447
     * @return string A representation of the exception that should be understandable for the user.
448
     */
449
    protected function renderException()
450
    {
451
        $this->template->workOnSubpart('solr_search_error');
452
453
        return $this->template->render();
454
    }
455
456
    /**
457
     * Should be overwritten to do things before rendering.
458
     *
459
     */
460 2
    protected function preRender()
461
    {
462 2
    }
463
464
    /**
465
     * Overwrite this method to perform changes to the content after rendering.
466
     *
467
     * @param string $content The content rendered by the plugin so far
468
     * @return string The content that should be presented on the website, might be different from the output rendered before
469
     */
470 25
    protected function postRender($content)
471
    {
472 25
        if (isset($this->conf['stdWrap.'])) {
473
            $content = $this->cObj->stdWrap($content, $this->conf['stdWrap.']);
474
        }
475
476 25
        return $content;
477
    }
478
479
    // Helper methods
480
481
    /**
482
     * Determines the template file from the configuration.
483
     *
484
     * Overwrite this method to use a different template.
485
     *
486
     * @return string The template file name to be used for the plugin
487
     */
488 25
    protected function getTemplateFile()
489
    {
490 25
        return $this->typoScriptConfiguration->getTemplateByFileKey($this->getTemplateFileKey());
491
    }
492
493
    /**
494
     * This method should be implemented to return the TSconfig key which
495
     * contains the template name for this template.
496
     *
497
     * @see initializeTemplateEngine()
498
     * @return string The TSconfig key containing the template name
499
     */
500
    abstract protected function getTemplateFileKey();
501
502
    /**
503
     * Gets the plugin's template instance.
504
     *
505
     * @return Template The plugin's template.
506
     */
507 25
    public function getTemplate()
508
    {
509 25
        return $this->template;
510
    }
511
512
    /**
513
     * Gets the plugin's javascript manager.
514
     *
515
     * @return JavascriptManager The plugin's javascript manager.
516
     */
517 25
    public function getJavascriptManager()
518
    {
519 25
        return $this->javascriptManager;
520
    }
521
522
    /**
523
     * Should return the relevant subpart of the template.
524
     *
525
     * @see initializeTemplateEngine()
526
     * @return string The subpart of the template to be used
527
     */
528
    abstract protected function getSubpart();
529
530
    /**
531
     * This method should return the plugin key. Reads some configuration
532
     * options in initializeTemplateEngine()
533
     *
534
     * @see initializeTemplateEngine()
535
     * @return string The plugin key
536
     */
537
    abstract protected function getPluginKey();
538
539
    /**
540
     * Gets the target page Id for links. Might have been set through either
541
     * flexform or TypoScript. If none is set, TSFE->id is used.
542
     *
543
     * @return int The page Id to be used for links
544
     */
545 18
    public function getLinkTargetPageId()
546
    {
547 18
        return $this->typoScriptConfiguration->getSearchTargetPage();
548
    }
549
550
    /**
551
     * Gets the user's query term and cleans it so that it can be used in
552
     * templates f.e.
553
     *
554
     * @return string The cleaned user query.
555
     */
556 25
    public function getCleanUserQuery()
557
    {
558 25
        $userQuery = $this->getRawUserQuery();
559
560 25
        if (!is_null($userQuery)) {
561 21
            $userQuery = Query::cleanKeywords($userQuery);
562
        }
563
564
        // escape triple hashes as they are used in the template engine
565
        // TODO remove after switching to fluid templates
566 25
        $userQuery = Template::escapeMarkers($userQuery);
567
568 25
        return $userQuery;
569
    }
570
571
    /**
572
     * Gets the raw user query
573
     *
574
     * @return string Raw user query.
575
     */
576 25
    public function getRawUserQuery()
577
    {
578 25
        return $this->rawUserQuery;
579
    }
580
581
    /**
582
     * @return string
583
     */
584 25
    protected function getCurrentUrlWithQueryLinkBuilder()
585
    {
586 25
        $currentUrl = $this->pi_linkTP_keepPIvars_url();
587 25
        $resultService = $this->getSearchResultSetService();
588
589 25
        if (!$resultService instanceof SearchResultSetService) {
590
            return $currentUrl;
591
        }
592
593 25
        if ($resultService->getIsSolrAvailable() && $this->getSearchResultSetService()->getHasSearched()) {
594 4
            $queryLinkBuilder = GeneralUtility::makeInstance('ApacheSolrForTypo3\\Solr\\Query\\LinkBuilder', $this->getSearchResultSetService()->getSearch()->getQuery());
595 4
            $currentUrl = $queryLinkBuilder->getQueryUrl();
596 4
            return $currentUrl;
597
        }
598 25
        return $currentUrl;
599
    }
600
}
601