
Twilio Phone Interview
By: a guest on
Feb 26th, 2012 | syntax:
PHP | size: 1.00 KB | hits: 2,939 | expires: Never
Tweet Search Engine
*Navigation bar at top of page - contains links to “Search” and “Insert Tweet”
Search
*Can search by word
*Once query is submitted, return list of all matching tweets
Insert
*”Tweets” can be inserted into database
global $db = array();
interface Tweet { content:String }
function save(Tweet $doc) { // String
$words = explode(“ “, $doc->content);
foreach ($words as $word)
{
if (!isset($db[$word]))
$db[$word] = array($doc);
else if (!in_array($doc, $db[word]))
array_push($db[$word], $doc);
}
}
$tweet = Tweet(“this this this is a tweet”);
$tweet2 = Tweet(“this is another”);
save($tweet);
save($tweet2);
array(
“this” => array($tweet, $tweet2)),
array(“is”, $tweet),
array(“a”, $tweet),
array(“tweet”, $tweet),
array(“this”, $tweet2),
)
function retrieve($keyword) { // String -> [Tweet]
if (isset($db[$keyword])
return $db[$keyword];
else return array();//
}