diff --git a/baremaps-core/src/main/java/org/apache/baremaps/geocoder/DataRowMapper.java b/baremaps-core/src/main/java/org/apache/baremaps/geocoder/DataRowMapper.java index 2475a84c5..7414dfd8e 100644 --- a/baremaps-core/src/main/java/org/apache/baremaps/geocoder/DataRowMapper.java +++ b/baremaps-core/src/main/java/org/apache/baremaps/geocoder/DataRowMapper.java @@ -29,17 +29,7 @@ import org.apache.baremaps.data.storage.DataColumn; import org.apache.baremaps.data.storage.DataRow; import org.apache.baremaps.data.storage.DataSchema; -import org.apache.lucene.document.Document; -import org.apache.lucene.document.DoublePoint; -import org.apache.lucene.document.Field; -import org.apache.lucene.document.FloatPoint; -import org.apache.lucene.document.IntPoint; -import org.apache.lucene.document.LatLonPoint; -import org.apache.lucene.document.LatLonShape; -import org.apache.lucene.document.LongPoint; -import org.apache.lucene.document.StoredField; -import org.apache.lucene.document.StringField; -import org.apache.lucene.document.TextField; +import org.apache.lucene.document.*; import org.locationtech.jts.geom.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -54,123 +44,120 @@ public Document apply(DataRow dataRow) { DataSchema schema = dataRow.schema(); List columns = schema.columns(); for (int i = 0; i < columns.size(); i++) { - DataColumn column = columns.get(i); - String columnName = column.name(); Object value = dataRow.get(i); - if (value == null) + if (value == null) { continue; - DataColumn.Type type = column.type(); + } + + DataColumn column = columns.get(i); + applyValue(column, doc, value); + } + return doc; + } - try { - switch (type) { - case BINARY: - doc.add(new StoredField(columnName, (byte[]) value)); - break; - case BYTE: - doc.add(new IntPoint(columnName, ((Byte) value).intValue())); - doc.add(new StoredField(columnName, ((Byte) value).intValue())); - break; - case BOOLEAN: - doc.add(new StringField(columnName, value.toString(), Field.Store.YES)); - break; - case SHORT: - doc.add(new IntPoint(columnName, ((Short) value).intValue())); - doc.add(new StoredField(columnName, ((Short) value).intValue())); - break; - case INTEGER: - doc.add(new IntPoint(columnName, (Integer) value)); - doc.add(new StoredField(columnName, (Integer) value)); - break; - case LONG: - doc.add(new LongPoint(columnName, (Long) value)); - doc.add(new StoredField(columnName, (Long) value)); - break; - case FLOAT: - doc.add(new FloatPoint(columnName, (Float) value)); - doc.add(new StoredField(columnName, (Float) value)); - break; - case DOUBLE: - doc.add(new DoublePoint(columnName, (Double) value)); - doc.add(new StoredField(columnName, (Double) value)); - break; - case STRING: - doc.add(new TextField(columnName, (String) value, Field.Store.YES)); - break; - case COORDINATE: - Coordinate coord = (Coordinate) value; - double lat = coord.getY(); - double lon = coord.getX(); - doc.add(new LatLonPoint(columnName, lat, lon)); - doc.add(new StoredField(columnName + "_lat", lat)); - doc.add(new StoredField(columnName + "_lon", lon)); - break; - case POINT: - Point point = (Point) value; - double pointLat = point.getY(); - double pointLon = point.getX(); - doc.add(new LatLonPoint(columnName, pointLat, pointLon)); - doc.add(new StoredField(columnName + "_lat", pointLat)); - doc.add(new StoredField(columnName + "_lon", pointLon)); - break; - case LINESTRING: - case POLYGON: - case MULTIPOINT: - case MULTILINESTRING: - case MULTIPOLYGON: - case GEOMETRYCOLLECTION: - case GEOMETRY: - Geometry geometry = (Geometry) value; - if (geometry != null) { - Field[] shapeFields = createShapeFields(columnName, geometry); - for (Field field : shapeFields) { - doc.add(field); - } - doc.add(new StoredField(columnName + "_wkt", geometry.toText())); + private void applyValue(DataColumn column, Document doc, Object value) { + String columnName = column.name(); + DataColumn.Type type = column.type(); + try { + switch (type) { + case BINARY: + doc.add(new StoredField(columnName, (byte[]) value)); + break; + case BYTE: + doc.add(new IntPoint(columnName, ((Byte) value).intValue())); + doc.add(new StoredField(columnName, ((Byte) value).intValue())); + break; + case BOOLEAN: + doc.add(new StringField(columnName, value.toString(), Field.Store.YES)); + break; + case SHORT: + doc.add(new IntPoint(columnName, ((Short) value).intValue())); + doc.add(new StoredField(columnName, ((Short) value).intValue())); + break; + case INTEGER: + doc.add(new IntPoint(columnName, (Integer) value)); + doc.add(new StoredField(columnName, (Integer) value)); + break; + case LONG: + doc.add(new LongPoint(columnName, (Long) value)); + doc.add(new StoredField(columnName, (Long) value)); + break; + case FLOAT: + doc.add(new FloatPoint(columnName, (Float) value)); + doc.add(new StoredField(columnName, (Float) value)); + break; + case DOUBLE: + doc.add(new DoublePoint(columnName, (Double) value)); + doc.add(new StoredField(columnName, (Double) value)); + break; + case STRING: + doc.add(new TextField(columnName, (String) value, Field.Store.YES)); + break; + case COORDINATE: + Coordinate coord = (Coordinate) value; + double lat = coord.getY(); + double lon = coord.getX(); + doc.add(new LatLonPoint(columnName, lat, lon)); + doc.add(new StoredField(columnName + "_lat", lat)); + doc.add(new StoredField(columnName + "_lon", lon)); + break; + case POINT: + Point point = (Point) value; + double pointLat = point.getY(); + double pointLon = point.getX(); + doc.add(new LatLonPoint(columnName, pointLat, pointLon)); + doc.add(new StoredField(columnName + "_lat", pointLat)); + doc.add(new StoredField(columnName + "_lon", pointLon)); + break; + case LINESTRING, POLYGON, MULTIPOINT, MULTILINESTRING, MULTIPOLYGON, GEOMETRYCOLLECTION, GEOMETRY: + Geometry geometry = (Geometry) value; + if (geometry != null) { + Field[] shapeFields = createShapeFields(columnName, geometry); + for (Field field : shapeFields) { + doc.add(field); } - break; - case ENVELOPE: - Envelope envelope = (Envelope) value; - String envelopeStr = envelope.toString(); - doc.add(new StringField(columnName, envelopeStr, Field.Store.YES)); - break; - case INET_ADDRESS: - case INET4_ADDRESS: - case INET6_ADDRESS: - InetAddress addr = (InetAddress) value; - doc.add(new StringField(columnName, addr.getHostAddress(), Field.Store.YES)); - break; - case LOCAL_DATE: - LocalDate date = (LocalDate) value; - doc.add(new StringField(columnName, date.toString(), Field.Store.YES)); - break; - case LOCAL_TIME: - LocalTime time = (LocalTime) value; - doc.add(new StringField(columnName, time.toString(), Field.Store.YES)); - break; - case LOCAL_DATE_TIME: - LocalDateTime dateTime = (LocalDateTime) value; - doc.add(new StringField(columnName, dateTime.toString(), Field.Store.YES)); - break; - case NESTED: - Map map = (Map) value; - for (Map.Entry entry : map.entrySet()) { - String nestedKey = columnName + "." + entry.getKey(); - Object nestedValue = entry.getValue(); - if (nestedValue != null) { - doc.add(new TextField(nestedKey, nestedValue.toString(), Field.Store.YES)); - } + doc.add(new StoredField(columnName + "_wkt", geometry.toText())); + } + break; + case ENVELOPE: + Envelope envelope = (Envelope) value; + String envelopeStr = envelope.toString(); + doc.add(new StringField(columnName, envelopeStr, Field.Store.YES)); + break; + case INET_ADDRESS, INET4_ADDRESS, INET6_ADDRESS: + InetAddress addr = (InetAddress) value; + doc.add(new StringField(columnName, addr.getHostAddress(), Field.Store.YES)); + break; + case LOCAL_DATE: + LocalDate date = (LocalDate) value; + doc.add(new StringField(columnName, date.toString(), Field.Store.YES)); + break; + case LOCAL_TIME: + LocalTime time = (LocalTime) value; + doc.add(new StringField(columnName, time.toString(), Field.Store.YES)); + break; + case LOCAL_DATE_TIME: + LocalDateTime dateTime = (LocalDateTime) value; + doc.add(new StringField(columnName, dateTime.toString(), Field.Store.YES)); + break; + case NESTED: + Map map = (Map) value; + for (Map.Entry entry : map.entrySet()) { + String nestedKey = columnName + "." + entry.getKey(); + Object nestedValue = entry.getValue(); + if (nestedValue != null) { + doc.add(new TextField(nestedKey, nestedValue.toString(), Field.Store.YES)); } - break; - default: - doc.add(new StringField(columnName, value.toString(), Field.Store.YES)); - break; - } - } catch (Exception e) { - logger.error("Error processing column '{}' with value '{}': {}", columnName, value, - e.getMessage()); + } + break; + default: + doc.add(new StringField(columnName, value.toString(), Field.Store.YES)); + break; } + } catch (Exception e) { + logger.error("Error processing column '{}' with value '{}': {}", columnName, value, + e.getMessage()); } - return doc; } private Field[] createShapeFields(String fieldName, Geometry geometry) { diff --git a/baremaps-core/src/main/java/org/apache/baremaps/geocoder/DataTableQueryBuilder.java b/baremaps-core/src/main/java/org/apache/baremaps/geocoder/DataTableQueryBuilder.java index b654f1832..947907b3b 100644 --- a/baremaps-core/src/main/java/org/apache/baremaps/geocoder/DataTableQueryBuilder.java +++ b/baremaps-core/src/main/java/org/apache/baremaps/geocoder/DataTableQueryBuilder.java @@ -130,13 +130,4 @@ public Query build() { builder.add(termsQuery, BooleanClause.Occur.MUST); return builder.build(); } - - /** - * Get the analyzer. - * - * @return the analyzer - */ - private static Analyzer getAnalyzer() { - return GeocoderConstants.ANALYZER; - } } diff --git a/baremaps-data/src/main/java/org/apache/baremaps/data/storage/DataSchemaImpl.java b/baremaps-data/src/main/java/org/apache/baremaps/data/storage/DataSchemaImpl.java index 81dfc4036..e0f79b8e8 100644 --- a/baremaps-data/src/main/java/org/apache/baremaps/data/storage/DataSchemaImpl.java +++ b/baremaps-data/src/main/java/org/apache/baremaps/data/storage/DataSchemaImpl.java @@ -25,31 +25,6 @@ */ public record DataSchemaImpl(String name, List columns) implements DataSchema { - /** - * Constructs a schema with the specified name and columns. - * - * @param name the name of the schema - * @param columns the columns of the schema - */ - public DataSchemaImpl { - } - - /** - * {@inheritDoc} - */ - @Override - public String name() { - return name; - } - - /** - * {@inheritDoc} - */ - @Override - public List columns() { - return columns; - } - /** * {@inheritDoc} */