Skip to content

Commit

Permalink
moved method from crawler to webpage for higher cohesion
Browse files Browse the repository at this point in the history
  • Loading branch information
gooh committed Mar 19, 2012
1 parent 7ae7957 commit 05575b2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
25 changes: 11 additions & 14 deletions src/app/mvc/model/ChatSearch/Crawler.php
Expand Up @@ -6,6 +6,11 @@ class Crawler
*/ */
protected $webpage; protected $webpage;


/**
* @var integer
*/
protected $maxScrapes = 25;

/** /**
* @return void * @return void
*/ */
Expand All @@ -20,25 +25,17 @@ public function __construct(Webpage $chatSearchUrl)
public function findAllQuestionIds() public function findAllQuestionIds()
{ {
$allLinks = array(); $allLinks = array();
$noResultsFound = false; $maxScrapes = $this->maxScrapes;
while (!$noResultsFound) { do {
$this->setUrlToNextPage(); $this->webpage->setUrlToNextPage();
$links = $this->scrapeCurrentUrlForQuestionIds(); $links = $this->scrapeCurrentUrlForQuestionIds();
$noResultsFound = empty($links);
$allLinks = array_merge($allLinks, $links); $allLinks = array_merge($allLinks, $links);
} } while (
--$maxScrapes !== 0 && !empty($links)
);
return array_unique($allLinks); return array_unique($allLinks);
} }


/**
* @return void
*/
protected function setUrlToNextPage()
{
$query = $this->webpage->getQuery();
$query['page'] = $query['page'] + 1;
}

/** /**
* @return array * @return array
*/ */
Expand Down
11 changes: 10 additions & 1 deletion src/app/mvc/model/ChatSearch/Webpage.php
Expand Up @@ -7,7 +7,7 @@ class Webpage extends Url
protected $siteUrl = 'http://chat.stackoverflow.com/search'; protected $siteUrl = 'http://chat.stackoverflow.com/search';


/** /**
* @var QueryString * @var array
*/ */
protected $query = array( protected $query = array(
'q' => 'cv-pls', 'q' => 'cv-pls',
Expand All @@ -24,4 +24,13 @@ public function __construct()
parent::__construct($this->siteUrl); parent::__construct($this->siteUrl);
$this->setQuery(new QueryString($this->query)); $this->setQuery(new QueryString($this->query));
} }

/**
* @return void
*/
public function setUrlToNextPage()
{
$query = $this->getQuery();
$query['page'] = $query['page'] + 1;
}
} }

0 comments on commit 05575b2

Please sign in to comment.