- ORDER BY rank_address desc, isin_tokens && keywords desc, isguess asc, ST_Distance(point, centroid) * CASE WHEN rank_address = 16 AND rank_search = 16 THEN 0.25 WHEN rank_address = 16 AND rank_search = 17 THEN 0.5 ELSE 1 END ASC
+ GROUP BY place_id, keywords, rank_address, rank_search, isguess, centroid
+ ORDER BY rank_address, isin_tokens && keywords desc, isguess asc,
+ ST_Distance(point, centroid) *
+ CASE
+ WHEN rank_address = 16 AND rank_search = 15 THEN 0.2 -- capital city
+ WHEN rank_address = 16 AND rank_search = 16 THEN 0.25 -- city
+ WHEN rank_address = 16 AND rank_search = 17 THEN 0.5 -- town
+ ELSE 1 END ASC -- everything else