This probably isn't as detailed as you'd like - but I don't have a database to test on right here (and I'm too lazy to ssh to a machine where I do).
1) Take your string $query.
2) Might there be multiple consecutive spaces? Collapse them to single spaces: $query=preg_replace('/\s+/',' ',$query);
3) $query_array=explode($query);
And there's your array of words. Better yet:
4) $query_array=array_unique($query_array);
Now, when you're asking for a "search word" I guess right now you're doing something like "WHERE message LIKE '%word%'", right? Okay: we'll take each word in the array and turn it into "message LIKE '%word%'". Note: at this point one might have to worry about apostrophes in the words - deal with those whoever you're doing it now. Anyway:
foreach($query_array as $entry=>$word)
{ $query_array[$entry] = "message LIKE '%$word%'";
}
Now the array has been turned into SQL clauses - we want to join them together into one because clause with OR if I'm not mistaken:
$query=join(' OR ',$query_array);
and now $query is seomthing that can be stuck into a SQL SELECT query following the WHERE.
That's just a rough-and-ready guide. Please, anyone else with improvements (or replacements) feel free to chip in.