Open qifeng-bai opened 3 years ago
public double[] getBBox(SpatialSearchRequestParams requestParams) throws Exception {
SolrQuery query = initSolrQuery(requestParams, false, null);
query.setRows(0);
query.setFacet(false);
query.add("json.facet", "{x2:\"max(decimalLongitude)\",x1:\"min(decimalLongitude)\",y2:\"max(decimalLatitude)\",y1:\"min(decimalLatitude)\"}");
QueryResponse qr = indexDao.query(query);
SimpleOrderedMap facets = SearchUtils.getMap(qr.getResponse(), "facets");
return new double[]{toDouble(facets.get("x1")), toDouble(facets.get("y1")), toDouble(facets.get("x2")), toDouble(facets.get("y2"))};
}
it fails in last line facets.get("x1") because facets is an empty map
the actual query being sent to solr is
q=taxonConceptID:"https://id.biodiversity.org.au/taxon/apni/51311124"&fq=spatiallyValid:true&fq=-occurrenceStatus:ABSENT&fq=geohash:"Intersects(POLYGON((94.130859375+-33.6089008561002,102.3046875+-33.6089008561002,102.3046875+-28.25963451165,94.130859375+-28.25963451165,94.130859375+-33.6089008561002)))"&qt=standard&rows=0&start=0&sort=score+asc&fl=country,raw_countryCode,references,scientificName,year,point-0.01,lat_long,decimalLatitude,catalogNumber,basisOfRecord,raw_scientificName,raw_vernacularName,taxonConceptID,point-0.1,id,assertions,spatiallyValid,order,taxonRankID,dataResourceName,recordNumber,raw_basisOfRecord,stateProvince,decimalLongitude,collectionCode,speciesID,occurrenceID,point-1,sensitive,point-0.0001,license,month,dataResourceUid,genus,dataHubUid,lft,subspecies,imageIDs,eventDate,imageID,raw_typeStatus,coordinateUncertaintyInMeters,taxonRank,genusID,identificationVerificationStatus,collectionName,vernacularName,locationRemarks,institutionCode,rights,class,collectionUid,rgt,countryConservation,names_and_lsid,point-0.001,typeStatus,kingdom,dataProviderUid,recordedBy,multimedia,phylum,institutionUid,species,dataProviderName,institutionName,dataHubName,subspeciesID,eventDateEnd,occurrenceRemarks,speciesGroup,stateConservation,family,userAssertions&json.facet={x2:"max(decimalLongitude)",x1:"min(decimalLongitude)",y2:"max(decimalLatitude)",y1:"min(decimalLatitude)"}
but the thing is the query itself returns 0 record
which causes (facets.get("x1")) fail seems
@nickdos SP expects a string
var bb = response.data.split(",");
return [[bb[1], bb[0]], [bb[3], bb[2]]];
biocache-service:
@RequestMapping(value = {"/webportal/bbox", "/mapping/bbox"}, method = RequestMethod.GET)
public void boundingBox(
SpatialSearchRequestParams requestParams,
HttpServletResponse response)
throws Exception {
double[] bbox = null;
if (bbox == null) {
bbox = searchDAO.getBBox(requestParams);
}
writeBytes(response, (bbox[0] + "," + bbox[1] + "," + bbox[2] + "," + bbox[3]).getBytes(StandardCharsets.UTF_8));
}
but searchDAO.getBBox
doesn't find anything so return new double[]{toDouble(facets.get("x1")), toDouble(facets.get("y1")), toDouble(facets.get("x2")), toDouble(facets.get("y2"))};
throws an exception
Is every call to /webportal/bbox
supposed to return a valid value? what to do if like in this case solr search returns nothing?
@adam-collins - see comment above, can you answer that?
@nickdos @adam-collins At this moment, SP cannot handle an empty "BBox", but I think anyway Biocache should return a meaningful info back. SP will update code after
At this moment, SP created two promises : /bbox and /occurrences. If there is no occurrences, SP can display "no occurrences" warning.
SP should report no occurrences. Not concerned about the 500 when there is no data for /bbox.
@adam-collins SP can report no occurrences, after SP is able to catch the 500 error returned from /bbox query. I have fixed it up
Hi @nickdos , the API is supposed to return a ,
separated string in normal case, what do you recommend to return in case of no record found?
""
so caller needs to check this special case: String[] parts = str.split('); if (parts.length == 4) {}
, if caller not already doing this check, return ""
may cause them to crash Other geospatial libraries must have to deal with this... Maybe look into what Geotools does? @adam-collins Any ideas on best string representation?
My guess is 0,0,0,0
is easiest to read, as being an empty envelope...
Moving to biocache-service
Prod url that fails https://biocache.ala.org.au/ws/mapping/bbox?q=-: Test url that works https://biocache-ws-test.ala.org.au/ws/mapping/bbox?q=-:
Test is working for me - pass
For example:
Suppose return a bbox when I search Acacia in the middle of ocean
https://biocache.ala.org.au/ws/webportal/bbox?q=qid:1634854192098&type=application/json
{ message: "null", errorType: "Server error", statusCode: 500 }