Changes for search queries - #964

Fixes -#964
Changes logic for search queries.