/**
  * Fetch search results, log it, check spelling (if necessary) 
  */
 public function resultsAction()
 {
     // params
     $start = $this->query->start;
     $max = $this->query->max;
     $sort = $this->query->sort;
     $sort_id = $this->query->sort_id;
     $include_facets = $this->request->getParam('include_facets', $this->include_facets);
     // keep search refinements, if not set by user already and so configured
     if ($this->request->getSessionData('clear_facets') == '' && $this->config->getConfig('KEEP_SEARCH_REFINEMENT', false, false)) {
         $this->request->setSessionData('clear_facets', 'false');
     }
     // search
     $results = $this->engine->searchRetrieve($this->query, $start, $max, $sort, $include_facets);
     // total
     $total = $results->getTotal();
     // display spelling suggestion
     if ($start <= 1) {
         $suggestion = $this->checkSpelling();
         $this->helper->addSpellingLink($suggestion);
         $this->response->setVariable('spelling', $suggestion);
     }
     // track the query
     $id = $this->helper->getQueryID();
     if ($this->request->getSessionData("stat-{$id}") == "") {
         // log it
         try {
             $log = new Stats();
             $log->logSearch($this->id, $this->query, $results);
         } catch (\Exception $e) {
             trigger_error('search stats warning: ' . $e->getMessage(), E_USER_WARNING);
         }
         // mark we've saved this search log
         $this->request->setSessionData("stat-{$id}", (string) $total);
     }
     // include original record
     if ($this->config->getConfig('INCLUDE_ORIGINAL_RECORD_IN_BRIEF_RESULTS', false)) {
         foreach ($results->getRecords() as $record) {
             $record->includeOriginalRecord();
         }
     }
     // always cache the total based on the last action
     $this->request->setSessionData($id, (string) $total);
     // add links & labels
     $this->helper->addResultsLabels($results);
     $this->helper->addRecordLinks($results);
     $this->helper->addFacetLinks($results);
     $this->helper->addQueryLinks($this->query);
     // summary, sort & paging elements
     $results->summary = $this->helper->summary($total, $start, $max);
     $results->pager = $this->helper->pager($total, $start, $max);
     $results->sort_display = $this->helper->sortDisplay($sort_id);
     // response
     $this->response->setVariable('query', $this->query);
     $this->response->setVariable('results', $results);
     // view template
     $this->response->setView($this->id . '/results.xsl');
     return $this->response;
 }