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(); } }
private function addReport($options, $connection) { $report = new Report(); $report->setDescription(self::generateDescription()); $report->setTitle(implode(', ', array_keys($options['queries']))); $report->save(); foreach ($options['queries'] as $key => $value) { $query = new Query(); $query->setQuery($key); $query->save(); $report_query = new ReportQuery(); $report_query->setQuery($query); $report_query->setTitle($key); $report_query->setReport($report); $report_query->save(); $date_start = strtotime($options['start_date']); $date_end = strtotime($options['end_date']); $start = $value['rand_start']; while ($date_start < $date_end) { if (rand(0, 100) > $value['rand']) { $query_result = new QueryResultBulk(); $query_result->setQuery($query); $start += rand($value['rand_min'], $value['rand_max']) * $value['rand_diff']; $query_result->setResultSize($start); $query_result->setCreatedAt($date_start); $query_result->save(); } $date_start = strtotime(date('Y-m-d', $date_start) . ' +1 days'); } $sql = "DELETE FROM %s where date(%s) = '%s' and %s = %s"; $sql = sprintf($sql, QueryResultPeer::TABLE_NAME, QueryResultPeer::RESULT_DATE, date('Y-m-d'), QueryResultPeer::QUERY_ID, $query->getId()); $statement = $connection->prepareStatement($sql); $statement->executeQuery(); } $tags = self::generateTags(); foreach ($tags as $tag) { $tag->setReport($report); $tag->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())); }