array ( 'HTTP Response' => 400, 'Message' => 'Unknown Error' ), 1 => array ( 'HTTP Response' => 200, 'Message' => 'Success' ), 2 => array ( 'HTTP Response' => 403, 'Message' => 'HTTPS Required' ), 3 => array ( 'HTTP Response' => 401, 'Message' => 'Authentication Required' ), 4 => array ( 'HTTP Response' => 401, 'Message' => 'Authentication Failed' ), 5 => array ( 'HTTP Response' => 404, 'Message' => 'Invalid Request' ), 6 => array ( 'HTTP Response' => 400, 'Message' => 'Invalid Response Format' ) ); $method=""; $filters = [ ]; if (isset ( $_GET ['unitID'] )) { $filters ['unitID'] = $_GET ['unitID']; } else { $filters ['unitID'] = '*'; } if (isset ( $_GET ['sampleType'] )) { $filters ['sampletype'] = $_GET ['sampleType']; } if (isset ( $_GET ['name'] )) { $filters ['fullScientificName'] = $_GET ['name']; } if (isset ( $_GET ['country'] )) { $filters ['country'] = $_GET ['country']; } if (isset ( $_GET ['isocountry'] )) { $filters ['countryisocode'] = $_GET ['isocountry']; } if (isset ( $_GET ['repository'] )) { $filters ['institution'] = $_GET ['repository']; } if (isset ( $_GET ['institution'] )) { $filters ['institution'] = $_GET ['institution']; } $facetnames = [ ]; if (isset ( $_GET ['getSampletype'] )){ $facetnames [] = 'sampletype'; $method="getSampletype"; } if (isset ( $_GET ['getClassification'] )) { $facetnames [] = 'familia'; $facetnames [] = 'genus'; $facetnames [] = 'ordo'; $facetnames [] = 'phylum'; $facetnames [] = 'regnum'; $method="getClassification"; } if (isset ( $_GET ['getCounts'] )) { $method="getCounts"; $facetnames = [ ]; $facetnames [] = 'sampletype'; $facetnames [] = 'familia'; $facetnames [] = 'genus'; $filters = [ ]; if (isset ( $_GET ['repository'] ) || isset ( $_GET ['institution'] )) { if (isset ( $_GET ['repository'] )) $filters ['institution'] = $_GET ['repository']; if (isset ( $_GET ['institution'] )) $filters ['institution'] = $_GET ['institution']; } else $filters ['institution'] = "---"; } if (isset ( $_GET ['getRepositories'] )) { $method="getRepositories"; $facetnames = [ ]; $facetnames [] = 'institution'; $filters = [ ]; $filters ['institution'] = "---"; } $config = SOLRQueryManager::getConfigSearch (); $query = SOLRQueryManager::createSearchQuery ( $config ); $q = [ ]; foreach ( $filters as $key => $value ) { $value = str_replace ( " ", "\ ", $value ); $value = str_replace ( "(", "\(", $value ); $value = str_replace ( ")", "\)", $value ); $value = str_replace ( ":", "\:", $value ); $q [] = SOLRQueryManager::getPartialQuery ( $key, $value, $filters, False ); } $fq =NULL; if(!empty($filters)){ $fq = "{!join from=tripleidstoreid to=tripleidstoreid fromIndex=" . Yii::$app->params ['solrdetailsname'] . "}*:*"; // $fq.=implode ( " AND ", $q ); } $query->setRows ( 0 ); $q2 = [ ]; foreach ( $q as $qq ) if (! empty ( $qq )) $q2 [] = $qq; if (empty ( $q2 )) $q2 = [ "*:*" ]; $q = $q2; $raw_response = SOLRQueryManager::apiQuery ( $query, implode ( " AND ", $q ), $fq, $facetnames, "[]" ); // echo "Hello World! This is a first test for API RESTful Webservice on GGBN index. Data retrieved from SOLR index using portal queries. Yeah! // TODO: encoding somehow wrong, but hex-unicode seems to be a browser problem only; wt=xml looks strange, since json is output format; // can enforce wt=json, but than portal facet search is no longer working // check whether to use one SOLR core for portal and API or better two separate cores -> need specification what is required from // third parties such as EOL, GBIF, INSDC, and EDIT // If we can use same SOLR core for both would it be easier to use the web service for portal too? // Currently working parameters: unitID, sampleType, name, country, isocountry // "; $format = 'json'; // $response ['code'] = 0; // $response ['status'] = $status; // echo $status; if (isset ( $_GET ['getCounts'] )) { $response = [ ]; $response["method"]=$method; foreach ($filters as $k=>$v) if($v!=="---" && $v!=="*") $response["filters"]=$k."=".$v; $response ['nbSamples'] = $raw_response->getNumFound (); $f = $raw_response->getFacetSet ()->getFacet ( "familia" ); $nb = 0; foreach ( $f as $ff ) { $nb += 1; } $response ['nbFamilies'] = $nb; $f = $raw_response->getFacetSet ()->getFacet ( "genus" ); $nb = 0; foreach ( $f as $ff ) { $nb += 1; } $response ['nbGenera'] = $nb; $response ['samples'] = $raw_response->getFacetSet ()->getFacet ( "sampletype" ); } else { $doc = $raw_response->getFacetSet (); $numFound = $raw_response->getNumFound (); $status = $raw_response->getStatus(); $response = [ ]; $response["method"]=[$method]; foreach ($filters as $k=>$v) if($v!=="---" && $v!=="*") $response["filters"]=$k."=".$v; $facets=$raw_response->getFacetSet(); foreach($facetnames as $fn ) $response[$fn] = $facets->getFacet($fn); } WebService::deliver_response ( $format, $response ); return; } }