Skip to content

Commit 901550d

Browse files
committed
[DE-376] geo index legacy polygons
1 parent b9e5af5 commit 901550d

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 class IndexEntity implements Entity {
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
@@ -31,6 +31,7 @@ public class GeoIndexOptions extends IndexOptions<GeoIndexOptions> {
3131
private Iterable<String> fields;
3232
private final IndexType type = IndexType.geo;
3333
private Boolean geoJson;
34+
private Boolean legacyPolygons;
3435

3536
public GeoIndexOptions() {
3637
super();
@@ -72,4 +73,21 @@ public GeoIndexOptions geoJson(final Boolean geoJson) {
7273
return this;
7374
}
7475

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

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,6 +1323,9 @@ void createGeoIndex(ArangoCollection collection) {
13231323
} else {
13241324
assertThat(indexResult.getType()).isEqualTo(IndexType.geo1);
13251325
}
1326+
if (isAtLeastVersion(3, 10)) {
1327+
assertThat(indexResult.getLegacyPolygons()).isFalse();
1328+
}
13261329
}
13271330

13281331
@ParameterizedTest(name = "{index}")
@@ -1350,6 +1353,40 @@ void createGeoIndexWithOptions(ArangoCollection collection) {
13501353
assertThat(indexResult.getType()).isEqualTo(IndexType.geo1);
13511354
}
13521355
assertThat(indexResult.getName()).isEqualTo(name);
1356+
if (isAtLeastVersion(3, 10)) {
1357+
assertThat(indexResult.getLegacyPolygons()).isFalse();
1358+
}
1359+
}
1360+
1361+
@ParameterizedTest(name = "{index}")
1362+
@MethodSource("cols")
1363+
void createGeoIndexLegacyPolygons(ArangoCollection collection) {
1364+
assumeTrue(isAtLeastVersion(3, 10));
1365+
1366+
String name = "geoIndex-" + rnd();
1367+
final GeoIndexOptions options = new GeoIndexOptions();
1368+
options.name(name);
1369+
options.legacyPolygons(true);
1370+
1371+
String f1 = "field-" + rnd();
1372+
final Collection<String> fields = Collections.singletonList(f1);
1373+
final IndexEntity indexResult = collection.ensureGeoIndex(fields, options);
1374+
assertThat(indexResult).isNotNull();
1375+
assertThat(indexResult.getFields()).contains(f1);
1376+
assertThat(indexResult.getId()).startsWith(COLLECTION_NAME);
1377+
assertThat(indexResult.getIsNewlyCreated()).isTrue();
1378+
assertThat(indexResult.getMinLength()).isNull();
1379+
assertThat(indexResult.getSparse()).isTrue();
1380+
assertThat(indexResult.getUnique()).isFalse();
1381+
if (isAtLeastVersion(3, 4)) {
1382+
assertThat(indexResult.getType()).isEqualTo(IndexType.geo);
1383+
} else {
1384+
assertThat(indexResult.getType()).isEqualTo(IndexType.geo1);
1385+
}
1386+
assertThat(indexResult.getName()).isEqualTo(name);
1387+
if (isAtLeastVersion(3, 10)) {
1388+
assertThat(indexResult.getLegacyPolygons()).isTrue();
1389+
}
13531390
}
13541391

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

0 commit comments

Comments
 (0)