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
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
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.
-- 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
|| 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);