Method solution for mysql Chinese fuzzy retrieval problems

xiaoxiao2021-03-06  14

Under MySQL, when a Chinese blur retrieval is performed, some discretion is often returned, and if "% a%" is found, if the "% a%", the returned may have a Chinese character, but there is no A character exists. I have encountered similar problems before, read in detail MANUAL, found that there is a way to solve and get satisfactory results. Example: · I hope that through the "Title" to retrieve the newslet, the keyword may contain a Chinese and English, the following SQL statement: select ID, title, name from achech_com.news where title Like '% a%' returned, some The Title field determines that the "A" keyword, and some only have Chinese, but it also returns in the search results. Solution, use binary properties to retrieve, such as: select ID, title, name from achech_com.news where binary title Like '% a%' return result is correct than before, but English letters are case sensitive, so sometimes it is in retrieving The result of Achech "and" Achech "is different. I know that using the binary property can solve the previous problem, then look at the ucase and concat functions supported by MySQL, where ucase is transferred to uppercase, and the role of the Concat function is to connect to the characters, the following is completely solved SQL statement: Select ID, title, name from achech_com.news where binary ucase (title) LIKE Concat ('%', ucase ('a'), '%') The step of retrieving the attribute first as binary, with accurate Retrieving results, and the possibility of cases of Like's title content, I use the UCase function to convert the field content into capital letters, then perform the LIKE operation, and the LIKE operation uses the fuzzy method, the advantage of using Concat is the transmission If you come in, you can be a direct keyword. You don't need to bring a "%" multi-manager. Of course, you can also write this: select ID, title, name from achech_com.news where binary ucse (title) Like ucase ('% a%') The result is satisfactory, but the speed may be slower n milliseconds .

转载请注明原文地址:https://www.9cbs.com/read-48450.html

New Post(0)