Advertisement
Guest User

Untitled

a guest
Sep 5th, 2012
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.90 KB | None | 0 0
  1. <?php
  2.  
  3. $input = "one two three";
  4. print "$input => ".expand_to_sphinx_query($input)."\n\n";
  5.  
  6. $input = "one two three four";
  7. print "$input => ".expand_to_sphinx_query($input)."\n\n";
  8.  
  9. $input = "one two";
  10. print "$input => ".expand_to_sphinx_query($input)."\n\n";
  11.  
  12. $input = "one";
  13. print "$input => ".expand_to_sphinx_query($input)."\n\n";
  14.  
  15.  
  16. function expand_to_sphinx_query($input) {
  17.         $words = explode(" ",$input);
  18.  
  19.         if (count($words) < 2) {
  20.                 return $input;
  21.         }
  22.  
  23.         $bits = array();
  24.  
  25.         for($q=0;$q<count($words)-1;$q++) {
  26.                 $new = $words[$q].' '.$words[$q+1];
  27.                 $bits[] = "\"$new\"~2";
  28.                 $bits[] = "\"$new\"~50";
  29.                 $bits[] = "\"$new\"";
  30.         }
  31.  
  32.         if (count($words) > 2)
  33.                 $bits[] = "\"$input\"";
  34.         $bits[] = "($input)";
  35.  
  36.         return implode(' | ',$bits);
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement