X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/754846d9dc125e3caa8a97b8381918b565a55289..5d32ac9ac918929c11602a740c3033bcfdb0f929:/lib-sql/functions/address_lookup.sql

diff --git a/lib-sql/functions/address_lookup.sql b/lib-sql/functions/address_lookup.sql
index b6c552c4..3ea72cb1 100644
--- a/lib-sql/functions/address_lookup.sql
+++ b/lib-sql/functions/address_lookup.sql
@@ -223,11 +223,13 @@ BEGIN
                  OR placex.country_code = place.country_code)
       ORDER BY rank_address desc,
                (place_addressline.place_id = in_place_id) desc,
-               (fromarea and place.centroid is not null and not isaddress
-                and (place.address is null or avals(name) && avals(place.address))
-                and ST_Contains(geometry, place.centroid)) desc,
-               isaddress desc, fromarea desc,
-               distance asc, rank_search desc
+               (CASE WHEN coalesce((avals(name) && avals(place.address)), False) THEN 2
+                     WHEN isaddress THEN 0
+                     WHEN fromarea
+                          and place.centroid is not null
+                          and ST_Contains(geometry, place.centroid) THEN 1
+                     ELSE -1 END) desc,
+               fromarea desc, distance asc, rank_search desc
   LOOP
     -- RAISE WARNING '%',location;
     location_isaddress := location.rank_address != current_rank_address;
