fixing a really weird edge case bug with queries ending in ...like '%foo%'