<commit_before><?php
// src/Blogger/BlogBundle/Entity/Repository/BlogRepository.php

namespace Blogger\BlogBundle\Entity\Repository;

use Doctrine\ORM\EntityRepository;

/**
 * BlogRepository
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */
class BlogRepository extends EntityRepository
{
	public function getLatestBlogs($limit = null)
	{
		$qb = $this->createQueryBuilder('b')
		           ->select('b')
		           ->addOrderBy('b.created', 'DESC');

		if (false === is_null($limit)) {
			$qb->setMaxResults($limit);
		}

		return $qb->getQuery()
		          ->getResult();
	}<commit_msg>Added join to reduce SQL queries Added methods for tags<commit_after><?php
// src/Blogger/BlogBundle/Entity/Repository/BlogRepository.php

namespace Blogger\BlogBundle\Entity\Repository;

use Doctrine\ORM\EntityRepository;

/**
 * BlogRepository
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */
class BlogRepository extends EntityRepository
{
    public function getLatestBlogs($limit = null)
    {
        $qb = $this->createQueryBuilder('b')
                   ->select('b', 'c')
                   ->leftJoin('b.comments', 'c')
                   ->addOrderBy('b.created', 'DESC');

        if (false === is_null($limit)) {
            $qb->setMaxResults($limit);
        }

        return $qb->getQuery()
                  ->getResult();
    }

    public function getTags()
    {
        $blogTags = $this->createQueryBuilder('b')
                         ->select('b.tags')
                         ->getQuery()
                         ->getResult();

        $tags = array();
        foreach ($blogTags as $blogTag) {
            $tags = array_merge(explode(",", $blogTag['tags']), $tags);
        }
        foreach ($tags as $tag) {
            $tag = trim($tag);
        }

        return $tags;
    }

    public function getTagWeights($tags)
    {
        $tagWeights = array();
        if (empty($tags)) {
            return $tagWeights;
        }

        foreach ($tags as $tag) {
            $tagWeights[$tag] = (isset($tagWeights[$tag])) ? $tagWeights[$tag] + 1 : 1;
        }

        uksort($tagWeights, function() {
            return rand() > rand();
        });

        $max = max($tagWeights);

        $multiplier = ($max > 5) ? 5 / $max : 1;
        foreach ($tagWeights as $tag) {
            $tag = ceil($tag * $multiplier);
        }

        return $tagWeights;
    }
{'fraction_non_alphanumeric': 0.1444, 'fraction_numerical': 0.002, 'mean_word_length': 2.064950980392157, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6741601', 'n_tokens_mistral': 762, 'n_tokens_neox': 719, 'n_words': 162}