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

https://bugzilla.mozilla.org/show_bug.cgi?id=974939