/** * Send query to SOLR and return response body. * * @param string $handler SOLR request handler to use * @param ParamBag $params Request parameters * * @return string Response body */ public function query($handler, ParamBag $params) { $url = $this->url . '/' . $handler; $paramString = implode('&', $params->request()); if (strlen($paramString) > self::MAX_GET_URL_LENGTH) { $method = Request::METHOD_POST; } else { $method = Request::METHOD_GET; } if ($method === Request::METHOD_POST) { $client = $this->createClient($url, $method); $client->setRawBody($paramString); $client->setEncType(HttpClient::ENC_URLENCODED); $client->setHeaders(['Content-Length' => strlen($paramString)]); } else { $url = $url . '?' . $paramString; $client = $this->createClient($url, $method); } $this->debug(sprintf('Query %s', $paramString)); return $this->send($client); }
/** * Perform a search and return record collection. * * @param AbstractQuery $query Search query * @param integer $offset Search offset * @param integer $limit Search limit * @param ParamBag $params Search backend parameters * *@return \VuFindSearch\Response\RecordCollectionInterface **/ public function search(AbstractQuery $query, $offset, $limit, ParamBag $params = null) { // process EDS API communication tokens. $authenticationToken = $this->getAuthenticationToken(); $sessionToken = $this->getSessionToken(); $this->debugPrint("Authentication Token: {$authenticationToken}, SessionToken: {$sessionToken}"); // check to see if there is a parameter to only process this call as a setup if (null !== $params && true == $params->get('setuponly')) { return false; } // create query parameters from VuFind data $queryString = !empty($query) ? $query->getAllTerms() : ''; $paramsStr = implode('&', null !== $params ? $params->request() : []); $this->debugPrint("Query: {$queryString}, Limit: {$limit}, Offset: {$offset}, " . "Params: {$paramsStr}"); $baseParams = $this->getQueryBuilder()->build($query); $paramsStr = implode('&', $baseParams->request()); $this->debugPrint("BaseParams: {$paramsStr} "); if (null !== $params) { $baseParams->mergeWith($params); } $baseParams->set('resultsPerPage', $limit); $page = $limit > 0 ? floor($offset / $limit) + 1 : 1; $baseParams->set('pageNumber', $page); $searchModel = $this->paramBagToEBSCOSearchModel($baseParams); $qs = $searchModel->convertToQueryString(); $this->debugPrint("Search Model query string: {$qs}"); try { $response = $this->client->search($searchModel, $authenticationToken, $sessionToken); } catch (\EbscoEdsApiException $e) { // if the auth or session token was invalid, try once more switch ($e->getApiErrorCode()) { case 104: case 108: case 109: try { // For error 104, retry auth token; for 108/9, retry sess token: if ($e->getApiErrorCode() == 104) { $authenticationToken = $this->getAuthenticationToken(true); } else { $sessionToken = $this->getSessionToken(true); } $response = $this->client->search($searchModel, $authenticationToken, $sessionToken); } catch (Exception $e) { throw new BackendException($e->getMessage(), $e->getCode(), $e); } break; default: $response = []; break; } } catch (Exception $e) { $this->debugPrint("Exception found: " . $e->getMessage()); throw new BackendException($e->getMessage(), $e->getCode(), $e); } $collection = $this->createRecordCollection($response); $this->injectSourceIdentifier($collection); return $collection; }
/** * Send query to SOLR and return response body. * * @param string $handler SOLR request handler to use * @param ParamBag $params Request parameters * * @return string Response body */ public function query($handler, ParamBag $params) { $urlSuffix = '/' . $handler; $paramString = implode('&', $params->request()); if (strlen($paramString) > self::MAX_GET_URL_LENGTH) { $method = Request::METHOD_POST; $callback = function ($client) use($paramString) { $client->setRawBody($paramString); $client->setEncType(HttpClient::ENC_URLENCODED); $client->setHeaders(['Content-Length' => strlen($paramString)]); }; } else { $method = Request::METHOD_GET; $urlSuffix .= '?' . $paramString; $callback = null; } $this->debug(sprintf('Query %s', $paramString)); return $this->trySolrUrls($method, $urlSuffix, $callback); }