search function and pagination