protected function SearchApiStatsBlock::getStats in Search API Stats 8
Retrieve keywords, num values from database.
Return value
array An array of the stats retrieved.
1 call to SearchApiStatsBlock::getStats()
- SearchApiStatsBlock::build in modules/
search_api_stats_block/ src/ Plugin/ Block/ SearchApiStatsBlock.php - Builds and returns the renderable array for this block plugin.
File
- modules/
search_api_stats_block/ src/ Plugin/ Block/ SearchApiStatsBlock.php, line 92
Class
- SearchApiStatsBlock
- Provides a 'SearchApiStatsBlock' block.
Namespace
Drupal\search_api_stats_block\Plugin\BlockCode
protected function getStats() {
$result = [];
$database = Database::getConnection();
$config = $this
->getConfiguration();
$serverName = $this
->getServer();
$indexName = $this
->getDerivativeId();
$stats = $database
->queryRange("SELECT keywords, COUNT(*) as num FROM search_api_stats WHERE s_name = :s_name AND i_name=:i_name AND keywords != '' GROUP BY `keywords` ORDER BY num DESC", 0, $config['num_phrases'], [
':s_name' => $serverName,
':i_name' => $indexName,
]);
foreach ($stats as $stat) {
$result[$stat->keywords] = $stat->num;
}
return $result;
}