I'm trying to implement an autocomplete feature for a search engine. I have a database of words(stemmed) that occur in the documents that I have. what I'm doing is:
Constructing a graph with words as nodes and weighted edges with weights as the number of times those 2 words have been searched together.
Each node also keeps track of which is the most commonly typed word next to it.
Whenever a user starts typing his query, this graph is queried and the first word is predicted by string matching and then ranking the matched words according to search frequency.
When the user starts typing the next word, the graph is visited and the neighbours of this node are retrieved and shown to the user in order of frequency(weight of edges.).
This is a rough overview of what I am trying to achieve. Are there any optimizations that could be made to this or something else entirely that can replace this?