Add a function to construct filtering queries