Implement sorting for indexed documents