Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'type' field to geocodejson output #473

Merged
merged 1 commit into from
Jun 24, 2020
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
4 changes: 4 additions & 0 deletions es/mappings.json
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,10 @@
"type": "keyword",
"index": true
},
"object_type": {
"type": "text",
"index": false
},
"postcode": {
"type": "text",
"index": false,
Expand Down
1 change: 1 addition & 0 deletions src/main/java/de/komoot/photon/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ public class Constants {
public static final String OSM_TYPE = "osm_type";
public static final String OSM_KEY = "osm_key";
public static final String OSM_VALUE = "osm_value";
public static final String OBJECT_TYPE = "object_type";
}
23 changes: 19 additions & 4 deletions src/main/java/de/komoot/photon/PhotonDoc.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class PhotonDoc {
final private double importance;
final private CountryCode countryCode;
final private long linkedPlaceId; // 0 if unset
final private int rankSearch;
final private int rankAddress;

private Map<String, String> street;
private Map<String, String> locality;
Expand All @@ -46,7 +46,7 @@ public class PhotonDoc {
private String houseNumber;
private Point centroid;

public PhotonDoc(long placeId, String osmType, long osmId, String tagKey, String tagValue, Map<String, String> name, String houseNumber, Map<String, String> address, Map<String, String> extratags, Envelope bbox, long parentPlaceId, double importance, CountryCode countryCode, Point centroid, long linkedPlaceId, int rankSearch) {
public PhotonDoc(long placeId, String osmType, long osmId, String tagKey, String tagValue, Map<String, String> name, String houseNumber, Map<String, String> address, Map<String, String> extratags, Envelope bbox, long parentPlaceId, double importance, CountryCode countryCode, Point centroid, long linkedPlaceId, int rankAddress) {
String place = extratags != null ? extratags.get("place") : null;
if (place != null) {
// take more specific extra tag information
Expand All @@ -69,7 +69,7 @@ public PhotonDoc(long placeId, String osmType, long osmId, String tagKey, String
this.countryCode = countryCode;
this.centroid = centroid;
this.linkedPlaceId = linkedPlaceId;
this.rankSearch = rankSearch;
this.rankAddress = rankAddress;
}

public PhotonDoc(PhotonDoc other) {
Expand All @@ -89,7 +89,7 @@ public PhotonDoc(PhotonDoc other) {
this.countryCode = other.countryCode;
this.centroid = other.centroid;
this.linkedPlaceId = other.linkedPlaceId;
this.rankSearch = other.rankSearch;
this.rankAddress = other.rankAddress;
this.street = other.street;
this.locality = other.locality;
this.district = other.district;
Expand All @@ -115,6 +115,21 @@ public static PhotonDoc create(long placeId, String osmType, long osmId, Map<Str
"", null, null, null, 0, 0, null, null, 0, 0);
}

/**
* Return the GeocodeJSON place type.
*
* @return A string representation of the type
*/
public final String getObjectType() {
if (rankAddress >= 28) return "house";
if (rankAddress >= 26) return "street";
if (rankAddress >= 13 && rankAddress <= 16) return "city";
if (rankAddress >= 5 && rankAddress <= 12) return "region";
if (rankAddress == 4) return "country";

return "locality";
}

public boolean isUsefulForIndex() {
if ("place".equals(tagKey) && "houses".equals(tagValue)) return false;

Expand Down
1 change: 1 addition & 0 deletions src/main/java/de/komoot/photon/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public static XContentBuilder convert(PhotonDoc doc, String[] languages) throws
.field(Constants.OSM_TYPE, doc.getOsmType())
.field(Constants.OSM_KEY, doc.getTagKey())
.field(Constants.OSM_VALUE, doc.getTagValue())
.field(Constants.OBJECT_TYPE, doc.getObjectType())
.field(Constants.IMPORTANCE, doc.getImportance());

if (doc.getCentroid() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public NominatimResult mapRow(ResultSet rs, int rowNum) throws SQLException {
CountryCode.getByCode(rs.getString("country_code")),
(Point) DBUtils.extractGeometry(rs, "centroid"),
rs.getLong("linked_place_id"),
rs.getInt("rank_search")
rs.getInt("rank_address")
);

doc.setPostcode(rs.getString("postcode"));
Expand All @@ -207,7 +207,7 @@ public NominatimResult mapRow(ResultSet rs, int rowNum) throws SQLException {
return result;
}
};
private final String selectColsPlaceX = "place_id, osm_type, osm_id, class, type, name, housenumber, postcode, address, extratags, ST_Envelope(geometry) AS bbox, parent_place_id, linked_place_id, rank_search, importance, country_code, centroid";
private final String selectColsPlaceX = "place_id, osm_type, osm_id, class, type, name, housenumber, postcode, address, extratags, ST_Envelope(geometry) AS bbox, parent_place_id, linked_place_id, rank_address, rank_search, importance, country_code, centroid";
private final String selectColsOsmline = "place_id, osm_id, parent_place_id, startnumber, endnumber, interpolationtype, postcode, country_code, linegeo";
private final String selectColsAddress = "p.place_id, p.name, p.class, p.type, p.rank_address";
private Importer importer;
Expand Down Expand Up @@ -282,7 +282,7 @@ public AddressRow mapRow(ResultSet rs, int rowNum) throws SQLException {
}
};

boolean isPoi = doc.getRankSearch() > 28;
boolean isPoi = doc.getRankAddress() > 28;
long placeId = (isPoi) ? doc.getParentPlaceId() : doc.getPlaceId();

List<AddressRow> terms = template.query("SELECT " + selectColsAddress + " FROM placex p, place_addressline pa WHERE p.place_id = pa.address_place_id and pa.place_id = ? and pa.cached_rank_address > 4 and pa.address_place_id != ? and pa.isaddress order by rank_address desc,fromarea desc,distance asc,rank_search desc", new Object[]{placeId, placeId}, rowMapper);
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/de/komoot/photon/utils/ConvertToJson.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public List<JSONObject> convert(SearchResponse searchResponse) {
properties.put(key, getLocalised(source, key, lang));
}

// place type
properties.put("type", source.get(Constants.OBJECT_TYPE));

// add extent of geometry
final Map<String, Object> extent = (Map<String, Object>) source.get("extent");
if (extent != null) {
Expand Down