Skip to content

Commit

Permalink
Refactors GeoBoundingBoxQueryBuilder/-Parser
Browse files Browse the repository at this point in the history
This add equals, hashcode, read/write methods, validation, separates toQuery
and JSON parsing and adds serialization and query generation tests.

Deprecates two types of initializing the bounding box: In our documentation we
speak about specifying top/left and bottom/right corner of a bounding box. Here
we also allow for top/right and bottom/left. This adds not only to the amount
of code but also testing needed w/o too much benefit for the user other than
more chances to confuse top/right/bottom/left/latitude/longitude IMHO.

Missing: The toQuery method with type set to "indexed" is not tested at the
moment.

Cleanup changes unrelated to base refactoring:
* Switched from type String to enum for types in GeoBoundingBoxQueryBuilder.
* Switched to using type GeoPoint for storing the bounding box coordinates
  instead of array of double values.

Relates to elastic#10217 for the query refactoring part.
Relates to elastic#12016 for how missing mappings are handled.

Adds a utility class for generating random geo data.

Adds some missing documentation.

Extend test to MEMORY type config

Fix final review comments and rebase
  • Loading branch information
Isabel Drost-Fromm committed Sep 20, 2015
1 parent 37cff7b commit 91b97a6
Show file tree
Hide file tree
Showing 12 changed files with 740 additions and 207 deletions.
1 change: 0 additions & 1 deletion core/src/main/java/org/elasticsearch/common/Numbers.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,5 +178,4 @@ public static boolean isValidDouble(double value) {
}
return true;
}

}
8 changes: 6 additions & 2 deletions core/src/main/java/org/elasticsearch/common/geo/GeoPoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable;
import java.io.IOException;

import java.io.IOException;

import org.apache.lucene.util.BitUtil;
import org.apache.lucene.util.XGeoHashUtils;
Expand Down Expand Up @@ -59,6 +59,10 @@ public GeoPoint(double lat, double lon) {
this.lon = lon;
}

public GeoPoint(GeoPoint template) {
this(template.getLat(), template.getLon());
}

public GeoPoint reset(double lat, double lon) {
this.lat = lat;
this.lon = lon;
Expand Down Expand Up @@ -175,7 +179,7 @@ public static GeoPoint fromGeohash(long geohashLong) {
public static GeoPoint fromIndexLong(long indexLong) {
return new GeoPoint().resetFromIndexHash(indexLong);
}

@Override
public GeoPoint readFrom(StreamInput in) throws IOException {
double lat = in.readDouble();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.lucene.spatial.prefix.tree.QuadPrefixTree;
import org.apache.lucene.util.SloppyMath;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.Numbers;
import org.elasticsearch.common.unit.DistanceUnit;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentParser.Token;
Expand Down
Loading

0 comments on commit 91b97a6

Please sign in to comment.