--- 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/15 16:53:13 2303
@@ -23,21 +23,23 @@
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;
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 +47,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 +54,48 @@
if (split.husnr.length() == 0) {
return new SearchResult(Status.ERROR_MISSING_HOUSENUMBER);
}
-//long start4 = System.currentTimeMillis();
Long gadeident = postnrVeje.get(vasketVejnavn);
+
+ if ( gadeident == null) {
+ gadeident = helperCache.get(vasketVejnavn);
+ }
+
+
+ if ( gadeident == null) {
+ String googleVej = GeocodeHelper.googleHelper(postnr, split.vej );
+ if (googleVej != null) {
+ String googleVasket = AddressUtils.vaskVejnavn( googleVej );
+ gadeident = postnrVeje.get(googleVasket);
+ google = true;
+ if (gadeident != null) {
+ helperCache.put(googleVasket, gadeident);
+ }
+ }
+ }
+
+ if ( gadeident == null) {
+ String osmVej = GeocodeHelper.openstreetmapHelper(postnr, split.vej );
+ if (osmVej != null) {
+ String osmVasket = AddressUtils.vaskVejnavn( osmVej );
+ gadeident = postnrVeje.get(osmVasket);
+ osm = true;
+ if (gadeident != null) {
+ helperCache.put(osmVasket, 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 +106,20 @@
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();
+
System.out.println("Build -- stage 1");
alleAdresser = DatabaseLayer.getAllAdresses();