Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/changelog/84229.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 84229
summary: Normalise polygons only when necessary
area: Geo
type: enhancement
issues:
- 35349
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ public List<IndexableField> indexShape(Geometry geometry) {
if (geometry == null) {
return Collections.emptyList();
}
geometry = GeometryNormalizer.apply(orientation, geometry);
if (GeometryNormalizer.needsNormalize(orientation, geometry)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the code, needsNormalize does quite an extensive check, so I presume this adds some performance cost?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needsNormalize should run several times faster than the normalisation.

geometry = GeometryNormalizer.apply(orientation, geometry);
}
LuceneGeometryIndexer visitor = new LuceneGeometryIndexer(name);
geometry.visit(visitor);
return visitor.fields();
Expand Down Expand Up @@ -125,7 +127,7 @@ public Void visit(Point point) {

@Override
public Void visit(Polygon polygon) {
addFields(LatLonShape.createIndexableFields(name, GeoShapeUtils.toLucenePolygon(polygon)));
addFields(LatLonShape.createIndexableFields(name, GeoShapeUtils.toLucenePolygon(polygon), true));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The additional checks in the tesselator also add some performance cost.

Copy link
Contributor Author

@iverase iverase Mar 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the hope is that the overhead of checking for intersection in the tessellator is compensated with skipping the normalisation step.

return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public void testIgnoreMalformedValues() throws IOException {
ParsedDocument document = ignoreMapper.parse(sourceToParse);
assertThat(document.docs().get(0).getFields("field").length, equalTo(0));
MapperParsingException exception = expectThrows(MapperParsingException.class, () -> failMapper.parse(sourceToParse));
assertThat(exception.getCause().getMessage(), containsString("at least 4 polygon points required"));
assertThat(exception.getCause().getMessage(), containsString("at least three non-collinear points required"));
}
}

Expand Down