Skip to content

Commit 389590e

Browse files
committed
[DE-376] geo index legacy polygons
(cherry picked from commit 901550d)
1 parent af43f69 commit 389590e

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
lines changed

src/main/java/com/arangodb/entity/IndexEntity.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ public final class IndexEntity {
4242
private Integer expireAfter;
4343
private Boolean inBackground;
4444
private Boolean estimates;
45-
4645
private Boolean cacheEnabled;
46+
private Boolean legacyPolygons;
4747

4848
public IndexEntity() {
4949
super();
@@ -113,4 +113,8 @@ public Boolean getCacheEnabled() {
113113
return cacheEnabled;
114114
}
115115

116+
public Boolean getLegacyPolygons() {
117+
return legacyPolygons;
118+
}
119+
116120
}

src/main/java/com/arangodb/model/GeoIndexOptions.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public final class GeoIndexOptions extends IndexOptions<GeoIndexOptions> {
3232
private final IndexType type = IndexType.geo;
3333
private Iterable<String> fields;
3434
private Boolean geoJson;
35+
private Boolean legacyPolygons;
3536

3637
public GeoIndexOptions() {
3738
super();
@@ -73,4 +74,21 @@ public GeoIndexOptions geoJson(final Boolean geoJson) {
7374
return this;
7475
}
7576

77+
public Boolean getLegacyPolygons() {
78+
return legacyPolygons;
79+
}
80+
81+
/**
82+
* @param legacyPolygons If `true` will use the old rules (pre-3.10) for the parsing GeoJSON polygons. This
83+
* allows you to let old indexes produce the same, potentially wrong results as before an
84+
* upgrade. A geo index with `legacyPolygons` set to `false` will use the new, correct and
85+
* consistent method for parsing of GeoJSON polygons.
86+
* See <a href="https://www.arangodb.com/docs/stable/indexing-geo.html#legacy-polygons">Legacy Polygons</a>.
87+
* @return options
88+
* @since ArangoDB 3.10
89+
*/
90+
public GeoIndexOptions legacyPolygons(final Boolean legacyPolygons) {
91+
this.legacyPolygons = legacyPolygons;
92+
return this;
93+
}
7694
}

src/test/java/com/arangodb/ArangoCollectionTest.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,6 +1302,9 @@ void createGeoIndex(ArangoCollection collection) {
13021302
} else {
13031303
assertThat(indexResult.getType()).isEqualTo(IndexType.geo1);
13041304
}
1305+
if (isAtLeastVersion(3, 10)) {
1306+
assertThat(indexResult.getLegacyPolygons()).isFalse();
1307+
}
13051308
}
13061309

13071310
@ParameterizedTest(name = "{index}")
@@ -1329,6 +1332,40 @@ void createGeoIndexWithOptions(ArangoCollection collection) {
13291332
assertThat(indexResult.getType()).isEqualTo(IndexType.geo1);
13301333
}
13311334
assertThat(indexResult.getName()).isEqualTo(name);
1335+
if (isAtLeastVersion(3, 10)) {
1336+
assertThat(indexResult.getLegacyPolygons()).isFalse();
1337+
}
1338+
}
1339+
1340+
@ParameterizedTest(name = "{index}")
1341+
@MethodSource("cols")
1342+
void createGeoIndexLegacyPolygons(ArangoCollection collection) {
1343+
assumeTrue(isAtLeastVersion(3, 10));
1344+
1345+
String name = "geoIndex-" + rnd();
1346+
final GeoIndexOptions options = new GeoIndexOptions();
1347+
options.name(name);
1348+
options.legacyPolygons(true);
1349+
1350+
String f1 = "field-" + rnd();
1351+
final Collection<String> fields = Collections.singletonList(f1);
1352+
final IndexEntity indexResult = collection.ensureGeoIndex(fields, options);
1353+
assertThat(indexResult).isNotNull();
1354+
assertThat(indexResult.getFields()).contains(f1);
1355+
assertThat(indexResult.getId()).startsWith(COLLECTION_NAME);
1356+
assertThat(indexResult.getIsNewlyCreated()).isTrue();
1357+
assertThat(indexResult.getMinLength()).isNull();
1358+
assertThat(indexResult.getSparse()).isTrue();
1359+
assertThat(indexResult.getUnique()).isFalse();
1360+
if (isAtLeastVersion(3, 4)) {
1361+
assertThat(indexResult.getType()).isEqualTo(IndexType.geo);
1362+
} else {
1363+
assertThat(indexResult.getType()).isEqualTo(IndexType.geo1);
1364+
}
1365+
assertThat(indexResult.getName()).isEqualTo(name);
1366+
if (isAtLeastVersion(3, 10)) {
1367+
assertThat(indexResult.getLegacyPolygons()).isTrue();
1368+
}
13321369
}
13331370

13341371
@ParameterizedTest(name = "{index}")

0 commit comments

Comments
 (0)