adding distance sorting for the queries for which sort is 0