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_nc'] = $_GET ['name']; } if (isset ( $_GET ['country'] )) { $filters ['country'] = $_GET ['country']; } if (isset ( $_GET ['isocountry'] )) { $filters ['isocountrycode'] = $_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 ['getCollYear'] )){ $facetnames [] = 'gatheringyear'; $method="getCollYear"; } if (isset ( $_GET ['getClassification'] )) { $facetnames [] = 'familia'; $facetnames [] = 'genus'; $facetnames [] = 'species'; $facetnames [] = 'classis'; $facetnames [] = 'ordo'; $facetnames [] = 'phylum'; $facetnames [] = 'regnum'; $method="getClassification"; } /* if (isset ( $_GET ['getRecords'] )) { $facetnames [] = 'sampletype'; $method="getRecords"; if(isset ( $_GET ['unitID'])) { $filters ['unitID_nc'] = "(".$_GET ['unitID'].")";} if(isset ( $_GET ['collCode'])) { $filters ['collectioncode'] = $_GET ['collCode'];} if(isset ( $_GET ['instCode'])) { $filters ['institutioncode'] = $_GET ['instCode'];} } */ if (isset ( $_GET ['getCounts'] )) { $method="getCounts"; $facetnames = [ ]; $facetnames [] = 'sampletype'; $facetnames [] = 'familia'; $facetnames [] = 'genus'; $facetnames [] = 'species'; $facetnames [] = 'voucherCol'; $facetnames [] = 'institution'; $facetnames [] = 'country'; $facetnames [] = 'continent'; $facetnames [] = 'sea'; $facetnames [] = 'ocean'; $facetnames [] = 'gatheringyear'; // $facetnames [] = 'isMarine'; $filters = [ ]; if(isset ( $_GET ['name'])) { $filters ['fullScientificName_nc'] = $_GET ['name'];} if(isset ( $_GET ['isocountry'])) { $filters ['isocountrycode'] = $_GET ['isocountry'];} 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'] = "---"; if (isset ( $_GET ['sampleType'] )) { $filters ['sampletype'] = $_GET ['sampleType']; } } $config = SOLRQueryManager::getConfigSearch (); $query = SOLRQueryManager::createSearchQuery ( $config ); $q = [ ]; foreach ( $filters as $key => $value ) { if (strpos($value, 'AND') > -1) { $booleanOperator = true; $value = str_replace (" AND ", "XANDX", $value); } else $booleanOperator = false; $value = str_replace ( " ", "\ ", $value ); // the " AND " will be masked too, hence the extraloop with replacement $value = str_replace ( "(", "\(", $value ); $value = str_replace ( ")", "\)", $value ); $value = str_replace ( ":", "\:", $value ); if ($booleanOperator == true) { $value = "(".str_replace ("XANDX", " AND ", $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 = [ "*:*".Yii::$app->params['thematicSOLRfilter'] ]; $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; $f = $raw_response->getFacetSet ()->getFacet ( "species" ); $nb = 0; foreach ( $f as $ff ) { $nb += 1; } $response ['nbSpecies'] = $nb; $f = $raw_response->getFacetSet ()->getFacet ( "institution" ); $nb = 0; foreach ( $f as $ff ) { $nb += 1; } $response ['nbSampleCollections'] = $nb; $f = $raw_response->getFacetSet ()->getFacet ( "voucherCol" ); $nb = 0; foreach ( $f as $ff ) { $nb += 1; } $response ['nbVoucherCollections'] = $nb; $f = $raw_response->getFacetSet ()->getFacet ( "country" ); $nb = 0; foreach ( $f as $ff ) { $nb += 1; } $response ['nbCountries'] = $nb; $f = $raw_response->getFacetSet ()->getFacet ( "continent" ); $nb = 0; foreach ( $f as $ff ) { $nb += 1; } $response ['nbContinents'] = $nb; $f = $raw_response->getFacetSet ()->getFacet ( "sea" ); $nb = 0; foreach ( $f as $ff ) { $nb += 1; } $response ['nbSeas'] = $nb; $f = $raw_response->getFacetSet ()->getFacet ( "ocean" ); $nb = 0; foreach ( $f as $ff ) { $nb += 1; } $response ['nbOceans'] = $nb; /* $nbMarine = $raw_response->getFacetSet ()->getFacet ( "isMarine" ); foreach ($nbMarine as $key => $count) { $response ['nbIsMarine'] = $nbMarine; } */ $nbCollectionYear = $raw_response->getFacetSet ()->getFacet ( "gatheringyear" ); foreach ($nbCollectionYear as $key => $count) { $response ['nbCollectionYear'] = $nbCollectionYear; } $response ['samples'] = $raw_response->getFacetSet ()->getFacet ( "sampletype" ); $response ['continents'] = $raw_response->getFacetSet ()->getFacet ( "continent" ); $response ['countries'] = $raw_response->getFacetSet ()->getFacet ( "country" ); $response ['oceans'] = $raw_response->getFacetSet ()->getFacet ( "ocean" ); $response ['seas'] = $raw_response->getFacetSet ()->getFacet ( "sea" ); } 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; } }