implement Query() and search_messages()