Java Code Examples for org.apache.lucene.index.PointValues#Relation

The following examples show how to use org.apache.lucene.index.PointValues#Relation . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FloatPointNearestNeighbor.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public PointValues.Relation compare(byte[] minPackedValue, byte[] maxPackedValue) {
  if (hitQueue.size() == topN && pointToRectangleDistanceSquared(minPackedValue, maxPackedValue, origin) > bottomNearestDistanceSquared) {
    return PointValues.Relation.CELL_OUTSIDE_QUERY;
  }
  return PointValues.Relation.CELL_CROSSES_QUERY;
}
 
Example 2
Source File: Rectangle2D.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public PointValues.Relation relate(double minX, double maxX, double minY, double maxY) {
  if (Component2D.disjoint(this.minX, this.maxX, this.minY, this.maxY, minX, maxX, minY, maxY)) {
    return PointValues.Relation.CELL_OUTSIDE_QUERY;
  }
  if (Component2D.within(minX, maxX, minY, maxY, this.minX, this.maxX, this.minY, this.maxY)) {
    return PointValues.Relation.CELL_INSIDE_QUERY;
  }
  return PointValues.Relation.CELL_CROSSES_QUERY;
}
 
Example 3
Source File: GeoUtils.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Compute the relation between the provided box and distance query.
 * This only works for boxes that do not cross the dateline.
 */
public static PointValues.Relation relate(
    double minLat, double maxLat, double minLon, double maxLon,
    double lat, double lon, double distanceSortKey, double axisLat) {

  if (minLon > maxLon) {
    throw new IllegalArgumentException("Box crosses the dateline");
  }

  if ((lon < minLon || lon > maxLon) && (axisLat + Rectangle.AXISLAT_ERROR < minLat || axisLat - Rectangle.AXISLAT_ERROR > maxLat)) {
    // circle not fully inside / crossing axis
    if (SloppyMath.haversinSortKey(lat, lon, minLat, minLon) > distanceSortKey &&
        SloppyMath.haversinSortKey(lat, lon, minLat, maxLon) > distanceSortKey &&
        SloppyMath.haversinSortKey(lat, lon, maxLat, minLon) > distanceSortKey &&
        SloppyMath.haversinSortKey(lat, lon, maxLat, maxLon) > distanceSortKey) {
      // no points inside
      return Relation.CELL_OUTSIDE_QUERY;
    }
  }

  if (within90LonDegrees(lon, minLon, maxLon) &&
      SloppyMath.haversinSortKey(lat, lon, minLat, minLon) <= distanceSortKey &&
      SloppyMath.haversinSortKey(lat, lon, minLat, maxLon) <= distanceSortKey &&
      SloppyMath.haversinSortKey(lat, lon, maxLat, minLon) <= distanceSortKey &&
      SloppyMath.haversinSortKey(lat, lon, maxLat, maxLon) <= distanceSortKey) {
    // we are fully enclosed, collect everything within this subtree
    return Relation.CELL_INSIDE_QUERY;
  }

  return Relation.CELL_CROSSES_QUERY;
}
 
Example 4
Source File: Point2D.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public PointValues.Relation relate(double minX, double maxX, double minY, double maxY) {
  if (Component2D.containsPoint(x, y, minX, maxX, minY, maxY)) {
    return PointValues.Relation.CELL_CROSSES_QUERY;
  }
  return PointValues.Relation.CELL_OUTSIDE_QUERY;
}
 
Example 5
Source File: TestRectangle2D.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public void testRandomTriangles() {
  Random random = random();
  XYRectangle rectangle = ShapeTestUtil.nextBox(random);
  Component2D rectangle2D = Rectangle2D.create(rectangle);
  for (int i =0; i < 100; i++) {
    float ax = ShapeTestUtil.nextFloat(random);
    float ay = ShapeTestUtil.nextFloat(random);
    float bx = ShapeTestUtil.nextFloat(random);
    float by = ShapeTestUtil.nextFloat(random);
    float cx = ShapeTestUtil.nextFloat(random);
    float cy = ShapeTestUtil.nextFloat(random);

    float tMinX = StrictMath.min(StrictMath.min(ax, bx), cx);
    float tMaxX = StrictMath.max(StrictMath.max(ax, bx), cx);
    float tMinY = StrictMath.min(StrictMath.min(ay, by), cy);
    float tMaxY = StrictMath.max(StrictMath.max(ay, by), cy);


    PointValues.Relation r = rectangle2D.relate(tMinX, tMaxX, tMinY, tMaxY);
    if (r == PointValues.Relation.CELL_OUTSIDE_QUERY) {
      assertFalse(rectangle2D.intersectsTriangle(ax, ay, bx, by, cx, cy));
      assertFalse(rectangle2D.intersectsLine(ax, ay, bx, by));
      assertFalse(rectangle2D.containsTriangle(ax, ay, bx, by , cx, cy));
      assertFalse(rectangle2D.containsLine(ax, ay, bx, by));
      assertEquals(Component2D.WithinRelation.DISJOINT, rectangle2D.withinTriangle(ax, ay, true, bx, by, true, cx, cy, true));
    }
    else if (r == PointValues.Relation.CELL_INSIDE_QUERY) {
      assertTrue(rectangle2D.intersectsTriangle(ax, ay, bx, by, cx, cy));
      assertTrue(rectangle2D.intersectsLine(ax, ay, bx, by));
      assertTrue(rectangle2D.containsTriangle(ax, ay, bx, by , cx, cy));
      assertTrue(rectangle2D.containsLine(ax, ay, bx, by));
    }
  }
}
 
Example 6
Source File: GraphTermsQParserPlugin.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public PointValues.Relation compare(byte[] minPackedValue, byte[] maxPackedValue) {

  boolean crosses = false;

  for(int dim=0;dim<numDims;dim++) {
    int offset = dim*bytesPerDim;

    int cmpMin = Arrays.compareUnsigned(minPackedValue, offset, offset + bytesPerDim, pointBytes, offset, offset + bytesPerDim);
    if (cmpMin > 0) {
      return PointValues.Relation.CELL_OUTSIDE_QUERY;
    }

    int cmpMax = Arrays.compareUnsigned(maxPackedValue, offset, offset + bytesPerDim, pointBytes, offset, offset + bytesPerDim);
    if (cmpMax < 0) {
      return PointValues.Relation.CELL_OUTSIDE_QUERY;
    }

    if (cmpMin != 0 || cmpMax != 0) {
      crosses = true;
    }
  }

  if (crosses) {
    return PointValues.Relation.CELL_CROSSES_QUERY;
  } else {
    // NOTE: we only hit this if we are on a cell whose min and max values are exactly equal to our point,
    // which can easily happen if many docs share this one value
    return PointValues.Relation.CELL_INSIDE_QUERY;
  }
}
 
Example 7
Source File: PointMerger.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public PointValues.Relation compare(byte[] minPackedValue, byte[] maxPackedValue) {
  int v = IntPoint.decodeDimension(maxPackedValue, 0);
  if (v >= last) {
    return PointValues.Relation.CELL_CROSSES_QUERY;
  } else {
    return PointValues.Relation.CELL_OUTSIDE_QUERY;
  }
}
 
Example 8
Source File: PointMerger.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public PointValues.Relation compare(byte[] minPackedValue, byte[] maxPackedValue) {
  long v = LongPoint.decodeDimension(maxPackedValue, 0);
  if (v >= last) {
    return PointValues.Relation.CELL_CROSSES_QUERY;
  } else {
    return PointValues.Relation.CELL_OUTSIDE_QUERY;
  }
}
 
Example 9
Source File: PointMerger.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public PointValues.Relation compare(byte[] minPackedValue, byte[] maxPackedValue) {
  float v = FloatPoint.decodeDimension(maxPackedValue, 0);
  if (v >= last) {
    return PointValues.Relation.CELL_CROSSES_QUERY;
  } else {
    return PointValues.Relation.CELL_OUTSIDE_QUERY;
  }
}
 
Example 10
Source File: PointMerger.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public PointValues.Relation compare(byte[] minPackedValue, byte[] maxPackedValue) {
  double v = DoublePoint.decodeDimension(maxPackedValue, 0);
  if (v >= last) {
    return PointValues.Relation.CELL_CROSSES_QUERY;
  } else {
    return PointValues.Relation.CELL_OUTSIDE_QUERY;
  }
}
 
Example 11
Source File: Component2D.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
/** relates this component2D with a bounding box **/
PointValues.Relation relate(double minX, double maxX, double minY, double maxY);