// determine the discoverable target, set names
String sErr;
Discoverable discoverable = spatialClause.getTarget();
if (discoverable == null) {
sErr = "The SpatialClause.target is null.";
throw new DiscoveryException(sErr);
}
if (discoverable.getStorable() == null) {
sErr = "The SpatialClause.target.storeable is null.";
throw new DiscoveryException(sErr);
} else {
Storeable storeable = (Storeable)discoverable.getStorable();
if (!(storeable instanceof GeometryProperty)) {
sErr = "The SpatialClause.target.storeable is not a GeometryProperty.";
throw new DiscoveryException(sErr);
}
}
// check the envelope
envelope = spatialClause.getBoundingEnvelope();
if ((envelope == null) || envelope.isEmpty()) {
sErr = "The SpatialClause.boundingEnvelope is empty.";
throw new DiscoveryException(sErr);
}
// initialize the values of the input query envelope
qryMinX = envelope.getMinX();
qryMinY = envelope.getMinY();
qryMaxX = envelope.getMaxX();
qryMaxY = envelope.getMaxY();
if (qryMinX > qryMaxX) {
qryCrossedDateline = true;
}
// determine spatialRelevance parameters
// (original defaults were queryPower=2.0, targetPower=0.5)
RequestContext rc = this.getQueryAdapter().getIndexAdapter().getRequestContext();
StringAttributeMap params = rc.getCatalogConfiguration().getParameters();
double queryPower = Val.chkDbl(params.getValue("spatialRelevance.queryPower"),1.0);
double targetPower = Val.chkDbl(params.getValue("spatialRelevance.targetPower"),1.0);
String rankingOption = Val.chkStr(params.getValue("spatialRelevance.ranking.enabled"));
int rankingMaxDoc = Val.chkInt(params.getValue("spatialRelevance.ranking.maxDoc"),50000);
boolean bUseSpatialRanking = false;
if (rankingOption.equalsIgnoreCase("true")) {
bUseSpatialRanking = true;
} else if (rankingOption.equalsIgnoreCase("false")) {
bUseSpatialRanking = false;
} else {
// default spatialRelevance.ranking.enabled option is "auto"
if (this.getQueryAdapter() != null) {
int maxDoc = this.getQueryAdapter().getMaxDoc();
if ((maxDoc > 0) && (maxDoc <= rankingMaxDoc)) {
bUseSpatialRanking = true;
}
}
}
// Handle each operation - Beyond, Crosses, DWithin and Touches are not implemented
if (bUseSpatialRanking) {
Query spatialQuery = null;
if (spatialClause instanceof SpatialClause.GeometryBBOXIntersects) {
spatialQuery = this.makeIntersects();
} else if (spatialClause instanceof SpatialClause.GeometryContains) {
spatialQuery = this.makeContains();
} else if (spatialClause instanceof SpatialClause.GeometryIntersects) {
spatialQuery = this.makeIntersects();
} else if (spatialClause instanceof SpatialClause.GeometryIsDisjointTo) {
bUseSpatialRanking = false;
} else if (spatialClause instanceof SpatialClause.GeometryIsEqualTo) {
bUseSpatialRanking = false;
} else if (spatialClause instanceof SpatialClause.GeometryIsWithin) {
spatialQuery = this.makeWithin();
} else if (spatialClause instanceof SpatialClause.GeometryOverlaps) {
spatialQuery = this.makeIntersects();
} else {
sErr = "Unrecognized spatial clause type: ";
throw new DiscoveryException(sErr+spatialClause.getClass().getName());
}
if (bUseSpatialRanking) {
SpatialRankingValueSource srvs = new SpatialRankingValueSource(envelope,queryPower,targetPower);
Query spatialRankingQuery = new ValueSourceQuery(srvs);
BooleanQuery bq = new BooleanQuery();
bq.add(spatialQuery,BooleanClause.Occur.MUST);
bq.add(spatialRankingQuery,BooleanClause.Occur.MUST);
appendQuery(activeBooleanQuery,activeLogicalClause,bq);
this.getQueryAdapter().setHasScoredExpression(true);
}
}
if (!bUseSpatialRanking) {
if (spatialClause instanceof SpatialClause.GeometryBBOXIntersects) {
appendQuery(activeBooleanQuery,activeLogicalClause,makeIntersects());
} else if (spatialClause instanceof SpatialClause.GeometryContains) {
appendQuery(activeBooleanQuery,activeLogicalClause,makeContains());
} else if (spatialClause instanceof SpatialClause.GeometryIntersects) {
appendQuery(activeBooleanQuery,activeLogicalClause,makeIntersects());
} else if (spatialClause instanceof SpatialClause.GeometryIsDisjointTo) {
appendQuery(activeBooleanQuery,activeLogicalClause,makeDisjoint());
} else if (spatialClause instanceof SpatialClause.GeometryIsEqualTo) {
appendQuery(activeBooleanQuery,activeLogicalClause,makeEquals());
} else if (spatialClause instanceof SpatialClause.GeometryIsWithin) {
appendQuery(activeBooleanQuery,activeLogicalClause,makeWithin());
} else if (spatialClause instanceof SpatialClause.GeometryOverlaps) {
appendQuery(activeBooleanQuery,activeLogicalClause,makeIntersects());
} else {
sErr = "Unrecognized spatial clause type: ";
throw new DiscoveryException(sErr+spatialClause.getClass().getName());
}
}
}