It is possibile to to make query where max distance dist is calculated dynamically, depending on what is a field connected with a document being searched.
I mean something like:
ctx.makeCircle(la, lo, DistanceUtils.dist2Degrees(Min(100km, currentDocumnet.getField("max_distance")),DistanceUtils.EARTH_MEAN_RADIUS_KM))
Instead of:
new SpatialArgs(SpatialOperation.Intersects,ctx.makeCircle(la, lo, DistanceUtils.dist2Degrees(dist,DistanceUtils.EARTH_MEAN_RADIUS_KM)));
To get the results I want I’m doing some manual filtering on my ScoreDoc:
String maxDistance = d.get(Offer.MAX_DISTANCE);
if (maxDistance != null && maxDistance.length() > 0) {
logger.info("Contractor max. distance =" + maxDistance);
int maxContractorDistance = Integer
.parseInt(maxDistance);
if (distKM > maxContractorDistance
&& maxContractorDistance > 0) {
logger.info("Contractor is too far"
+ maxContractorDistance);
continue;
}
}
Ahh; interesting. You should implement this with two spatial filters together. One of them, filters based on the index distance requirement, and the other filters based on the query index requirement.
The first spatial field should be RecursivePrefixTreeStrategy which is where you should index the circle shapes. When making the query/filter for this field, your query shape is a point. The second spatial field should also use RecursivePrefixTreeStrategy but this one you should index the center points of those circles alone. Your query shape is a circle for this second field. Both queries/filters would alone match more than you want but if you combine them such that a matching document must satisfy both, you will get the correct document set.