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 | 1 | * Fetches must popular search keys words from the table tx_solr_statistics |
|
44 | * |
||
45 | 1 | * @param int $rootPageId |
|
46 | 1 | * @param int $days number of days of history to query |
|
47 | 1 | * @param int $limit |
|
48 | 1 | * @return mixed |
|
49 | */ |
||
50 | 1 | public function getSearchStatistics(int $rootPageId, int $days = 30, $limit = 10) |
|
73 | |||
74 | /** |
||
75 | * Returns prepared QueryBuilder for two purposes: |
||
76 | * for getSearchStatistics() and getTopKeyWordsWithOrWithoutHits() methods |
||
77 | * |
||
78 | * @param int $rootPageId |
||
79 | * @param int $timeStart |
||
80 | * @param int $limit |
||
81 | * @return QueryBuilder |
||
82 | 1 | */ |
|
83 | protected function getPreparedQueryBuilderForSearchStatisticsAndTopKeywords(int $rootPageId, int $timeStart, int $limit) : QueryBuilder |
||
102 | |||
103 | /** |
||
104 | * Find Top search keywords with results |
||
105 | * |
||
106 | * @param int $rootPageId |
||
107 | * @param int $days number of days of history to query |
||
108 | * @param int $limit |
||
109 | 3 | * @return array |
|
110 | */ |
||
111 | 3 | public function getTopKeyWordsWithHits(int $rootPageId, int $days = 30, int $limit = 10) : array |
|
115 | 3 | ||
116 | 3 | /** |
|
117 | * Find Top search keywords without results |
||
118 | * |
||
119 | 3 | * @param int $rootPageId |
|
120 | 2 | * @param int $days number of days of history to query |
|
121 | * @param int $limit |
||
122 | 1 | * @return array |
|
123 | */ |
||
124 | public function getTopKeyWordsWithoutHits(int $rootPageId, int $days = 30, int $limit = 10) : array |
||
128 | 3 | ||
129 | 3 | /** |
|
130 | 3 | * Find Top search keywords with or without results |
|
131 | * |
||
132 | * @param int $rootPageId |
||
133 | * @param int $days number of days of history to query |
||
134 | 3 | * @param int $limit |
|
135 | * @param bool $withoutHits |
||
136 | 3 | * @return array |
|
137 | */ |
||
138 | protected function getTopKeyWordsWithOrWithoutHits(int $rootPageId, int $days = 30, int $limit = 10, bool $withoutHits = false) : array |
||
156 | 2 | ||
157 | 2 | /** |
|
158 | * This method groups rows with the same term and different count and hits |
||
159 | * and calculates the average. |
||
160 | 2 | * |
|
161 | * @param array $statisticsRows |
||
162 | 2 | * @return array |
|
163 | 2 | */ |
|
164 | protected function mergeRowsWithSameKeyword(array $statisticsRows) : array |
||
186 | |||
187 | /** |
||
188 | * Get number of queries over time |
||
189 | * |
||
190 | * @param int $rootPageId |
||
191 | * @param int $days number of days of history to query |
||
192 | * @param int $bucketSeconds Seconds per bucket |
||
193 | * @return array [labels, data] |
||
194 | */ |
||
195 | public function getQueriesOverTime(int $rootPageId, int $days = 30, int $bucketSeconds = 3600) : array |
||
219 | 4 | ||
220 | /** |
||
221 | 4 | * Regurns a result set by given plugin.tx_solr.search.frequentSearches.select configuration. |
|
222 | * |
||
223 | * @param array $frequentSearchConfiguration |
||
224 | * @return array Array of frequent search terms, keys are the terms, values are hits |
||
225 | */ |
||
226 | public function getFrequentSearchTermsFromStatisticsByFrequentSearchConfiguration(array $frequentSearchConfiguration) : array |
||
242 | |||
243 | /** |
||
244 | * This method is used to get an average value from merged statistic rows. |
||
245 | * |
||
246 | * @param array $mergedRow |
||
247 | * @param array $statisticsRow |
||
248 | * @param string $fieldName |
||
249 | * @return float|int |
||
250 | */ |
||
251 | protected function getAverageFromField(array &$mergedRow, array $statisticsRow, string $fieldName) |
||
265 | |||
266 | /** |
||
267 | * Persists statistics record |
||
268 | * |
||
269 | * @param array $statisticsRecord |
||
270 | * @return void |
||
271 | */ |
||
272 | public function saveStatisticsRecord(array $statisticsRecord) |
||
277 | |||
278 | /** |
||
279 | * Counts rows for specified site |
||
280 | * |
||
281 | * @param int $rootPageId |
||
282 | * @return int |
||
283 | */ |
||
284 | public function countByRootPageId(int $rootPageId): int |
||
293 | } |
||
294 |