Fixes ordering of search queries and removes prefixes.