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 | public function getSearchStatistics(int $rootPageId, int $days = 30, $limit = 10) |
||
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 | 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 | 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 | 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 | 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 |
||
175 | |||
176 | /** |
||
177 | * Regurns a result set by given plugin.tx_solr.search.frequentSearches.select configuration. |
||
178 | * |
||
179 | * @param array $frequentSearchConfiguration |
||
180 | * @return array Array of frequent search terms, keys are the terms, values are hits |
||
181 | */ |
||
182 | public function getFrequentSearchTermsFromStatisticsByFrequentSearchConfiguration(array $frequentSearchConfiguration) : array |
||
198 | |||
199 | /** |
||
200 | * Counts rows for specified site |
||
201 | * |
||
202 | * @param int $rootPageId sites root page id |
||
203 | * @return int |
||
204 | */ |
||
205 | public function countByRootPageId(int $rootPageId) : int |
||
206 | { |
||
207 | $queryBuilder = $this->getQueryBuilder(); |
||
208 | $numberRows = $this->getQueryBuilder() |
||
209 | ->count('*') |
||
210 | ->from($this->table) |
||
211 | ->andWhere($queryBuilder->expr()->eq('root_pid', $rootPageId)) |
||
212 | ->execute()->fetchColumn(0); |
||
213 | |||
214 | return (int)$numberRows; |
||
215 | } |
||
216 | |||
217 | /** |
||
218 | * Persists statistics record |
||
219 | * |
||
220 | * @param array $statisticsRecord |
||
221 | * @return void |
||
222 | */ |
||
223 | public function saveStatisticsRecord(array $statisticsRecord) |
||
224 | { |
||
225 | $queryBuilder = $this->getQueryBuilder(); |
||
226 | $queryBuilder->insert($this->table)->values($statisticsRecord)->execute(); |
||
227 | } |
||
228 | |||
229 | /** |
||
230 | * Counts rows for specified site |
||
231 | * |
||
232 | * @param int $rootPageId |
||
233 | * @return int |
||
234 | */ |
||
235 | public function countByRootPageId(int $rootPageId): int |
||
244 | } |
||
245 |