【发布时间】:2017-06-23 11:03:23
【问题描述】:
我有 SQL 查询,它在带有地址字段的表中搜索。我的问题是在城市领域。 我假设搜索列街道有门牌号但没有他,但我忘记了社区的划分,例如:Kolin IV、Kolín II 等。我的问题是,可以以某种方式从使用 SQL 函数的列中仅比较城市名称而没有该地区所属的任何迹象?
$where = " WHERE (LOWER(city) LIKE LOWER('%$fullAddress%')
OR LOWER(street) LIKE LOWER('%$fullAddress%')
OR CAST(postal_code AS TEXT) LIKE LOWER('%$fullAddress%')
OR CAST(house_number AS TEXT) LIKE LOWER('%$fullAddress%')
OR (LOWER(street || ', ' || city) LIKE LOWER('%$fullAddress%'))
OR (LOWER(street || ' ' || CAST(house_number AS TEXT)) LIKE LOWER('%$fullAddress%'))
OR (LOWER(city || ' ' || CAST(postal_code AS TEXT)) LIKE LOWER('%$fullAddress%'))
OR (LOWER(street || ', ' || city || ' ' || CAST(postal_code AS TEXT)) LIKE LOWER('%$fullAddress%'))
OR (LOWER(street || ' ' || CAST(house_number AS TEXT) || ', ' || city) LIKE LOWER('%$fullAddress%'))
OR (LOWER(street || ' ' || CAST(house_number AS TEXT) || ', ' || city || ' ' || CAST(postal_code AS TEXT)) LIKE LOWER('%$fullAddress%'))) AND deleteby is null";
$results = $fce->_slctSQL("public.configurations_view", "", "services", $where, "", " ORDER BY city ASC, street ASC, house_number ASC, postal_code ASC", "");
【问题讨论】:
-
顺便说一句:当我比较时:Vrchlické 789,Kolín IV 28002 - 它的 OK Vrchlické 789,Kolín 28002 - 它的失败
-
似乎没有必要将所有内容与完整地址进行比较。
标签: sql postgresql search full-text-search