Sort documents before applying filters