1 | <?php declare(strict_types = 1); |
||
35 | class StatisticsRepository extends AbstractRepository |
||
36 | { |
||
37 | /** |
||
38 | * @var string |
||
39 | */ |
||
40 | protected $table = 'tx_solr_statistics'; |
||
41 | |||
42 | /** |
||
43 | * Fetches must popular search keys words from the table tx_solr_statistics |
||
44 | * |
||
45 | * @param int $rootPageId |
||
46 | * @param int $days number of days of history to query |
||
47 | * @param int $limit |
||
48 | * @return mixed |
||
49 | */ |
||
50 | 1 | public function getSearchStatistics(int $rootPageId, int $days = 30, $limit = 10) |
|
51 | { |
||
52 | 1 | $now = time(); |
|
53 | 1 | $timeStart = (int)($now - 86400 * $days); // 86400 seconds/day |
|
54 | 1 | $limit = (int)$limit; |
|
55 | |||
56 | 1 | return $this->getPreparedQueryBuilderForSearchStatisticsAndTopKeywords($rootPageId, $timeStart, $limit) |
|
57 | 1 | ->execute()->fetchAll(); |
|
58 | } |
||
59 | |||
60 | /** |
||
61 | * Returns prepared QueryBuilder for two purposes: |
||
62 | * for getSearchStatistics() and getTopKeyWordsWithOrWithoutHits() methods |
||
63 | * |
||
64 | * @param int $rootPageId |
||
65 | * @param int $timeStart |
||
66 | * @param int $limit |
||
67 | * @return QueryBuilder |
||
68 | */ |
||
69 | 4 | protected function getPreparedQueryBuilderForSearchStatisticsAndTopKeywords(int $rootPageId, int $timeStart, int $limit) : QueryBuilder |
|
91 | |||
92 | /** |
||
93 | * Find Top search keywords with results |
||
94 | * |
||
95 | * @param int $rootPageId |
||
96 | * @param int $days number of days of history to query |
||
97 | * @param int $limit |
||
98 | * @return array |
||
99 | */ |
||
100 | 1 | public function getTopKeyWordsWithHits(int $rootPageId, int $days = 30, int $limit = 10) : array |
|
104 | |||
105 | /** |
||
106 | * Find Top search keywords without results |
||
107 | * |
||
108 | * @param int $rootPageId |
||
109 | * @param int $days number of days of history to query |
||
110 | * @param int $limit |
||
111 | * @return array |
||
112 | */ |
||
113 | 2 | public function getTopKeyWordsWithoutHits(int $rootPageId, int $days = 30, int $limit = 10) : array |
|
117 | |||
118 | /** |
||
119 | * Find Top search keywords with or without results |
||
120 | * |
||
121 | * @param int $rootPageId |
||
122 | * @param int $days number of days of history to query |
||
123 | * @param int $limit |
||
124 | * @param bool $withoutHits |
||
125 | * @return array |
||
126 | */ |
||
127 | 3 | protected function getTopKeyWordsWithOrWithoutHits(int $rootPageId, int $days = 30, int $limit = 10, bool $withoutHits = false) : array |
|
142 | |||
143 | /** |
||
144 | * Get number of queries over time |
||
145 | * |
||
146 | * @param int $rootPageId |
||
147 | * @param int $days number of days of history to query |
||
148 | * @param int $bucketSeconds Seconds per bucket |
||
149 | * @return array [labels, data] |
||
150 | */ |
||
151 | public function getQueriesOverTime(int $rootPageId, int $days = 30, int $bucketSeconds = 3600) : array |
||
174 | |||
175 | /** |
||
176 | * Regurns a result set by given plugin.tx_solr.search.frequentSearches.select configuration. |
||
177 | * |
||
178 | * @param array $frequentSearchConfiguration |
||
179 | * @return array Array of frequent search terms, keys are the terms, values are hits |
||
180 | */ |
||
181 | 29 | public function getFrequentSearchTermsFromStatisticsByFrequentSearchConfiguration(array $frequentSearchConfiguration) : array |
|
197 | |||
198 | /** |
||
199 | * Persists statistics record |
||
200 | * |
||
201 | * @param array $statisticsRecord |
||
202 | * @return void |
||
203 | */ |
||
204 | 24 | public function saveStatisticsRecord(array $statisticsRecord) |
|
209 | |||
210 | /** |
||
211 | * Counts rows for specified site |
||
212 | * |
||
213 | * @param int $rootPageId |
||
214 | * @return int |
||
215 | */ |
||
216 | 5 | public function countByRootPageId(int $rootPageId): int |
|
225 | } |
||
226 |