LUCENE-5648: Bug fix for detecting Contains relation when on the edge.

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1601734 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
David Wayne Smiley 2014-06-10 18:41:22 +00:00
parent 43a3f7edb8
commit ce0e2100a9
2 changed files with 39 additions and 6 deletions

View File

@ -730,13 +730,24 @@ public abstract class NumberRangePrefixTree extends SpatialPrefixTree {
if (endCmp < 0) {//end comes before this cell
return SpatialRelation.DISJOINT;
}
if ((startCmp < 0 || startCmp == 0 && nrShape.getMinLV().getLevel() <= getLevel())
&& (endCmp > 0 || endCmp == 0 && nrShape.getMaxLV().getLevel() <= getLevel()))
int nrMinLevel = nrShape.getMinLV().getLevel();
int nrMaxLevel = nrShape.getMaxLV().getLevel();
if ((startCmp < 0 || startCmp == 0 && nrMinLevel <= getLevel())
&& (endCmp > 0 || endCmp == 0 && nrMaxLevel <= getLevel()))
return SpatialRelation.WITHIN;//or equals
if (startCmp == 0 && endCmp == 0
&& nrShape.getMinLV().getLevel() >= getLevel() && nrShape.getMaxLV().getLevel() >= getLevel())
return SpatialRelation.CONTAINS;
return SpatialRelation.INTERSECTS;
//At this point it's Contains or Within.
if (startCmp != 0 || endCmp != 0)
return SpatialRelation.INTERSECTS;
//if min or max Level is less, it might be on the equivalent edge.
for (;nrMinLevel < getLevel(); nrMinLevel++) {
if (getValAtLevel(nrMinLevel + 1) != 0)
return SpatialRelation.INTERSECTS;
}
for (;nrMaxLevel < getLevel(); nrMaxLevel++) {
if (getValAtLevel(nrMaxLevel + 1) != getNumSubCells(getLVAtLevel(nrMaxLevel-1)) - 1)
return SpatialRelation.INTERSECTS;
}
return SpatialRelation.CONTAINS;
}
@Override
@ -806,6 +817,24 @@ public abstract class NumberRangePrefixTree extends SpatialPrefixTree {
str += "";//bullet (won't be confused with textual representation)
return str;
}
/** Configure your IDE to use this. */
public String toStringDebug() {
String pretty = toString();
if (getLevel() == 0)
return pretty;
//now prefix it by an array of integers of the cell levels
StringBuilder buf = new StringBuilder(100);
buf.append('[');
for (int level = 1; level <= getLevel(); level++) {
if (level != 1)
buf.append(',');
buf.append(getLVAtLevel(level).cellNumber);
}
buf.append("] ").append(pretty);
return buf.toString();
}
} // END OF NRCell
}

View File

@ -135,6 +135,10 @@ public class DateRangePrefixTreeTest extends LuceneTestCase {
}
public void testShapeRelations() throws ParseException {
//note: left range is 264000 at the thousand year level whereas right value is exact year
assertEquals(SpatialRelation.WITHIN,
tree.parseShape("[-264000 TO -264000-11-20]").relate(tree.parseShape("-264000")));
Shape shapeA = tree.parseShape("[3122-01-23 TO 3122-11-27]");
Shape shapeB = tree.parseShape("[3122-08 TO 3122-11]");
assertEquals(SpatialRelation.INTERSECTS, shapeA.relate(shapeB));