How to develop the auto complete Smart prompt feature

Source: Internet
Author: User

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"

    1. ds={}

    2. ds[']= ' Brooks '

    3. ds[' ruta ']= ' Brooks '

    4. ds[' Rutaf ']= ' Brooks '

    5. ds[' l ']= ' Roubaix '

    6. ....

    7. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.