/[projects]/dao/DaoAdresseService/src/dk/daoas/daoadresseservice/AdressSearch.java
ViewVC logotype

Diff of /dao/DaoAdresseService/src/dk/daoas/daoadresseservice/AdressSearch.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2295 by torben, Sun Feb 15 09:57:55 2015 UTC revision 2305 by torben, Sun Feb 15 17:09:02 2015 UTC
# Line 23  public class AdressSearch { Line 23  public class AdressSearch {
23    
24          List<Address> alleAdresser;          List<Address> alleAdresser;
25                    
26            Map<String,Long> helperCache;
27            
28                    
29          Map<Integer,HundredePctBean> hundredePct;          Map<Integer,HundredePctBean> hundredePct;
30                    
31                    
32          public SearchResult search(String postnrStr, String adresse)  {          public SearchResult search(String postnrStr, String adresse)  {
 //long start1 = System.currentTimeMillis();  
33                                    
34                  int postnr=0;                  int postnr=0;
35                    boolean google = false;
36                    boolean osm = false;
37                    String helperSearchKey = "";
38                                    
39                  try {                  try {
40                          postnr = Integer.parseInt(postnrStr);                          postnr = Integer.parseInt(postnrStr);
41                  } catch (Exception E) {                  } catch (Exception E) {
42                          return new SearchResult(Status.ERROR_UNKNOWN_POSTAL);                          return new SearchResult(Status.ERROR_UNKNOWN_POSTAL);
43                  }                                }              
 //long start2 = System.currentTimeMillis();  
44                                    
45                  Map<String,Long> postnrVeje = searchPostnrVejnavnGadeid.get(postnr);                                      Map<String,Long> postnrVeje = searchPostnrVejnavnGadeid.get(postnr);                    
46                                    
# Line 45  public class AdressSearch { Line 48  public class AdressSearch {
48                          return new SearchResult(Status.ERROR_UNKNOWN_POSTAL);                          return new SearchResult(Status.ERROR_UNKNOWN_POSTAL);
49                  }                  }
50                                    
 //long start3 = System.currentTimeMillis();  
51                                    
52                  SplitResult split = AddressUtils.splitAdresse(adresse);                  SplitResult split = AddressUtils.splitAdresse(adresse);
53                  String vasketVejnavn = AddressUtils.vaskVejnavn( split.vej );                                            String vasketVejnavn = AddressUtils.vaskVejnavn( split.vej );                          
# Line 53  public class AdressSearch { Line 55  public class AdressSearch {
55                  if (split.husnr.length() == 0) {                  if (split.husnr.length() == 0) {
56                          return new SearchResult(Status.ERROR_MISSING_HOUSENUMBER);                                                return new SearchResult(Status.ERROR_MISSING_HOUSENUMBER);                      
57                  }                  }
 //long start4 = System.currentTimeMillis();  
58                                    
59                  Long gadeident =  postnrVeje.get(vasketVejnavn);                  Long gadeident =  postnrVeje.get(vasketVejnavn);
60                    
61                    
62                    if ( gadeident == null) {
63                            helperSearchKey = "" + postnr + "/" + vasketVejnavn;
64                            gadeident = helperCache.get(helperSearchKey);
65                    }
66                    
67                    
68                    if ( gadeident == null) {
69                            String googleVej = GeocodeHelper.googleHelper(postnr, split.vej );
70                            google = true;
71                            
72                            if (googleVej != null) {
73                                    String googleVasket = AddressUtils.vaskVejnavn( googleVej );
74                                    gadeident =  postnrVeje.get(googleVasket);
75                                    
76                                    if (gadeident != null) {
77                                            helperCache.put(helperSearchKey, gadeident);
78                                    }
79                            }
80                    }
81                    
82                    if ( gadeident == null) {
83                            String osmVej = GeocodeHelper.openstreetmapHelper(postnr, split.vej );
84                            osm = true;
85                            
86                            if (osmVej != null) {
87                                    String osmVasket = AddressUtils.vaskVejnavn( osmVej );
88                                    gadeident =  postnrVeje.get(osmVasket);
89                                    
90                                    if (gadeident != null) {
91                                            helperCache.put(helperSearchKey, gadeident);
92                                    }
93                            }
94                    }
95                    
96                  if (gadeident == null) {                  if (gadeident == null) {
97                          return new SearchResult(Status.ERROR_UNKNOWN_STREETNAME);                          return new SearchResult(Status.ERROR_UNKNOWN_STREETNAME);
98                  }                  }
 //long start5 = System.currentTimeMillis();  
99                                    
100                  Map<String, Address> gade =  searchGadeidentAdresser.get(gadeident); //Denne søgning må ikke fejle                  Map<String, Address> gade =  searchGadeidentAdresser.get(gadeident); //Denne søgning må ikke fejle
101                                    
 //long start6 = System.currentTimeMillis();  
102                                    
103                  String husnrSearch = "" + split.husnr + split.litra;                  String husnrSearch = "" + split.husnr + split.litra;
104                  Address addr = gade.get(husnrSearch);                  Address addr = gade.get(husnrSearch);
105  //long start7 = System.currentTimeMillis();  
106                  if (addr == null) {                  if (addr == null) {
107                          return new SearchResult(Status.ERROR_UNKNOWN_ADDRESSPOINT);                          return new SearchResult(Status.ERROR_UNKNOWN_ADDRESSPOINT);
108                  }                  }
# Line 78  public class AdressSearch { Line 113  public class AdressSearch {
113                                    
114                  if (addr.distributor.equals("LUKKET")) {                  if (addr.distributor.equals("LUKKET")) {
115                          return new SearchResult(Status.STATUS_NOT_COVERED); //Skal vi have en special status til Lukkede adresser ?                          return new SearchResult(Status.STATUS_NOT_COVERED); //Skal vi have en special status til Lukkede adresser ?
116                  }                  }              
                   
 /*  
 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) );  
 */  
   
                                   
117                                    
118                  return new SearchResult(addr);                  SearchResult res = new SearchResult(addr);
119                    res.google = google;
120                    res.osm = osm;
121                    return res;
122          }          }
123                    
124                    
125          public void buildSearchStructures() throws SQLException{          public void buildSearchStructures() throws SQLException{
126                  searchPostnrVejnavnGadeid = new HashMap<Integer, Map<String,Long>>();                  searchPostnrVejnavnGadeid = new HashMap<Integer, Map<String,Long>>();
127                  searchGadeidentAdresser = new HashMap<Long,  Map<String,Address>>();                  searchGadeidentAdresser = new HashMap<Long,  Map<String,Address>>();
128                                                    helperCache = new ConcurrentHashMap<String,Long>();
129                    
130                  System.out.println("Build -- stage 1");                  System.out.println("Build -- stage 1");
131                                    
132                  alleAdresser = DatabaseLayer.getAllAdresses();                  alleAdresser = DatabaseLayer.getAllAdresses();

Legend:
Removed from v.2295  
changed lines
  Added in v.2305

  ViewVC Help
Powered by ViewVC 1.1.20