CMS-2471 Improve query parser. Added tests.