Move facet query outside of if statement