public function search() { $searchKey = new SearchKey(); $this->tmpl->assign('htmlSearchKey', $searchKey->asHtml()); if (!$searchKey->isGiven()) { return; } if ($searchKey->getOption() != 'random') { $this->createFeedLink($searchKey); $this->createSaveLink(); } $serverPool = ExternalServerPool::activeServerPool(); /* * Important order! ExternalBookListReader starts HTTP requests in the * constructor. The local database can be read while the external * servers are busy. Calling read(0) will read and parse the answers of * the servers. */ $externalReader = new ExternalBookListReader($serverPool, $searchKey); $localBookList = new LocalSearchBookList($searchKey); $nearbyBookListArray = $externalReader->readNextGroup(0); if ($localBookList->size() || sizeof($nearbyBookListArray)) { $results = $this->tmpl->addSubtemplate('searchResults'); $results->assign('HtmlRows', $localBookList->toHtmlRows()); foreach ($nearbyBookListArray as $nearbyBookList) { $set = $results->addSubtemplate('nearbyResultSet'); $set->assign('locationName', $nearbyBookList->locationName()); $set->assign('HtmlRows', $nearbyBookList->toHtmlRows()); } } else { /* Nothing found here, ask other servers group by group. */ $externalBookListArray = $externalReader->readNextGroup(255); if (sizeof($externalBookListArray) == 0) { $this->tmpl->addSubtemplate('noResults'); return; } $external = $this->tmpl->addSubtemplate('externalSearch'); foreach ($externalBookListArray as $externalBookList) { $set = $external->addSubtemplate('externalResultSet'); $set->assign('locationName', $externalBookList->locationName()); $set->assign('HtmlRows', $externalBookList->toHtmlRows()); } } }