|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ApacheSolrForTypo3\Solr\Domain\Search\LastSearches; |
|
4
|
|
|
|
|
5
|
|
|
/*************************************************************** |
|
6
|
|
|
* Copyright notice |
|
7
|
|
|
* |
|
8
|
|
|
* (c) 2017 Timo Hund <[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\LastSearches\LastSearchesService; |
|
29
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\SearchResultSet; |
|
30
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Search\ResultSet\SearchResultSetProcessor; |
|
31
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Writes the last searches |
|
35
|
|
|
* |
|
36
|
|
|
* @author Timo Hund <[email protected]> |
|
37
|
|
|
*/ |
|
38
|
|
|
class LastSearchesWriterProcessor implements SearchResultSetProcessor |
|
39
|
|
|
{ |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @param SearchResultSet $resultSet |
|
43
|
|
|
* @return SearchResultSet |
|
44
|
|
|
*/ |
|
45
|
26 |
|
public function process(SearchResultSet $resultSet) { |
|
46
|
|
|
|
|
47
|
26 |
|
if ($resultSet->getAllResultCount() === 0) { |
|
48
|
|
|
// when the search does not produce a result we do not store the last searches |
|
49
|
5 |
|
return $resultSet; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
21 |
|
if (!isset($GLOBALS['TSFE'])) { |
|
53
|
|
|
return $resultSet; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
21 |
|
$query = $resultSet->getUsedSearchRequest()->getRawUserQuery(); |
|
57
|
|
|
|
|
58
|
21 |
|
if (is_string($query)) { |
|
59
|
19 |
|
$lastSearchesService = $this->getLastSearchesService($resultSet); |
|
60
|
19 |
|
$lastSearchesService->addToLastSearches($query); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
21 |
|
return $resultSet; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @param SearchResultSet $resultSet |
|
68
|
|
|
* @return LastSearchesService |
|
69
|
|
|
*/ |
|
70
|
19 |
|
protected function getLastSearchesService(SearchResultSet $resultSet) { |
|
71
|
19 |
|
return GeneralUtility::makeInstance(LastSearchesService::class, |
|
72
|
19 |
|
$resultSet->getUsedSearchRequest()->getContextTypoScriptConfiguration()); |
|
73
|
19 |
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|