protected function buildCase(Column $column, array $words)
    {
        // THIS IS BAD
        // @todo refactor

        $operator = $this->getLikeOperator();

        $bindings['select'] = $bindings['where'] = array_map(function ($word) {
            return $this->caseBinding($word);
        }, $words);

        $case = $this->buildEqualsCase($column, $words);

        if (strpos(implode('', $words), '*') !== false) {
            $leftMatching = [];

            foreach ($words as $key => $word) {
                if ($this->isLeftMatching($word)) {
                    $leftMatching[] = sprintf('%s %s ?', $column->getWrapped(), $operator);
                    $bindings['select'][] = $bindings['where'][$key] = $this->caseBinding($word) . '%';
                }
            }

            if (count($leftMatching)) {
                $leftMatching = implode(' or ', $leftMatching);
                $score = 5 * $column->getWeight();
                $case .= " + case when {$leftMatching} then {$score} else 0 end";
            }

            $wildcards = [];

            foreach ($words as $key => $word) {
                if ($this->isWildcard($word)) {
                    $wildcards[] = sprintf('%s %s ?', $column->getWrapped(), $operator);
                    $bindings['select'][] = $bindings['where'][$key] = '%'.$this->caseBinding($word) . '%';
                }
            }

            if (count($wildcards)) {
                $wildcards = implode(' or ', $wildcards);
                $score = 1 * $column->getWeight();
                $case .= " + case when {$wildcards} then {$score} else 0 end";
            }
        }

        return [$case, $bindings];
    }
protected function buildCase(Column $column, array $words)
    {
        // THIS IS BAD
        // @todo refactor

        $operator = $this->getLikeOperator();

        $bindings['select'] = $bindings['where'] = array_map(function ($word) {
            return $this->caseBinding($word);
        }, $words);

        $case = $this->buildEqualsCase($column, $words);

        if (strpos(implode('', $words), '*') !== false) {
            $leftMatching = [];

            foreach ($words as $key => $word) {
                if ($this->isLeftMatching($word)) {
                    $leftMatching[] = sprintf('%s %s ?', $column->getWrapped(), $operator);
                    $bindings['select'][] = $bindings['where'][$key] = $this->caseBinding($word) . '%';
                }
            }

            if (count($leftMatching)) {
                $leftMatching = implode(' or ', $leftMatching);
                $score = 5 * $column->getWeight();
                $case .= " + case when {$leftMatching} then {$score} else 0 end";
            }

            $wildcards = [];

            foreach ($words as $key => $word) {
                if ($this->isWildcard($word)) {
                    $wildcards[] = sprintf('%s %s ?', $column->getWrapped(), $operator);
                    $bindings['select'][] = $bindings['where'][$key] = '%'.$this->caseBinding($word) . '%';
                }
            }

            if (count($wildcards)) {
                $wildcards = implode(' or ', $wildcards);
                $score = 1 * $column->getWeight();
                $case .= " + case when {$wildcards} then {$score} else 0 end";
            }
        }

        return [$case, $bindings];
    }
protected function buildCase ( Column $ column , array $ words ) { // THIS IS BAD // @todo refactor $ operator = $ this -> getLikeOperator ( ) ; $ bindings [ 'select' ] = $ bindings [ 'where' ] = array_map ( function ( $ word ) { return $ this -> caseBinding ( $ word ) ; } , $ words ) ; $ case = $ this -> buildEqualsCase ( $ column , $ words ) ; if ( strpos ( implode ( '' , $ words ) , '*' ) !== false ) { $ leftMatching = [ ] ; foreach ( $ words as $ key => $ word ) { if ( $ this -> isLeftMatching ( $ word ) ) { $ leftMatching [ ] = sprintf ( '%s %s ?' , $ column -> getWrapped ( ) , $ operator ) ; $ bindings [ 'select' ] [ ] = $ bindings [ 'where' ] [ $ key ] = $ this -> caseBinding ( $ word ) . '%' ; } } if ( count ( $ leftMatching ) ) { $ leftMatching = implode ( ' or ' , $ leftMatching ) ; $ score = 5 * $ column -> getWeight ( ) ; $ case .= " + case when {$leftMatching} then {$score} else 0 end" ; } $ wildcards = [ ] ; foreach ( $ words as $ key => $ word ) { if ( $ this -> isWildcard ( $ word ) ) { $ wildcards [ ] = sprintf ( '%s %s ?' , $ column -> getWrapped ( ) , $ operator ) ; $ bindings [ 'select' ] [ ] = $ bindings [ 'where' ] [ $ key ] = '%' . $ this -> caseBinding ( $ word ) . '%' ; } } if ( count ( $ wildcards ) ) { $ wildcards = implode ( ' or ' , $ wildcards ) ; $ score = 1 * $ column -> getWeight ( ) ; $ case .= " + case when {$wildcards} then {$score} else 0 end" ; } } return [ $ case , $ bindings ] ; }
Build case clause from all words for a single column.

@param  \Sofa\Eloquence\Searchable\Column $column
@param  array  $words
@return array
Build case clause from all words for a single column .