]> granicus.if.org Git - postgis/commitdiff
more optimizations
authorRegina Obe <lr@pcorp.us>
Wed, 11 May 2011 14:59:55 +0000 (14:59 +0000)
committerRegina Obe <lr@pcorp.us>
Wed, 11 May 2011 14:59:55 +0000 (14:59 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@7131 b70326c6-7e19-0410-871a-916f4a2858ee

extras/tiger_geocoder/tiger_2010/normalize/location_extract_place_exact.sql
extras/tiger_geocoder/tiger_2010/normalize/normalize_address.sql

index 62fc7da06e8b0dd326638030bd7325de9b8a7e79..1ab61016420dffd6179c01c5a7801d5d3b0638e8 100644 (file)
@@ -21,11 +21,12 @@ BEGIN
   IF stateAbbrev IS NOT NULL THEN
     lstate := statefp FROM state WHERE stusps = stateAbbrev;
     SELECT INTO tempInt count(*) FROM place
-        WHERE place.statefp = lstate
+        WHERE place.statefp = lstate AND fullStreet ILIKE '%' || name || '%'
         AND texticregexeq(fullStreet, '(?i)' || name || '$');
   ELSE
     SELECT INTO tempInt count(*) FROM place
-        WHERE texticregexeq(fullStreet, '(?i)' || name || '$');
+        WHERE fullStreet ILIKE '%' || name || '%' AND
+               texticregexeq(fullStreet, '(?i)' || name || '$');
   END IF;
 
   IF tempInt > 0 THEN
@@ -33,7 +34,7 @@ BEGIN
     IF stateAbbrev IS NOT NULL THEN
       FOR rec IN SELECT substring(fullStreet, '(?i)('
           || name || ')$') AS value, name FROM place
-          WHERE place.statefp = lstate
+          WHERE place.statefp = lstate AND fullStreet ILIKE '%' || name || '%'
           AND texticregexeq(fullStreet, '(?i)'
           || name || '$') ORDER BY length(name) DESC LOOP
         -- Since the regex is end of string, only the longest (first) result
@@ -44,7 +45,7 @@ BEGIN
     ELSE
       FOR rec IN SELECT substring(fullStreet, '(?i)('
           || name || ')$') AS value, name FROM place
-          WHERE texticregexeq(fullStreet, '(?i)'
+          WHERE fullStreet ILIKE '%' || name || '%' AND texticregexeq(fullStreet, '(?i)'
           || name || '$') ORDER BY length(name) DESC LOOP
         -- Since the regex is end of string, only the longest (first) result
         -- is useful.
index 76ca40dae282a4f3d37bfd893f60716541deeb5c..43bf3804307ddc014a66e805874dfe2f6cd37ca3 100644 (file)
@@ -225,14 +225,14 @@ BEGIN
   -- or suite number.
   -- this count is surprisingly slow by itself but much faster if you add an ILIKE AND clause
   SELECT INTO tempInt count(*) FROM secondary_unit_lookup
-      WHERE texticregexeq(fullStreet, '(?i)' || ws || name || '('
+      WHERE fullStreet ILIKE '%' || name || '%' AND texticregexeq(fullStreet, '(?i)' || ws || name || '('
           || ws || '|$)');
   IF tempInt = 1 THEN
     result.internal := substring(fullStreet, '(?i)' || ws || '('
         || name ||  ws || '*#?' || ws
         || '*(?:[0-9][-0-9a-zA-Z]*)?' || ')(?:' || ws || '|$)')
         FROM secondary_unit_lookup
-        WHERE texticregexeq(fullStreet, '(?i)' || ws || name || '('
+        WHERE fullStreet ILIKE '%' || name || '%' AND texticregexeq(fullStreet, '(?i)' || ws || name || '('
         || ws || '|$)');
     ELSIF tempInt > 1 THEN
     -- In the event of multiple matches to a secondary unit designation, we
@@ -242,7 +242,7 @@ BEGIN
         || name || '(?:' || ws || '*#?' || ws
         || '*(?:[0-9][-0-9a-zA-Z]*)?)' || ws || '?|$)')) as value
         FROM secondary_unit_lookup
-        WHERE texticregexeq(fullStreet, '(?i)' || ws || name || '('
+        WHERE fullStreet ILIKE '%' || name || '%' AND  texticregexeq(fullStreet, '(?i)' || ws || name || '('
         || ws || '|$)') LOOP
       IF tempInt < position(rec.value in fullStreet) THEN
         tempInt := position(rec.value in fullStreet);