mirror of https://github.com/apache/lucene.git
LUCENE-4413 Standardize on throwing UnsupportedOperationException for a shape the strategy doesn't support. Document it.
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1388872 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
255e8f1aa8
commit
a7979cf3f7
|
@ -96,6 +96,7 @@ public abstract class SpatialStrategy {
|
|||
* since it doesn't use it.
|
||||
*
|
||||
* @return Not null nor will it have null elements.
|
||||
* @throws UnsupportedOperationException if given a shape incompatible with the strategy
|
||||
*/
|
||||
public abstract Field[] createIndexableFields(Shape shape);
|
||||
|
||||
|
@ -111,6 +112,10 @@ public abstract class SpatialStrategy {
|
|||
* and {@link Shape} from the supplied {@code args}.
|
||||
* The default implementation is
|
||||
* <pre>return new ConstantScoreQuery(makeFilter(args));</pre>
|
||||
*
|
||||
* @throws UnsupportedOperationException If the strategy does not support the shape in {@code args}
|
||||
* @throws org.apache.lucene.spatial.query.UnsupportedSpatialOperation If the strategy does not support the {@link
|
||||
* org.apache.lucene.spatial.query.SpatialOperation} in {@code args}.
|
||||
*/
|
||||
public ConstantScoreQuery makeQuery(SpatialArgs args) {
|
||||
return new ConstantScoreQuery(makeFilter(args));
|
||||
|
@ -124,6 +129,10 @@ public abstract class SpatialStrategy {
|
|||
* {@link #makeQuery(org.apache.lucene.spatial.query.SpatialArgs)}
|
||||
* then this method could be simply:
|
||||
* <pre>return new QueryWrapperFilter(makeQuery(args).getQuery());</pre>
|
||||
*
|
||||
* @throws UnsupportedOperationException If the strategy does not support the shape in {@code args}
|
||||
* @throws org.apache.lucene.spatial.query.UnsupportedSpatialOperation If the strategy does not support the {@link
|
||||
* org.apache.lucene.spatial.query.SpatialOperation} in {@code args}.
|
||||
*/
|
||||
public abstract Filter makeFilter(SpatialArgs args);
|
||||
|
||||
|
|
|
@ -95,7 +95,7 @@ public class BBoxStrategy extends SpatialStrategy {
|
|||
public Field[] createIndexableFields(Shape shape) {
|
||||
if (shape instanceof Rectangle)
|
||||
return createIndexableFields((Rectangle)shape);
|
||||
throw new IllegalArgumentException("Can only index Rectangle, not " + shape);
|
||||
throw new UnsupportedOperationException("Can only index Rectangle, not " + shape);
|
||||
}
|
||||
|
||||
public Field[] createIndexableFields(Rectangle bbox) {
|
||||
|
@ -150,7 +150,7 @@ public class BBoxStrategy extends SpatialStrategy {
|
|||
private Query makeSpatialQuery(SpatialArgs args) {
|
||||
Shape shape = args.getShape();
|
||||
if (!(shape instanceof Rectangle))
|
||||
throw new IllegalArgumentException("Can only query by Rectangle, not " + shape);
|
||||
throw new UnsupportedOperationException("Can only query by Rectangle, not " + shape);
|
||||
|
||||
Rectangle bbox = (Rectangle) shape;
|
||||
Query spatial = null;
|
||||
|
|
|
@ -18,7 +18,6 @@ package org.apache.lucene.spatial.vector;
|
|||
*/
|
||||
|
||||
import com.spatial4j.core.context.SpatialContext;
|
||||
import com.spatial4j.core.exception.InvalidShapeException;
|
||||
import com.spatial4j.core.shape.Circle;
|
||||
import com.spatial4j.core.shape.Point;
|
||||
import com.spatial4j.core.shape.Rectangle;
|
||||
|
@ -90,7 +89,7 @@ public class TwoDoublesStrategy extends SpatialStrategy {
|
|||
public Field[] createIndexableFields(Shape shape) {
|
||||
if (shape instanceof Point)
|
||||
return createIndexableFields((Point) shape);
|
||||
throw new IllegalArgumentException("Can only index Point, not " + shape);
|
||||
throw new UnsupportedOperationException("Can only index Point, not " + shape);
|
||||
}
|
||||
|
||||
/** @see #createIndexableFields(com.spatial4j.core.shape.Shape) */
|
||||
|
@ -139,7 +138,7 @@ public class TwoDoublesStrategy extends SpatialStrategy {
|
|||
circle.getRadius() );
|
||||
return new ConstantScoreQuery(vsf);
|
||||
} else {
|
||||
throw new InvalidShapeException("Only Rectangles and Circles are currently supported, " +
|
||||
throw new UnsupportedOperationException("Only Rectangles and Circles are currently supported, " +
|
||||
"found [" + shape.getClass() + "]");//TODO
|
||||
}
|
||||
}
|
||||
|
@ -149,7 +148,7 @@ public class TwoDoublesStrategy extends SpatialStrategy {
|
|||
// For starters, just limit the bbox
|
||||
Shape shape = args.getShape();
|
||||
if (!(shape instanceof Rectangle || shape instanceof Circle)) {
|
||||
throw new InvalidShapeException("Only Rectangles and Circles are currently supported, " +
|
||||
throw new UnsupportedOperationException("Only Rectangles and Circles are currently supported, " +
|
||||
"found [" + shape.getClass() + "]");//TODO
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@ package org.apache.lucene.spatial.vector;
|
|||
*/
|
||||
|
||||
import com.spatial4j.core.context.SpatialContext;
|
||||
import com.spatial4j.core.exception.InvalidShapeException;
|
||||
import com.spatial4j.core.shape.Circle;
|
||||
import com.spatial4j.core.shape.Point;
|
||||
import org.apache.lucene.search.Query;
|
||||
|
@ -50,7 +49,7 @@ public class TestTwoDoublesStrategy extends StrategyTestCase {
|
|||
assertNotNull(query);
|
||||
}
|
||||
|
||||
@Test(expected = InvalidShapeException.class)
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void testInvalidQueryShape() {
|
||||
Point point = ctx.makePoint(0, 0);
|
||||
SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects, point);
|
||||
|
|
Loading…
Reference in New Issue