public function __construct(ExternalServerPool $externalServerPool, SearchKey $searchKey)
 {
     if ($searchKey->getOption()) {
         // Options are not supported.
         return;
     }
     $this->serverPool = $externalServerPool;
     $this->serverPoolArray =& $externalServerPool->toArray();
     $this->scriptRequest = self::scriptRequest($searchKey);
     $localServer = new LocalServer();
     $this->acceptServers = $localServer->acceptSuggestedServers();
     if ($this->hasServer(0)) {
         $this->startNextQueries();
     }
 }
Exemple #2
0
 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());
         }
     }
 }