|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the TYPO3 CMS project. |
|
5
|
|
|
* |
|
6
|
|
|
* It is free software; you can redistribute it and/or modify it under |
|
7
|
|
|
* the terms of the GNU General Public License, either version 2 |
|
8
|
|
|
* of the License, or any later version. |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please read the |
|
11
|
|
|
* LICENSE.txt file that was distributed with this source code. |
|
12
|
|
|
* |
|
13
|
|
|
* The TYPO3 project - inspiring people to share! |
|
14
|
|
|
*/ |
|
15
|
|
|
|
|
16
|
|
|
namespace ApacheSolrForTypo3\Solr\Domain\Search\LastSearches; |
|
17
|
|
|
|
|
18
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\SearchResultSet; |
|
19
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\SearchResultSetProcessor; |
|
20
|
|
|
use Doctrine\DBAL\Driver\Exception as DBALDriverException; |
|
21
|
|
|
use Doctrine\DBAL\Exception as DBALException; |
|
22
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Writes the last searches |
|
26
|
|
|
* |
|
27
|
|
|
* @author Timo Hund <[email protected]> |
|
28
|
|
|
*/ |
|
29
|
|
|
class LastSearchesWriterProcessor implements SearchResultSetProcessor |
|
30
|
|
|
{ |
|
31
|
|
|
/** |
|
32
|
|
|
* @param SearchResultSet $resultSet |
|
33
|
|
|
* |
|
34
|
|
|
* @throws DBALDriverException |
|
35
|
|
|
* @throws DBALException|\Doctrine\DBAL\DBALException |
|
36
|
|
|
* @return SearchResultSet |
|
37
|
|
|
*/ |
|
38
|
2 |
|
public function process(SearchResultSet $resultSet): SearchResultSet |
|
39
|
|
|
{ |
|
40
|
2 |
|
if ($resultSet->getAllResultCount() === 0) { |
|
41
|
|
|
// when the search does not produce a result we do not store the last searches |
|
42
|
1 |
|
return $resultSet; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
1 |
|
if (!isset($GLOBALS['TSFE'])) { |
|
46
|
|
|
return $resultSet; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
1 |
|
$query = $resultSet->getUsedSearchRequest()->getRawUserQuery(); |
|
50
|
|
|
|
|
51
|
1 |
|
if (is_string($query)) { |
|
|
|
|
|
|
52
|
1 |
|
$lastSearchesService = $this->getLastSearchesService($resultSet); |
|
53
|
1 |
|
$lastSearchesService->addToLastSearches($query); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
1 |
|
return $resultSet; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @param SearchResultSet $resultSet |
|
61
|
|
|
* @return LastSearchesService |
|
62
|
|
|
*/ |
|
63
|
1 |
|
protected function getLastSearchesService(SearchResultSet $resultSet): LastSearchesService |
|
64
|
|
|
{ |
|
65
|
1 |
|
return GeneralUtility::makeInstance( |
|
66
|
|
|
LastSearchesService::class, |
|
67
|
|
|
/** @scrutinizer ignore-type */ |
|
68
|
1 |
|
$resultSet->getUsedSearchRequest()->getContextTypoScriptConfiguration() |
|
69
|
|
|
); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|