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?
-
Create an index for the nickname field in this table of the database
Key 'nikename' ('nikename ')
-
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.