Ejemplo n.º 1
0
 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()));
 }