Getting Started With MySQL's Full-Text Search Capabilities - Conclusion (Page 6 of 6 )
In this article we've seen how to setup and use MySQL full-text and Boolean searches. Just to reiterate, here are the steps you need to take to get full-text working on your database:
1. Create/alter a table, making sure a call to the FULLTEXT command is issued when creating/altering the table.
2. To perform a full-text normal search, use the MATCH and AGAINST commands in your query for fields that have been marked as full text, like this:
SELECT *, MATCH(field1, field3) AGAINST('my_query') as relevance FROM myTable WHERE MATCH(field1, field3) AGAINST('my_query')
4. To perform a full-text Boolean search, use the MATCH and AGAINST commands in combination with the IN BOOLEAN MODE keywords in your query for fields that have been marked as full text, like this:
SELECT *, MATCH(field1, field3) AGAINST('my_query' IN BOOLEAN MODE) as relevance FROM myTable WHERE MATCH(field1, field3) AGAINST('my_query IN BOOLEAN MODE')
Using the examples and information provided in this article you should now be able to create a basic full-text search against your database. Simply use a scripting language such as PHP to gather a search query from your users. Next, pass this string to your MySQL query as the parameter to the AGAINST command. Lastly, iterate through the results, displaying the relevance ranking if desired.
In my next article I will create a full-text search engine using PHP, MySQL and MySQL's full-text Boolean search capabilities. Until then, visit our forums.
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.