Skip to content

Commit af62580

Browse files
committed
Improve user-facing docs for geo package (#14534)
1 parent 0a354cb commit af62580

File tree

5 files changed

+142
-21
lines changed

5 files changed

+142
-21
lines changed

lucene/CHANGES.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ New Features
2222

2323
Improvements
2424
---------------------
25-
* GITHUB#14458 : Add an IndexDeletion policy that retains the last N commits. (Owais Kazi)
25+
* GITHUB#14458: Add an IndexDeletion policy that retains the last N commits. (Owais Kazi)
2626

2727
* GITHUB#14476: Removing unnecessary splitX in ComponentTree (Ankit Jain)
2828

29+
* GITHUB#14534: Improve user-facing docs for geo package (Ankit Jain)
30+
2931
* GITHUB#14602: Refactor the expressions compiler to use official ClassData BSM with indexed lookup
3032
(Uwe Schindler)
3133

lucene/core/src/java/org/apache/lucene/geo/Circle.java

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,43 @@
1717
package org.apache.lucene.geo;
1818

1919
/**
20-
* Represents a circle on the earth's surface.
20+
* Represents a circle on the Earth's surface defined by a center point and radius.
2121
*
22-
* <p>NOTES:
22+
* <p>The circle is defined using:
2323
*
24-
* <ol>
25-
* <li>Latitude/longitude values must be in decimal degrees.
26-
* <li>Radius must be in meters.
27-
* <li>For more advanced GeoSpatial indexing and query operations see the {@code spatial-extras}
28-
* module
29-
* </ol>
24+
* <ul>
25+
* <li>Center point (latitude/longitude in degrees)
26+
* <li>Radius in meters
27+
* </ul>
28+
*
29+
* <p>Important Notes:
30+
*
31+
* <ul>
32+
* <li>The circle is approximated on the spherical Earth model
33+
* <li>For very large circles or circles near poles, consider using polygons instead
34+
* <li>Dateline crossing is handled automatically
35+
* </ul>
36+
*
37+
* <p>Example usage:
38+
*
39+
* <pre>{@code
40+
* // Create a circle with 1km radius around the Eiffel Tower
41+
* Circle circle = new Circle(48.8584, 2.2945, 1000);
42+
*
43+
* // Create a query using this circle
44+
* Query query = LatLonShape.newDistanceQuery("location", circle);
45+
* }</pre>
3046
*
3147
* @lucene.experimental
3248
*/
3349
public final class Circle extends LatLonGeometry {
34-
/** Center latitude */
50+
/** Center latitude of the circle in degrees (-90 to 90) */
3551
private final double lat;
3652

37-
/** Center longitude */
53+
/** Center longitude of the circle in degrees (-180 to 180) */
3854
private final double lon;
3955

40-
/** radius in meters */
56+
/** radius of the circle in meters */
4157
private final double radiusMeters;
4258

4359
/** Creates a new circle from the supplied latitude/longitude center and a radius in meters.. */

lucene/core/src/java/org/apache/lucene/geo/GeoUtils.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,28 @@
2323
import org.apache.lucene.util.SloppyMath;
2424

2525
/**
26-
* Basic reusable geo-spatial utility methods
26+
* Utility methods for geo-spatial calculations and coordinate validation.
27+
*
28+
* <p>This class provides:
29+
*
30+
* <ul>
31+
* <li>Coordinate validation methods
32+
* <li>Earth model constants
33+
* <li>Common geometric calculations
34+
* <li>Coordinate normalization utilities
35+
* </ul>
36+
*
37+
* <p>Important Constants:
38+
*
39+
* <ul>
40+
* <li>Earth's mean radius: 6,371,008.7714 meters
41+
* <li>Latitude range: -90° to +90°
42+
* <li>Longitude range: -180° to +180°
43+
* </ul>
44+
*
45+
* <p>Note: This class uses a spherical Earth model for simplicity and performance. For applications
46+
* requiring higher precision, consider using a geodetic library that implements the WGS84 ellipsoid
47+
* model.
2748
*
2849
* @lucene.experimental
2950
*/

lucene/core/src/java/org/apache/lucene/geo/Rectangle.java

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,51 @@
3232
import static org.apache.lucene.util.SloppyMath.cos;
3333
import static org.apache.lucene.util.SloppyMath.sin;
3434

35-
/** Represents a lat/lon rectangle. */
35+
/**
36+
* Represents a rectangular bounding box on Earth's surface.
37+
*
38+
* <p>A rectangle is defined by its minimum and maximum latitude/longitude coordinates. It can cross
39+
* the dateline, in which case minLon &gt; maxLon.
40+
*
41+
* <p>Key Features:
42+
*
43+
* <ul>
44+
* <li>Handles dateline crossing automatically
45+
* <li>Supports point-in-box testing
46+
* <li>Can be used to create spatial queries
47+
* <li>Useful for creating bounding boxes around other shapes
48+
* </ul>
49+
*
50+
* <p>Example usage:
51+
*
52+
* <pre>{@code
53+
* // Create a rectangle covering central London
54+
* Rectangle bbox = new Rectangle(51.4, 51.6, -0.2, 0.0);
55+
*
56+
* // Create a rectangle crossing the dateline
57+
* Rectangle datelineBox = new Rectangle(20, 30, 170, -170);
58+
*
59+
* // Create a bounding box around a point with given radius
60+
* Rectangle circle = Rectangle.fromPointDistance(lat, lon, radiusMeters);
61+
* }</pre>
62+
*
63+
* <p>Note: When working with areas near poles, consider that rectangles become highly distorted and
64+
* may not provide accurate representation of the actual area.
65+
*/
3666
public class Rectangle extends LatLonGeometry {
37-
/** maximum longitude value (in degrees) */
67+
/** Minimum latitude in degrees (-90 to 90) */
3868
public final double minLat;
3969

40-
/** minimum longitude value (in degrees) */
41-
public final double minLon;
42-
43-
/** maximum latitude value (in degrees) */
70+
/** Maximum latitude in degrees (-90 to 90) */
4471
public final double maxLat;
4572

46-
/** minimum latitude value (in degrees) */
73+
/**
74+
* Minimum longitude in degrees (-180 to 180). May be greater than maxLon when crossing the
75+
* dateline.
76+
*/
77+
public final double minLon;
78+
79+
/** Maximum longitude in degrees (-180 to 180) */
4780
public final double maxLon;
4881

4982
/**

lucene/core/src/java/org/apache/lucene/geo/package-info.java

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,54 @@
1515
* limitations under the License.
1616
*/
1717

18-
/** Geospatial Utility Implementations for Lucene Core */
18+
/**
19+
* Core geo-spatial types and utilities for handling geographical data and spatial operations in
20+
* Lucene.
21+
*
22+
* <h2>Overview</h2>
23+
*
24+
* This package provides classes for representing, indexing, and querying geographical data in
25+
* Lucene. It uses the WGS84 coordinate system with latitude/longitude pairs to represent points on
26+
* Earth.
27+
*
28+
* <h2>Core Concepts</h2>
29+
*
30+
* <ul>
31+
* <li>Coordinate System: WGS84 (World Geodetic System 1984)
32+
* <ul>
33+
* <li>Latitude: -90° to +90° (negative for South, positive for North)
34+
* <li>Longitude: -180° to +180° (negative for West, positive for East)
35+
* </ul>
36+
* <li>Distance calculations use haversine formula on a spherical Earth model
37+
* <li>Areas near poles and the dateline receive special handling
38+
* </ul>
39+
*
40+
* <h2>Key Components</h2>
41+
*
42+
* <ul>
43+
* <li>{@link org.apache.lucene.geo.Point}: Represents a point on Earth's surface
44+
* <li>{@link org.apache.lucene.geo.Rectangle}: Defines a bounding box for spatial queries
45+
* <li>{@link org.apache.lucene.geo.Circle}: Represents a circular area with a center point and
46+
* radius
47+
* <li>{@link org.apache.lucene.geo.Polygon}: Represents an arbitrary polygon shape
48+
* <li>{@link org.apache.lucene.geo.Line}: Represents a path or line string
49+
* </ul>
50+
*
51+
* <h2>Common Operations</h2>
52+
*
53+
* <ul>
54+
* <li>Distance calculations between points
55+
* <li>Point-in-polygon testing
56+
* <li>Rectangle containment and intersection
57+
* <li>Creation of bounding boxes
58+
* <li>Polygon validation and preprocessing
59+
* </ul>
60+
*
61+
* <h2>Usage Examples</h2>
62+
*
63+
* <pre>{@code
64+
* Rectangle bbox = Rectangle.fromPointDistance(51.5, -0.12, 5000); // 5km around London
65+
* Circle circle = new Circle(48.8566, 2.3522, 1000); // 1km around Paris
66+
* }</pre>
67+
*/
1968
package org.apache.lucene.geo;

0 commit comments

Comments
 (0)