Parent address are cached and reused between ranks 29 and 30 objects with the same parent
@@ -162,6 +162,9 @@ public class NominatimConnector {
return result.getDocsWithHousenumber();
}
+ private long parentPlaceId = -1;
+ private List<AddressRow> parentTerms = null;
+
List<AddressRow> getAddresses(PhotonDoc doc) {
RowMapper<AddressRow> rowMapper = (rs, rowNum) -> new AddressRow(
dbutils.getMap(rs, "name"),
@@ -176,19 +179,33 @@ public class NominatimConnector {
return Collections.emptyList();
}
- long placeId = (atype == AddressType.HOUSE) ? doc.getParentPlaceId() : doc.getPlaceId();
+ List<AddressRow> terms = null;
- List<AddressRow> terms = template.query(SELECT_COLS_ADDRESS
+ if (atype == AddressType.HOUSE) {
+ long placeId = doc.getParentPlaceId();
+ if (placeId != parentPlaceId) {
+ parentTerms = template.query(SELECT_COLS_ADDRESS
+ " 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",
rowMapper, placeId, placeId);
- if (atype == AddressType.HOUSE) {
// need to add the term for the parent place ID itself
- terms.addAll(0, template.query(SELECT_COLS_ADDRESS + " FROM placex p WHERE p.place_id = ?",
+ parentTerms.addAll(0, template.query(SELECT_COLS_ADDRESS + " FROM placex p WHERE p.place_id = ?",
rowMapper, placeId));
+ parentPlaceId = placeId;
+ }
+ terms = parentTerms;
+
+ } else {
+ long placeId = doc.getPlaceId();
+ terms = template.query(SELECT_COLS_ADDRESS
+ + " 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",
+ rowMapper, placeId, placeId);
}
return terms;
@@ -227,7 +244,7 @@ public class NominatimConnector {
template.query(SELECT_COLS_PLACEX + " FROM placex " +
" WHERE linked_place_id IS NULL AND centroid IS NOT NULL " + andCountryCodeStr +
- " ORDER BY geometry_sector; ", rs -> {
+ " ORDER BY parent_place_id, geometry_sector; ", rs -> {
// turns a placex row into a photon document that gathers all de-normalised information
NominatimResult docs = placeRowMapper.mapRow(rs, 0);
@@ -238,7 +255,7 @@ public class NominatimConnector {
template.query(SELECT_COLS_OSMLINE + " FROM location_property_osmline " +
whereCountryCodeStr +
- " ORDER BY geometry_sector; ", rs -> {
+ " ORDER BY parent_place_id, geometry_sector; ", rs -> {
NominatimResult docs = osmlineRowMapper.mapRow(rs, 0);
if (docs != null) {
