From d0544fd0de99be9f3c2bb4842ea84a689826f535 Mon Sep 17 00:00:00 2001 From: Regina Obe Date: Sat, 25 Jun 2011 08:13:16 +0000 Subject: [PATCH] #1051 - fix rating logic (typo in direction weight) causing - select (g.addy).*, astext(g.geomout), g.* from geocode('150 2nd Ave S, Minneapolis, MN 55401') as g To return north instead of south. Also change functions to use named args git-svn-id: http://svn.osgeo.org/postgis/trunk@7474 b70326c6-7e19-0410-871a-916f4a2858ee --- .../tiger_2010/geocode/rate_attributes.sql | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/extras/tiger_geocoder/tiger_2010/geocode/rate_attributes.sql b/extras/tiger_geocoder/tiger_2010/geocode/rate_attributes.sql index 187ac4a93..75f03ca01 100644 --- a/extras/tiger_geocoder/tiger_2010/geocode/rate_attributes.sql +++ b/extras/tiger_geocoder/tiger_2010/geocode/rate_attributes.sql @@ -5,16 +5,18 @@ -- non-null. The other eight values are handled by the other rate_attributes -- function, so it's requirements must also be met. -- changed: 2010-10-18 Regina Obe - all references to verbose to var_verbose since causes compile errors in 9.0 -CREATE OR REPLACE FUNCTION rate_attributes(VARCHAR, VARCHAR, VARCHAR, VARCHAR, - VARCHAR, VARCHAR, VARCHAR, VARCHAR, VARCHAR, VARCHAR) RETURNS INTEGER +-- changed: 2011-06-25 revise to use real named args and fix direction rating typo +CREATE OR REPLACE FUNCTION rate_attributes(dirpA VARCHAR, dirpB VARCHAR, streetNameA VARCHAR, streetNameB VARCHAR, + streetTypeA VARCHAR, streetTypeB VARCHAR, dirsA VARCHAR, dirsB VARCHAR, locationA VARCHAR, locationB VARCHAR) RETURNS INTEGER AS $_$ DECLARE +--$Id$ result INTEGER := 0; locationWeight INTEGER := 14; var_verbose BOOLEAN := FALSE; BEGIN - IF $9 IS NOT NULL AND $10 IS NOT NULL THEN - result := levenshtein_ignore_case($9, $10); + IF locationA IS NOT NULL AND locationB IS NOT NULL THEN + result := levenshtein_ignore_case(locationA, locationB); ELSE IF var_verbose THEN RAISE NOTICE 'rate_attributes() - Location names cannot be null!'; @@ -31,8 +33,8 @@ $_$ LANGUAGE plpgsql IMMUTABLE; -- Rates the street based on the given attributes. Only streetNames are -- required. If any others are null (either A or B) they are treated as -- empty strings. -CREATE OR REPLACE FUNCTION rate_attributes(VARCHAR, VARCHAR, VARCHAR, VARCHAR, - VARCHAR, VARCHAR, VARCHAR, VARCHAR) RETURNS INTEGER +CREATE OR REPLACE FUNCTION rate_attributes(dirpA VARCHAR, dirpB VARCHAR, streetNameA VARCHAR, streetNameB VARCHAR, + streetTypeA VARCHAR, streetTypeB VARCHAR, dirsA VARCHAR, dirsB VARCHAR) RETURNS INTEGER AS $_$ DECLARE result INTEGER := 0; @@ -43,7 +45,7 @@ DECLARE BEGIN result := result + levenshtein_ignore_case(cull_null($1), cull_null($2)) * directionWeight; - IF $3 IS NOT NULL AND $4 IS NOT NULL THEN + IF streetNameA IS NOT NULL AND streetNameB IS NOT NULL THEN result := result + levenshtein_ignore_case($3, $4) * nameWeight; ELSE IF var_verbose THEN @@ -51,9 +53,9 @@ BEGIN END IF; RETURN NULL; END IF; - result := result + levenshtein_ignore_case(cull_null($5), cull_null($6)) * + result := result + levenshtein_ignore_case(cull_null(streetTypeA), cull_null(streetTypeB)) * typeWeight; - result := result + levenshtein_ignore_case(cull_null($7), cull_null($7)) * + result := result + levenshtein_ignore_case(cull_null(dirsA), cull_null(dirsB)) * directionWeight; return result; END; -- 2.50.1