search function code