server side query building