Frontend\Modules\Search\Engine\Model::buildTerm PHP Method

buildTerm() public static method

Build the search term
public static buildTerm ( array $terms ) : array
$terms array The string to build.
return array
    public static function buildTerm($terms)
    {
        // loop all items
        foreach ($terms as $i => $term) {
            // trim terms
            $term = trim($term);
            // last word may be incomplete (still typing)
            $split = explode(' ', $term);
            $last = (string) array_pop($split);
            $terms[$i] = ($split ? '+' . implode(' +', $split) . ' ' : '') . '(>+' . $last . ' <+' . $last . '*)';
            // current string encountered
            $terms[$i] = '>' . $terms[$i];
            if (mb_strpos($terms[$i], ' ') !== false) {
                // part of words encountered
                $terms[$i] .= ' <(' . implode(' ', $split) . ' ' . trim($last) . '*)';
            }
        }
        return $terms;
    }