functionalize query and search