mirror of https://github.com/apache/lucene.git
LUCENE-4166: Fixed bad type checking of Circle shapes in TwoDoublesStrategy
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1354801 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
21f39d3e1e
commit
c4b08cf35c
|
@ -113,10 +113,13 @@ public class TwoDoublesStrategy extends SpatialStrategy<TwoDoublesFieldInfo> {
|
|||
public Query makeQuery(SpatialArgs args, TwoDoublesFieldInfo fieldInfo) {
|
||||
// For starters, just limit the bbox
|
||||
Shape shape = args.getShape();
|
||||
if (!(shape instanceof Rectangle)) {
|
||||
throw new InvalidShapeException("A rectangle is the only supported shape (so far), not "+shape.getClass());//TODO
|
||||
if (!(shape instanceof Rectangle || shape instanceof Circle)) {
|
||||
throw new InvalidShapeException("Only Rectangles and Circles are currently supported, " +
|
||||
"found [" + shape.getClass() + "]");//TODO
|
||||
}
|
||||
Rectangle bbox = (Rectangle) shape;
|
||||
|
||||
Rectangle bbox = shape.getBoundingBox();
|
||||
|
||||
if (bbox.getCrossesDateLine()) {
|
||||
throw new UnsupportedOperationException( "Crossing dateline not yet supported" );
|
||||
}
|
||||
|
|
|
@ -18,7 +18,15 @@
|
|||
package org.apache.lucene.spatial.vector;
|
||||
|
||||
import com.spatial4j.core.context.simple.SimpleSpatialContext;
|
||||
import com.spatial4j.core.exception.InvalidShapeException;
|
||||
import com.spatial4j.core.query.SpatialArgs;
|
||||
import com.spatial4j.core.query.SpatialOperation;
|
||||
import com.spatial4j.core.shape.Circle;
|
||||
import com.spatial4j.core.shape.Point;
|
||||
import com.spatial4j.core.shape.simple.CircleImpl;
|
||||
import com.spatial4j.core.shape.simple.PointImpl;
|
||||
import org.apache.lucene.search.FieldCache;
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.apache.lucene.spatial.SpatialMatchConcern;
|
||||
import org.apache.lucene.spatial.StrategyTestCase;
|
||||
import org.apache.lucene.spatial.util.NumericFieldInfo;
|
||||
|
@ -39,6 +47,22 @@ public class TestTwoDoublesStrategy extends StrategyTestCase<TwoDoublesFieldInfo
|
|||
this.fieldInfo = new TwoDoublesFieldInfo(getClass().getSimpleName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCircleShapeSupport() {
|
||||
Circle circle = new CircleImpl(new PointImpl(0, 0), 10, this.ctx);
|
||||
SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects, circle);
|
||||
Query query = this.strategy.makeQuery(args, this.fieldInfo);
|
||||
|
||||
assertNotNull(query);
|
||||
}
|
||||
|
||||
@Test(expected = InvalidShapeException.class)
|
||||
public void testInvalidQueryShape() {
|
||||
Point point = new PointImpl(0, 0);
|
||||
SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects, point);
|
||||
this.strategy.makeQuery(args, this.fieldInfo);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCitiesWithinBBox() throws IOException {
|
||||
getAddAndVerifyIndexedDocuments(DATA_WORLD_CITIES_POINTS);
|
||||
|
|
Loading…
Reference in New Issue