Example #1
0
 /**
  *
  * @param Opus_SolrSearch_Query $query
  * @param bool $validateDocIds check document IDs coming from Solr index against database
  * @return Opus_SolrSearch_ResultList
  * @throws Opus_SolrSearch Exception If Solr server responds with an error or the response is empty.
  */
 public function search($query, $validateDocIds = true)
 {
     /**
      * @var Apache_Solr_Response $solr_response
      */
     $solr_response = null;
     try {
         $this->log->debug("query: " . $query->getQ());
         $solr_response = $this->solr_server->search($query->getQ(), $query->getStart(), $query->getRows(), $this->getParams($query));
     } catch (Exception $e) {
         $msg = 'Solr server responds with an error ' . $e->getMessage();
         $this->log->err($msg);
         if ($e instanceof Apache_Solr_HttpTransportException) {
             if ($e->getResponse()->getHttpStatus() == '400') {
                 // 400 seems to indicate org.apache.lucene.query.ParserParseException
                 throw new Opus_SolrSearch_Exception($msg, Opus_SolrSearch_Exception::INVALID_QUERY, $e);
             }
             if ($e->getResponse()->getHttpStatus() == '404') {
                 // 404 seems to indicate Solr server is unreachable
                 throw new Opus_SolrSearch_Exception($msg, Opus_SolrSearch_Exception::SERVER_UNREACHABLE, $e);
             }
         }
         throw new Opus_SolrSearch_Exception($msg, null, $e);
     }
     if (is_null($solr_response)) {
         $msg = 'could not get an Apache_Solr_Response object';
         $this->log->err($msg);
         throw new Opus_SolrSearch_Exception($msg);
     }
     $responseRenderer = new Opus_SolrSearch_ResponseRenderer($solr_response, $validateDocIds, $query->getSeriesId());
     return $responseRenderer->getResultList();
 }