mirror of https://github.com/apache/lucene.git
LUCENE-4375 Fix use of BBoxWithin BBoxIntersects and IsWithin
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1383773 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e8c6d5b242
commit
15b4b09ff3
|
@ -51,7 +51,7 @@ public class RecursivePrefixTreeStrategy extends PrefixTreeStrategy {
|
|||
@Override
|
||||
public Filter makeFilter(SpatialArgs args) {
|
||||
final SpatialOperation op = args.getOperation();
|
||||
if (! SpatialOperation.is(op, SpatialOperation.IsWithin, SpatialOperation.Intersects, SpatialOperation.BBoxWithin, SpatialOperation.BBoxIntersects))
|
||||
if (op != SpatialOperation.Intersects)
|
||||
throw new UnsupportedSpatialOperation(op);
|
||||
|
||||
Shape shape = args.getShape();
|
||||
|
@ -59,7 +59,7 @@ public class RecursivePrefixTreeStrategy extends PrefixTreeStrategy {
|
|||
int detailLevel = grid.getLevelForDistance(args.resolveDistErr(ctx, distErrPct));
|
||||
|
||||
return new RecursivePrefixTreeFilter(
|
||||
getFieldName(), grid,shape, prefixGridScanLevel, detailLevel);
|
||||
getFieldName(), grid, shape, prefixGridScanLevel, detailLevel);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ public class TermQueryPrefixTreeStrategy extends PrefixTreeStrategy {
|
|||
@Override
|
||||
public Filter makeFilter(SpatialArgs args) {
|
||||
final SpatialOperation op = args.getOperation();
|
||||
if (! SpatialOperation.is(op, SpatialOperation.IsWithin, SpatialOperation.Intersects, SpatialOperation.BBoxWithin, SpatialOperation.BBoxIntersects))
|
||||
if (op != SpatialOperation.Intersects)
|
||||
throw new UnsupportedSpatialOperation(op);
|
||||
|
||||
Shape shape = args.getShape();
|
||||
|
|
|
@ -109,10 +109,7 @@ public class SpatialArgs {
|
|||
this.operation = operation;
|
||||
}
|
||||
|
||||
/** Considers {@link SpatialOperation#BBoxWithin} in returning the shape. */
|
||||
public Shape getShape() {
|
||||
if (shape != null && (operation == SpatialOperation.BBoxWithin || operation == SpatialOperation.BBoxIntersects))
|
||||
return shape.getBoundingBox();
|
||||
return shape;
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,10 @@ public class SpatialOperation implements Serializable {
|
|||
private static final List<SpatialOperation> list = new ArrayList<SpatialOperation>();
|
||||
|
||||
// Geometry Operations
|
||||
|
||||
/** Bounding box of the *indexed* shape. */
|
||||
public static final SpatialOperation BBoxIntersects = new SpatialOperation("BBoxIntersects", true, false, false);
|
||||
/** Bounding box of the *indexed* shape. */
|
||||
public static final SpatialOperation BBoxWithin = new SpatialOperation("BBoxWithin", true, false, false);
|
||||
public static final SpatialOperation Contains = new SpatialOperation("Contains", true, true, false);
|
||||
public static final SpatialOperation Intersects = new SpatialOperation("Intersects", true, false, false);
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
[San Francisco] G5391959 @ Intersects(-122.524918 37.674973 -122.360123 37.817108)
|
||||
[Wellington] G2179537 @ Intersects(174.711456 -41.360779 174.854279 -41.213837)
|
||||
[Barcelona] G6544100 G3128760 @ Intersects(2.127228 41.333313 2.226105 41.408844)
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
[San Francisco] G5391959 @ IsWithin(-122.524918 37.674973 -122.360123 37.817108)
|
||||
[Wellington] G2179537 @ IsWithin(174.711456 -41.360779 174.854279 -41.213837)
|
||||
[Barcelona] G6544100 G3128760 @ IsWithin(2.127228 41.333313 2.226105 41.408844)
|
||||
|
||||
|
||||
|
||||
|
|
@ -192,7 +192,6 @@ public class PortedSolr3Test extends StrategyTestCase {
|
|||
addDocument(newDoc(idStr,shape));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Document newDoc(String id, Shape shape) {
|
||||
Document doc = new Document();
|
||||
doc.add(new StringField("id", id, Field.Store.YES));
|
||||
|
@ -205,17 +204,19 @@ public class PortedSolr3Test extends StrategyTestCase {
|
|||
}
|
||||
|
||||
private void checkHitsCircle(String ptStr, double distKM, int assertNumFound, int... assertIds) {
|
||||
_checkHits(SpatialOperation.Intersects, ptStr, distKM, assertNumFound, assertIds);
|
||||
_checkHits(false, ptStr, distKM, assertNumFound, assertIds);
|
||||
}
|
||||
private void checkHitsBBox(String ptStr, double distKM, int assertNumFound, int... assertIds) {
|
||||
_checkHits(SpatialOperation.BBoxIntersects, ptStr, distKM, assertNumFound, assertIds);
|
||||
_checkHits(true, ptStr, distKM, assertNumFound, assertIds);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void _checkHits(SpatialOperation op, String ptStr, double distKM, int assertNumFound, int... assertIds) {
|
||||
private void _checkHits(boolean bbox, String ptStr, double distKM, int assertNumFound, int... assertIds) {
|
||||
SpatialOperation op = SpatialOperation.Intersects;
|
||||
Point pt = (Point) new ShapeReadWriter(ctx).readShape(ptStr);
|
||||
double distDEG = DistanceUtils.dist2Degrees(distKM, DistanceUtils.EARTH_MEAN_RADIUS_KM);
|
||||
Shape shape = ctx.makeCircle(pt, distDEG);
|
||||
if (bbox)
|
||||
shape = shape.getBoundingBox();
|
||||
|
||||
SpatialArgs args = new SpatialArgs(op,shape);
|
||||
//args.setDistPrecision(0.025);
|
||||
|
|
|
@ -27,7 +27,6 @@ import org.apache.lucene.document.Document;
|
|||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.StoredField;
|
||||
import org.apache.lucene.document.StringField;
|
||||
import org.apache.lucene.index.IndexableField;
|
||||
import org.apache.lucene.spatial.query.SpatialArgsParser;
|
||||
import org.junit.Assert;
|
||||
|
||||
|
@ -52,7 +51,7 @@ public abstract class StrategyTestCase extends SpatialTestCase {
|
|||
|
||||
public static final String QTEST_States_IsWithin_BBox = "states-IsWithin-BBox.txt";
|
||||
public static final String QTEST_States_Intersects_BBox = "states-Intersects-BBox.txt";
|
||||
public static final String QTEST_Cities_IsWithin_BBox = "cities-IsWithin-BBox.txt";
|
||||
public static final String QTEST_Cities_Intersects_BBox = "cities-Intersects-BBox.txt";
|
||||
public static final String QTEST_Simple_Queries_BBox = "simple-Queries-BBox.txt";
|
||||
|
||||
private Logger log = Logger.getLogger(getClass().getName());
|
||||
|
|
|
@ -17,7 +17,6 @@ package org.apache.lucene.spatial;
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import com.spatial4j.core.context.SpatialContext;
|
||||
import com.spatial4j.core.context.SpatialContext;
|
||||
import com.spatial4j.core.shape.Rectangle;
|
||||
import org.apache.lucene.spatial.query.SpatialArgsParser;
|
||||
|
@ -40,7 +39,7 @@ public class TestTestFramework extends LuceneTestCase {
|
|||
|
||||
@Test
|
||||
public void testQueries() throws IOException {
|
||||
String name = StrategyTestCase.QTEST_Cities_IsWithin_BBox;
|
||||
String name = StrategyTestCase.QTEST_Cities_Intersects_BBox;
|
||||
|
||||
InputStream in = getClass().getClassLoader().getResourceAsStream(name);
|
||||
SpatialContext ctx = SpatialContext.GEO;
|
||||
|
@ -57,7 +56,7 @@ public class TestTestFramework extends LuceneTestCase {
|
|||
Assert.assertEquals( 1, sf.ids.size() );
|
||||
Assert.assertTrue( sf.ids.get(0).equals( "G5391959" ) );
|
||||
Assert.assertTrue( sf.args.getShape() instanceof Rectangle);
|
||||
Assert.assertEquals( SpatialOperation.IsWithin, sf.args.getOperation() );
|
||||
Assert.assertEquals( SpatialOperation.Intersects, sf.args.getOperation() );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -51,10 +51,10 @@ public class TestBBoxStrategy extends StrategyTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testCitiesWithinBBox() throws IOException {
|
||||
public void testCitiesIntersectsBBox() throws IOException {
|
||||
getAddAndVerifyIndexedDocuments(DATA_WORLD_CITIES_POINTS);
|
||||
|
||||
executeQueries(SpatialMatchConcern.FILTER, QTEST_Cities_IsWithin_BBox);
|
||||
executeQueries(SpatialMatchConcern.FILTER, QTEST_Cities_Intersects_BBox);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ public class TestRecursivePrefixTreeStrategy extends StrategyTestCase {
|
|||
//execute queries for each prefix grid scan level
|
||||
for(int i = 0; i <= maxLength; i++) {
|
||||
((RecursivePrefixTreeStrategy)strategy).setPrefixGridScanLevel(i);
|
||||
executeQueries(SpatialMatchConcern.FILTER, QTEST_Cities_IsWithin_BBox);
|
||||
executeQueries(SpatialMatchConcern.FILTER, QTEST_Cities_Intersects_BBox);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,6 @@ package org.apache.lucene.spatial.prefix;
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import com.spatial4j.core.context.SpatialContext;
|
||||
import com.spatial4j.core.context.SpatialContext;
|
||||
import com.spatial4j.core.shape.Shape;
|
||||
import org.apache.lucene.document.Document;
|
||||
|
@ -55,7 +54,7 @@ public class TestTermQueryPrefixGridStrategy extends SpatialTestCase {
|
|||
SpatialArgsParser spatialArgsParser = new SpatialArgsParser();
|
||||
// TODO... use a non polygon query
|
||||
// SpatialArgs spatialArgs = spatialArgsParser.parse(
|
||||
// "IsWithin(POLYGON((-127.00390625 39.8125,-112.765625 39.98828125,-111.53515625 31.375,-125.94921875 30.14453125,-127.00390625 39.8125)))",
|
||||
// "Intersects(POLYGON((-127.00390625 39.8125,-112.765625 39.98828125,-111.53515625 31.375,-125.94921875 30.14453125,-127.00390625 39.8125)))",
|
||||
// new SimpleSpatialContext());
|
||||
|
||||
// Query query = prefixGridStrategy.makeQuery(spatialArgs, fieldInfo);
|
||||
|
|
|
@ -58,8 +58,8 @@ public class TestTwoDoublesStrategy extends StrategyTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testCitiesWithinBBox() throws IOException {
|
||||
public void testCitiesIntersectsBBox() throws IOException {
|
||||
getAddAndVerifyIndexedDocuments(DATA_WORLD_CITIES_POINTS);
|
||||
executeQueries(SpatialMatchConcern.FILTER, QTEST_Cities_IsWithin_BBox);
|
||||
executeQueries(SpatialMatchConcern.FILTER, QTEST_Cities_Intersects_BBox);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue