function generateSearchKey($text) { $stopWords = getSearchKeyStopWords(); $text = strtolower($text); $tokens = split(' ', $text); $ok_words = array(); foreach ($tokens as $t) { if ($t == '' || isset($stopWords[$t])) { continue; } $ok_words[] = $t; } sort($ok_words); $key = join(' ', $ok_words); $key = trim($key); return $key; }
function removeStopWords($tweet) { if (strlen($tweet) > 0) { $eTweet = explode(' ', $tweet); $stopWords = getSearchKeyStopWords(); $stopWords['#lazyweb'] = 1; array_walk($eTweet, 'trim'); $eTweet = array_flip($eTweet); $diff = array_diff_key($eTweet, $stopWords); $eTweet = array_flip($diff); $tweet = implode(' ', $eTweet); return $tweet; } else { throw new InvalidArgumentException('tweet cannot be null'); } }