MATCH…AGAINST

The MATCH…AGAINST construct can be used on columns that have been given a FULL TEXT index. With it, you can make own-language searches as you would in an internet search engine.
Unlike the use of WHERE…= or WHERE…LIKE, MATCH…AGAINST lets you enter multiple words in a search query and checks them against all words in the FULLTEXT columns. FULLTEXT indexes are case-insensitive, so it makes no difference what case is used in your queries.

Assuming that you have added a FULLTEXT index to the author and title columns, enter the three queries. The first asks for any rows that contain
the word and to be returned. Because and is a stopword, MySQL will ignore it and the query will always produce an empty set—no matter what is stored in the columns. The second query asks for any rows that contain both of the words curiosity and shop anywhere in them, in any order, to be returned. And the last query applies the same kind of search for the words Aro and Markku.

Using MATCH…AGAINST on FULLTEXT indexes:

SELECT author,title FROM classics
WHERE MATCH(author,title) AGAINST(’30’);
SELECT author,title FROM classics
WHERE MATCH(author,title) AGAINST(‘kautta aikain’);
SELECT author,title FROM classics
WHERE MATCH(author,title) AGAINST(‘parhaat’);

Leave a Reply

Your email address will not be published. Required fields are marked *