@@ -31,53 +31,45 @@ public Iterator<PhotonDoc> iterator() {
3131 }
3232
3333 private void addPlaceAddress (PhotonDoc base , Map <String , String > address , String key ) {
34- Map <AddressType , Map <String , String >> placeAddress = null ;
35- for (String hnr : splitHousenumber (address , key )) {
36- if (placeAddress == null ) {
37- placeAddress = new EnumMap <>(AddressType .class );
38-
39- for (var entry : base .getAddressParts ().entrySet ()) {
40- if (entry .getKey () != AddressType .STREET ) {
41- placeAddress .put (entry .getKey (), entry .getValue ());
42- }
34+ final String place = address .get ("place" );
35+ if (place != null && !place .isBlank ()) {
36+ Map <AddressType , Map <String , String >> placeAddress = null ;
37+ for (String hnr : splitHousenumber (address , key )) {
38+ if (placeAddress == null ) {
39+ placeAddress = copyAddressWithStreet (base , place );
4340 }
4441
45- final String place = address .get ("place" );
46- if (place != null && !place .isBlank ()) {
47- placeAddress .put (AddressType .STREET , Map .of ("default" , place ));
48- }
42+ docs .add (new PhotonDoc (base ).replaceAddress (placeAddress ).houseNumber (hnr ));
4943 }
50-
51- docs .add (new PhotonDoc (base ).replaceAddress (placeAddress ).houseNumber (hnr ));
5244 }
5345 }
5446
5547 private void addStreetAddress (PhotonDoc base , Map <String , String > address , String key ) {
56- for (String hnr : splitHousenumber (address , key )) {
57- docs .add (new PhotonDoc (base ).houseNumber (hnr ));
48+ if (address .containsKey ("street" )) {
49+ for (String hnr : splitHousenumber (address , key )) {
50+ docs .add (new PhotonDoc (base ).houseNumber (hnr ));
51+ }
5852 }
5953 }
6054
6155 private void addGenericAddress (PhotonDoc base , Map <String , String > address , String key ) {
6256 Map <AddressType , Map <String , String >> placeAddress = null ;
6357 for (String hnr : splitHousenumber (address , key )) {
6458 if (placeAddress == null ) {
65- String place = address .get ("place" );
66- if (place == null || place .isBlank ()) {
67- place = address .get ("block_number" );
68- }
69- if (place != null && !place .isBlank ()) {
70- placeAddress = new EnumMap <>(AddressType .class );
71-
72- for (var entry : base .getAddressParts ().entrySet ()) {
73- if (entry .getKey () != AddressType .STREET ) {
74- placeAddress .put (entry .getKey (), entry .getValue ());
75- }
76- }
77-
78- placeAddress .put (AddressType .STREET , Map .of ("default" , place ));
59+ String block = address .get ("block_number" );
60+ if (block != null && !block .isBlank ()) {
61+ // block numbers replace streets unconditionally.
62+ // We assume that addr:street is a tagging error and ignore it.
63+ placeAddress = copyAddressWithStreet (base , block );
7964 } else {
80- placeAddress = base .getAddressParts ();
65+ String place = address .get ("place" );
66+ // When addr:place and addr:Street appear together, then assume
67+ // that addr:place is a tagging error and ignore it.
68+ if (place != null && !place .isBlank () && !address .containsKey ("street" )) {
69+ placeAddress = copyAddressWithStreet (base , place );
70+ } else {
71+ placeAddress = base .getAddressParts ();
72+ }
8173 }
8274 }
8375
@@ -98,4 +90,18 @@ private String[] splitHousenumber(Map<String, String> address, String key) {
9890 .toArray (String []::new );
9991 }
10092
93+ private EnumMap <AddressType , Map <String , String >> copyAddressWithStreet (PhotonDoc base , String streetName ) {
94+ final EnumMap <AddressType , Map <String , String >> outmap = new EnumMap <>(AddressType .class );
95+
96+ for (var entry : base .getAddressParts ().entrySet ()) {
97+ if (entry .getKey () != AddressType .STREET ) {
98+ outmap .put (entry .getKey (), entry .getValue ());
99+ }
100+ }
101+
102+ outmap .put (AddressType .STREET , Map .of ("default" , streetName ));
103+
104+ return outmap ;
105+ }
106+
101107}
0 commit comments