building query from UI