Skip to content

Commit

Permalink
Merge pull request #547 from alfmarcua/issue_529
Browse files Browse the repository at this point in the history
Cache parent address for rank 29 and 30 (#529)
  • Loading branch information
lonvia authored Apr 4, 2021
2 parents e4a024e + 4c417c5 commit e278ace
Showing 1 changed file with 30 additions and 13 deletions.
43 changes: 30 additions & 13 deletions src/main/java/de/komoot/photon/nominatim/NominatimConnector.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ public List<PhotonDoc> getInterpolationsByPlaceId(long placeId) {
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"),
Expand All @@ -172,19 +175,33 @@ List<AddressRow> getAddresses(PhotonDoc doc) {
return Collections.emptyList();
}

long placeId = (atype == AddressType.HOUSE) ? doc.getParentPlaceId() : doc.getPlaceId();

List<AddressRow> 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);
List<AddressRow> terms = null;

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 = ?",
rowMapper, placeId));
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);

// need to add the term for the parent place ID itself
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;
Expand Down Expand Up @@ -223,7 +240,7 @@ public void readEntireDatabase(String... countryCodes) {

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 geometry_sector, parent_place_id; ", rs -> {
// turns a placex row into a photon document that gathers all de-normalised information
NominatimResult docs = placeRowMapper.mapRow(rs, 0);
assert(docs != null);
Expand All @@ -235,7 +252,7 @@ public void readEntireDatabase(String... countryCodes) {

template.query(SELECT_COLS_OSMLINE + " FROM location_property_osmline " +
whereCountryCodeStr +
" ORDER BY geometry_sector; ", rs -> {
" ORDER BY geometry_sector, parent_place_id; ", rs -> {
NominatimResult docs = osmlineRowMapper.mapRow(rs, 0);
assert(docs != null);

Expand Down

0 comments on commit e278ace

Please sign in to comment.