--- dao/DaoAdresseService/src/dk/daoas/daoadresseservice/AdressSearch.java 2015/02/15 09:57:55 2295
+++ dao/DaoAdresseService/src/dk/daoas/daoadresseservice/AdressSearch.java 2015/02/16 13:24:45 2309
@@ -23,21 +23,24 @@
List
alleAdresser;
+ Map helperCache;
+
Map hundredePct;
public SearchResult search(String postnrStr, String adresse) {
-//long start1 = System.currentTimeMillis();
int postnr=0;
+ boolean google = false;
+ boolean osm = false;
+ String helperSearchKey = "";
try {
postnr = Integer.parseInt(postnrStr);
} catch (Exception E) {
return new SearchResult(Status.ERROR_UNKNOWN_POSTAL);
}
-//long start2 = System.currentTimeMillis();
Map postnrVeje = searchPostnrVejnavnGadeid.get(postnr);
@@ -45,7 +48,6 @@
return new SearchResult(Status.ERROR_UNKNOWN_POSTAL);
}
-//long start3 = System.currentTimeMillis();
SplitResult split = AddressUtils.splitAdresse(adresse);
String vasketVejnavn = AddressUtils.vaskVejnavn( split.vej );
@@ -53,21 +55,54 @@
if (split.husnr.length() == 0) {
return new SearchResult(Status.ERROR_MISSING_HOUSENUMBER);
}
-//long start4 = System.currentTimeMillis();
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 );
+ 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) {
return new SearchResult(Status.ERROR_UNKNOWN_STREETNAME);
}
-//long start5 = System.currentTimeMillis();
Map gade = searchGadeidentAdresser.get(gadeident); //Denne søgning må ikke fejle
-//long start6 = System.currentTimeMillis();
String husnrSearch = "" + split.husnr + split.litra;
Address addr = gade.get(husnrSearch);
-//long start7 = System.currentTimeMillis();
+
if (addr == null) {
return new SearchResult(Status.ERROR_UNKNOWN_ADDRESSPOINT);
}
@@ -78,27 +113,21 @@
if (addr.distributor.equals("LUKKET")) {
return new SearchResult(Status.STATUS_NOT_COVERED); //Skal vi have en special status til Lukkede adresser ?
- }
-
-/*
-System.out.println("Search2: " + (start2-start1) );
-System.out.println("Search3: " + (start3-start1) );
-System.out.println("Search4: " + (start4-start1) );
-System.out.println("Search5: " + (start5-start1) );
-System.out.println("Search6: " + (start6-start1) );
-System.out.println("Search7: " + (start7-start1) );
-*/
-
-
+ }
- return new SearchResult(addr);
+ SearchResult res = new SearchResult(addr);
+ res.google = google;
+ res.osm = osm;
+ return res;
}
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();
@@ -141,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();
@@ -198,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();
@@ -224,6 +257,8 @@
}
////////////////////////////////////////////////////////////////////////////////////
+ long stop = System.currentTimeMillis();
+ System.out.println("Build, stage3 elapsed: " + (stop-start3) );
System.out.println("Build -- Gathering statistics");
int direkteCount = 0;
@@ -252,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");
}