<commit_before><?php

namespace Coyote\Http\Controllers\Job;

use Coyote\Http\Controllers\Controller;
use Coyote\Repositories\Contracts\JobRepositoryInterface as JobRepository;
use Coyote\Repositories\Contracts\TagRepositoryInterface as TagRepository;
use Coyote\Services\Elasticsearch\Builders\Job\AdBuilder;
use Coyote\Services\Elasticsearch\Raw;
use Coyote\Services\Skills\Predictions;

class AdController extends Controller
{
    /**
     * @var JobRepository
     */
    private $job;

    /**
     * @var TagRepository
     */
    private $tag;

    /**
     * @param JobRepository $job
     * @param TagRepository $tag
     */
    public function __construct(JobRepository $job, TagRepository $tag)
    {
        debugbar()->disable();
        parent::__construct();

        $this->job = $job;
        $this->tag = $tag;

        $this->middleware('geocode');
    }

    /**
     * @param Predictions $predictions
     * @return string
     */
    public function index(Predictions $predictions)
    {
        $builder = new AdBuilder($this->request);
        $builder->boostLocation($this->request->attributes->get('geocode'));

        $data = [];
        $tags = $predictions->getTags();

        if (!empty($tags)) {
            $builder->boostTags($this->boost($tags));
        }

        $result = $this->job->search($builder);
        if (!$result->total()) {
            return '';
        }

        // search jobs that might be interesting for user
        return (string) view(
            'job.ad',
            $data,
            ['jobs' => $result->getSource(), 'inverse_tags' => $tags, 'major_tag' => $this->getMajorTag($tags)]
        );
    }

    /**
     * @param array $assoc
     * @return array
     */
    private function boost($assoc)
    {
        $result = [];

        foreach ($assoc as $tag) {
            if (!empty($tag)) {
                $result[] = sprintf('%s^%.1F', Raw::escape($tag), 1);
            }
        }

        return $result;
    }

    /**
     * @param array $tags
     * @return array|\Coyote\Tag
     */
    private function getMajorTag($tags)
    {
        if (empty($tags)) {
            return [];
        }

        return $this->tag->findBy('name', $tags[0]);
    }
}<commit_msg>wybieranie losowo elementu z tablicy<commit_after><?php

namespace Coyote\Http\Controllers\Job;

use Coyote\Http\Controllers\Controller;
use Coyote\Repositories\Contracts\JobRepositoryInterface as JobRepository;
use Coyote\Repositories\Contracts\TagRepositoryInterface as TagRepository;
use Coyote\Services\Elasticsearch\Builders\Job\AdBuilder;
use Coyote\Services\Elasticsearch\Raw;
use Coyote\Services\Skills\Predictions;

class AdController extends Controller
{
    /**
     * @var JobRepository
     */
    private $job;

    /**
     * @var TagRepository
     */
    private $tag;

    /**
     * @param JobRepository $job
     * @param TagRepository $tag
     */
    public function __construct(JobRepository $job, TagRepository $tag)
    {
        debugbar()->disable();
        parent::__construct();

        $this->job = $job;
        $this->tag = $tag;

        $this->middleware('geocode');
    }

    /**
     * @param Predictions $predictions
     * @return string
     */
    public function index(Predictions $predictions)
    {
        $builder = new AdBuilder($this->request);
        $builder->boostLocation($this->request->attributes->get('geocode'));

        $data = [];
        $tags = $predictions->getTags();

        if (!empty($tags)) {
            $builder->boostTags($this->boost($tags));
        }

        $result = $this->job->search($builder);
        if (!$result->total()) {
            return '';
        }

        // search jobs that might be interesting for user
        return (string) view(
            'job.ad',
            $data,
            ['jobs' => $result->getSource(), 'inverse_tags' => $tags, 'major_tag' => $this->getMajorTag($tags)]
        );
    }

    /**
     * @param array $assoc
     * @return array
     */
    private function boost($assoc)
    {
        $result = [];

        foreach ($assoc as $tag) {
            if (!empty($tag)) {
                $result[] = sprintf('%s^%.1F', Raw::escape($tag), 1);
            }
        }

        return $result;
    }

    /**
     * @param array $tags
     * @return array|\Coyote\Tag
     */
    private function getMajorTag($tags)
    {
        if (empty($tags)) {
            return [];
        }

        return $this->tag->findBy('name', $tags[array_rand($tags)]);
    }
}
{'fraction_non_alphanumeric': 0.15131433620499227, 'fraction_numerical': 0.001104484205875856, 'mean_word_length': 2.1034955448937627, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 47, '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': '3819888', 'n_tokens_mistral': 1367, 'n_tokens_neox': 1326, 'n_words': 260}