Complete auto-completion search function with Redis (ii)

Source: Internet
Author: User

The general idea of automatic completion is described earlier, and the function of search times is now combined. I use the hash table to do, of course, can also be in the composition of the word, another ordered set to maintain the order, and then 2 ordered set of intersection can be . Here is a description of the hash method to achieve.

Generate Word dist.php

<?PHP
require'./redis.php ';//participle$words= [' Flower News ', ' NBA ', ' NBA Live ', ' NBA games ', ' NBA Playoffs ', ' NBA videos ', ' Flower News brand ', ' Flower News ', ' flower ', ' n '];//using PipelinesCache::getinstance ()pipeline ();foreach($words as $val) { $len= Mb_strlen ($val, ' Utf-8 '); for($i= 0;$i<=$len;$i++){ $key= Mb_substr ($val, 0,$i+1, ' Utf-8 '); if($i==$len) { $key. = ' * '; Cache:: getinstance ()->hset ("Search:hits",$key, 0); } Cache:: getinstance ()->zadd (' Search ', 0,$key); }}cache:: getinstance ()exec();

Auto Prompt complete.php

 

  

  

  

Complete auto-completion search function with Redis (ii)

Related Article

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.