Skip to content

Commit 8466a42

Browse files
JNS87Michael Nitschinger
authored andcommitted
JCBC-1613: Add experimental support for FTS polygon queries.
To have a way to perform geo polygon query via the SDK, Added a GeoPolygonQuery class, as well as a geoPolygon factory method. Change-Id: I69659c5fb30d8260870a0087230cb390467900ce Reviewed-on: http://review.couchbase.org/c/couchbase-java-client/+/124218 Reviewed-by: David Nault <david.nault@couchbase.com> Tested-by: David Nault <david.nault@couchbase.com>
1 parent d8bf968 commit 8466a42

File tree

3 files changed

+125
-1
lines changed

3 files changed

+125
-1
lines changed

src/main/java/com/couchbase/client/java/search/SearchQuery.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package com.couchbase.client.java.search;
1717

1818
import java.util.HashMap;
19+
import java.util.List;
1920
import java.util.Map;
2021
import java.util.concurrent.TimeUnit;
2122

@@ -32,11 +33,13 @@
3233
import com.couchbase.client.java.search.queries.BooleanFieldQuery;
3334
import com.couchbase.client.java.search.queries.BooleanQuery;
3435
import com.couchbase.client.java.search.queries.ConjunctionQuery;
36+
import com.couchbase.client.java.search.queries.Coordinate;
3537
import com.couchbase.client.java.search.queries.DateRangeQuery;
3638
import com.couchbase.client.java.search.queries.DisjunctionQuery;
3739
import com.couchbase.client.java.search.queries.DocIdQuery;
3840
import com.couchbase.client.java.search.queries.GeoBoundingBoxQuery;
3941
import com.couchbase.client.java.search.queries.GeoDistanceQuery;
42+
import com.couchbase.client.java.search.queries.GeoPolygonQuery;
4043
import com.couchbase.client.java.search.queries.MatchAllQuery;
4144
import com.couchbase.client.java.search.queries.MatchNoneQuery;
4245
import com.couchbase.client.java.search.queries.MatchPhraseQuery;
@@ -53,7 +56,6 @@
5356
import com.couchbase.client.java.search.result.SearchQueryRow;
5457
import com.couchbase.client.java.search.sort.SearchSort;
5558
import com.couchbase.client.java.subdoc.DocumentFragment;
56-
import rx.Observable;
5759

5860
/**
5961
* The FTS API entry point. Describes an FTS query entirely (index, query body and parameters) and can
@@ -614,4 +616,11 @@ public static GeoBoundingBoxQuery geoBoundingBox(double topLeftLon, double topLe
614616
public static GeoDistanceQuery geoDistance(double locationLon, double locationLat, String distance) {
615617
return new GeoDistanceQuery(locationLon, locationLat, distance);
616618
}
619+
620+
/** Prepare a {@link GeoPolygonQuery} body. */
621+
@InterfaceStability.Experimental
622+
public static GeoPolygonQuery geoPolygon(final List<Coordinate> points) {
623+
return new GeoPolygonQuery(points);
624+
}
625+
617626
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (c) 2020 Couchbase, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.couchbase.client.java.search.queries;
17+
18+
import com.couchbase.client.core.annotations.InterfaceAudience;
19+
import com.couchbase.client.core.annotations.InterfaceStability;
20+
21+
/**
22+
* The {@link Coordinate} represents the longitude and latitude of a point.
23+
*
24+
* @author Jyotsna Nayak
25+
*/
26+
@InterfaceStability.Experimental
27+
@InterfaceAudience.Public
28+
public class Coordinate {
29+
30+
private final double lon;
31+
private final double lat;
32+
33+
public static Coordinate ofLonLat(double lon, double lat) {
34+
return new Coordinate(lon, lat);
35+
}
36+
37+
private Coordinate(final double lon, final double lat) {
38+
this.lon = lon;
39+
this.lat = lat;
40+
}
41+
42+
public double lon() {
43+
return lon;
44+
}
45+
46+
public double lat() {
47+
return lat;
48+
}
49+
50+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright (c) 2017 Couchbase, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.couchbase.client.java.search.queries;
17+
18+
import java.util.List;
19+
20+
import com.couchbase.client.core.annotations.InterfaceAudience;
21+
import com.couchbase.client.core.annotations.InterfaceStability;
22+
import com.couchbase.client.java.document.json.JsonArray;
23+
import com.couchbase.client.java.document.json.JsonObject;
24+
25+
/**
26+
* A FTS query which allows to match on geo polygons.
27+
*
28+
* @author Jyotsna Nayak
29+
*/
30+
@InterfaceStability.Experimental
31+
@InterfaceAudience.Public
32+
public class GeoPolygonQuery extends AbstractFtsQuery {
33+
34+
private final List<Coordinate> coordinates;
35+
36+
private String field;
37+
38+
public GeoPolygonQuery(final List<Coordinate> coordinates) {
39+
this.coordinates = coordinates;
40+
}
41+
42+
public GeoPolygonQuery field(final String field) {
43+
this.field = field;
44+
return this;
45+
}
46+
47+
@Override
48+
public GeoPolygonQuery boost(double boost) {
49+
super.boost(boost);
50+
return this;
51+
}
52+
53+
@Override
54+
protected void injectParams(final JsonObject input) {
55+
JsonArray points = JsonArray.empty();
56+
for (Coordinate coordinate : coordinates) {
57+
points.add(JsonArray.from(coordinate.lon(), coordinate.lat()));
58+
}
59+
input.put("polygon_points", points);
60+
61+
if (field != null) {
62+
input.put("field", field);
63+
}
64+
}
65+
}

0 commit comments

Comments
 (0)