String matching and ranking algorithm for autocomplete