<commit_before><?php namespace Nicolaslopezj\Searchable;

use Illuminate\Database\Query\Expression;

/**
 * Trait SearchableTrait
 * @package Nicolaslopezj\Searchable
 */
trait SearchableTrait
{

    /**
     * Makes the search process
     * @param $query
     * @param $search
     * @return mixed
     */
    public function scopeSearch($query, $search) {

        if (!$search) {
            return $query;
        }

        $relevance_count = 0;
        $words = explode(' ', $search);

        $selects = [];
        foreach ($this->getColumns() as $column => $relevance) {
            $relevance_count += $relevance;
            $queries = $this->getSearchQueriesForColumn($column, $relevance, $words);
            foreach ($queries as $select) {
                $selects[] = $select;
            }
        }

        $this->addSelectsToQuery($query, $selects);
        $this->filterQueryWithRelevace($query, ($relevance_count / 4));

        $this->makeJoins($query);

        return $query;
    }

    /**
     * Returns the search columns
     * @return array
     */
    protected function getColumns() {
        return $this->searchable['columns'];
    }

    /**
     * Returns the tables that has to join
     * @return array
     */
    protected function getJoins() {
        return $this->searchable['joins'];
    }

    /**
     * Adds the join sql to the query
     * @param $query
     */
    protected function makeJoins(&$query) {
        foreach ($this->getJoins() as $table => $keys) {
            $query->join($table, $keys[0], '=', $keys[1]);
        }
    }
<commit_msg>Change join to left join<commit_after><?php namespace Nicolaslopezj\Searchable;

use Illuminate\Database\Query\Expression;

/**
 * Trait SearchableTrait
 * @package Nicolaslopezj\Searchable
 */
trait SearchableTrait
{

    /**
     * Makes the search process
     * @param $query
     * @param $search
     * @return mixed
     */
    public function scopeSearch($query, $search) {

        if (!$search) {
            return $query;
        }

        $relevance_count = 0;
        $words = explode(' ', $search);

        $selects = [];
        foreach ($this->getColumns() as $column => $relevance) {
            $relevance_count += $relevance;
            $queries = $this->getSearchQueriesForColumn($column, $relevance, $words);
            foreach ($queries as $select) {
                $selects[] = $select;
            }
        }

        $this->addSelectsToQuery($query, $selects);
        $this->filterQueryWithRelevace($query, ($relevance_count / 4));

        $this->makeJoins($query);

        return $query;
    }

    /**
     * Returns the search columns
     * @return array
     */
    protected function getColumns() {
        return $this->searchable['columns'];
    }

    /**
     * Returns the tables that has to join
     * @return array
     */
    protected function getJoins() {
        return $this->searchable['joins'];
    }

    /**
     * Adds the join sql to the query
     * @param $query
     */
    protected function makeJoins(&$query) {
        foreach ($this->getJoins() as $table => $keys) {
            $query->leftJoin($table, $keys[0], '=', $keys[1]);
        }
    }

{'fraction_non_alphanumeric': 0.14138897539707257, 'fraction_numerical': 0.002491435689816257, 'mean_word_length': 2.061963775023832, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, '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': '4507205', 'n_tokens_mistral': 974, 'n_tokens_neox': 939, 'n_words': 214}