Skip to content

Commit

Permalink
LUCENE-9553: Adds a XYPoint query that accepts an array of XYGeometr…
Browse files Browse the repository at this point in the history
…ies (apache#1939)
  • Loading branch information
iverase authored and epugh@opensourceconnections.com committed Jan 15, 2021
1 parent e929e62 commit 8184bb7
Show file tree
Hide file tree
Showing 6 changed files with 236 additions and 217 deletions.
2 changes: 2 additions & 0 deletions lucene/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ New Features

* LUCENE-9552: New LatLonPoint query that accepts an array of LatLonGeometries. (Ignacio Vera)

* LUCENE-9553: New XYPoint query that accepts an array of XYGeometries. (Ignacio Vera)

Improvements
---------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import org.apache.lucene.geo.XYCircle;
import org.apache.lucene.geo.XYEncodingUtils;
import org.apache.lucene.geo.XYGeometry;
import org.apache.lucene.geo.XYPolygon;
import org.apache.lucene.geo.XYRectangle;
import org.apache.lucene.index.DocValuesType;
Expand All @@ -36,6 +37,10 @@
* <p>
* This field defines static factory methods for common operations:
* <ul>
* <li>{@link #newSlowBoxQuery newSlowBoxQuery()} for matching points within a bounding box.
* <li>{@link #newSlowDistanceQuery newSlowDistanceQuery()} for matching points within a specified distance.
* <li>{@link #newSlowPolygonQuery newSlowPolygonQuery()} for matching points within an arbitrary polygon.
* <li>{@link #newSlowGeometryQuery newSlowGeometryQuery()} for matching points within an arbitrary geometry.
* <li>{@link #newDistanceSort newDistanceSort()} for ordering documents by distance from a specified location.
* </ul>
* <p>
Expand Down Expand Up @@ -173,6 +178,21 @@ public static Query newSlowDistanceQuery(String field, float x, float y, float r
* @throws IllegalArgumentException if {@code field} is null or polygons is empty or contain a null polygon.
*/
public static Query newSlowPolygonQuery(String field, XYPolygon... polygons) {
return new XYDocValuesPointInGeometryQuery(field, polygons);
return newSlowGeometryQuery(field, polygons);
}

/**
* Create a query for matching points within the supplied geometries. XYLine geometries are not supported.
* This query is usually slow as it does not use an index structure and needs
* to verify documents one-by-one in order to know whether they match. It is
* best used wrapped in an {@link IndexOrDocValuesQuery} alongside a
* {@link XYPointField#newGeometryQuery(String, XYGeometry...)}.
* @param field field name. must not be null.
* @param geometries array of XY geometries. must not be null or empty.
* @return query matching points within the given geometries.
* @throws IllegalArgumentException if {@code field} is null, {@code polygons} is null, empty or contains a null or XYLine geometry.
*/
public static Query newSlowGeometryQuery(String field, XYGeometry... geometries) {
return new XYDocValuesPointInGeometryQuery(field, geometries);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.apache.lucene.geo.Polygon;
import org.apache.lucene.geo.XYCircle;
import org.apache.lucene.geo.XYEncodingUtils;
import org.apache.lucene.geo.XYGeometry;
import org.apache.lucene.geo.XYPolygon;
import org.apache.lucene.geo.XYRectangle;
import org.apache.lucene.index.FieldInfo;
Expand All @@ -40,6 +41,7 @@
* <li>{@link #newBoxQuery newBoxQuery()} for matching points within a bounding box.
* <li>{@link #newDistanceQuery newDistanceQuery()} for matching points within a specified distance.
* <li>{@link #newPolygonQuery newPolygonQuery()} for matching points within an arbitrary polygon.
* <li>{@link #newGeometryQuery newGeometryQuery()} for matching points within an arbitrary geometry collection.
* </ul>
* <p>
* If you also need per-document operations such as sort by distance, add a separate {@link XYDocValuesField} instance.
Expand Down Expand Up @@ -167,6 +169,17 @@ public static Query newDistanceQuery(String field, float x, float y, float radiu
* @see Polygon
*/
public static Query newPolygonQuery(String field, XYPolygon... polygons) {
return new XYPointInGeometryQuery(field, polygons);
return newGeometryQuery(field, polygons);
}

/** create a query to find all indexed shapes that intersect a provided geometry collection. XYLine geometries are not supported.
* @param field field name. must not be null.
* @param xyGeometries array of geometries. must not be null or empty.
* @return query matching points within this geometry collection.
* @throws IllegalArgumentException if {@code field} is null, {@code polygons} is null, empty or contains a null or XYLine geometry.
* @see XYGeometry
**/
public static Query newGeometryQuery(String field, XYGeometry... xyGeometries) {
return new XYPointInGeometryQuery(field, xyGeometries);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.apache.lucene.document.Document;
import org.apache.lucene.document.XYDocValuesField;
import org.apache.lucene.geo.BaseXYPointTestCase;
import org.apache.lucene.geo.XYGeometry;
import org.apache.lucene.geo.XYPolygon;

public class TestXYDocValuesQueries extends BaseXYPointTestCase {
Expand All @@ -42,4 +43,9 @@ protected Query newDistanceQuery(String field, float centerX, float centerY, flo
protected Query newPolygonQuery(String field, XYPolygon... polygons) {
return XYDocValuesField.newSlowPolygonQuery(field, polygons);
}

@Override
protected Query newGeometryQuery(String field, XYGeometry... geometries) {
return XYDocValuesField.newSlowGeometryQuery(field, geometries);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.apache.lucene.document.Document;
import org.apache.lucene.document.XYPointField;
import org.apache.lucene.geo.BaseXYPointTestCase;
import org.apache.lucene.geo.XYGeometry;
import org.apache.lucene.geo.XYPolygon;

public class TestXYPointQueries extends BaseXYPointTestCase {
Expand All @@ -42,4 +43,9 @@ protected Query newDistanceQuery(String field, float centerX, float centerY, flo
protected Query newPolygonQuery(String field, XYPolygon... polygons) {
return XYPointField.newPolygonQuery(field, polygons);
}

@Override
protected Query newGeometryQuery(String field, XYGeometry... geometries) {
return XYPointField.newGeometryQuery(field, geometries);
}
}
Loading

0 comments on commit 8184bb7

Please sign in to comment.