Search function working with ordering