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;
}