public function save($con = null) { // if the first save $going_to_save = !$this->getId(); parent::save($con); // if it is the first then connect to google // for the queries and get the results. if ($going_to_save) { $query_result = new QueryResultBulk(); $query_result->setQuery($this); //$searchEngine = new GoogleRegexp(); //$count = $searchEngine->search($this->getQuery()); $searchEngine = new GoogleHitFetcher(); $count = $searchEngine->fetch($this->getQuery()); $query_result->setResultSize($count); $query_result->save(); } }
protected function execute($arguments = array(), $options = array()) { $stop_watch = new StopWatch(); $stop_watch->start(); logline('Started processing.'); $searchEngine = new GoogleHitFetcher(); $databaseManager = new sfDatabaseManager($this->configuration); $queries = QueryPeer::doSelect(new Criteria()); logline(sprintf("There are %s queries to process.", sizeof($queries))); foreach ($queries as $query) { $qr = new QueryResultBulk(); $qr->setQuery($query); $result_size = $searchEngine->fetch($query->getQuery()); $qr->setResultSize($result_size); logline(sprintf("Found %s results for %s.", $result_size, $query->getQuery())); $qr->save(); } logline(sprintf("Finished processing.")); $stop_watch->end(); logline(sprintf('Execution time: %s seconds.', $stop_watch->getTime())); logline(sprintf('!!!!!CAN RUN %s TIMES A DAY!!!!!', 24 * 60 * 60 / $stop_watch->getTime())); }
<?php include dirname(__FILE__) . '/../bootstrap/unit.php'; $t = new lime_test(4, new lime_output_color()); ProjectConfiguration::getApplicationConfiguration('frontend', 'test', true); $hitFetcher = new GoogleHitFetcher(); $hit = $hitFetcher->extractHit(file_get_contents(dirname(__FILE__) . '/google.umut.utkan.html')); $t->is($hit, 789, 'Result count has to be 789 for file google.umut.utkan.html'); $hit = $hitFetcher->extractHit(file_get_contents(dirname(__FILE__) . '/google.less.than.10.html')); $t->is($hit, 1, 'Result count has to be 1 for google.less.than.10.html'); $hit = $hitFetcher->extractHit(file_get_contents(dirname(__FILE__) . '/google.nothing.html')); $t->is($hit, 0, 'Result count has to be 0 for google.nothing.html'); $hit = $hitFetcher->extractHit(file_get_contents(dirname(__FILE__) . '/google.very.much.results.html')); $t->is($hit, 95700000, 'Result count has to be 95700000 for google.very.much.results.html');