示例#1
0
 /**
  * Executes a query against a Solr server.
  *
  * 1) Gets the query string
  * 2) Conducts the actual search
  * 3) Checks debug settings
  *
  * @param Tx_Solr_Query $query The query with keywords, filters, and so on.
  * @param integer $offset Result offset for pagination.
  * @param integer $limit Maximum number of results to return. If set to NULL, this value is taken from the query object.
  * @return Apache_Solr_Response Solr response
  */
 public function search(Tx_Solr_Query $query, $offset = 0, $limit = 10)
 {
     $query = $this->modifyQuery($query);
     $this->query = $query;
     if (empty($limit)) {
         $limit = $query->getResultsPerPage();
     }
     try {
         $response = $this->solr->search($query->getQueryString(), $offset, $limit, $query->getQueryParameters());
         if ($GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_solr.']['logging.']['query.']['queryString']) {
             GeneralUtility::devLog('Querying Solr, getting result', 'solr', 0, array('query string' => $query->getQueryString(), 'query parameters' => $query->getQueryParameters(), 'response' => json_decode($response->getRawResponse(), TRUE)));
         }
     } catch (RuntimeException $e) {
         $response = $this->solr->getResponse();
         if ($GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_solr.']['logging.']['exceptions']) {
             GeneralUtility::devLog('Exception while querying Solr', 'solr', 3, array('exception' => $e->__toString(), 'query' => (array) $query, 'offset' => $offset, 'limit' => $limit));
         }
     }
     $response = $this->modifyResponse($response);
     $this->response = $response;
     $this->hasSearched = TRUE;
     return $this->response;
 }