Extract some duplicate code for ORing queries