auto-complete search algorithm