SELECT
SIGN(COALESCE(location_id, 0)) + SIGN(COALESCE(division_id, 0)) + SIGN(COALESCE(position_id, 0)) as score,
keyword.*
FROM
keyword
WHERE
(city_id = 5 OR city_id IS NULL) AND
(location_id = 7 OR location_id IS NULL) AND
division_id IS NULL AND
position_id IS NULL AND
MATCH (keyword) AGAINST ('еда банкомат')
GROUP BY
title
DESC
ORDER BY
score
DESC
LIMIT 10