<?php
$input = "one two three";
print "$input => ".expand_to_sphinx_query($input)."\n\n";
$input = "one two three four";
print "$input => ".expand_to_sphinx_query($input)."\n\n";
$input = "one two";
print "$input => ".expand_to_sphinx_query($input)."\n\n";
$input = "one";
print "$input => ".expand_to_sphinx_query($input)."\n\n";
function expand_to_sphinx_query($input) {
$words = explode(" ",$input);
if (count($words) < 2) {
return $input;
}
$bits = array();
for($q=0;$q<count($words)-1;$q++) {
$new = $words[$q].' '.$words[$q+1];
$bits[] = "\"$new\"~2";
$bits[] = "\"$new\"~50";
$bits[] = "\"$new\"";
}
if (count($words) > 2)
$bits[] = "\"$input\"";
$bits[] = "($input)";
return implode(' | ',$bits);
}