How does mysql perform a quick fuzzy search by nickname?

Source: Internet
Author: User
Mysql performs fuzzy search for nicknames. if a user has more like queries, the query will be slow. how can this problem be solved? Mysql performs fuzzy search for nicknames. if a user has more like queries, the query will be slow. how can this problem be solved?

Reply content:

Mysql performs fuzzy search for nicknames. if a user has more like queries, the query will be slow. how can this problem be solved?

  1. Create an index for the nickname field in this table of the database

    Key 'nikename' ('nikename ')

  2. Full-text index with SQL statement

    Alter table 'user' add fulltext 'fidx _ user_nikename' ('nickname ')

Then use the following method to query

SELECT * FROM \`user\` WHERE MATCH (nickname)AGAINST ('xxx')

If it is like % name %, there is no difference in my cognitive scope. if there is no % in front, you can create an index, or try the LOCATE function, but it is not effective.

What about instr?

For fuzzy search, perform word segmentation. Sphsf-coreseek or xunsearch)

If your mysql version is later than 5.7, you can use the ngram full-text index to support Chinese word segmentation. I have used it in the project and I have already used it online.

Use a search engine to index frequently used search fields and then use them together with the cache.

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.