Hi team,
I am using Lucene 6.6.2, Spatial4j 0.7, lucene-spatial-extras 6.6.2. I am
trying to create a Spatial Query string for a given longitude, latitude &
radius in miles.
The query string generated using SpatialHelper (code as attached ) for
long: -122.8515139 & lat: 45.5099231 in .25 miles radius is as follow :
#(+location__x:[-122.85667708964212 TO -122.84635071035788]
+location__y:[45.50630481040378 TO 45.51354138959622])
#frange(DistanceValueSource(PointVectorStrategy field:location
ctx=SpatialContext.GEO, Pt(x=-122.8515139,y=45.5099231))):[0.0 TO
0.00361828959621958]
My lucene index is as follows:
create lucene index --name=myLuceneIndex --region=stations --field=title
--analyzer=org.apache.lucene.analysis.en.EnglishAnalyzer
I get error
Syntax Error, cannot parse
ConstantScore(#(+location__x:[-122.85667708964212 TO -122.84635071035788]
+location__y:[45.50630481040378 TO 45.51354138959622])
#frange(DistanceValueSource(PointVectorStrategy field:location
ctx=SpatialContext.GEO, Pt(x=-122.8515139,y=45.5099231))):[0.0 TO
0.00361828959621958]):
What am I doing wrong ?
Regards,
Aj
package com.aj.stations;
import org.apache.lucene.document.Field;
import org.apache.lucene.search.Query;
import org.apache.lucene.spatial.query.SpatialArgs;
import org.apache.lucene.spatial.query.SpatialOperation;
import org.apache.lucene.spatial.vector.PointVectorStrategy;
import org.locationtech.spatial4j.context.SpatialContext;
import org.locationtech.spatial4j.distance.DistanceUtils;
import org.locationtech.spatial4j.shape.Point;
import org.locationtech.spatial4j.shape.impl.GeoCircle;
import org.locationtech.spatial4j.shape.impl.PointImpl;
public class SpatialHelper {
private static final SpatialContext CONTEXT = SpatialContext.GEO;
private static final PointVectorStrategy STRATEGY =
new PointVectorStrategy(CONTEXT, "location", PointVectorStrategy.DEFAULT_FIELDTYPE);
/** Return a lucene query that finds all points within the given radius from the given point */
public static Query findWithin(double longitude, double latitude, double radiusMiles) {
double radiusDEG = DistanceUtils.dist2Degrees(radiusMiles, DistanceUtils.EARTH_MEAN_RADIUS_MI);
// Create a query that looks for all points within a circle around the given point
SpatialArgs args =
new SpatialArgs(
SpatialOperation.IsWithin,
new GeoCircle(createPoint(longitude, latitude), radiusDEG, CONTEXT));
return STRATEGY.makeQuery(args);
}
/** Return a list of fields that should be added to lucene document to index the given point */
public static Field[] getIndexableFields(double longitude, double latitude) {
Point point = createPoint(longitude, latitude);
return STRATEGY.createIndexableFields(point);
}
private static Point createPoint(double longitude, double latitude) {
return new PointImpl(longitude, latitude, CONTEXT);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]