* OPTIONAL for all arg ontology_type (will apply a heuristic search only grabbing onts that level and below
*
*/
BaseQueryBuilder parseGeoTerm(AdvancedQueryPojo.QueryTermPojo.GeoTermPojo geo, StringBuffer sQueryTerm, GeoParseField parseFields)
{
BoolQueryBuilder boolQ = QueryBuilders.boolQuery().minimumNumberShouldMatch(1);
List<String> ont_terms = null;
//Get ontology types
if ( null != geo.ontology_type )
{
//get all ontology terms we are looking for
ont_terms = GeoOntologyMapping.getOntologyList(geo.ontology_type);
}
else
{
ont_terms = GeoOntologyMapping.getOntologyList(null);
}
if ((null != geo.centerll) && (null != geo.dist))
{
double lat, lon;
if ('(' == geo.centerll.charAt(0)) {
geo.centerll = geo.centerll.substring(1, geo.centerll.length() - 1);
}
String[] latlon = geo.centerll.split("\\s*,\\s*");
if (2 == latlon.length)
{
lat = Double.parseDouble(latlon[0]);
lon = Double.parseDouble(latlon[1]);
char c = geo.dist.charAt(geo.dist.length() - 1);
if ((c < 0x30) || (c > 0x39)) // not a digit, difference calculation is different
{
//ENT
//Add in ontology_type if necessary
//in the end this results in query = CURR_GEO_QUERY AND (ONT_TYPE = [ont1 OR ont2 OR ont3])
if ( parseFields == GeoParseField.ALL || parseFields == GeoParseField.ENT )
{
//use a 2nd variable so we dont have to keep casting termQ to BoolQuery
BoolQueryBuilder subQ = QueryBuilders.boolQuery().must(QueryBuilders.constantScoreQuery(FilterBuilders.geoDistanceFilter(EntityPojo.docQuery_geotag_).distance(geo.dist).point(lat, lon)).boost(1.0F));
subQ.must(QueryBuilders.termQuery(EntityPojo.docQuery_ontology_type_, ont_terms.toArray()));
boolQ.should(QueryBuilders.nestedQuery(DocumentPojo.entities_, subQ).scoreMode("max").boost((float)1.0));
}
//ASSOC AND DOCGEO (only added if ont is point or null)
if ( parseFields == GeoParseField.ALL || parseFields == GeoParseField.ASSOC )
boolQ.should(QueryBuilders.nestedQuery(DocumentPojo.associations_, FilterBuilders.geoDistanceFilter(AssociationPojo.docQuery_geotag_).distance(geo.dist).point(lat, lon)).scoreMode("max").boost((float)1.0));
if ( parseFields == GeoParseField.ALL || parseFields == GeoParseField.DOC )
boolQ.should(QueryBuilders.constantScoreQuery(FilterBuilders.geoDistanceFilter(DocumentPojo.docGeo_).distance(geo.dist).point(lat, lon)));
}
else // (identical to the above except geo distance parsing is different)
{
//ENT
//Add in ontology_type if necessary
//in the end this results in query = CURR_GEO_QUERY AND (ONT_TYPE = [ont1 OR ont2 OR ont3])
if ( parseFields == GeoParseField.ALL || parseFields == GeoParseField.ENT )
{
//use a 2nd variable so we dont have to keep casting termQ to BoolQuery
BoolQueryBuilder subQ = QueryBuilders.boolQuery().must(QueryBuilders.constantScoreQuery(FilterBuilders.geoDistanceFilter(EntityPojo.docQuery_geotag_).distance(Double.parseDouble(geo.dist), DistanceUnit.KILOMETERS).point(lat, lon)).boost(1.0F));
subQ.must(QueryBuilders.termsQuery(EntityPojo.docQuery_ontology_type_, ont_terms.toArray()));
boolQ.should(QueryBuilders.nestedQuery(DocumentPojo.entities_, subQ).scoreMode("max").boost((float)1.0));
}
//ASSOC AND DOCGEO (only added if ont is point or null)
if ( parseFields == GeoParseField.ALL || parseFields == GeoParseField.ASSOC )
boolQ.should(QueryBuilders.nestedQuery(DocumentPojo.associations_, FilterBuilders.geoDistanceFilter(AssociationPojo.docQuery_geotag_).distance(Double.parseDouble(geo.dist), DistanceUnit.KILOMETERS).point(lat, lon)).scoreMode("max").boost((float)1.0));
if ( parseFields == GeoParseField.ALL || parseFields == GeoParseField.DOC )
boolQ.should(QueryBuilders.constantScoreQuery(FilterBuilders.geoDistanceFilter(DocumentPojo.docGeo_).distance(Double.parseDouble(geo.dist), DistanceUnit.KILOMETERS).point(lat, lon)));
}
sQueryTerm.append("dist(*.geotag, (").append(geo.centerll).append(")) < ").append(geo.dist);
}
}//TESTED logic11,logic12
else if ((null != geo.minll) && (null != geo.maxll))
{
double latmin, lonmin, latmax, lonmax;
if ('(' == geo.minll.charAt(0)) {
geo.minll = geo.minll.substring(1, geo.minll.length() - 1);
}
String[] latlon1 = geo.minll.split("\\s*,\\s*");
if ('(' == geo.maxll.charAt(0)) {
geo.maxll = geo.maxll.substring(1, geo.maxll.length() - 1);
}
String[] latlon2 = geo.maxll.split("\\s*,\\s*");
if ((2 == latlon1.length) && (2 == latlon2.length))
{
latmin = Double.parseDouble(latlon1[0]);
lonmin = Double.parseDouble(latlon1[1]);
latmax = Double.parseDouble(latlon2[0]);
lonmax = Double.parseDouble(latlon2[1]);
// top left = max,min
latmin = latmin < latmax ? latmin : latmax;
latmax = latmin >= latmax ? latmin : latmax;
lonmin = lonmin < lonmax ? lonmin : lonmax;
lonmax = lonmin >= lonmax ? lonmin : lonmax;
// If we've got this far, we've found all the different locations
if ( parseFields == GeoParseField.ALL || parseFields == GeoParseField.ENT )
{
//use a 2nd variable so we dont have to keep casting termQ to BoolQuery
BoolQueryBuilder subQ = QueryBuilders.boolQuery().must(QueryBuilders.constantScoreQuery(FilterBuilders.geoBoundingBoxFilter(EntityPojo.docQuery_geotag_).topLeft(latmax,lonmin).bottomRight(latmin, lonmax)).boost(1.0F));
subQ.must(QueryBuilders.termsQuery(EntityPojo.docQuery_ontology_type_, ont_terms.toArray()));
boolQ.should(QueryBuilders.nestedQuery(DocumentPojo.entities_, subQ).scoreMode("max").boost((float)1.0));
}
//ASSOC AND DOCGEO (only added if ont is point or null)
if ( parseFields == GeoParseField.ALL || parseFields == GeoParseField.ASSOC )