Bug 947939 - Fix mixed up logic in the search query generator