Algorithm for autocomplete?

后端 未结 9 1253
暖寄归人
暖寄归人 2020-11-28 00:45

I am referring to the algorithm that is used to give query suggestions when a user types a search term in Google.

I am mainly interested in: 1. Most important resul

9条回答
  •  一生所求
    2020-11-28 01:25

    Google's exact algorithm is unknown, but it is said to work by statistical analysis of users input. An approach not suitable for most cases. More commonly auto completion is implemented using one of the following:

    • Trees. By indexing the searchable text in a tree structure (prefix tree, suffix tree, dawg, etc..) one can execute very fast searches at the expense of memory storage. The tree traversal can be adapted for approximate matching.
    • Pattern Partitioning. By partitioning the text into tokens (ngrams) one can execute searches for pattern occurrences using a simple hashing scheme.
    • Filtering. Find a set of potential matches and then apply a sequential algorithm to check each candidate.

    Take a look at completely, a Java autocomplete library that implements some of the latter concepts.

提交回复
热议问题