11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 36 • INDEXES AND SEARCHINGwww.it-ebooks.infoThe following query would not benefit:SELECT lastname FROM employees WHERE firstname="Ed";To improve this latter query’s performance, you’d need to create separate indexes for the firstnamecolumn.Full-Text IndexesFull-text indexes offer an efficient means for searching text stored in CHAR, VARCHAR, or TEXT datatypes.Before delving into examples, a bit of background regarding <strong>MySQL</strong>’s special handling of this index is inorder.Because <strong>MySQL</strong> assumes that full-text searches will be implemented for sifting through largeamounts of natural-language text, it provides a mechanism for retrieving data that produces results thatbest fit the user’s desired result. More specifically, if a user were to search using a string like Apache isthe world's most popular web server, the words is and the should play little or no role in determiningresult relevance. In fact, <strong>MySQL</strong> splits searchable text into words, by default eliminating any word offewer than four characters. You’ll learn how to modify this behavior later in this section.Creating a full-text index is much like creating indexes of other types. As an example, revisit thebookmarks table created earlier in this chapter, indexing its description column using the full-textvariant:CREATE TABLE bookmarks (id INT UNSIGNED NOT NULL AUTO_INCREMENT,name VARCHAR(75) NOT NULL,url VARCHAR(200) NOT NULL,description MEDIUMTEXT NOT NULL,FULLTEXT(description),PRIMARY KEY(id));In addition to the typical primary index, this example creates a full-text index consisting of thedescription column. For demonstration purposes, Table 36-1 presents the data found in the bookmarks table.Table 36-1. Sample Table Dataid name url description1 Python.org www.python.org The official Python Web site2 <strong>MySQL</strong> manual http://dev.mysql.com/doc The <strong>MySQL</strong> reference manual3 Apache site http://httpd.apache.org Includes Apache 2 manual4 <strong>PHP</strong>: Hypertext www.php.<strong>net</strong> The official <strong>PHP</strong> Web site5 Apache Week www.apacheweek.com Offers a dedicated Apache 2 section698

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!