Ternary search Tree App--smart tips for searching boxes

Source: Internet
Author: User

In the previous ternary search tree and its implementation, you can use ternary search tree to implement the searching box only hints, because the ternary search tree prefix matching efficiency is very high, The general idea is as follows (many of which can be modified according to their own needs, I just write my approach):

For example, when searching for songs, smart tips:

Build ternary Search Tree

    1. Put the string of all song names in a map, key for the song name, value to store the song information, can be a class object domain, where you can follow the key value of the same song to accumulate the number of plays, and the song name to pinyin, using the pinyin4j
    2. Convert map to Song object list store
    3. A new field is added to the node class, and index is used to hold an object's subscript value in the list (this is the key part of the ternary search tree, which is to get the corresponding index after all the song names that are prefixed with a are queried. Get (index) directly in list to get the appropriate information for that song
    4. Insert the song name Pinyin and the song's index in the list into the ternary search tree by one end, for the reason reference--------------------------, in order for the ternary Search tree to balance

Inquire

When querying, such as user input A, all song names prefixed with a are searched.

    1. Go to ternary search tree to query the name of a song prefixed with a, and deposit Map,key as the song name Pinyin, value is index
    2. Get information about the song according to index
    3. Put the number of songs played as value,index as key into TreeMap to sort, rewrite comparator descending order
    4. Take N records from TreeMap, get corresponding resultlist, get relevant song information according to index
    5. Return

To summarize, ternary search tree is used to query all songs that match the prefix

After all the matching songs are queried, there is a series of processing based on the sort of a field and so on.

Ternary search tree query + topk sort

Extended

Highlight function

First letter matching, that is, to build a tree, query after the order of the number of playback to heavy

Serialization of the trie to avoid rebuilding the trie every time the restart causes the service to be unavailable

......

Ternary search Tree App--smart tips for searching boxes

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.