public function loadByBlog(Blog $blog, $max = null)
    {
        $results = $this->getTagRepository()->findByBlog($blog, true, $max);
        $tags = [];

        if (0 < count($results)) {
            $maxWeight = intval($results[0]['frequency']);
            $resultsValues = array_values($results);
            $endResult = end($resultsValues);
            $minWeight = intval($endResult['frequency']);
            $diff = $maxWeight - $minWeight;

            foreach ($results as $result) {
                /** @var \Icap\BlogBundle\Entity\Tag $tag */
                $tag = $result[0];

                if ($diff > 10) {
                    $weight = round(((intval($result['frequency']) - $minWeight) / $diff) * 9 + 1);
                } else {
                    $weight = intval($result['frequency']) - $minWeight + 1;
                }

                $tagArray = [
                    'name' => $tag->getName(),
                    'slug' => $tag->getSlug(),
                    'weight' => $weight,
                    'countPosts' => intval($result['countPosts']),
                    'text' => $tag->getName(),
                    'id' => $tag->getId(),
                ];
                array_push($tags, $tagArray);
            }
        }

        return $tags;
    }