Refine MySQL search (replace long regex with subquery)

I have a MySQL query

select query from HR_Health_Logs where query REGEXP 'CPU|MAC|PC|abacus|calculator|laptop|mainframe|microcomputer|minicomputer|machine'; 

Except that the regular expression is much longer and contains many synonyms and spelling errors.

I need to cut out this short one and have a table with all synonyms and spelling errors so that I can avoid this very long query. So I'm looking for something like

 select query from HR_Health_Logs where query REGEXP '**HAVE A TABLE WITH ALL MY SYNONYMS AND MISSPELLINGS SEARCHED HERE**'; 
+4
source share
3 answers
 SELECT query FROM HR_Health_Logs l, synonym s WHERE l.query = s.synonym 
+1
source

What about ANY function ?

 select query from HR_Health_Logs where query REGEXP ANY (SELECT spell FROM misspelled WHERE correct = 'masturbate' ) ; 
+3
source
 SELECT query FROM HR_Health_Logs WHERE query IN ( SELECT synonym AS query FROM synonyms_table WHERE word = 'masturbation' UNION SELECT misspelling AS query FROM misspellings_table WHERE word = 'masturbation' ) 

Assuming your synonyms and spelling errors are in two separate tables. Otherwise, you will use only one of the subqueries and reset UNION.

0
source

Source: https://habr.com/ru/post/1286568/


All Articles