Skip to content

Commit

Permalink
Merge pull request #468 from mfdz/county
Browse files Browse the repository at this point in the history
Import and index county field
  • Loading branch information
lonvia authored Jun 10, 2020
2 parents 2a9a871 + cf70c6e commit 126c544
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 26 deletions.
41 changes: 40 additions & 1 deletion es/mappings.json
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,46 @@
]
}
}
}
},
"county": {
"properties": {
"de": {
"type": "text",
"index": false,
"copy_to": [
"collector.de"
]
},
"default": {
"type": "text",
"index": false,
"copy_to": [
"collector.default"
]
},
"en": {
"type": "text",
"index": false,
"copy_to": [
"collector.en"
]
},
"fr": {
"type": "text",
"index": false,
"copy_to": [
"collector.fr"
]
},
"it": {
"type": "text",
"index": false,
"copy_to": [
"collector.it"
]
}
}
}
}
}
}
43 changes: 18 additions & 25 deletions src/main/java/de/komoot/photon/PhotonDoc.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class PhotonDoc {
private Map<String, String> locality;
private Map<String, String> district;
private Map<String, String> city;
private Map<String, String> county; // careful, this is county not count_r_y
private Set<Map<String, String>> context = new HashSet<Map<String, String>>();
private Map<String, String> country;
private Map<String, String> state;
Expand Down Expand Up @@ -93,6 +94,7 @@ public PhotonDoc(PhotonDoc other) {
this.locality = other.locality;
this.district = other.district;
this.city = other.city;
this.county= other.county;
this.context = other.context;
this.country = other.country;
this.state = other.state;
Expand Down Expand Up @@ -131,30 +133,12 @@ public boolean isUsefulForIndex() {
public void completeFromAddress() {
if (address == null) return;

String addressStreet = address.get("street");
if (addressStreet != null) {
this.street = nullToEmptyMap(this.street);
setOrReplace(addressStreet, this.street, "street");
}

String addressCity = address.get("city");
if (addressCity != null) {
this.city = nullToEmptyMap(this.city);
setOrReplace(addressCity, this.city, "city");
}

String addressDistrict = address.get("suburb");
if (addressDistrict != null) {
this.district = nullToEmptyMap(this.district);
setOrReplace(addressDistrict, this.district, "suburb");
}

String addressLocality = address.get("neighbourhood");
if (addressLocality != null) {
this.locality = nullToEmptyMap(this.locality);
setOrReplace(addressLocality, this.locality, "neighbourhood");
}

this.street = extractAddress(this.street, address, "street");
this.city = extractAddress(this.city, address, "city");
this.district = extractAddress(this.district, address, "suburb");
this.locality = extractAddress(this.locality, address, "neighbourhood");
this.county = extractAddress(this.county, address, "county");

String addressPostCode = address.get("postcode");
if (addressPostCode != null && !addressPostCode.equals(this.postcode)) {
if (log.isDebugEnabled()) {
Expand All @@ -164,7 +148,16 @@ public void completeFromAddress() {
}
}

private static Map<String, String> nullToEmptyMap(Map<String, String> map) {
private Map<String, String> extractAddress(Map<String, String> existingField, Map<String, String> completeAddress, String addressFieldName) {
String field = completeAddress.get(addressFieldName);
if(field != null) {
Map<String, String> map = nullToEmptyMap(existingField);
setOrReplace(field, map, addressFieldName);
return map;
} else return null;
}

private Map<String, String> nullToEmptyMap(Map<String, String> map) {
if (map == null) {
return new HashMap<>();
} else return map;
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 @@ -55,6 +55,7 @@ public static XContentBuilder convert(PhotonDoc doc, String[] languages) throws
writeIntlNames(builder, doc.getStreet(), "street", languages);
writeIntlNames(builder, doc.getLocality(), "locality", languages);
writeIntlNames(builder, doc.getDistrict(), "district", languages);
writeIntlNames(builder, doc.getCounty(), "county", languages);
writeContext(builder, doc.getContext(), languages);
writeExtent(builder, doc.getBbox());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,11 @@ private void completePlace(PhotonDoc doc) {
continue;
}

if (address.isCounty() && doc.getCounty() == null) {
doc.setCounty(address.getName());
continue;
}

if (address.isState() && doc.getState() == null) {
doc.setState(address.getName());
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ public boolean isCity() {
return 13 <= rankAddress && rankAddress <= 16;
}

/**
* @return whether nominatim thinks this place is a county
*/
public boolean isCounty() {
return 5 <= rankAddress && rankAddress <= 9;
}

public boolean isPostcode() {
if ("place".equals(osmKey) && "postcode".equals(osmValue)) {
return true;
Expand Down

0 comments on commit 126c544

Please sign in to comment.