tags:

views:

252

answers:

3

Hey , i got this MySQL Query :

select query from HR_Health_Logs where query REGEXP 'masturbation|masturbate|masturbated|wank|wanking|wanked|masturbat|mansturbation|marstabation|marturbation|mastabation|mastarbation|master basion|masterbate|masterbation|masterbeting|masturation|masturbatin|masturbating|masturbatn|masturbtion|mensturbation|mesitarbation|murstabation|mursturbation|mustabate|mustabetion|mustarbation|musterabuion|musterbation|musturbated|musturbation|masterbasion|masturbates|wanks|wankings|masturbats|mansturbations|marstabations|marturbations|mastabations|mastarbations|master basions|masterbates|masterbations|masterbetings|masturations|masturbatins|masturbatings|masturbatns|masturbtions|mensturbations|mesitarbations|murstabations|mursturbations|mustabates|mustabetions|mustarbations|musterabuions|musterbations|musturbateds|musturbations|masterbasions';

I need to cut this short and have a table with all the synonyms and misspellings, so that i can avoid all this writeup , so will need something like:

select query from HR_Health_Logs where query REGEXP '**HAVE A TABLE WITH ALL MY SYNONYMS AND MISSPELLINGS SEARCHED HERE**';
+1  A: 
SELECT  query
FROM    HR_Health_Logs l, synonym s
WHERE   l.query = s.synonym
Quassnoi
+2  A: 

How about the ANY function ?

select query from HR_Health_Logs where query REGEXP ANY (SELECT spell FROM misspelled WHERE correct = 'masturbate' ) ;
streetpc
got a problem with this > why does this come in ? WHERE correct = 'masturbate' , basically any word [syn + misp] are all correct- so i need to only run through all
Mzee_Richo
My query was specificly designed to search for all HR_Health_Logs.query that contined 'masturbation' synonyms, because I (incorrectly) thought that was your need. Now if you just want all the matches of all the synonyms, just remove the WHERE clause in the subquery... Also I named it misspelled, but that could be synonyms.
streetpc
Jst a Quick one > What Engine are you using to test this ?
Mzee_Richo
InnoDB, but I think this would work with MyIsam as well. But if you don't need REGEXP, you shouldn't use it, since it's far slower than simple equality.
streetpc
A: 
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 misspellings are in two separate tables. Otherwise you'll only use one of the subqueries and drop the UNION.

Dustin Fineout