Directory (?) [+]
How to develop the auto complete Smart prompt feature
Recently the internet seems to have been spread with REDIS implementation, in fact, smart tips and what storage relationship is not much 07, I have a similar project
I have thousands of names, and as the user enters Chinese characters or pinyin in the input box, a drop-down list is used to prompt it for possible entries.
Drop-down box, check the state, nature is to do with JS, here is mainly about the backend code how to implement, the principle is very simple
This is an inverted index table, and the work we're going to do is primarily to prepare the data for this index table, assuming I have a name
Rutaf
The first step, to generate pinyin for the name, the Chinese characters and pinyin are placed in a text file, one line to put a
Roubaix
Lutaf
The second step, using the largest pre-order method to cut the word , specifically, it is "the" "Lu"-cut into 3 lines
Lu
Ruta
Roubaix
Lutaf This pinyin is also cut into the shape below
L
Lu
Lut
Luta
Lutaf
Then use a hash table to load the Cut "fields", each key corresponding to the value of the natural "RUTAF"
ds={}
ds[']= ' Brooks '
ds[' ruta ']= ' Brooks '
ds[' Rutaf ']= ' Brooks '
ds[' l ']= ' Roubaix '
....
ds[' Lutaf ']= ' Brooks '
Thousands of names can be used to do the same, but encountered with the same prefix how to do? For example, "The Lupin" and "The Flowers" will hit.
Lu
L
Lu
Very simply, the value of the hash table is changed from a string to a list, a prefix for a listing, each element of the list is the name of the prefix, so the hash table becomes the following
ds[' Lu ']=[', ' Lupin ', ' Lu Zhishen ', ' Lu Master ']
ds[' Lu ']=[', ' Lupin ', ' Lu Zhishen ', ' Lu Master ']
The rest of the matter, it is simple, to develop a Web application, the user's request parameter is the user's current input, and then in this hash table inside query, get the result list, with JSON encode, render to the user can
What I did was to use web.py to develop this service, hash table directly with the Dbhash, with FastCGI way to deploy behind Nginx, very simple
The auto complete feature does not have anything to do with technology storage
Most of the code for this project was developed in Python, in order to reduce maintenance difficulties, I later asked a novice programmer to convert this code into PHP, stored directly with MySQL on the line
Udpate
2013, re-made a smart hint with Nodejs http://lutaf.com/223.htm
How to develop the auto complete Smart prompt feature