implementing the search query generation