--- dao/DaoAdresseService/src/dk/daoas/daoadresseservice/AdressSearch.java 2015/02/15 11:00:48 2298 +++ dao/DaoAdresseService/src/dk/daoas/daoadresseservice/AdressSearch.java 2015/02/16 13:24:45 2309 @@ -23,6 +23,8 @@ List
alleAdresser; + Map helperCache; + Map hundredePct; @@ -31,6 +33,8 @@ int postnr=0; boolean google = false; + boolean osm = false; + String helperSearchKey = ""; try { postnr = Integer.parseInt(postnrStr); @@ -53,11 +57,40 @@ } Long gadeident = postnrVeje.get(vasketVejnavn); + + + if ( gadeident == null) { + helperSearchKey = "" + postnr + "/" + vasketVejnavn; + gadeident = helperCache.get(helperSearchKey); + } + + if ( gadeident == null) { String googleVej = GeocodeHelper.googleHelper(postnr, split.vej ); - String googleVasket = AddressUtils.vaskVejnavn( googleVej ); - gadeident = postnrVeje.get(googleVasket); google = true; + + if (googleVej != null) { + String googleVasket = AddressUtils.vaskVejnavn( googleVej ); + gadeident = postnrVeje.get(googleVasket); + + if (gadeident != null) { + helperCache.put(helperSearchKey, gadeident); + } + } + } + + if ( gadeident == null) { + String osmVej = GeocodeHelper.openstreetmapHelper(postnr, split.vej ); + osm = true; + + if (osmVej != null) { + String osmVasket = AddressUtils.vaskVejnavn( osmVej ); + gadeident = postnrVeje.get(osmVasket); + + if (gadeident != null) { + helperCache.put(helperSearchKey, gadeident); + } + } } if (gadeident == null) { @@ -84,6 +117,7 @@ SearchResult res = new SearchResult(addr); res.google = google; + res.osm = osm; return res; } @@ -91,7 +125,9 @@ public void buildSearchStructures() throws SQLException{ searchPostnrVejnavnGadeid = new HashMap>(); searchGadeidentAdresser = new HashMap>(); - + helperCache = new ConcurrentHashMap(); + + long start1 = System.currentTimeMillis(); System.out.println("Build -- stage 1"); alleAdresser = DatabaseLayer.getAllAdresses(); @@ -134,6 +170,8 @@ //////////////////////////////////////////////////////////////////////////////////////// + long start2 = System.currentTimeMillis(); + System.out.println("Build, stage1 elapsed: " + (start2-start1) ); System.out.println("Build -- stage 2 udvidet dækning"); List extDao = DatabaseLayer.getExtendedAdresslist(); @@ -191,6 +229,8 @@ idAddressMap = null; ////////////////////////////////////////////////////////////////////////////////////// + long start3 = System.currentTimeMillis(); + System.out.println("Build, stage2 elapsed: " + (start3-start2) ); System.out.println("Build -- stage 3 - 100pct"); hundredePct = DatabaseLayer.get100PctList(); @@ -217,6 +257,8 @@ } //////////////////////////////////////////////////////////////////////////////////// + long stop = System.currentTimeMillis(); + System.out.println("Build, stage3 elapsed: " + (stop-start3) ); System.out.println("Build -- Gathering statistics"); int direkteCount = 0; @@ -245,6 +287,7 @@ System.out.println("Build: hundredePctCount: " + hundredePctCount); System.out.println("Build: ikkeDaekketCount: " + ikkeDaekketCount); + System.out.println("Build: Total Elapsed: " + (stop-start1) ); System.out.println("Build Completed"); }