Sunday, May 9, 2010

Search in Mysql database for exact term with MATCH AGAINST

Search in Mysql database for exact term with MATCH AGAINST:

SELECT id,text from TABLE WHERE MATCH(text) AGAINST('value' IN BOOLEAN
MODE) HAVING text='value'

If you want to perform a general search for all term occurrences also in the text corpus:
SELECT id,text from TABLE WHERE MATCH(text) AGAINST('value' IN BOOLEAN
MODE)

The same goes for variables, for instance this searches for the term in the text body
SELECT *
FROM `$Language1-$Language2`
WHERE MATCH (`$Language1`) AGAINST ('$search') HAVING `$Language1`='$search' ORDER BY (`$Language1`)
LIMIT 0 , 5000

and this searches only for exact matches:

SELECT *
FROM `$Language1-$Language2`
WHERE MATCH (`$Language1`) AGAINST ('$search') HAVING `$Language1`='$search' ORDER BY (`$Language1`)
LIMIT 0 , 5000