Skip to content

Commit dca95df

Browse files
authored
Merge pull request #425 from Gerungofulus/countryCodes
Country codes
2 parents 1316aca + 4e2a455 commit dca95df

File tree

5 files changed

+13
-2
lines changed

5 files changed

+13
-2
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ http://localhost:2322/api?q=berlin&osm_tag=tourism
170170
"name": "Berlin",
171171
"state": "Berlin",
172172
"country": "Germany",
173+
"countrycode": "DE",
173174
"osm_key": "place",
174175
"osm_value": "city",
175176
"osm_type": "N",
@@ -192,6 +193,7 @@ http://localhost:2322/api?q=berlin&osm_tag=tourism
192193
"postcode": "14053",
193194
"state": "Berlin",
194195
"country": "Germany",
196+
"countrycode": "DE",
195197
"osm_key": "leisure",
196198
"osm_value": "stadium",
197199
"osm_type": "W",

es/mappings.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,10 @@
216216
}
217217
}
218218
},
219+
"countrycode": {
220+
"type": "text",
221+
"index": false
222+
},
219223
"housenumber": {
220224
"type": "text",
221225
"index": true,
@@ -482,4 +486,4 @@
482486
}
483487
}
484488
}
485-
}
489+
}

src/main/java/de/komoot/photon/Constants.java

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class Constants {
1010
public static final String HOUSENUMBER = "housenumber";
1111
public static final String NAME = "name";
1212
public static final String COUNTRY = "country";
13+
public static final String COUNTRYCODE = "countrycode";
1314
public static final String CITY = "city";
1415
public static final String STREET = "street";
1516
public static final String STATE = "state";

src/main/java/de/komoot/photon/Utils.java

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.google.common.base.Joiner;
44
import com.google.common.collect.HashMultimap;
55
import com.google.common.collect.SetMultimap;
6+
import com.neovisionaries.i18n.CountryCode;
67
import com.vividsolutions.jts.geom.Envelope;
78
import org.elasticsearch.common.xcontent.XContentBuilder;
89
import org.elasticsearch.common.xcontent.XContentFactory;
@@ -47,6 +48,9 @@ public static XContentBuilder convert(PhotonDoc doc, String[] languages) throws
4748
writeName(builder, doc.getName(), languages);
4849
writeIntlNames(builder, doc.getCity(), "city", languages);
4950
writeIntlNames(builder, doc.getCountry(), "country", languages);
51+
CountryCode countryCode = doc.getCountryCode();
52+
if (countryCode != null)
53+
builder.field(Constants.COUNTRYCODE, countryCode.getAlpha2());
5054
writeIntlNames(builder, doc.getState(), "state", languages);
5155
writeIntlNames(builder, doc.getStreet(), "street", languages);
5256
writeContext(builder, doc.getContext(), languages);

src/main/java/de/komoot/photon/utils/ConvertToJson.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919
@Slf4j
2020
public class ConvertToJson implements OneWayConverter<SearchResponse, List<JSONObject>> {
21-
private final static String[] KEYS_LANG_UNSPEC = {Constants.OSM_ID, Constants.OSM_VALUE, Constants.OSM_KEY, Constants.POSTCODE, Constants.HOUSENUMBER, Constants.OSM_TYPE};
21+
private final static String[] KEYS_LANG_UNSPEC = {Constants.OSM_ID, Constants.OSM_VALUE, Constants.OSM_KEY, Constants.POSTCODE, Constants.HOUSENUMBER, Constants.COUNTRYCODE, Constants.OSM_TYPE};
2222
private final static String[] KEYS_LANG_SPEC = {Constants.NAME, Constants.COUNTRY, Constants.CITY, Constants.STREET, Constants.STATE};
2323
private final String lang;
2424

0 commit comments

Comments
 (0)