--- android/TrainInfoService/src/dk/thoerup/traininfoservice/db/StationDAO.java 2011/06/08 16:11:27 1507 +++ android/TrainInfoService/src/dk/thoerup/traininfoservice/db/StationDAO.java 2011/07/09 07:31:01 1569 @@ -124,19 +124,19 @@ public StationBean getByNameFuzzy(final String name) throws SQLException { - String SQL = "SELECT id,name,latitude,longitude,stationcode_fjrn,stationcode_stog, stationcode_metro, address, 0.0, " + - "levenshtein(lower(name),lower(?) ) as leven " + - "FROM trainstations " + - "WHERE (levenshtein(lower(name),lower(?) ) <= 3) AND enabled = true " + - "AND enabled = true " + - "ORDER BY leven " + - "LIMIT 1"; + String SQL = "SELECT * FROM (" + + " SELECT id,name,latitude,longitude,stationcode_fjrn,stationcode_stog, stationcode_metro, address, 0.0, " + + " levenshtein(lower(name),lower(?) ) as leven " + + " FROM trainstations " + + " WHERE enabled = true ) as lev2 " + + "WHERE (leven <= 3) " + + "ORDER BY leven " + + "LIMIT 1"; class NameSetter implements StatementParamSetter { @Override public void setParams(PreparedStatement stmt) throws SQLException { stmt.setString(1, name ); - stmt.setString(2, name ); } } @@ -145,12 +145,25 @@ return stations; } - public StationBean getByName(final String name) throws SQLException { + private String removeSuffix(String str, String suffix) { + if (str.endsWith(suffix)) { + return str.substring(0, str.length() - suffix.length() ); + } else { + return str; + } + } + + public StationBean getByName(String name) throws SQLException { + name = removeSuffix(name, " st."); + name = removeSuffix(name, " st"); + name = removeSuffix(name, " station"); + StationBean stations = getByNameNormal(name); if (stations.entries.size() == 0) { - logger.info("getByName failover: " + name); stations = getByNameFuzzy(name); + + logger.info("getByName failover: " + name + "(" + (stations.entries.size() >0) + ")" ); } return stations; } @@ -160,7 +173,9 @@ //Latitude (horizonal), longitude(vertical) so // 1 degree latitude is ~ 111320 meters, since the distance between the horizonal lines is always the same // 1 degree longitude is ~111320 meters at equator but gets shorter as we get closer to the poles. - // the "hack" with max 0.4 degrees latitude and 0.75 degrees longitude is only valid since we only service danish trains, + // so 1 degree longitude is 64.5 km at denmarks southern point (gedser=54.55,11.95) + // and is 59.4km at northern point (skagen = 57.75,10.65) + // The "hack" with max 0.4 degrees latitude and 0.75 degrees longitude is only valid since we only service danish trains, // in denmark 0.4dg latitude ~ 44km, 0.75dg longitude ~ 47km // the ultra fast method (and only slightly inaccurate as long as we only cover a limited geographically area) @@ -243,7 +258,7 @@ } //used to create full dump in order to populate Google Appengine DB - @Deprecated + //after 1.1.0 also used to populate client-side station list public StationBean dumpAll() throws SQLException { String SQL = "SELECT id,name,latitude,longitude,stationcode_fjrn,stationcode_stog,stationcode_metro,address,0.0,aliases " +