public function ajaxgethitsAction()
 {
     // the remote fetch should only occur once, when a new pz2
     // session is created for a new query. Otherwise, the existing
     // result should be returned.
     $uo = new UserOptions($this->request);
     $sid = $uo->getSessionData('pz2session');
     $aid = $uo->getSessionData('aim25session');
     if ($aid != $sid) {
         $aid = null;
         // new pz2session, so new query, restart
     }
     $hits = array();
     if (is_null($sid)) {
         // if there's no session yet, just return nothing
         $hits['hits'] = 0;
     } else {
         $hits = $this->engine->getHitCount($aid, $sid, $this->query);
         $uo->setSessionData('aim25session', $sid);
     }
     $response = $this->getResponse();
     $response->headers()->addHeaderLine("Content-type", "application/json");
     $response->setContent(json_encode($hits));
     // returned to View\Listener
     return $response;
 }
 public function searchAction()
 {
     $uo = new UserOptions($this->request);
     if ($this->request->getParam('Submit') == 'GO') {
         // initialise the session for a new search
         $sid = $this->engine->initializePazpar2Client();
         $uo->setSessionData('pz2session', $sid);
     } else {
         $sid = $uo->getSessionData('pz2session');
     }
     // kick the search off
     $this->query->sid = $sid;
     $max_records = $uo->getSessionData('max_records');
     try {
         $this->engine->search($this->query, $max_records);
         // non-blocking call
     } catch (\Exception $e) {
         $this->flashMessenger->addMessage('Error|Session timeout: ' . $e->getMessage());
         // assume the session died - cab't initialise a new one
         // as might be infinite loop
         // Need to generate an error message
         // and routing back to search start page
         $this->engine->clearPazpar2Client($sid);
         $params = $this->query->getAllSearchParams();
         $params['lang'] = $this->request->getParam('lang');
         $params['controller'] = $this->request->getParam('controller');
         $params['action'] = 'index';
         $url = $this->request->url_for($params);
         return $this->redirect()->toUrl($url);
     }
     // set the url params for where we are going to redirect,
     // usually to the results action, but can be overriden
     $base = $this->helper->searchRedirectParams();
     $params = $this->query->getAllSearchParams();
     $params = array_merge($base, $params);
     $params['lang'] = $this->request->getParam('lang');
     $params['action'] = 'status';
     $params['Submit'] = '';
     // check spelling
     $this->checkSpelling();
     // construct the actual url and redirect
     $url = $this->request->url_for($params);
     return $this->redirect()->toUrl($url);
 }